Ignore:
Timestamp:
Nov 6, 2013, 2:37:46 PM (12 years ago)
Author:
[email protected]
Message:

Support iteration of the Arguments object
https://bugs.webkit.org/show_bug.cgi?id=123835

Reviewed by Mark Lam.

Source/JavaScriptCore:

Add an ArgumentsIterator object, and associated classes so that we can support
iteration of the arguments object.

This is a largely mechanical patch. The only gnarliness is in the
logic to avoid reifying the Arguments object in for(... of arguments)
scenarios.

  • GNUmakefile.list.am:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::emitEnumeration):

  • runtime/Arguments.cpp:

(JSC::Arguments::getOwnPropertySlot):
(JSC::argumentsFuncIterator):

  • runtime/Arguments.h:
  • runtime/ArgumentsIteratorConstructor.cpp: Added.

(JSC::ArgumentsIteratorConstructor::finishCreation):

  • runtime/ArgumentsIteratorConstructor.h: Added.

(JSC::ArgumentsIteratorConstructor::create):
(JSC::ArgumentsIteratorConstructor::createStructure):
(JSC::ArgumentsIteratorConstructor::ArgumentsIteratorConstructor):

  • runtime/ArgumentsIteratorPrototype.cpp: Added.

(JSC::ArgumentsIteratorPrototype::finishCreation):
(JSC::argumentsIteratorPrototypeFuncIterator):
(JSC::argumentsIteratorPrototypeFuncNext):

  • runtime/ArgumentsIteratorPrototype.h: Added.

(JSC::ArgumentsIteratorPrototype::create):
(JSC::ArgumentsIteratorPrototype::createStructure):
(JSC::ArgumentsIteratorPrototype::ArgumentsIteratorPrototype):

  • runtime/CommonIdentifiers.h:
  • runtime/JSArgumentsIterator.cpp: Added.

(JSC::JSArgumentsIterator::finishCreation):

  • runtime/JSArgumentsIterator.h: Added.

(JSC::JSArgumentsIterator::createStructure):
(JSC::JSArgumentsIterator::create):
(JSC::JSArgumentsIterator::next):
(JSC::JSArgumentsIterator::JSArgumentsIterator):

  • runtime/JSArrayIterator.cpp:

(JSC::createIteratorResult):

  • runtime/JSGlobalObject.cpp:
  • runtime/JSGlobalObject.h:

LayoutTests:

Add test cases

  • js/arguments-iterator-expected.txt: Added.
  • js/arguments-iterator.html: Added.
  • js/script-tests/arguments-iterator.js: Added.

(shouldThrow.test):
(testAlias):
(testStrict):
(testReifiedArguments):
(testOverwrittenArguments):
(testNullArguments):
(testNonArrayLikeArguments):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/Arguments.cpp

    r156984 r158793  
    2828#include "CallFrameInlines.h"
    2929#include "JSActivation.h"
     30#include "JSArgumentsIterator.h"
    3031#include "JSFunction.h"
    3132#include "JSGlobalObject.h"
     
    5152    visitor.append(&thisObject->m_activation);
    5253}
     54   
     55static EncodedJSValue JSC_HOST_CALL argumentsFuncIterator(ExecState*);
    5356
    5457void Arguments::destroy(JSCell* cell)
     
    152155        thisObject->createStrictModeCallerIfNecessary(exec);
    153156
    154     return JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot);
     157    if (JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot))
     158        return true;
     159    if (propertyName == exec->propertyNames().iteratorPrivateName) {
     160        VM& vm = exec->vm();
     161        JSGlobalObject* globalObject = exec->lexicalGlobalObject();
     162        thisObject->JSC_NATIVE_FUNCTION(exec->propertyNames().iteratorPrivateName, argumentsFuncIterator, DontEnum, 0);
     163        if (JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot))
     164            return true;
     165    }
     166    return false;
    155167}
    156168
     
    362374    }
    363375}
     376   
     377EncodedJSValue JSC_HOST_CALL argumentsFuncIterator(ExecState* exec)
     378{
     379    JSObject* thisObj = exec->hostThisValue().toThis(exec, StrictMode).toObject(exec);
     380    Arguments* arguments = jsDynamicCast<Arguments*>(thisObj);
     381    if (!arguments)
     382        return JSValue::encode(throwTypeError(exec, "Attempted to use Arguments iterator on non-Arguments object"));
     383    return JSValue::encode(JSArgumentsIterator::create(exec->vm(), exec->callee()->globalObject()->argumentsIteratorStructure(), arguments));
     384}
     385
    364386
    365387} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.