Ignore:
Timestamp:
Feb 21, 2021, 4:41:30 PM (5 years ago)
Author:
[email protected]
Message:

Implement the Top-level await proposal
https://bugs.webkit.org/show_bug.cgi?id=202484

Reviewed by Yusuke Suzuki.

JSTests:

  • test262/config.yaml:

Source/JavaScriptCore:

This patch adds support for the TLA proposal. The bulk of this patch is adding a couple of main parts.

1) converting the AbstractModuleRecord to contain many of same internal fields as JSGenerator so much of the async codegen can be shared.

2) having the link phase of the module loader record whether a module subgraph is async.
3) teaching the module loader that evaluating a module may require more than one vm entry and forwarding the awaited value as well as the resume mode to the VM.

One thing particularly interesting about this patch is that moduleEvaluation now *sometimes* (when a strongly connected subgraph is async) will return a promise. This happened to already be awaited when called from loadAndEvaluateModule (unnecessarily before) but now also needs to be handled by requestImportModule.

No new tests because every test I came up with was subsumed by tests already in test262.

  • API/JSAPIGlobalObject.h:
  • API/JSAPIGlobalObject.mm:

(JSC::JSAPIGlobalObject::moduleLoaderEvaluate):

(globalPrivate.newRegistryEntry):
(link):
(async requestImportModule):
(moduleEvaluation): Deleted.
(requestImportModule): Deleted.

  • bytecode/BytecodeGeneratorification.cpp:

(JSC::BytecodeGeneratorification::run):
(JSC::performGeneratorification):

  • bytecode/BytecodeIntrinsicRegistry.cpp:

(JSC::BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry):

  • bytecode/BytecodeIntrinsicRegistry.h:
  • bytecode/BytecodeList.rb:
  • bytecode/BytecodeUseDef.cpp:

(JSC::computeUsesForBytecodeIndexImpl):

  • bytecode/UnlinkedModuleProgramCodeBlock.h:
  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::generate):
(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::emitWillLeaveCallFrameDebugHook):
(JSC::BytecodeGenerator::emitGenericEnumeration):
(JSC::BytecodeGenerator::emitYieldPoint):
(JSC::BytecodeGenerator::emitYield):
(JSC::BytecodeGenerator::emitDelegateYield):
(JSC::BytecodeGenerator::emitGeneratorStateChange):

  • bytecompiler/BytecodeGenerator.h:

(JSC::BytecodeGenerator::generatorStateRegister):
(JSC::BytecodeGenerator::generatorValueRegister):
(JSC::BytecodeGenerator::generatorResumeModeRegister):
(JSC::BytecodeGenerator::generatorFrameRegister):

  • bytecompiler/NodesCodegen.cpp:

(JSC::abstractModuleRecordInternalFieldIndex):
(JSC::BytecodeIntrinsicNode::emit_intrinsic_getAbstractModuleRecordInternalField):
(JSC::FunctionNode::emitBytecode):

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::executeModuleProgram):

  • interpreter/Interpreter.h:
  • parser/ASTBuilder.h:

(JSC::ASTBuilder::createAwait):
(JSC::ASTBuilder::usesAwait):

  • parser/Nodes.cpp:

(JSC::ModuleProgramNode::ModuleProgramNode):

  • parser/Nodes.h:
  • parser/Parser.cpp:

(JSC::JSToken::dump const):
(JSC::Parser<LexerType>::parseForStatement):
(JSC::Parser<LexerType>::parseAwaitExpression):
(JSC::Parser<LexerType>::parsePrimaryExpression):
(JSC::Parser<LexerType>::parseUnaryExpression):

  • parser/ParserModes.h:
  • parser/ParserTokens.h:
  • runtime/AbstractModuleRecord.cpp:

(JSC::AbstractModuleRecord::finishCreation):
(JSC::AbstractModuleRecord::link):
(JSC::AbstractModuleRecord::evaluate):

  • runtime/AbstractModuleRecord.h:

(JSC::AbstractModuleRecord::initialValues):
(JSC::AbstractModuleRecord::internalField):
(JSC::AbstractModuleRecord::internalField const):

  • runtime/JSAsyncGenerator.h:
  • runtime/JSGenerator.h:
  • runtime/JSGlobalObject.h:
  • runtime/JSModuleLoader.cpp:

(JSC::JSModuleLoader::evaluate):
(JSC::JSModuleLoader::evaluateNonVirtual):
(JSC::JSC_DEFINE_HOST_FUNCTION):

  • runtime/JSModuleLoader.h:
  • runtime/JSModuleRecord.cpp:

(JSC::JSModuleRecord::link):
(JSC::JSModuleRecord::evaluate):

  • runtime/JSModuleRecord.h:
  • runtime/ModuleProgramExecutable.h:
  • runtime/OptionsList.h:
  • runtime/SymbolTable.cpp:

(JSC::SymbolTable::dump const):

  • runtime/SymbolTable.h:
  • wasm/js/WebAssemblyModuleRecord.cpp:

(JSC::WebAssemblyModuleRecord::link):
(JSC::WebAssemblyModuleRecord::linkImpl):

  • wasm/js/WebAssemblyModuleRecord.h:

Source/WebCore:

  • bindings/js/JSDOMGlobalObject.cpp:

(WebCore::JSDOMGlobalObject::moduleLoaderEvaluate):

  • bindings/js/JSDOMGlobalObject.h:
  • bindings/js/ScriptController.cpp:

(WebCore::ScriptController::evaluateModule):

  • bindings/js/ScriptController.h:
  • bindings/js/ScriptModuleLoader.cpp:

(WebCore::ScriptModuleLoader::evaluate):

  • bindings/js/ScriptModuleLoader.h:
  • workers/WorkerOrWorkletScriptController.cpp:

(WebCore::WorkerOrWorkletScriptController::evaluateModule):

  • workers/WorkerOrWorkletScriptController.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Nodes.h

    r272883 r273225  
    19911991        unsigned startColumn() const { return m_startColumn; }
    19921992        unsigned endColumn() const { return m_endColumn; }
     1993        bool usesAwait() const { return m_usesAwait; }
    19931994
    19941995        static constexpr bool scopeIsFunction = false;
     
    20032004        unsigned m_startColumn;
    20042005        unsigned m_endColumn;
     2006        bool m_usesAwait;
    20052007        Ref<ModuleScopeData> m_moduleScopeData;
    20062008    };
Note: See TracChangeset for help on using the changeset viewer.