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

Unified Diff: src/runtime.cc

Issue 1960001: Throw an exception when wrong arguments are passed into SwapElements. (Closed)
Patch Set: Created 10 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 242d2ccbe483b1387155fbcef04d5e2a3c9081d3..823889aced4b952183c336d3319fc43e27edf68e 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -7777,29 +7777,23 @@ static Object* Runtime_SwapElements(Arguments args) {
ASSERT_EQ(3, args.length());
- Handle<Object> object = args.at<Object>(0);
+ CONVERT_ARG_CHECKED(JSObject, object, 0);
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
Handle<Object> key2 = args.at<Object>(2);
uint32_t index1, index2;
- // That must be the most common case.
- if (object->IsJSObject()
- && Array::IndexFromObject(*key1, &index1)
- && Array::IndexFromObject(*key2, &index2)) {
- Handle<JSObject> jsobject = Handle<JSObject>::cast(object);
- Handle<Object> tmp1 = GetElement(jsobject, index1);
- Handle<Object> tmp2 = GetElement(jsobject, index2);
-
- SetElement(jsobject, index1, tmp2);
- SetElement(jsobject, index2, tmp1);
- } else {
- Handle<Object> tmp1 = GetProperty(object, key1);
- Handle<Object> tmp2 = GetProperty(object, key2);
-
- SetProperty(object, key1, tmp2, NONE);
- SetProperty(object, key2, tmp1, NONE);
+ if (!Array::IndexFromObject(*key1, &index1)
+ || !Array::IndexFromObject(*key2, &index2)) {
+ return Top::ThrowIllegalOperation();
}
+ Handle<JSObject> jsobject = Handle<JSObject>::cast(object);
+ Handle<Object> tmp1 = GetElement(jsobject, index1);
+ Handle<Object> tmp2 = GetElement(jsobject, index2);
+
+ SetElement(jsobject, index1, tmp2);
+ SetElement(jsobject, index2, tmp1);
+
return Heap::undefined_value();
}
« 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