Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: src/runtime.cc

Issue 1960001: Throw an exception when wrong arguments are passed into SwapElements. (Closed)
Patch Set: Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 7759 matching lines...) Expand 10 before | Expand all | Expand 10 after
7770 return array->length(); 7770 return array->length();
7771 } 7771 }
7772 } 7772 }
7773 7773
7774 7774
7775 static Object* Runtime_SwapElements(Arguments args) { 7775 static Object* Runtime_SwapElements(Arguments args) {
7776 HandleScope handle_scope; 7776 HandleScope handle_scope;
7777 7777
7778 ASSERT_EQ(3, args.length()); 7778 ASSERT_EQ(3, args.length());
7779 7779
7780 Handle<Object> object = args.at<Object>(0); 7780 CONVERT_ARG_CHECKED(JSObject, object, 0);
7781 Handle<Object> key1 = args.at<Object>(1); 7781 Handle<Object> key1 = args.at<Object>(1);
Lasse Reichstein 2010/05/06 09:03:47 Consider using CONVERT_ARG_CHECKED for the remaini
antonm 2010/05/06 16:40:16 Lasse, any chances you meant some other macro:
Lasse Reichstein 2010/05/07 07:02:03 No, that's the one. See the definition of Argument
antonm 2010/05/07 10:06:01 Sorry, I use Handle<Object> key1 = arg.at<Object>(
Lasse Reichstein 2010/05/07 11:44:01 Whoops, my bad. Didn't read your rhs' properly (to
7782 Handle<Object> key2 = args.at<Object>(2); 7782 Handle<Object> key2 = args.at<Object>(2);
7783 7783
7784 uint32_t index1, index2; 7784 uint32_t index1, index2;
7785 // That must be the most common case. 7785 if (!Array::IndexFromObject(*key1, &index1)
7786 if (object->IsJSObject() 7786 || !Array::IndexFromObject(*key2, &index2)) {
7787 && Array::IndexFromObject(*key1, &index1) 7787 return Top::ThrowIllegalOperation();
7788 && Array::IndexFromObject(*key2, &index2)) { 7788 }
7789 Handle<JSObject> jsobject = Handle<JSObject>::cast(object);
7790 Handle<Object> tmp1 = GetElement(jsobject, index1);
7791 Handle<Object> tmp2 = GetElement(jsobject, index2);
7792 7789
7793 SetElement(jsobject, index1, tmp2); 7790 Handle<JSObject> jsobject = Handle<JSObject>::cast(object);
7794 SetElement(jsobject, index2, tmp1); 7791 Handle<Object> tmp1 = GetElement(jsobject, index1);
7795 } else { 7792 Handle<Object> tmp2 = GetElement(jsobject, index2);
7796 Handle<Object> tmp1 = GetProperty(object, key1);
7797 Handle<Object> tmp2 = GetProperty(object, key2);
7798 7793
7799 SetProperty(object, key1, tmp2, NONE); 7794 SetElement(jsobject, index1, tmp2);
7800 SetProperty(object, key2, tmp1, NONE); 7795 SetElement(jsobject, index2, tmp1);
7801 }
7802 7796
7803 return Heap::undefined_value(); 7797 return Heap::undefined_value();
7804 } 7798 }
7805 7799
7806 7800
7807 // Returns an array that tells you where in the [0, length) interval an array 7801 // Returns an array that tells you where in the [0, length) interval an array
7808 // might have elements. Can either return keys or intervals. Keys can have 7802 // might have elements. Can either return keys or intervals. Keys can have
7809 // gaps in (undefined). Intervals can also span over some undefined keys. 7803 // gaps in (undefined). Intervals can also span over some undefined keys.
7810 static Object* Runtime_GetArrayKeys(Arguments args) { 7804 static Object* Runtime_GetArrayKeys(Arguments args) {
7811 ASSERT(args.length() == 2); 7805 ASSERT(args.length() == 2);
(...skipping 2458 matching lines...) Expand 10 before | Expand all | Expand 10 after
10270 } else { 10264 } else {
10271 // Handle last resort GC and make sure to allow future allocations 10265 // Handle last resort GC and make sure to allow future allocations
10272 // to grow the heap without causing GCs (if possible). 10266 // to grow the heap without causing GCs (if possible).
10273 Counters::gc_last_resort_from_js.Increment(); 10267 Counters::gc_last_resort_from_js.Increment();
10274 Heap::CollectAllGarbage(false); 10268 Heap::CollectAllGarbage(false);
10275 } 10269 }
10276 } 10270 }
10277 10271
10278 10272
10279 } } // namespace v8::internal 10273 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698