Changeset 223744 in webkit


Ignore:
Timestamp:
Oct 20, 2017 12:19:02 AM (7 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:
Location:
trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r223718 r223744  
     12017-10-20  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] ScriptFetcher should be notified directly from module pipeline
     4        https://bugs.webkit.org/show_bug.cgi?id=178340
     5
     6        Reviewed by Sam Weinig.
     7
     8        * http/tests/security/contentSecurityPolicy/1.1/module-scriptnonce-redirect-expected.txt:
     9        * http/tests/security/module-no-mime-type-expected.txt:
     10        * js/dom/modules/module-execution-error-should-be-propagated-to-onerror-expected.txt:
     11
    1122017-10-19  Youenn Fablet  <youenn@apple.com>
    213
  • trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/module-scriptnonce-redirect-expected.txt

    r208788 r223744  
    11CONSOLE MESSAGE: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
    2 CONSOLE MESSAGE: line 1: TypeError: Cross-origin script load denied by Cross-Origin Resource Sharing policy.
     2CONSOLE MESSAGE: line 11: TypeError: Cross-origin script load denied by Cross-Origin Resource Sharing policy.
    33This tests whether a deferred script load caused by a redirect is properly allowed by a nonce.
  • trunk/LayoutTests/http/tests/security/module-no-mime-type-expected.txt

    r208788 r223744  
    1 CONSOLE MESSAGE: line 1: TypeError: 'application/octet-stream' is not a valid JavaScript MIME type.
     1CONSOLE MESSAGE: line 11: TypeError: 'application/octet-stream' is not a valid JavaScript MIME type.
    22Test module rejects scripts with no mime type.
    33
  • trunk/LayoutTests/js/dom/modules/module-execution-error-should-be-propagated-to-onerror-expected.txt

    r208788 r223744  
     1CONSOLE MESSAGE: line 19: Error: module is executed.
    12Test window.onerror will be fired when the inlined module throws an error.
    23
  • trunk/Source/JavaScriptCore/ChangeLog

    r223738 r223744  
     12017-10-20  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] ScriptFetcher should be notified directly from module pipeline
     4        https://bugs.webkit.org/show_bug.cgi?id=178340
     5
     6        Reviewed by Sam Weinig.
     7
     8        Previously, we use JSStdFunction to let WebCore inform the module pipeline results.
     9        We setup JSStdFunction to the resulted promise of the module pipeline. It is super
     10        ad-hoc since JSStdFunction's lambda need extra-careful to make it non-cyclic-referenced.
     11        JSStdFunction's lambda can capture variables, but they are not able to be marked by GC.
     12
     13        But now, we have ScriptFetcher. It is introduced after we implemented the module pipeline
     14        notification mechanism by using JSStdFunction. But it is appropriate one to receive notification
     15        from the module pipeline by observer style.
     16
     17        This patch removes the above ad-hoc JSStdFunction use. And now ScriptFetcher receives
     18        completion/failure notifications from the module pipeline.
     19
     20        * builtins/ModuleLoaderPrototype.js:
     21        (loadModule):
     22        (loadAndEvaluateModule):
     23        * runtime/Completion.cpp:
     24        (JSC::loadModule):
     25        * runtime/Completion.h:
     26        * runtime/JSModuleLoader.cpp:
     27        (JSC::jsValueToModuleKey):
     28        (JSC::JSModuleLoader::notifyCompleted):
     29        (JSC::JSModuleLoader::notifyFailed):
     30        * runtime/JSModuleLoader.h:
     31        * runtime/ModuleLoaderPrototype.cpp:
     32        (JSC::moduleLoaderPrototypeNotifyCompleted):
     33        (JSC::moduleLoaderPrototypeNotifyFailed):
     34        * runtime/ScriptFetcher.h:
     35        (JSC::ScriptFetcher::notifyLoadCompleted):
     36        (JSC::ScriptFetcher::notifyLoadFailed):
     37
    1382017-10-19  JF Bastien  <jfbastien@apple.com>
    239
  • trunk/Source/JavaScriptCore/builtins/ModuleLoaderPrototype.js

    r223331 r223744  
    321321    return this.resolve(moduleName, @undefined, fetcher).then((key) => {
    322322        return this.requestSatisfy(this.ensureRegistered(key), parameters, fetcher);
    323     }).then((entry) => {
    324         return entry.key;
    325     });
     323    }).then(
     324        (entry) => {
     325            this.notifyCompleted(fetcher, entry.key);
     326            return entry;
     327        },
     328        (error) => {
     329            this.notifyFailed(fetcher, error);
     330            throw error;
     331        });
    326332}
    327333
     
    342348    "use strict";
    343349
    344     return this.loadModule(moduleName, parameters, fetcher).then((key) => {
    345         return this.linkAndEvaluateModule(key, fetcher);
     350    return this.loadModule(moduleName, parameters, fetcher).then((entry) => {
     351        return this.linkAndEvaluateModule(entry.key, fetcher);
    346352    });
    347353}
  • trunk/Source/JavaScriptCore/runtime/Completion.cpp

    r223237 r223744  
    184184}
    185185
    186 JSInternalPromise* loadModule(ExecState* exec, const String& moduleName, JSValue parameters, JSValue scriptFetcher)
    187 {
    188     VM& vm = exec->vm();
    189     JSLockHolder lock(vm);
    190     RELEASE_ASSERT(vm.atomicStringTable() == Thread::current().atomicStringTable());
    191     RELEASE_ASSERT(!vm.isCollectorBusyOnCurrentThread());
    192 
    193     return exec->vmEntryGlobalObject()->moduleLoader()->loadModule(exec, identifierToJSValue(vm, Identifier::fromString(exec, moduleName)), parameters, scriptFetcher);
    194 }
    195 
    196 JSInternalPromise* loadModule(ExecState* exec, const SourceCode& source, JSValue scriptFetcher)
     186void loadModule(ExecState* exec, const String& moduleName, JSValue parameters, JSValue scriptFetcher)
     187{
     188    VM& vm = exec->vm();
     189    JSLockHolder lock(vm);
     190    RELEASE_ASSERT(vm.atomicStringTable() == Thread::current().atomicStringTable());
     191    RELEASE_ASSERT(!vm.isCollectorBusyOnCurrentThread());
     192
     193    exec->vmEntryGlobalObject()->moduleLoader()->loadModule(exec, identifierToJSValue(vm, Identifier::fromString(exec, moduleName)), parameters, scriptFetcher);
     194}
     195
     196void loadModule(ExecState* exec, const SourceCode& source, JSValue scriptFetcher)
    197197{
    198198    VM& vm = exec->vm();
     
    209209    // FIXME: Introduce JSSourceCode object to wrap around this source.
    210210    globalObject->moduleLoader()->provideFetch(exec, key, source);
    211     RETURN_IF_EXCEPTION(scope, rejectPromise(exec, globalObject));
    212 
    213     return globalObject->moduleLoader()->loadModule(exec, key, jsUndefined(), scriptFetcher);
     211    RETURN_IF_EXCEPTION(scope, void());
     212
     213    globalObject->moduleLoader()->loadModule(exec, key, jsUndefined(), scriptFetcher);
    214214}
    215215
  • trunk/Source/JavaScriptCore/runtime/Completion.h

    r223237 r223744  
    6262
    6363// Fetch the module source, and instantiate the module record.
    64 JS_EXPORT_PRIVATE JSInternalPromise* loadModule(ExecState*, const String& moduleName, JSValue parameters, JSValue scriptFetcher);
    65 JS_EXPORT_PRIVATE JSInternalPromise* loadModule(ExecState*, const SourceCode&, JSValue scriptFetcher);
     64JS_EXPORT_PRIVATE void loadModule(ExecState*, const String& moduleName, JSValue parameters, JSValue scriptFetcher);
     65JS_EXPORT_PRIVATE void loadModule(ExecState*, const SourceCode&, JSValue scriptFetcher);
    6666
    6767// Link and evaluate the already linked module. This function is called in a sync manner.
  • 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
  • trunk/Source/JavaScriptCore/runtime/JSModuleLoader.h

    r223331 r223744  
    6969    JSValue linkAndEvaluateModule(ExecState*, JSValue moduleKey, JSValue scriptFetcher);
    7070    JSInternalPromise* requestImportModule(ExecState*, const Identifier&, JSValue parameters, JSValue scriptFetcher);
     71    JSValue notifyCompleted(ExecState*, JSValue scriptFetcher, JSValue key);
     72    JSValue notifyFailed(ExecState*, JSValue scriptFetcher, JSValue error);
    7173
    7274    // Platform dependent hooked APIs.
  • trunk/Source/JavaScriptCore/runtime/ModuleLoaderPrototype.cpp

    r223331 r223744  
    5757static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeFetch(ExecState*);
    5858static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeGetModuleNamespaceObject(ExecState*);
     59static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeNotifyCompleted(ExecState*);
     60static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeNotifyFailed(ExecState*);
    5961
    6062}
     
    9193    resolveSync                    moduleLoaderPrototypeResolveSync                    DontEnum|Function 2
    9294    fetch                          moduleLoaderPrototypeFetch                          DontEnum|Function 3
     95    notifyCompleted                moduleLoaderPrototypeNotifyCompleted                DontEnum|Function 2
     96    notifyFailed                   moduleLoaderPrototypeNotifyFailed                   DontEnum|Function 2
    9397@end
    9498*/
     
    171175}
    172176
     177EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeNotifyCompleted(ExecState* exec)
     178{
     179    VM& vm = exec->vm();
     180    JSModuleLoader* loader = jsDynamicCast<JSModuleLoader*>(vm, exec->thisValue());
     181    if (!loader)
     182        return JSValue::encode(jsUndefined());
     183    return JSValue::encode(loader->notifyCompleted(exec, exec->argument(0), exec->argument(1)));
     184}
     185
     186EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeNotifyFailed(ExecState* exec)
     187{
     188    VM& vm = exec->vm();
     189    JSModuleLoader* loader = jsDynamicCast<JSModuleLoader*>(vm, exec->thisValue());
     190    if (!loader)
     191        return JSValue::encode(jsUndefined());
     192    return JSValue::encode(loader->notifyFailed(exec, exec->argument(0), exec->argument(1)));
     193}
     194
    173195// ------------------------------ Hook Functions ---------------------------
    174196
  • trunk/Source/JavaScriptCore/runtime/ScriptFetcher.h

    r210585 r223744  
    2626#pragma once
    2727
     28#include "JSCJSValue.h"
    2829#include <wtf/RefCounted.h>
    2930
    3031namespace JSC {
    3132
     33class ExecState;
     34
    3235class ScriptFetcher : public RefCounted<ScriptFetcher> {
    3336public:
    3437    virtual ~ScriptFetcher() { }
     38
     39    virtual void notifyLoadCompleted(UniquedStringImpl&) { }
     40    virtual void notifyLoadFailed(ExecState*, JSValue) { }
    3541};
    3642
  • trunk/Source/WebCore/ChangeLog

    r223743 r223744  
     12017-10-20  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] ScriptFetcher should be notified directly from module pipeline
     4        https://bugs.webkit.org/show_bug.cgi?id=178340
     5
     6        Reviewed by Sam Weinig.
     7
     8        No behavior change.
     9
     10        * bindings/js/JSMainThreadExecState.h:
     11        (WebCore::JSMainThreadExecState::loadModule):
     12        * bindings/js/ScriptController.cpp:
     13        (WebCore::ScriptController::loadModuleScriptInWorld):
     14        (WebCore::jsValueToModuleKey): Deleted.
     15        (WebCore::ScriptController::setupModuleScriptHandlers): Deleted.
     16        * bindings/js/ScriptController.h:
     17        * dom/LoadableModuleScript.cpp:
     18        (WebCore::LoadableModuleScript::notifyLoadFailed):
     19        * dom/LoadableModuleScript.h:
     20
    1212017-10-19  Ms2ger  <Ms2ger@igalia.com>
    222
  • trunk/Source/WebCore/bindings/js/JSMainThreadExecState.h

    r223237 r223744  
    9191    }
    9292
    93     static JSC::JSInternalPromise& loadModule(JSC::ExecState& state, const String& moduleName, JSC::JSValue parameters, JSC::JSValue scriptFetcher)
     93    static void loadModule(JSC::ExecState& state, const String& moduleName, JSC::JSValue parameters, JSC::JSValue scriptFetcher)
    9494    {
    9595        JSMainThreadExecState currentState(&state);
    96         return *JSC::loadModule(&state, moduleName, parameters, scriptFetcher);
     96        JSC::loadModule(&state, moduleName, parameters, scriptFetcher);
    9797    }
    9898
    99     static JSC::JSInternalPromise& loadModule(JSC::ExecState& state, const JSC::SourceCode& sourceCode, JSC::JSValue scriptFetcher)
     99    static void loadModule(JSC::ExecState& state, const JSC::SourceCode& sourceCode, JSC::JSValue scriptFetcher)
    100100    {
    101101        JSMainThreadExecState currentState(&state);
    102         return *JSC::loadModule(&state, sourceCode, scriptFetcher);
     102        JSC::loadModule(&state, sourceCode, scriptFetcher);
    103103    }
    104104
  • trunk/Source/WebCore/bindings/js/ScriptController.cpp

    r223476 r223744  
    4141#include "LoadableModuleScript.h"
    4242#include "MainFrame.h"
    43 #include "ModuleFetchFailureKind.h"
    4443#include "ModuleFetchParameters.h"
    4544#include "NP_jsobject.h"
     
    6362#include <runtime/JSLock.h>
    6463#include <runtime/JSModuleRecord.h>
    65 #include <runtime/JSNativeStdFunction.h>
    6664#include <runtime/JSScriptFetchParameters.h>
    6765#include <runtime/JSScriptFetcher.h>
     
    200198    auto& state = *proxy.window()->globalExec();
    201199
    202     auto& promise = JSMainThreadExecState::loadModule(state, moduleName, JSC::JSScriptFetchParameters::create(state.vm(), WTFMove(topLevelFetchParameters)), JSC::JSScriptFetcher::create(state.vm(), { &moduleScript }));
    203     setupModuleScriptHandlers(moduleScript, promise, world);
     200    JSMainThreadExecState::loadModule(state, moduleName, JSC::JSScriptFetchParameters::create(state.vm(), WTFMove(topLevelFetchParameters)), JSC::JSScriptFetcher::create(state.vm(), { &moduleScript }));
    204201}
    205202
     
    216213    auto& state = *proxy.window()->globalExec();
    217214
    218     auto& promise = JSMainThreadExecState::loadModule(state, sourceCode.jsSourceCode(), JSC::JSScriptFetcher::create(state.vm(), { &moduleScript }));
    219     setupModuleScriptHandlers(moduleScript, promise, world);
     215    JSMainThreadExecState::loadModule(state, sourceCode.jsSourceCode(), JSC::JSScriptFetcher::create(state.vm(), { &moduleScript }));
    220216}
    221217
     
    363359
    364360    return &windowProxy;
    365 }
    366 
    367 static Identifier jsValueToModuleKey(ExecState* exec, JSValue value)
    368 {
    369     if (value.isSymbol())
    370         return Identifier::fromUid(jsCast<Symbol*>(value)->privateName());
    371     ASSERT(value.isString());
    372     return asString(value)->toIdentifier(exec);
    373 }
    374 
    375 void ScriptController::setupModuleScriptHandlers(LoadableModuleScript& moduleScriptRef, JSInternalPromise& promise, DOMWrapperWorld& world)
    376 {
    377     auto& proxy = *windowProxy(world);
    378     auto& state = *proxy.window()->globalExec();
    379 
    380     // It is not guaranteed that either fulfillHandler or rejectHandler is eventually called.
    381     // For example, if the page load is canceled, the DeferredPromise used in the module loader pipeline will stop executing JS code.
    382     // Thus the promise returned from this function could remain unresolved.
    383 
    384     RefPtr<LoadableModuleScript> moduleScript(&moduleScriptRef);
    385 
    386     auto& fulfillHandler = *JSNativeStdFunction::create(state.vm(), proxy.window(), 1, String(), [moduleScript](ExecState* exec) {
    387         Identifier moduleKey = jsValueToModuleKey(exec, exec->argument(0));
    388         moduleScript->notifyLoadCompleted(*moduleKey.impl());
    389         return JSValue::encode(jsUndefined());
    390     });
    391 
    392     auto& rejectHandler = *JSNativeStdFunction::create(state.vm(), proxy.window(), 1, String(), [moduleScript](ExecState* exec) {
    393         VM& vm = exec->vm();
    394         JSValue errorValue = exec->argument(0);
    395         if (errorValue.isObject()) {
    396             auto* object = JSC::asObject(errorValue);
    397             if (JSValue failureKindValue = object->getDirect(vm, static_cast<JSVMClientData&>(*vm.clientData).builtinNames().failureKindPrivateName())) {
    398                 // This is host propagated error in the module loader pipeline.
    399                 switch (static_cast<ModuleFetchFailureKind>(failureKindValue.asInt32())) {
    400                 case ModuleFetchFailureKind::WasErrored:
    401                     moduleScript->notifyLoadFailed(LoadableScript::Error {
    402                         LoadableScript::ErrorType::CachedScript,
    403                         std::nullopt
    404                     });
    405                     break;
    406                 case ModuleFetchFailureKind::WasCanceled:
    407                     moduleScript->notifyLoadWasCanceled();
    408                     break;
    409                 }
    410                 return JSValue::encode(jsUndefined());
    411             }
    412         }
    413 
    414         auto scope = DECLARE_CATCH_SCOPE(vm);
    415         moduleScript->notifyLoadFailed(LoadableScript::Error {
    416             LoadableScript::ErrorType::CachedScript,
    417             LoadableScript::ConsoleMessage {
    418                 MessageSource::JS,
    419                 MessageLevel::Error,
    420                 retrieveErrorMessage(*exec, vm, errorValue, scope),
    421             }
    422         });
    423         return JSValue::encode(jsUndefined());
    424     });
    425 
    426     promise.then(&state, &fulfillHandler, &rejectHandler);
    427361}
    428362
  • trunk/Source/WebCore/bindings/js/ScriptController.h

    r223237 r223744  
    183183private:
    184184    WEBCORE_EXPORT JSDOMWindowProxy* initScript(DOMWrapperWorld&);
    185     void setupModuleScriptHandlers(LoadableModuleScript&, JSC::JSInternalPromise&, DOMWrapperWorld&);
    186185
    187186    void disconnectPlatformScriptObjects();
  • trunk/Source/WebCore/dom/LoadableModuleScript.cpp

    r223728 r223744  
    2929#include "Document.h"
    3030#include "Frame.h"
     31#include "JSDOMExceptionHandling.h"
     32#include "ModuleFetchFailureKind.h"
    3133#include "ModuleFetchParameters.h"
    3234#include "ScriptController.h"
    3335#include "ScriptElement.h"
     36#include "WebCoreJSClientData.h"
     37#include <heap/StrongInlines.h>
     38#include <runtime/CatchScope.h>
    3439
    3540namespace WebCore {
     
    7075}
    7176
     77void LoadableModuleScript::notifyLoadFailed(JSC::ExecState* exec, JSC::JSValue errorValue)
     78{
     79    JSC::VM& vm = exec->vm();
     80    if (errorValue.isObject()) {
     81        auto* object = JSC::asObject(errorValue);
     82        if (JSC::JSValue failureKindValue = object->getDirect(vm, static_cast<JSVMClientData&>(*vm.clientData).builtinNames().failureKindPrivateName())) {
     83            // This is host propagated error in the module loader pipeline.
     84            switch (static_cast<ModuleFetchFailureKind>(failureKindValue.asInt32())) {
     85            case ModuleFetchFailureKind::WasErrored:
     86                notifyLoadFailed(LoadableScript::Error {
     87                    LoadableScript::ErrorType::CachedScript,
     88                    std::nullopt
     89                });
     90                break;
     91            case ModuleFetchFailureKind::WasCanceled:
     92                notifyLoadWasCanceled();
     93                break;
     94            }
     95            return;
     96        }
     97    }
     98
     99    auto scope = DECLARE_CATCH_SCOPE(vm);
     100    notifyLoadFailed(LoadableScript::Error {
     101        LoadableScript::ErrorType::CachedScript,
     102        LoadableScript::ConsoleMessage {
     103            MessageSource::JS,
     104            MessageLevel::Error,
     105            retrieveErrorMessage(*exec, vm, errorValue, scope),
     106        }
     107    });
     108}
     109
    72110void LoadableModuleScript::notifyLoadFailed(LoadableScript::Error&& error)
    73111{
  • trunk/Source/WebCore/dom/LoadableModuleScript.h

    r223237 r223744  
    5454    void load(Document&, const ScriptSourceCode&);
    5555
    56     void notifyLoadCompleted(UniquedStringImpl&);
    57     void notifyLoadFailed(LoadableScript::Error&&);
    58     void notifyLoadWasCanceled();
     56    UniquedStringImpl* moduleKey() const { return m_moduleKey.get(); }
    5957
    60     UniquedStringImpl* moduleKey() const { return m_moduleKey.get(); }
     58    void notifyLoadCompleted(UniquedStringImpl&) final;
     59    void notifyLoadFailed(JSC::ExecState*, JSC::JSValue) final;
    6160
    6261private:
    6362    LoadableModuleScript(const String& nonce, const String& integrity, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree);
     63
     64    void notifyLoadFailed(LoadableScript::Error&&);
     65    void notifyLoadWasCanceled();
    6466
    6567    Ref<ModuleFetchParameters> m_parameters;
Note: See TracChangeset for help on using the changeset viewer.