| Index: src/runtime.cc
|
| diff --git a/src/runtime.cc b/src/runtime.cc
|
| index dd0a3d2a0dbb65390c05c76282407dbff04830ad..e2ff7f41240f064df2e192dd09fd5197cb1fb365 100644
|
| --- a/src/runtime.cc
|
| +++ b/src/runtime.cc
|
| @@ -7748,6 +7748,38 @@ static Object* Runtime_EstimateNumberOfElements(Arguments args) {
|
| }
|
|
|
|
|
| +static Object* Runtime_SwapElements(Arguments args) {
|
| + HandleScope handle_scope;
|
| +
|
| + ASSERT_EQ(3, args.length());
|
| +
|
| + Handle<Object> object = args.at<Object>(0);
|
| + Handle<Object> key1 = args.at<Object>(1);
|
| + 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);
|
| + }
|
| +
|
| + return Heap::undefined_value();
|
| +}
|
| +
|
| +
|
| // Returns an array that tells you where in the [0, length) interval an array
|
| // might have elements. Can either return keys or intervals. Keys can have
|
| // gaps in (undefined). Intervals can also span over some undefined keys.
|
|
|