Ignore:
Timestamp:
Oct 20, 2017, 12:19:02 AM (8 years ago)
Author:
Yusuke Suzuki
Message:

[JSC] ScriptFetcher should be notified directly from module pipeline
https://bugs.webkit.org/show_bug.cgi?id=178340

Reviewed by Sam Weinig.

Source/JavaScriptCore:

Previously, we use JSStdFunction to let WebCore inform the module pipeline results.
We setup JSStdFunction to the resulted promise of the module pipeline. It is super
ad-hoc since JSStdFunction's lambda need extra-careful to make it non-cyclic-referenced.
JSStdFunction's lambda can capture variables, but they are not able to be marked by GC.

But now, we have ScriptFetcher. It is introduced after we implemented the module pipeline
notification mechanism by using JSStdFunction. But it is appropriate one to receive notification
from the module pipeline by observer style.

This patch removes the above ad-hoc JSStdFunction use. And now ScriptFetcher receives
completion/failure notifications from the module pipeline.

  • builtins/ModuleLoaderPrototype.js:

(loadModule):
(loadAndEvaluateModule):

  • runtime/Completion.cpp:

(JSC::loadModule):

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

(JSC::jsValueToModuleKey):
(JSC::JSModuleLoader::notifyCompleted):
(JSC::JSModuleLoader::notifyFailed):

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

(JSC::moduleLoaderPrototypeNotifyCompleted):
(JSC::moduleLoaderPrototypeNotifyFailed):

  • runtime/ScriptFetcher.h:

(JSC::ScriptFetcher::notifyLoadCompleted):
(JSC::ScriptFetcher::notifyLoadFailed):

Source/WebCore:

No behavior change.

  • bindings/js/JSMainThreadExecState.h:

(WebCore::JSMainThreadExecState::loadModule):

  • bindings/js/ScriptController.cpp:

(WebCore::ScriptController::loadModuleScriptInWorld):
(WebCore::jsValueToModuleKey): Deleted.
(WebCore::ScriptController::setupModuleScriptHandlers): Deleted.

  • bindings/js/ScriptController.h:
  • dom/LoadableModuleScript.cpp:

(WebCore::LoadableModuleScript::notifyLoadFailed):

  • dom/LoadableModuleScript.h:

LayoutTests:

  • http/tests/security/contentSecurityPolicy/1.1/module-scriptnonce-redirect-expected.txt:
  • http/tests/security/module-no-mime-type-expected.txt:
  • js/dom/modules/module-execution-error-should-be-propagated-to-onerror-expected.txt:
File:
1 edited

Legend:

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

    r223331 r223744  
    4040#include "JSModuleEnvironment.h"
    4141#include "JSModuleRecord.h"
     42#include "JSScriptFetcher.h"
    4243#include "JSSourceCode.h"
    4344#include "ModuleAnalyzer.h"
     
    292293}
    293294
     295static Identifier jsValueToModuleKey(ExecState* exec, JSValue value)
     296{
     297    if (value.isSymbol())
     298        return Identifier::fromUid(jsCast<Symbol*>(value)->privateName());
     299    ASSERT(value.isString());
     300    return asString(value)->toIdentifier(exec);
     301}
     302
     303JSValue JSModuleLoader::notifyCompleted(ExecState* exec, JSValue scriptFetcher, JSValue key)
     304{
     305    auto* fetcherWrapper = jsDynamicCast<JSScriptFetcher*>(exec->vm(), scriptFetcher);
     306    if (!fetcherWrapper)
     307        return jsUndefined();
     308    auto* fetcher = fetcherWrapper->fetcher();
     309    if (!fetcher)
     310        return jsUndefined();
     311
     312    Identifier moduleKey = jsValueToModuleKey(exec, key);
     313    fetcher->notifyLoadCompleted(*moduleKey.impl());
     314    return jsUndefined();
     315}
     316
     317JSValue JSModuleLoader::notifyFailed(ExecState* exec, JSValue scriptFetcher, JSValue errorValue)
     318{
     319    auto* fetcherWrapper = jsDynamicCast<JSScriptFetcher*>(exec->vm(), scriptFetcher);
     320    if (!fetcherWrapper)
     321        return jsUndefined();
     322    auto* fetcher = fetcherWrapper->fetcher();
     323    if (!fetcher)
     324        return jsUndefined();
     325    fetcher->notifyLoadFailed(exec, errorValue);
     326    return jsUndefined();
     327}
     328
    294329} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.