Title: [271731] trunk
Revision
271731
Author
ysuz...@apple.com
Date
2021-01-21 18:51:26 -0800 (Thu, 21 Jan 2021)

Log Message

[JSC] JSPromise should not propagate TerminatedExecutionError
https://bugs.webkit.org/show_bug.cgi?id=220820
<rdar://problem/72929399>

Reviewed by Mark Lam.

JSTests:

* stress/terminated-execution-error-in-promise.js: Added.
(let.x.get toString):
(import.x.then):

Source/_javascript_Core:

TerminatedExecutionError is uncatcheable exception to finish JS execution as soon as possible.
We should not propagate TerminatedExecutionError in JSPromise's rejection.
In this patch, we do not reject promise if exception is TerminatedExecutionError.

* API/JSAPIGlobalObject.mm:
(JSC::JSAPIGlobalObject::moduleLoaderImportModule):
(JSC::JSAPIGlobalObject::moduleLoaderFetch):
* API/JSContext.mm:
(-[JSContext evaluateJSScript:]):
* jsc.cpp:
(GlobalObject::moduleLoaderImportModule):
(GlobalObject::moduleLoaderFetch):
(runWithOptions):
* runtime/Completion.cpp:
(JSC::rejectPromise):
(JSC::loadAndEvaluateModule):
(JSC::loadModule):
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* runtime/JSModuleLoader.cpp:
(JSC::reject):
(JSC::JSModuleLoader::importModule):
(JSC::JSModuleLoader::resolve):
(JSC::JSModuleLoader::fetch):
(JSC::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/JSWebAssembly.cpp:
(JSC::reject):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (271730 => 271731)


--- trunk/JSTests/ChangeLog	2021-01-22 02:48:17 UTC (rev 271730)
+++ trunk/JSTests/ChangeLog	2021-01-22 02:51:26 UTC (rev 271731)
@@ -1,3 +1,15 @@
+2021-01-21  Yusuke Suzuki  <ysuz...@apple.com>
+
+        [JSC] JSPromise should not propagate TerminatedExecutionError
+        https://bugs.webkit.org/show_bug.cgi?id=220820
+        <rdar://problem/72929399>
+
+        Reviewed by Mark Lam.
+
+        * stress/terminated-execution-error-in-promise.js: Added.
+        (let.x.get toString):
+        (import.x.then):
+
 2021-01-18  Yusuke Suzuki  <ysuz...@apple.com>
 
         [JSC] FTL::prepareOSREntry can clear OSR entry CodeBlock if it is already invalidated

Added: trunk/JSTests/stress/terminated-execution-error-in-promise.js (0 => 271731)


--- trunk/JSTests/stress/terminated-execution-error-in-promise.js	                        (rev 0)
+++ trunk/JSTests/stress/terminated-execution-error-in-promise.js	2021-01-22 02:51:26 UTC (rev 271731)
@@ -0,0 +1,10 @@
+//@ runDefault("--watchdog=100", "--watchdog-exception-ok")
+let x = {
+  get toString() {
+    while(1){}
+  }
+};
+
+import(x).then(()=>{}, function (error) {
+  error.__proto__ = undefined;
+});

Modified: trunk/Source/_javascript_Core/API/JSAPIGlobalObject.mm (271730 => 271731)


--- trunk/Source/_javascript_Core/API/JSAPIGlobalObject.mm	2021-01-22 02:48:17 UTC (rev 271730)
+++ trunk/Source/_javascript_Core/API/JSAPIGlobalObject.mm	2021-01-22 02:51:26 UTC (rev 271731)
@@ -135,13 +135,15 @@
 {
     VM& vm = globalObject->vm();
     auto scope = DECLARE_CATCH_SCOPE(vm);
-    auto reject = [&] (JSValue error) -> JSInternalPromise* {
+    auto reject = [&] (Exception* exception) -> JSInternalPromise* {
+        auto* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
+        if (UNLIKELY(isTerminatedExecutionException(vm, exception)))
+            return promise;
+        JSValue error = exception->value();
         scope.clearException();
-        auto* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
         // FIXME: We could have error since any JS call can throw stack-overflow errors.
         // https://bugs.webkit.org/show_bug.cgi?id=203402
         promise->reject(globalObject, error);
-        scope.clearException();
         return promise;
     };
 
@@ -148,21 +150,22 @@
     auto import = [&] (URL& url) {
         auto result = importModule(globalObject, Identifier::fromString(vm, url.string()), jsUndefined(), jsUndefined());
         if (UNLIKELY(scope.exception()))
-            return reject(scope.exception()->value());
+            return reject(scope.exception());
         return result;
     };
 
     auto specifier = specifierValue->value(globalObject);
-    if (UNLIKELY(scope.exception())) {
-        Exception* exception = scope.exception();
-        scope.clearException();
-        return reject(exception->value());
-    }
+    if (UNLIKELY(scope.exception()))
+        return reject(scope.exception());
 
     auto result = computeValidImportSpecifier(sourceOrigin.url(), specifier);
     if (result)
         return import(result.value());
-    return reject(createError(globalObject, result.error()));
+    auto* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
+    // FIXME: We could have error since any JS call can throw stack-overflow errors.
+    // https://bugs.webkit.org/show_bug.cgi?id=203402
+    promise->reject(globalObject, createError(globalObject, result.error()));
+    return promise;
 }
 
 JSInternalPromise* JSAPIGlobalObject::moduleLoaderFetch(JSGlobalObject* globalObject, JSModuleLoader*, JSValue key, JSValue, JSValue)
@@ -178,9 +181,10 @@
     Identifier moduleKey = key.toPropertyKey(globalObject);
     if (UNLIKELY(scope.exception())) {
         Exception* exception = scope.exception();
+        if (UNLIKELY(isTerminatedExecutionException(vm, exception)))
+            return promise;
         scope.clearException();
         promise->reject(globalObject, exception->value());
-        scope.clearException();
         return promise;
     }
 

Modified: trunk/Source/_javascript_Core/API/JSContext.mm (271730 => 271731)


--- trunk/Source/_javascript_Core/API/JSContext.mm	2021-01-22 02:48:17 UTC (rev 271730)
+++ trunk/Source/_javascript_Core/API/JSContext.mm	2021-01-22 02:51:26 UTC (rev 271731)
@@ -141,6 +141,8 @@
     if (scope.exception()) {
         JSValueRef exceptionValue = toRef(apiGlobalObject, scope.exception()->value());
         scope.clearException();
+        // FIXME: We should not clearException if it is TerminatedExecutionError.
+        // https://bugs.webkit.org/show_bug.cgi?id=220821
         return [JSValue valueWithNewPromiseRejectedWithReason:[JSValue valueWithJSValueRef:exceptionValue inContext:self] inContext:self];
     }
     return [JSValue valueWithJSValueRef:toRef(vm, result) inContext:self];

Modified: trunk/Source/_javascript_Core/ChangeLog (271730 => 271731)


--- trunk/Source/_javascript_Core/ChangeLog	2021-01-22 02:48:17 UTC (rev 271730)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-01-22 02:51:26 UTC (rev 271731)
@@ -1,3 +1,39 @@
+2021-01-21  Yusuke Suzuki  <ysuz...@apple.com>
+
+        [JSC] JSPromise should not propagate TerminatedExecutionError
+        https://bugs.webkit.org/show_bug.cgi?id=220820
+        <rdar://problem/72929399>
+
+        Reviewed by Mark Lam.
+
+        TerminatedExecutionError is uncatcheable exception to finish JS execution as soon as possible.
+        We should not propagate TerminatedExecutionError in JSPromise's rejection.
+        In this patch, we do not reject promise if exception is TerminatedExecutionError.
+
+        * API/JSAPIGlobalObject.mm:
+        (JSC::JSAPIGlobalObject::moduleLoaderImportModule):
+        (JSC::JSAPIGlobalObject::moduleLoaderFetch):
+        * API/JSContext.mm:
+        (-[JSContext evaluateJSScript:]):
+        * jsc.cpp:
+        (GlobalObject::moduleLoaderImportModule):
+        (GlobalObject::moduleLoaderFetch):
+        (runWithOptions):
+        * runtime/Completion.cpp:
+        (JSC::rejectPromise):
+        (JSC::loadAndEvaluateModule):
+        (JSC::loadModule):
+        * runtime/JSGlobalObjectFunctions.cpp:
+        (JSC::JSC_DEFINE_HOST_FUNCTION):
+        * runtime/JSModuleLoader.cpp:
+        (JSC::reject):
+        (JSC::JSModuleLoader::importModule):
+        (JSC::JSModuleLoader::resolve):
+        (JSC::JSModuleLoader::fetch):
+        (JSC::JSC_DEFINE_HOST_FUNCTION):
+        * wasm/js/JSWebAssembly.cpp:
+        (JSC::reject):
+
 2021-01-19  Yusuke Suzuki  <ysuz...@apple.com>
 
         Unreviewed, fix GCC warnings

Modified: trunk/Source/_javascript_Core/jsc.cpp (271730 => 271731)


--- trunk/Source/_javascript_Core/jsc.cpp	2021-01-22 02:48:17 UTC (rev 271730)
+++ trunk/Source/_javascript_Core/jsc.cpp	2021-01-22 02:51:26 UTC (rev 271731)
@@ -831,32 +831,39 @@
     auto* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
 
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
-    auto reject = [&] (JSValue rejectionReason) {
-        catchScope.clearException();
-        promise->reject(globalObject, rejectionReason);
-        catchScope.clearException();
+
+    auto rejectWithError = [&](JSValue error) {
+        promise->reject(globalObject, error);
         return promise;
     };
 
+    auto reject = [&](Exception* exception) {
+        if (UNLIKELY(isTerminatedExecutionException(vm, exception)))
+            return promise;
+        JSValue error = exception->value();
+        catchScope.clearException();
+        return rejectWithError(error);
+    };
+
     auto referrer = sourceOrigin.url();
     auto specifier = moduleNameValue->value(globalObject);
     RETURN_IF_EXCEPTION(throwScope, nullptr);
     if (UNLIKELY(catchScope.exception()))
-        return reject(catchScope.exception()->value());
+        return reject(catchScope.exception());
 
     if (!referrer.isLocalFile())
-        return reject(createError(globalObject, makeString("Could not resolve the referrer's path '", referrer.string(), "', while trying to resolve module '", specifier, "'.")));
+        return rejectWithError(createError(globalObject, makeString("Could not resolve the referrer's path '", referrer.string(), "', while trying to resolve module '", specifier, "'.")));
 
     if (!specifier.startsWith('/') && !specifier.startsWith("./") && !specifier.startsWith("../"))
-        return reject(createTypeError(globalObject, makeString("Module specifier, '"_s, specifier, "' does not start with \"/\", \"./\", or \"../\". Referenced from: "_s, referrer.fileSystemPath())));
+        return rejectWithError(createTypeError(globalObject, makeString("Module specifier, '"_s, specifier, "' does not start with \"/\", \"./\", or \"../\". Referenced from: "_s, referrer.fileSystemPath())));
 
     URL moduleURL(referrer, specifier);
     if (!moduleURL.isLocalFile())
-        return reject(createError(globalObject, makeString("Module url, '", moduleURL.string(), "' does not map to a local file.")));
+        return rejectWithError(createError(globalObject, makeString("Module url, '", moduleURL.string(), "' does not map to a local file.")));
 
     auto result = JSC::importModule(globalObject, Identifier::fromString(vm, moduleURL.string()), parameters, jsUndefined());
     if (UNLIKELY(catchScope.exception()))
-        return reject(catchScope.exception()->value());
+        return reject(catchScope.exception());
     return result;
 }
 
@@ -1175,16 +1182,23 @@
     JSInternalPromise* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
 
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
-    auto reject = [&] (JSValue rejectionReason) {
-        catchScope.clearException();
-        promise->reject(globalObject, rejectionReason);
-        catchScope.clearException();
+
+    auto rejectWithError = [&](JSValue error) {
+        promise->reject(globalObject, error);
         return promise;
     };
 
+    auto reject = [&](Exception* exception) {
+        if (UNLIKELY(isTerminatedExecutionException(vm, exception)))
+            return promise;
+        JSValue error = exception->value();
+        catchScope.clearException();
+        return rejectWithError(error);
+    };
+
     String moduleKey = key.toWTFString(globalObject);
     if (UNLIKELY(catchScope.exception()))
-        return reject(catchScope.exception()->value());
+        return reject(catchScope.exception());
 
     URL moduleURL({ }, moduleKey);
     ASSERT(moduleURL.isLocalFile());
@@ -1193,7 +1207,7 @@
 
     Vector<uint8_t> buffer;
     if (!fetchModuleFromLocalFileSystem(moduleURL, buffer))
-        return reject(createError(globalObject, makeString("Could not open file '", moduleKey, "'.")));
+        return rejectWithError(createError(globalObject, makeString("Could not open file '", moduleKey, "'.")));
 
 #if ENABLE(WEBASSEMBLY)
     // FileSystem does not have mime-type header. The JSC shell recognizes WebAssembly's magic header.
@@ -1204,7 +1218,6 @@
             auto sourceCode = JSSourceCode::create(vm, WTFMove(source));
             catchScope.releaseAssertNoException();
             promise->resolve(globalObject, sourceCode);
-            catchScope.clearException();
             return promise;
         }
     }
@@ -1213,7 +1226,6 @@
     auto sourceCode = JSSourceCode::create(vm, jscSource(stringFromUTF(buffer), SourceOrigin { moduleURL }, WTFMove(moduleKey), TextPosition(), SourceProviderSourceType::Module));
     catchScope.releaseAssertNoException();
     promise->resolve(globalObject, sourceCode);
-    catchScope.clearException();
     return promise;
 }
 
@@ -2999,8 +3011,8 @@
             if (!promise) {
                 // FIXME: This should use an absolute file URL https://bugs.webkit.org/show_bug.cgi?id=193077
                 promise = loadAndEvaluateModule(globalObject, jscSource(stringFromUTF(scriptBuffer), sourceOrigin, fileName, TextPosition(), SourceProviderSourceType::Module), jsUndefined());
+                RETURN_IF_EXCEPTION(scope, void());
             }
-            scope.clearException();
 
             JSFunction* fulfillHandler = JSNativeStdFunction::create(vm, globalObject, 1, String(), [&success, &options, isLastFile](JSGlobalObject* globalObject, CallFrame* callFrame) {
                 checkException(jsCast<GlobalObject*>(globalObject), isLastFile, false, callFrame->argument(0), options, success);

Modified: trunk/Source/_javascript_Core/runtime/Completion.cpp (271730 => 271731)


--- trunk/Source/_javascript_Core/runtime/Completion.cpp	2021-01-22 02:48:17 UTC (rev 271730)
+++ trunk/Source/_javascript_Core/runtime/Completion.cpp	2021-01-22 02:51:26 UTC (rev 271731)
@@ -176,15 +176,15 @@
     return Symbol::create(vm, privateName.uid());
 }
 
-static JSInternalPromise* rejectPromise(JSGlobalObject* globalObject)
+static JSInternalPromise* rejectPromise(CatchScope& scope, JSGlobalObject* globalObject)
 {
     VM& vm = globalObject->vm();
-    auto scope = DECLARE_CATCH_SCOPE(vm);
-    scope.assertNoException();
-    JSValue exception = scope.exception()->value();
+    JSInternalPromise* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
+    if (UNLIKELY(isTerminatedExecutionException(vm, scope.exception())))
+        return promise;
+    JSValue error = scope.exception()->value();
     scope.clearException();
-    JSInternalPromise* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
-    promise->reject(globalObject, exception);
+    promise->reject(globalObject, error);
     return promise;
 }
 
@@ -212,7 +212,7 @@
 {
     VM& vm = globalObject->vm();
     JSLockHolder lock(vm);
-    auto scope = DECLARE_THROW_SCOPE(vm);
+    auto scope = DECLARE_CATCH_SCOPE(vm);
     RELEASE_ASSERT(vm.atomStringTable() == Thread::current().atomStringTable());
     RELEASE_ASSERT(!vm.isCollectorBusyOnCurrentThread());
 
@@ -220,8 +220,7 @@
 
     // Insert the given source code to the ModuleLoader registry as the fetched registry entry.
     globalObject->moduleLoader()->provideFetch(globalObject, key, source);
-    RETURN_IF_EXCEPTION(scope, rejectPromise(globalObject));
-
+    RETURN_IF_EXCEPTION(scope, rejectPromise(scope, globalObject));
     return globalObject->moduleLoader()->loadAndEvaluateModule(globalObject, key, jsUndefined(), scriptFetcher);
 }
 
@@ -239,7 +238,7 @@
 {
     VM& vm = globalObject->vm();
     JSLockHolder lock(vm);
-    auto scope = DECLARE_THROW_SCOPE(vm);
+    auto scope = DECLARE_CATCH_SCOPE(vm);
     RELEASE_ASSERT(vm.atomStringTable() == Thread::current().atomStringTable());
     RELEASE_ASSERT(!vm.isCollectorBusyOnCurrentThread());
 
@@ -248,8 +247,7 @@
     // Insert the given source code to the ModuleLoader registry as the fetched registry entry.
     // FIXME: Introduce JSSourceCode object to wrap around this source.
     globalObject->moduleLoader()->provideFetch(globalObject, key, source);
-    RETURN_IF_EXCEPTION(scope, rejectPromise(globalObject));
-
+    RETURN_IF_EXCEPTION(scope, rejectPromise(scope, globalObject));
     return globalObject->moduleLoader()->loadModule(globalObject, key, jsUndefined(), scriptFetcher);
 }
 

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObjectFunctions.cpp (271730 => 271731)


--- trunk/Source/_javascript_Core/runtime/JSGlobalObjectFunctions.cpp	2021-01-22 02:48:17 UTC (rev 271730)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObjectFunctions.cpp	2021-01-22 02:51:26 UTC (rev 271731)
@@ -799,11 +799,14 @@
     auto* promise = JSPromise::create(vm, globalObject->promiseStructure());
 
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
-    auto reject = [&] (JSValue rejectionReason) {
+
+    auto reject = [&](Exception* exception) {
+        if (UNLIKELY(isTerminatedExecutionException(vm, exception)))
+            return promise;
+        JSValue error = exception->value();
         catchScope.clearException();
-        promise->reject(globalObject, rejectionReason);
-        catchScope.clearException();
-        return JSValue::encode(promise);
+        promise->reject(globalObject, error);
+        return promise;
     };
 
     auto sourceOrigin = callFrame->callerSourceOrigin(vm);
@@ -810,7 +813,7 @@
     RELEASE_ASSERT(callFrame->argumentCount() == 1);
     auto* specifier = callFrame->uncheckedArgument(0).toString(globalObject);
     if (Exception* exception = catchScope.exception())
-        return reject(exception->value());
+        return JSValue::encode(reject(exception));
 
     // We always specify parameters as undefined. Once dynamic import() starts accepting fetching parameters,
     // we should retrieve this from the arguments.
@@ -817,10 +820,9 @@
     JSValue parameters = jsUndefined();
     auto* internalPromise = globalObject->moduleLoader()->importModule(globalObject, specifier, parameters, sourceOrigin);
     if (Exception* exception = catchScope.exception())
-        return reject(exception->value());
+        return JSValue::encode(reject(exception));
+
     promise->resolve(globalObject, internalPromise);
-
-    catchScope.clearException();
     return JSValue::encode(promise);
 }
 

Modified: trunk/Source/_javascript_Core/runtime/JSModuleLoader.cpp (271730 => 271731)


--- trunk/Source/_javascript_Core/runtime/JSModuleLoader.cpp	2021-01-22 02:48:17 UTC (rev 271730)
+++ trunk/Source/_javascript_Core/runtime/JSModuleLoader.cpp	2021-01-22 02:51:26 UTC (rev 271731)
@@ -120,6 +120,18 @@
     return vm.propertyNames->emptyIdentifier.impl();
 }
 
+static JSInternalPromise* reject(JSGlobalObject* globalObject, CatchScope& catchScope, JSInternalPromise* promise)
+{
+    VM& vm = globalObject->vm();
+    Exception* exception = catchScope.exception();
+    ASSERT(exception);
+    if (UNLIKELY(isTerminatedExecutionException(vm, exception)))
+        return promise;
+    catchScope.clearException();
+    promise->reject(globalObject, exception->value());
+    return promise;
+}
+
 JSArray* JSModuleLoader::dependencyKeysIfEvaluated(JSGlobalObject* globalObject, JSValue key)
 {
     VM& vm = globalObject->vm();
@@ -244,24 +256,16 @@
     dataLogLnIf(Options::dumpModuleLoadingState(), "Loader [import] ", printableModuleKey(globalObject, moduleName));
 
     VM& vm = globalObject->vm();
-    auto throwScope = DECLARE_THROW_SCOPE(vm);
+    auto catchScope = DECLARE_CATCH_SCOPE(vm);
 
     if (globalObject->globalObjectMethodTable()->moduleLoaderImportModule)
-        RELEASE_AND_RETURN(throwScope, globalObject->globalObjectMethodTable()->moduleLoaderImportModule(globalObject, this, moduleName, parameters, referrer));
+        return globalObject->globalObjectMethodTable()->moduleLoaderImportModule(globalObject, this, moduleName, parameters, referrer);
 
     auto* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
-
-    auto catchScope = DECLARE_CATCH_SCOPE(vm);
-    auto moduleNameString = moduleName->value(globalObject);
-    if (UNLIKELY(catchScope.exception())) {
-        JSValue error = catchScope.exception()->value();
-        catchScope.clearException();
-        promise->reject(globalObject, error);
-        catchScope.clearException();
-        return promise;
-    }
+    String moduleNameString = moduleName->value(globalObject);
+    if (UNLIKELY(catchScope.exception()))
+        return reject(globalObject, catchScope, promise);
     promise->reject(globalObject, createError(globalObject, makeString("Could not import the module '", moduleNameString, "'.")));
-    catchScope.clearException();
     return promise;
 }
 
@@ -277,21 +281,13 @@
 JSInternalPromise* JSModuleLoader::resolve(JSGlobalObject* globalObject, JSValue name, JSValue referrer, JSValue scriptFetcher)
 {
     VM& vm = globalObject->vm();
+    auto catchScope = DECLARE_CATCH_SCOPE(vm);
 
     auto* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
-
-    auto catchScope = DECLARE_CATCH_SCOPE(vm);
-
     const Identifier moduleKey = resolveSync(globalObject, name, referrer, scriptFetcher);
-    if (UNLIKELY(catchScope.exception())) {
-        JSValue error = catchScope.exception()->value();
-        catchScope.clearException();
-        promise->reject(globalObject, error);
-        catchScope.clearException();
-        return promise;
-    }
+    if (UNLIKELY(catchScope.exception()))
+        return reject(globalObject, catchScope, promise);
     promise->resolve(globalObject, identifierToJSValue(vm, moduleKey));
-    catchScope.clearException();
     return promise;
 }
 
@@ -300,25 +296,16 @@
     dataLogLnIf(Options::dumpModuleLoadingState(), "Loader [fetch] ", printableModuleKey(globalObject, key));
 
     VM& vm = globalObject->vm();
-    auto throwScope = DECLARE_THROW_SCOPE(vm);
+    auto catchScope = DECLARE_CATCH_SCOPE(vm);
 
     if (globalObject->globalObjectMethodTable()->moduleLoaderFetch)
-        RELEASE_AND_RETURN(throwScope, globalObject->globalObjectMethodTable()->moduleLoaderFetch(globalObject, this, key, parameters, scriptFetcher));
+        return globalObject->globalObjectMethodTable()->moduleLoaderFetch(globalObject, this, key, parameters, scriptFetcher);
 
     auto* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
-
-    auto catchScope = DECLARE_CATCH_SCOPE(vm);
-
     String moduleKey = key.toWTFString(globalObject);
-    if (UNLIKELY(catchScope.exception())) {
-        JSValue error = catchScope.exception()->value();
-        catchScope.clearException();
-        promise->reject(globalObject, error);
-        catchScope.clearException();
-        return promise;
-    }
+    if (UNLIKELY(catchScope.exception()))
+        return reject(globalObject, catchScope, promise);
     promise->reject(globalObject, createError(globalObject, makeString("Could not open the module '", moduleKey, "'.")));
-    catchScope.clearException();
     return promise;
 }
 
@@ -369,16 +356,15 @@
     auto* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
 
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
-    auto reject = [&] (JSValue rejectionReason) {
-        catchScope.clearException();
-        promise->reject(globalObject, rejectionReason);
-        catchScope.clearException();
-        return JSValue::encode(promise);
+
+    auto rejectWithError = [&](JSValue error) {
+        promise->reject(globalObject, error);
+        return promise;
     };
 
     const Identifier moduleKey = callFrame->argument(0).toPropertyKey(globalObject);
     if (UNLIKELY(catchScope.exception()))
-        return reject(catchScope.exception()->value());
+        return JSValue::encode(reject(globalObject, catchScope, promise));
 
     JSValue source = callFrame->argument(1);
     auto* jsSourceCode = jsCast<JSSourceCode*>(source);
@@ -394,12 +380,12 @@
         vm, sourceCode, Identifier(), JSParserBuiltinMode::NotBuiltin,
         JSParserStrictMode::Strict, JSParserScriptMode::Module, SourceParseMode::ModuleAnalyzeMode, SuperBinding::NotNeeded, error);
     if (error.isValid())
-        return reject(error.toErrorObject(globalObject, sourceCode));
+        return JSValue::encode(rejectWithError(error.toErrorObject(globalObject, sourceCode)));
     ASSERT(moduleProgramNode);
 
     ModuleAnalyzer moduleAnalyzer(globalObject, moduleKey, sourceCode, moduleProgramNode->varDeclarations(), moduleProgramNode->lexicalVariables());
     if (UNLIKELY(catchScope.exception()))
-        return reject(catchScope.exception()->value());
+        return JSValue::encode(reject(globalObject, catchScope, promise));
 
     promise->resolve(globalObject, moduleAnalyzer.analyze(*moduleProgramNode));
     catchScope.clearException();

Modified: trunk/Source/_javascript_Core/wasm/js/JSWebAssembly.cpp (271730 => 271731)


--- trunk/Source/_javascript_Core/wasm/js/JSWebAssembly.cpp	2021-01-22 02:48:17 UTC (rev 271730)
+++ trunk/Source/_javascript_Core/wasm/js/JSWebAssembly.cpp	2021-01-22 02:51:26 UTC (rev 271731)
@@ -121,11 +121,13 @@
 
 static void reject(JSGlobalObject* globalObject, CatchScope& catchScope, JSPromise* promise)
 {
+    VM& vm = globalObject->vm();
     Exception* exception = catchScope.exception();
     ASSERT(exception);
+    if (UNLIKELY(isTerminatedExecutionException(vm, exception)))
+        return;
     catchScope.clearException();
     promise->reject(globalObject, exception->value());
-    CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, void());
 }
 
 static void webAssemblyModuleValidateAsyncInternal(JSGlobalObject* globalObject, JSPromise* promise, Vector<uint8_t>&& source)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to