Revision: 2897 Author: [email protected] Date: Wed Sep 16 01:25:54 2009 Log: [ES5] Made properties of the arguments array enumerable.
Review URL: http://codereview.chromium.org/200141 http://code.google.com/p/v8/source/detail?r=2897 Modified: /branches/bleeding_edge/src/handles.cc /branches/bleeding_edge/test/mjsunit/arguments-enum.js /branches/bleeding_edge/test/mjsunit/third_party/object-keys.js ======================================= --- /branches/bleeding_edge/src/handles.cc Tue Sep 15 04:51:40 2009 +++ /branches/bleeding_edge/src/handles.cc Wed Sep 16 01:25:54 2009 @@ -531,57 +531,49 @@ KeyCollectionType type) { Handle<FixedArray> content = Factory::empty_fixed_array(); - JSObject* arguments_boilerplate = - Top::context()->global_context()->arguments_boilerplate(); - JSFunction* arguments_function = - JSFunction::cast(arguments_boilerplate->map()->constructor()); - bool allow_enumeration = (object->map()->constructor() != arguments_function); - // Only collect keys if access is permitted. - if (allow_enumeration) { - for (Handle<Object> p = object; - *p != Heap::null_value(); - p = Handle<Object>(p->GetPrototype())) { - Handle<JSObject> current(JSObject::cast(*p)); - - // Check access rights if required. - if (current->IsAccessCheckNeeded() && - !Top::MayNamedAccess(*current, Heap::undefined_value(), - v8::ACCESS_KEYS)) { - Top::ReportFailedAccessCheck(*current, v8::ACCESS_KEYS); - break; - } - - // Compute the element keys. - Handle<FixedArray> element_keys = - Factory::NewFixedArray(current->NumberOfEnumElements()); - current->GetEnumElementKeys(*element_keys); - content = UnionOfKeys(content, element_keys); - - // Add the element keys from the interceptor. - if (current->HasIndexedInterceptor()) { - v8::Handle<v8::Array> result = - GetKeysForIndexedInterceptor(object, current); - if (!result.IsEmpty()) - content = AddKeysFromJSArray(content, v8::Utils::OpenHandle(*result)); - } - - // Compute the property keys. - content = UnionOfKeys(content, GetEnumPropertyKeys(current)); - - // Add the property keys from the interceptor. - if (current->HasNamedInterceptor()) { - v8::Handle<v8::Array> result = - GetKeysForNamedInterceptor(object, current); - if (!result.IsEmpty()) - content = AddKeysFromJSArray(content, v8::Utils::OpenHandle(*result)); - } - - // If we only want local properties we bail out after the first - // iteration. - if (type == LOCAL_ONLY) - break; - } + for (Handle<Object> p = object; + *p != Heap::null_value(); + p = Handle<Object>(p->GetPrototype())) { + Handle<JSObject> current(JSObject::cast(*p)); + + // Check access rights if required. + if (current->IsAccessCheckNeeded() && + !Top::MayNamedAccess(*current, Heap::undefined_value(), + v8::ACCESS_KEYS)) { + Top::ReportFailedAccessCheck(*current, v8::ACCESS_KEYS); + break; + } + + // Compute the element keys. + Handle<FixedArray> element_keys = + Factory::NewFixedArray(current->NumberOfEnumElements()); + current->GetEnumElementKeys(*element_keys); + content = UnionOfKeys(content, element_keys); + + // Add the element keys from the interceptor. + if (current->HasIndexedInterceptor()) { + v8::Handle<v8::Array> result = + GetKeysForIndexedInterceptor(object, current); + if (!result.IsEmpty()) + content = AddKeysFromJSArray(content, v8::Utils::OpenHandle(*result)); + } + + // Compute the property keys. + content = UnionOfKeys(content, GetEnumPropertyKeys(current)); + + // Add the property keys from the interceptor. + if (current->HasNamedInterceptor()) { + v8::Handle<v8::Array> result = + GetKeysForNamedInterceptor(object, current); + if (!result.IsEmpty()) + content = AddKeysFromJSArray(content, v8::Utils::OpenHandle(*result)); + } + + // If we only want local properties we bail out after the first + // iteration. + if (type == LOCAL_ONLY) + break; } return content; } ======================================= --- /branches/bleeding_edge/test/mjsunit/arguments-enum.js Tue Sep 9 13:08:45 2008 +++ /branches/bleeding_edge/test/mjsunit/arguments-enum.js Wed Sep 16 01:25:54 2009 @@ -42,11 +42,11 @@ } assertEquals(0, countArguments()); -assertEquals(0, countArguments(1)); -assertEquals(0, countArguments(1, 2)); -assertEquals(0, countArguments(1, 2, 3, 4, 5)); - -assertEquals(0, setArgumentCount()); -assertEquals(0, setArgumentCount(1)); -assertEquals(0, setArgumentCount(1, 2)); -assertEquals(0, setArgumentCount(1, 2, 3, 4, 5)); +assertEquals(1, countArguments(1)); +assertEquals(2, countArguments(1, 2)); +assertEquals(5, countArguments(1, 2, 3, 4, 5)); + +assertEquals(2, setArgumentCount()); +assertEquals(3, setArgumentCount(1)); +assertEquals(4, setArgumentCount(1, 2)); +assertEquals(7, setArgumentCount(1, 2, 3, 4, 5)); ======================================= --- /branches/bleeding_edge/test/mjsunit/third_party/object-keys.js Tue Sep 15 06:30:46 2009 +++ /branches/bleeding_edge/test/mjsunit/third_party/object-keys.js Wed Sep 16 01:25:54 2009 @@ -52,7 +52,7 @@ assertEquals(Object.keys(function () {}), []); function argsTest(a, b, c) { - assertEquals([], Object.keys(arguments)); + assertEquals([0, 1, 2], Object.keys(arguments)); } argsTest(1, 2, 3); --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
