Ignore:
Timestamp:
Aug 23, 2017, 10:05:33 AM (8 years ago)
Author:
[email protected]
Message:

[ESNext] Async iteration - Implement Async Generator - runtime
https://bugs.webkit.org/show_bug.cgi?id=175240

Reviewed by Yusuke Suzuki.

JSTests:

  • stress/async-iteration-async-from-sync.js: Added.

(assert):
(const.Logger):
(this.fullfilled):
(this.fullfilledDone):
(this.rejected):
(this.catched):
(this.isFinal):
(_assertLogger):
(const.assertLogger):
(const.getPromise.promiseHolder.return.new.Promise):
(foo):
(async.boo):
(bar):
(async.baz):
(async.goo):

  • stress/async-iteration-basic.js: Added.

(assert):
(const.Logger):
(this.fullfilled):
(this.fullfilledDone):
(this.rejected):
(this.catched):
(this.isFinal):
(_assertLogger):
(const.assertLogger):
(const.getPromise.promiseHolder.return.new.Promise):
(async.generator):
(iterator.next.then):
(async.baz):
(async.boo):
(async.foo):
(async.goo):
(A.prototype.async.foo):
(A.prototype.async.boo):
(A):
(asyncGenExp.async):
(async.joo):
(j.next.then):
(then):
(async.koo):
(async.loo):
(async.moo):
(async.noo):
(async.ooo):
(async.roo):
(async.poo):
(async.soo):
(async.too):

  • stress/async-iteration-evaluation.js: Added.

(assert):
(async.foo):
(catch):

  • stress/async-iteration-syntax.js:
  • stress/async-iteration-yield-promise.js: Added.

(assert):
(const.Logger):
(this.fullfilled):
(this.fullfilledDone):
(this.rejected):
(this.catched):
(this.isFinal):
(_assertLogger):
(const.assertLogger):
(const.getPromise.promiseHolder.return.new.Promise):
(async.foo):
(async.boo):
(async.bar):

  • stress/async-iteration-yield-star-interface.js: Added.

(assert):
(const.getPromise.promiseHolder.return.new.Promise):
(const.Logger):
(this.fullfilled):
(this.fullfilledDone):
(this.rejected):
(this.catched):
(this.custom):
(this.isFinal):
(_assertLogger):
(const.assertLogger):
(let.asyncIter.Symbol.asyncIterator):
(let.asyncIter.next):
(let.asyncIter.throw):
(let.asyncIter.return):
(async.foo):
(asyncIter.Symbol.asyncIterator):
(asyncIter.next):
(async.boo):
(asyncIter.return):
(async.bar):
(async.baz):
(async.foobar):

  • stress/async-iteration-yield-star.js: Added.

(assert):
(const.Logger):
(this.fullfilled):
(this.fullfilledDone):
(this.rejected):
(this.catched):
(this.custom):
(this.isFinal):
(_assertLogger):
(const.assertLogger):
(const.getPromise.promiseHolder.return.new.Promise):
(async.foo):
(async.boo):
(async.bar):
(async.baz):
(async.joo):
(async.goo):
(async.koo):
(async.loo):
(let.asyncIter.Symbol.asyncIterator):
(let.asyncIter.next):
(let.asyncIter.throw):
(let.asyncIter.return):
(async.moo):
(async.noo):

  • test262.yaml:

Source/JavaScriptCore:

Current implementation is draft version of Async Iteration.
Link to spec https://tc39.github.io/proposal-async-iteration/

To implement async generator added new states that show reason why async generator was suspended:

The main difference between async function and async generator is that,
async function returns promise but async generator returns
object with methods (next, throw and return) that return promise that
can be resolved with pair of properties value and done.
Async generator functions are similar to generator functions, with the following differences:
whose methods (next, throw, and return) return promises for { value, done },
instead of directly returning { value, done }.
This automatically makes the returned async generator objects async iterators.

delegation to sync and async iterables

  • CMakeLists.txt:
  • DerivedSources.make:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • builtins/AsyncFromSyncIteratorPrototype.js: Added.

(next.try):
(next):
(return.try):
(return):
(throw.try):
(throw):
(globalPrivate.createAsyncFromSyncIterator):
(globalPrivate.AsyncFromSyncIteratorConstructor):

  • builtins/AsyncGeneratorPrototype.js: Added.

(globalPrivate.createAsyncGeneratorQueue):
(globalPrivate.asyncGeneratorQueueIsEmpty):
(globalPrivate.asyncGeneratorQueueCreateItem):
(globalPrivate.asyncGeneratorQueueEnqueue):
(globalPrivate.asyncGeneratorQueueDequeue):
(globalPrivate.asyncGeneratorQueueGetFirstValue):
(globalPrivate.asyncGeneratorDequeue):
(globalPrivate.isExecutionState):
(globalPrivate.isSuspendYieldState):
(globalPrivate.asyncGeneratorReject):
(globalPrivate.asyncGeneratorResolve):
(asyncGeneratorYieldAwaited):
(globalPrivate.asyncGeneratorYield):
(const.onRejected):
(globalPrivate.awaitValue):
(const.onFulfilled):
(globalPrivate.doAsyncGeneratorBodyCall):
(globalPrivate.asyncGeneratorResumeNext.):
(globalPrivate.asyncGeneratorResumeNext):
(globalPrivate.asyncGeneratorEnqueue):
(next):
(return):
(throw):

  • builtins/AsyncIteratorPrototype.js: Added.

(symbolAsyncIteratorGetter):

  • builtins/BuiltinNames.h:
  • bytecode/BytecodeDumper.cpp:

(JSC::BytecodeDumper<Block>::dumpBytecode):

  • bytecode/BytecodeIntrinsicRegistry.cpp:

(JSC::BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry):

  • bytecode/BytecodeIntrinsicRegistry.h:
  • bytecode/BytecodeList.json:
  • bytecode/BytecodeUseDef.h:

(JSC::computeUsesForBytecodeOffset):
(JSC::computeDefsForBytecodeOffset):

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::emitCreateAsyncGeneratorQueue):
(JSC::BytecodeGenerator::emitPutAsyncGeneratorFields):
(JSC::BytecodeGenerator::emitNewFunctionExpressionCommon):
(JSC::BytecodeGenerator::emitNewFunction):
(JSC::BytecodeGenerator::emitIteratorNextWithValue):
(JSC::BytecodeGenerator::emitIteratorClose):
(JSC::BytecodeGenerator::emitYieldPoint):
(JSC::BytecodeGenerator::emitYield):
(JSC::BytecodeGenerator::emitCallIterator):
(JSC::BytecodeGenerator::emitAwait):
(JSC::BytecodeGenerator::emitGetIterator):
(JSC::BytecodeGenerator::emitGetAsyncIterator):
(JSC::BytecodeGenerator::emitDelegateYield):

  • bytecompiler/BytecodeGenerator.h:
  • bytecompiler/NodesCodegen.cpp:

(JSC::ReturnNode::emitBytecode):
(JSC::FunctionNode::emitBytecode):
(JSC::YieldExprNode::emitBytecode):
(JSC::AwaitExprNode::emitBytecode):

  • dfg/DFGAbstractInterpreterInlines.h:

(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):

  • dfg/DFGByteCodeParser.cpp:

(JSC::DFG::ByteCodeParser::parseBlock):

  • dfg/DFGCapabilities.cpp:

(JSC::DFG::capabilityLevel):

  • dfg/DFGClobberize.h:

(JSC::DFG::clobberize):

  • dfg/DFGClobbersExitState.cpp:

(JSC::DFG::clobbersExitState):

  • dfg/DFGDoesGC.cpp:

(JSC::DFG::doesGC):

  • dfg/DFGFixupPhase.cpp:

(JSC::DFG::FixupPhase::fixupNode):

  • dfg/DFGMayExit.cpp:
  • dfg/DFGNode.h:

(JSC::DFG::Node::convertToPhantomNewFunction):
(JSC::DFG::Node::convertToPhantomNewAsyncGeneratorFunction):
(JSC::DFG::Node::hasCellOperand):
(JSC::DFG::Node::isFunctionAllocation):
(JSC::DFG::Node::isPhantomFunctionAllocation):
(JSC::DFG::Node::isPhantomAllocation):

  • dfg/DFGNodeType.h:
  • dfg/DFGObjectAllocationSinkingPhase.cpp:
  • dfg/DFGPredictionPropagationPhase.cpp:
  • dfg/DFGSafeToExecute.h:

(JSC::DFG::safeToExecute):

  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::compileNewFunction):

  • dfg/DFGSpeculativeJIT32_64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • dfg/DFGSpeculativeJIT64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • dfg/DFGStoreBarrierInsertionPhase.cpp:
  • dfg/DFGValidate.cpp:
  • ftl/FTLCapabilities.cpp:

(JSC::FTL::canCompile):

  • ftl/FTLLowerDFGToB3.cpp:

(JSC::FTL::DFG::LowerDFGToB3::compileNode):
(JSC::FTL::DFG::LowerDFGToB3::compileNewFunction):

  • ftl/FTLOperations.cpp:

(JSC::FTL::operationPopulateObjectInOSR):
(JSC::FTL::operationMaterializeObjectInOSR):

  • jit/JIT.cpp:

(JSC::JIT::privateCompileMainPass):

  • jit/JIT.h:
  • jit/JITOpcodes.cpp:

(JSC::JIT::emitNewFuncCommon):
(JSC::JIT::emit_op_new_async_generator_func):
(JSC::JIT::emit_op_new_async_func):
(JSC::JIT::emitNewFuncExprCommon):
(JSC::JIT::emit_op_new_async_generator_func_exp):

  • jit/JITOperations.cpp:
  • jit/JITOperations.h:
  • llint/LLIntSlowPaths.cpp:

(JSC::LLInt::LLINT_SLOW_PATH_DECL):

  • llint/LLIntSlowPaths.h:
  • llint/LowLevelInterpreter.asm:
  • parser/ASTBuilder.h:

(JSC::ASTBuilder::createFunctionMetadata):

  • runtime/AsyncFromSyncIteratorPrototype.cpp: Added.

(JSC::AsyncFromSyncIteratorPrototype::AsyncFromSyncIteratorPrototype):
(JSC::AsyncFromSyncIteratorPrototype::finishCreation):
(JSC::AsyncFromSyncIteratorPrototype::create):

  • runtime/AsyncFromSyncIteratorPrototype.h: Added.

(JSC::AsyncFromSyncIteratorPrototype::createStructure):

  • runtime/AsyncGeneratorFunctionConstructor.cpp: Added.

(JSC::AsyncGeneratorFunctionConstructor::AsyncGeneratorFunctionConstructor):
(JSC::AsyncGeneratorFunctionConstructor::finishCreation):
(JSC::callAsyncGeneratorFunctionConstructor):
(JSC::constructAsyncGeneratorFunctionConstructor):
(JSC::AsyncGeneratorFunctionConstructor::getCallData):
(JSC::AsyncGeneratorFunctionConstructor::getConstructData):

  • runtime/AsyncGeneratorFunctionConstructor.h: Added.

(JSC::AsyncGeneratorFunctionConstructor::create):
(JSC::AsyncGeneratorFunctionConstructor::createStructure):

  • runtime/AsyncGeneratorFunctionPrototype.cpp: Added.

(JSC::AsyncGeneratorFunctionPrototype::AsyncGeneratorFunctionPrototype):
(JSC::AsyncGeneratorFunctionPrototype::finishCreation):

  • runtime/AsyncGeneratorFunctionPrototype.h: Added.

(JSC::AsyncGeneratorFunctionPrototype::create):
(JSC::AsyncGeneratorFunctionPrototype::createStructure):

  • runtime/AsyncGeneratorPrototype.cpp: Added.

(JSC::AsyncGeneratorPrototype::finishCreation):

  • runtime/AsyncGeneratorPrototype.h: Added.

(JSC::AsyncGeneratorPrototype::create):
(JSC::AsyncGeneratorPrototype::createStructure):
(JSC::AsyncGeneratorPrototype::AsyncGeneratorPrototype):

  • runtime/AsyncIteratorPrototype.cpp: Added.

(JSC::AsyncIteratorPrototype::finishCreation):

  • runtime/AsyncIteratorPrototype.h: Added.

(JSC::AsyncIteratorPrototype::create):
(JSC::AsyncIteratorPrototype::createStructure):
(JSC::AsyncIteratorPrototype::AsyncIteratorPrototype):

  • runtime/CommonIdentifiers.h:
  • runtime/FunctionConstructor.cpp:

(JSC::constructFunctionSkippingEvalEnabledCheck):

  • runtime/FunctionConstructor.h:
  • runtime/FunctionExecutable.h:
  • runtime/JSAsyncGeneratorFunction.cpp: Added.

(JSC::JSAsyncGeneratorFunction::JSAsyncGeneratorFunction):
(JSC::JSAsyncGeneratorFunction::createImpl):
(JSC::JSAsyncGeneratorFunction::create):
(JSC::JSAsyncGeneratorFunction::createWithInvalidatedReallocationWatchpoint):

  • runtime/JSAsyncGeneratorFunction.h: Added.

(JSC::JSAsyncGeneratorFunction::allocationSize):
(JSC::JSAsyncGeneratorFunction::createStructure):

  • runtime/JSFunction.cpp:

(JSC::JSFunction::getOwnPropertySlot):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::asyncIteratorPrototype const):
(JSC::JSGlobalObject::asyncGeneratorPrototype const):
(JSC::JSGlobalObject::asyncGeneratorFunctionPrototype const):
(JSC::JSGlobalObject::asyncGeneratorFunctionStructure const):

  • runtime/Options.h:

LayoutTests:

  • js/Object-getOwnPropertyNames-expected.txt:
  • js/script-tests/Object-getOwnPropertyNames.js:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r219301 r221080  
    5858class ArrayConstructor;
    5959class ArrayPrototype;
     60class AsyncIteratorPrototype;
    6061class AsyncFunctionPrototype;
     62class AsyncGeneratorPrototype;
     63class AsyncGeneratorFunctionPrototype;
    6164class BooleanPrototype;
    6265class ConsoleClient;
     
    285288    WriteBarrier<RegExpPrototype> m_regExpPrototype;
    286289    WriteBarrier<IteratorPrototype> m_iteratorPrototype;
     290    WriteBarrier<AsyncIteratorPrototype> m_asyncIteratorPrototype;
    287291    WriteBarrier<GeneratorFunctionPrototype> m_generatorFunctionPrototype;
    288292    WriteBarrier<GeneratorPrototype> m_generatorPrototype;
     293    WriteBarrier<AsyncGeneratorPrototype> m_asyncGeneratorPrototype;
    289294    WriteBarrier<ModuleLoaderPrototype> m_moduleLoaderPrototype;
    290295
     
    326331    WriteBarrier<Structure> m_regExpStructure;
    327332    WriteBarrier<AsyncFunctionPrototype> m_asyncFunctionPrototype;
     333    WriteBarrier<AsyncGeneratorFunctionPrototype> m_asyncGeneratorFunctionPrototype;
    328334    WriteBarrier<Structure> m_asyncFunctionStructure;
     335    WriteBarrier<Structure> m_asyncGeneratorFunctionStructure;
    329336    WriteBarrier<Structure> m_generatorFunctionStructure;
    330337    WriteBarrier<Structure> m_dollarVMStructure;
     
    562569    ErrorPrototype* errorPrototype() const { return m_errorPrototype.get(); }
    563570    IteratorPrototype* iteratorPrototype() const { return m_iteratorPrototype.get(); }
     571    AsyncIteratorPrototype* asyncIteratorPrototype() const { return m_asyncIteratorPrototype.get(); }
    564572    GeneratorFunctionPrototype* generatorFunctionPrototype() const { return m_generatorFunctionPrototype.get(); }
    565573    GeneratorPrototype* generatorPrototype() const { return m_generatorPrototype.get(); }
     
    568576    // Workaround for the name conflict between JSCell::setPrototype.
    569577    SetPrototype* jsSetPrototype() const { return m_setPrototype.get(); }
     578    AsyncGeneratorPrototype* asyncGeneratorPrototype() const { return m_asyncGeneratorPrototype.get(); }
     579    AsyncGeneratorFunctionPrototype* asyncGeneratorFunctionPrototype() const { return m_asyncGeneratorFunctionPrototype.get(); }
    570580
    571581    Structure* debuggerScopeStructure() const { return m_debuggerScopeStructure.get(this); }
     
    628638    Structure* generatorFunctionStructure() const { return m_generatorFunctionStructure.get(); }
    629639    Structure* asyncFunctionStructure() const { return m_asyncFunctionStructure.get(); }
     640    Structure* asyncGeneratorFunctionStructure() const { return m_asyncGeneratorFunctionStructure.get(); }
    630641    Structure* stringObjectStructure() const { return m_stringObjectStructure.get(); }
    631642    Structure* symbolObjectStructure() const { return m_symbolObjectStructure.get(); }
Note: See TracChangeset for help on using the changeset viewer.