Ignore:
Timestamp:
Jan 22, 2021, 4:07:28 PM (5 years ago)
Author:
[email protected]
Message:

REGRESSION (r271731): Unchecked JS exception under GlobalObject::moduleLoaderFetch
https://bugs.webkit.org/show_bug.cgi?id=220868

Reviewed by Mark Lam.

Because TerminatedExecutionError needs to be uncaught, CatchScope's semantics does not work well.
So, we extend ThrowScope to implement CatchScope's feature, and use ThrowScope etc.
We also add JSPromise::rejectWithCaughtException since this pattern is common enough.

  • API/JSAPIGlobalObject.mm:

(JSC::JSAPIGlobalObject::moduleLoaderImportModule):
(JSC::JSAPIGlobalObject::moduleLoaderFetch):

  • jsc.cpp:

(GlobalObject::moduleLoaderImportModule):
(GlobalObject::moduleLoaderFetch):

  • runtime/Completion.cpp:

(JSC::rejectPromise):
(JSC::loadAndEvaluateModule):
(JSC::loadModule):

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::JSC_DEFINE_HOST_FUNCTION):

  • runtime/JSInternalPromise.cpp:

(JSC::JSInternalPromise::rejectWithCaughtException):

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

(JSC::JSModuleLoader::importModule):
(JSC::JSModuleLoader::resolve):
(JSC::JSModuleLoader::fetch):
(JSC::JSC_DEFINE_HOST_FUNCTION):
(JSC::reject): Deleted.

  • runtime/JSPromise.cpp:

(JSC::JSPromise::rejectWithCaughtException):

  • runtime/JSPromise.h:
  • runtime/ThrowScope.h:

(JSC::ThrowScope::clearException):

  • wasm/js/JSWebAssembly.cpp:

(JSC::JSC_DEFINE_HOST_FUNCTION):
(JSC::resolve):
(JSC::JSWebAssembly::webAssemblyModuleValidateAsync):
(JSC::instantiate):
(JSC::compileAndInstantiate):
(JSC::JSWebAssembly::webAssemblyModuleInstantinateAsync):
(JSC::reject): Deleted.
(JSC::webAssemblyModuleValidateAsyncInternal): Deleted.
(JSC::webAssemblyModuleInstantinateAsyncInternal): Deleted.

File:
1 edited

Legend:

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

    r271731 r271766  
    2727
    2828#include "CallFrame.h"
    29 #include "CatchScope.h"
    3029#include "IndirectEvalExecutable.h"
    3130#include "Interpreter.h"
     
    799798    auto* promise = JSPromise::create(vm, globalObject->promiseStructure());
    800799
    801     auto catchScope = DECLARE_CATCH_SCOPE(vm);
    802 
    803     auto reject = [&](Exception* exception) {
    804         if (UNLIKELY(isTerminatedExecutionException(vm, exception)))
    805             return promise;
    806         JSValue error = exception->value();
    807         catchScope.clearException();
    808         promise->reject(globalObject, error);
    809         return promise;
    810     };
     800    auto scope = DECLARE_THROW_SCOPE(vm);
    811801
    812802    auto sourceOrigin = callFrame->callerSourceOrigin(vm);
    813803    RELEASE_ASSERT(callFrame->argumentCount() == 1);
    814804    auto* specifier = callFrame->uncheckedArgument(0).toString(globalObject);
    815     if (Exception* exception = catchScope.exception())
    816         return JSValue::encode(reject(exception));
     805    RETURN_IF_EXCEPTION(scope, JSValue::encode(promise->rejectWithCaughtException(globalObject, scope)));
    817806
    818807    // We always specify parameters as undefined. Once dynamic import() starts accepting fetching parameters,
     
    820809    JSValue parameters = jsUndefined();
    821810    auto* internalPromise = globalObject->moduleLoader()->importModule(globalObject, specifier, parameters, sourceOrigin);
    822     if (Exception* exception = catchScope.exception())
    823         return JSValue::encode(reject(exception));
    824 
     811    RETURN_IF_EXCEPTION(scope, JSValue::encode(promise->rejectWithCaughtException(globalObject, scope)));
     812
     813    scope.release();
    825814    promise->resolve(globalObject, internalPromise);
    826815    return JSValue::encode(promise);
Note: See TracChangeset for help on using the changeset viewer.