Ignore:
Timestamp:
Jan 11, 2017, 4:12:37 AM (8 years ago)
Author:
Yusuke Suzuki
Message:

Decouple module loading initiator from ScriptElement
https://bugs.webkit.org/show_bug.cgi?id=166888

Reviewed by Saam Barati and Ryosuke Niwa.

Source/JavaScriptCore:

Add ScriptFetcher and JSScriptFetcher.

  • CMakeLists.txt:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • builtins/ModuleLoaderPrototype.js:

(requestFetch):
(requestInstantiate):
(requestSatisfy):
(requestInstantiateAll):
(requestLink):
(moduleEvaluation):
(loadAndEvaluateModule):
(importModule):

  • llint/LLIntData.cpp:

(JSC::LLInt::Data::performAssertions):

  • llint/LowLevelInterpreter.asm:
  • runtime/Completion.cpp:

(JSC::loadAndEvaluateModule):
(JSC::loadModule):
(JSC::linkAndEvaluateModule):

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

(JSC::JSModuleLoader::loadAndEvaluateModule):
(JSC::JSModuleLoader::loadModule):
(JSC::JSModuleLoader::linkAndEvaluateModule):
(JSC::JSModuleLoader::resolve):
(JSC::JSModuleLoader::fetch):
(JSC::JSModuleLoader::instantiate):
(JSC::JSModuleLoader::evaluate):

  • runtime/JSModuleLoader.h:
  • runtime/JSScriptFetcher.cpp: Copied from Source/WebCore/dom/LoadableScript.cpp.

(JSC::JSScriptFetcher::destroy):

  • runtime/JSScriptFetcher.h: Added.

(JSC::JSScriptFetcher::createStructure):
(JSC::JSScriptFetcher::create):
(JSC::JSScriptFetcher::fetcher):
(JSC::JSScriptFetcher::JSScriptFetcher):

  • runtime/JSType.h:
  • runtime/ScriptFetcher.h: Copied from Source/WebCore/dom/LoadableScript.cpp.

(JSC::ScriptFetcher::~ScriptFetcher):

  • runtime/VM.cpp:

(JSC::VM::VM):

  • runtime/VM.h:

Source/WebCore:

Previously, we use ScriptElement (JSElement for ScriptElement) as the module loading initiator.
This element is used to transfer the metadata like charset throughout the module pipeline.
As a result, our module loader in the browser side is tightly coupled with ScriptElement.
It is not good since it prevent us from using the module loader in the non-DOM environment like
Web Workers.

So we decouple the necessary informations from ScriptElement. We move these information to
LoadableScript. And we use JSScriptFetcher to transfer LoadableScript through the JS implemented
module loader pipeline. We select LoadableScript instead of LoadableModuleScript since this initiator
information will be leveraged even in classic scripts once we implement the dynamic import.

No behavior change.

  • ForwardingHeaders/runtime/JSScriptFetcher.h: Copied from Source/WebCore/dom/LoadableScript.cpp.
  • ForwardingHeaders/runtime/ScriptFetcher.h: Copied from Source/WebCore/dom/LoadableScript.cpp.
  • bindings/js/CachedModuleScript.cpp:

(WebCore::CachedModuleScript::create):
(WebCore::CachedModuleScript::load):
(WebCore::CachedModuleScript::CachedModuleScript): Deleted.

  • bindings/js/CachedModuleScript.h:

Now we can merge CachedModuleScript to LoadableScript. But we do not do this in this patch since
we focus on decoupling the initiator information from ScriptElement.

(WebCore::CachedModuleScript::nonce): Deleted.
(WebCore::CachedModuleScript::crossOriginMode): Deleted.

  • bindings/js/CachedModuleScriptLoader.cpp:

(WebCore::CachedModuleScriptLoader::load):

  • bindings/js/CachedModuleScriptLoader.h:
  • bindings/js/JSDOMWindowBase.cpp:

(WebCore::JSDOMWindowBase::moduleLoaderResolve):
(WebCore::JSDOMWindowBase::moduleLoaderFetch):
(WebCore::JSDOMWindowBase::moduleLoaderEvaluate):

  • bindings/js/JSMainThreadExecState.h:

(WebCore::JSMainThreadExecState::loadModule):
(WebCore::JSMainThreadExecState::linkAndEvaluateModule):

  • bindings/js/ScriptController.cpp:

(WebCore::ScriptController::loadModuleScriptInWorld):
(WebCore::ScriptController::loadModuleScript):
(WebCore::ScriptController::linkAndEvaluateModuleScriptInWorld):
(WebCore::ScriptController::linkAndEvaluateModuleScript):

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

(WebCore::ScriptModuleLoader::fetch):

  • bindings/js/ScriptModuleLoader.h:
  • dom/LoadableClassicScript.cpp:

(WebCore::LoadableClassicScript::create):
(WebCore::LoadableClassicScript::~LoadableClassicScript):
(WebCore::LoadableClassicScript::isLoaded):
(WebCore::LoadableClassicScript::error):
(WebCore::LoadableClassicScript::wasCanceled):
(WebCore::LoadableClassicScript::notifyFinished):
(WebCore::LoadableClassicScript::load):

  • dom/LoadableClassicScript.h:
  • dom/LoadableModuleScript.cpp:

(WebCore::LoadableModuleScript::create):
(WebCore::LoadableModuleScript::LoadableModuleScript):
(WebCore::LoadableModuleScript::load):

  • dom/LoadableModuleScript.h:
  • dom/LoadableScript.cpp:

(WebCore::LoadableScript::requestScriptWithCache):

  • dom/LoadableScript.h:

(WebCore::LoadableScript::LoadableScript):

  • dom/ScriptElement.cpp:

(WebCore::ScriptElement::requestClassicScript):
(WebCore::ScriptElement::requestModuleScript):
(WebCore::ScriptElement::executeModuleScript):
(WebCore::ScriptElement::requestScriptWithCacheForModuleScript): Deleted.
(WebCore::ScriptElement::requestScriptWithCache): Deleted.

  • dom/ScriptElement.h:
File:
1 edited

Legend:

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

    r206525 r210585  
    5858
    5959// Load the module source and evaluate it.
    60 JS_EXPORT_PRIVATE JSInternalPromise* loadAndEvaluateModule(ExecState*, const String& moduleName, JSValue initiator = jsUndefined());
    61 JS_EXPORT_PRIVATE JSInternalPromise* loadAndEvaluateModule(ExecState*, const SourceCode&, JSValue initiator = jsUndefined());
     60JS_EXPORT_PRIVATE JSInternalPromise* loadAndEvaluateModule(ExecState*, const String& moduleName, JSValue scriptFetcher = jsUndefined());
     61JS_EXPORT_PRIVATE JSInternalPromise* loadAndEvaluateModule(ExecState*, const SourceCode&, JSValue scriptFetcher = jsUndefined());
    6262
    6363// Fetch the module source, and instantiate the module record.
    64 JS_EXPORT_PRIVATE JSInternalPromise* loadModule(ExecState*, const String& moduleName, JSValue initiator = jsUndefined());
    65 JS_EXPORT_PRIVATE JSInternalPromise* loadModule(ExecState*, const SourceCode&, JSValue initiator = jsUndefined());
     64JS_EXPORT_PRIVATE JSInternalPromise* loadModule(ExecState*, const String& moduleName, JSValue scriptFetcher = jsUndefined());
     65JS_EXPORT_PRIVATE JSInternalPromise* loadModule(ExecState*, const SourceCode&, JSValue scriptFetcher = jsUndefined());
    6666
    6767// Link and evaluate the already linked module. This function is called in a sync manner.
    68 JS_EXPORT_PRIVATE JSValue linkAndEvaluateModule(ExecState*, const Identifier& moduleKey, JSValue initiator = jsUndefined());
     68JS_EXPORT_PRIVATE JSValue linkAndEvaluateModule(ExecState*, const Identifier& moduleKey, JSValue scriptFetcher = jsUndefined());
    6969
    7070} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.