Title: [275648] trunk/Source
Revision
275648
Author
[email protected]
Date
2021-04-07 17:30:15 -0700 (Wed, 07 Apr 2021)

Log Message

Rename and make the TerminationException a singleton.
https://bugs.webkit.org/show_bug.cgi?id=224295

Reviewed by Keith Miller.

Source/_javascript_Core:

We previously call it the TerminatedExecutionException, which is a mouthful but
adds no meaningful information.  It's now renamed to TerminationException.

We can make it a singleton because the TerminationException is just a VM internal
mechanism for implementing the termination of the current execution stack.  It
should never be exposed to user JS code, and therefore, there is no value in
making it a JS object.  Making it a singleton simplifies the code.

A TerminationException is now implemented as an Exception cell which holds a
Symbol with the name "TerminationError".  The TerminationException is only created
if needed e.g. if the JSC watchdog is created, or if the VM is for a Worker thread
which needs to be able to handle termination requests.

We'll also stop notifying the debugger when we throw the TerminationException.
This is because the TerminationException is not like ordinary exceptions that
should be reported to the debugger. The fact that the TerminationException uses
the exception handling mechanism is just a VM internal implementation detail.
It is not meaningful to report it to the debugger as an exception.

* API/JSContext.mm:
(-[JSContext evaluateJSScript:]):
* API/tests/ExecutionTimeLimitTest.cpp:
(testExecutionTimeLimit):
* bindings/ScriptFunctionCall.cpp:
(Deprecated::ScriptFunctionCall::call):
* heap/Heap.cpp:
(JSC::Heap::addCoreConstraints):
* inspector/InjectedScriptManager.cpp:
(Inspector::InjectedScriptManager::injectedScriptFor):
* inspector/JSGlobalObjectInspectorController.cpp:
(Inspector::JSGlobalObjectInspectorController::reportAPIException):
* interpreter/Interpreter.cpp:
(JSC::Interpreter::unwind):
(JSC::Interpreter::notifyDebuggerOfExceptionToBeThrown):
* jit/JITOperations.cpp:
(JSC::JSC_DEFINE_JIT_OPERATION):
* jsc.cpp:
(checkException):
* llint/LLIntSlowPaths.cpp:
(JSC::LLInt::LLINT_SLOW_PATH_DECL):
* runtime/ExceptionHelpers.cpp:
(JSC::TerminatedExecutionError::defaultValue): Deleted.
(JSC::createTerminatedExecutionException): Deleted.
(JSC::isTerminatedExecutionException): Deleted.
(JSC::throwTerminatedExecutionException): Deleted.
* runtime/ExceptionHelpers.h:
(): Deleted.
* runtime/JSObject.h:
(JSC::JSObject::get const):
* runtime/JSPromise.cpp:
(JSC::JSPromise::rejectWithCaughtException):
* runtime/VM.cpp:
(JSC::VM::VM):
(JSC::VM::ensureWatchdog):
(JSC::VM::ensureTerminationException):
(JSC::VM::throwTerminationException):
(JSC::VM::throwException):
* runtime/VM.h:
(JSC::VM::terminationException const):
(JSC::VM::isTerminationException const):
* runtime/VMTraps.cpp:
(JSC::VMTraps::handleTraps):

Source/WebCore:

In the WorkerOrWorkletScriptController constructor, we ensure the TerminationException
because workers need to support termination requests.

* bindings/js/JSDOMExceptionHandling.cpp:
(WebCore::reportException):
* bindings/js/JSDOMGlobalObject.cpp:
(WebCore::JSC_DEFINE_HOST_FUNCTION):
(WebCore::handleResponseOnStreamingAction):
* bindings/js/JSDOMPromise.cpp:
(WebCore::DOMPromise::whenPromiseIsSettled):
* bindings/js/JSDOMPromiseDeferred.cpp:
(WebCore::DeferredPromise::reject):
* bindings/js/JSEventListener.cpp:
(WebCore::JSEventListener::handleEvent):
* bindings/js/ReadableStream.cpp:
(WebCore::invokeReadableStreamFunction):
(WebCore::ReadableStream::lock):
(WebCore::checkReadableStream):
* bindings/js/ReadableStreamDefaultController.cpp:
(WebCore::invokeReadableStreamDefaultControllerFunction):
(WebCore::ReadableStreamDefaultController::error):
(WebCore::ReadableStreamDefaultController::enqueue):
* workers/WorkerOrWorkletScriptController.cpp:
(WebCore::WorkerOrWorkletScriptController::WorkerOrWorkletScriptController):
(WebCore::WorkerOrWorkletScriptController::evaluate):
(WebCore::WorkerOrWorkletScriptController::linkAndEvaluateModule):
(WebCore::WorkerOrWorkletScriptController::loadAndEvaluateModule):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/JSContext.mm (275647 => 275648)


--- trunk/Source/_javascript_Core/API/JSContext.mm	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/API/JSContext.mm	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013-2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -140,7 +140,7 @@
     if (scope.exception()) {
         JSValueRef exceptionValue = toRef(apiGlobalObject, scope.exception()->value());
         scope.clearException();
-        // FIXME: We should not clearException if it is TerminatedExecutionError.
+        // FIXME: We should not clearException if it is the TerminationException.
         // https://bugs.webkit.org/show_bug.cgi?id=220821
         return [JSValue valueWithNewPromiseRejectedWithReason:[JSValue valueWithJSValueRef:exceptionValue inContext:self] inContext:self];
     }

Modified: trunk/Source/_javascript_Core/API/tests/ExecutionTimeLimitTest.cpp (275647 => 275648)


--- trunk/Source/_javascript_Core/API/tests/ExecutionTimeLimitTest.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/API/tests/ExecutionTimeLimitTest.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -179,7 +179,7 @@
             }
 
             if (!exception) {
-                printf("FAIL: %s TerminatedExecutionException was not thrown.\n", tierOptions.tier);
+                printf("FAIL: %s TerminationException was not thrown.\n", tierOptions.tier);
                 exit(1);
             }
 
@@ -225,7 +225,7 @@
             }
             
             if (!exception) {
-                printf("FAIL: %s TerminatedExecutionException was not thrown.\n", tierOptions.tier);
+                printf("FAIL: %s TerminationException was not thrown.\n", tierOptions.tier);
                 failed = true;
             }
 
@@ -268,7 +268,7 @@
             }
             
             if (!exception) {
-                printf("FAIL: %s TerminatedExecutionException was not thrown.\n", tierOptions.tier);
+                printf("FAIL: %s TerminationException was not thrown.\n", tierOptions.tier);
                 failed = true;
             }
 
@@ -275,7 +275,7 @@
             testResetAfterTimeout(failed);
         }
 
-        /* Test the script timeout's TerminatedExecutionException should NOT be catchable: */
+        /* Test the script timeout's TerminationException should NOT be catchable: */
         timeLimit = 100_ms + tierAdjustment;
         JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit.seconds(), shouldTerminateCallback, nullptr);
         {
@@ -313,9 +313,9 @@
             }
             
             if (exception)
-                printf("PASS: %s TerminatedExecutionException was not catchable as expected.\n", tierOptions.tier);
+                printf("PASS: %s TerminationException was not catchable as expected.\n", tierOptions.tier);
             else {
-                printf("FAIL: %s TerminatedExecutionException was caught.\n", tierOptions.tier);
+                printf("FAIL: %s TerminationException was caught.\n", tierOptions.tier);
                 failed = true;
             }
 
@@ -360,7 +360,7 @@
             }
             
             if (!exception) {
-                printf("FAIL: %s TerminatedExecutionException was not thrown.\n", tierOptions.tier);
+                printf("FAIL: %s TerminationException was not thrown.\n", tierOptions.tier);
                 failed = true;
             }
 
@@ -405,7 +405,7 @@
             }
             
             if (exception) {
-                printf("FAIL: %s Unexpected TerminatedExecutionException thrown.\n", tierOptions.tier);
+                printf("FAIL: %s Unexpected TerminationException thrown.\n", tierOptions.tier);
                 failed = true;
             }
         }
@@ -454,7 +454,7 @@
                     printf("FAIL: %s script timeout callback was not called after timeout extension.\n", tierOptions.tier);
                 
                 if (!exception)
-                    printf("FAIL: %s TerminatedExecutionException was not thrown during timeout extension test.\n", tierOptions.tier);
+                    printf("FAIL: %s TerminationException was not thrown during timeout extension test.\n", tierOptions.tier);
                 
                 failed = true;
             }

Modified: trunk/Source/_javascript_Core/ChangeLog (275647 => 275648)


--- trunk/Source/_javascript_Core/ChangeLog	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,3 +1,73 @@
+2021-04-07  Mark Lam  <[email protected]>
+
+        Rename and make the TerminationException a singleton.
+        https://bugs.webkit.org/show_bug.cgi?id=224295
+
+        Reviewed by Keith Miller.
+
+        We previously call it the TerminatedExecutionException, which is a mouthful but
+        adds no meaningful information.  It's now renamed to TerminationException.
+
+        We can make it a singleton because the TerminationException is just a VM internal
+        mechanism for implementing the termination of the current execution stack.  It
+        should never be exposed to user JS code, and therefore, there is no value in
+        making it a JS object.  Making it a singleton simplifies the code.
+
+        A TerminationException is now implemented as an Exception cell which holds a
+        Symbol with the name "TerminationError".  The TerminationException is only created
+        if needed e.g. if the JSC watchdog is created, or if the VM is for a Worker thread
+        which needs to be able to handle termination requests.
+
+        We'll also stop notifying the debugger when we throw the TerminationException.
+        This is because the TerminationException is not like ordinary exceptions that
+        should be reported to the debugger. The fact that the TerminationException uses
+        the exception handling mechanism is just a VM internal implementation detail.
+        It is not meaningful to report it to the debugger as an exception.
+
+        * API/JSContext.mm:
+        (-[JSContext evaluateJSScript:]):
+        * API/tests/ExecutionTimeLimitTest.cpp:
+        (testExecutionTimeLimit):
+        * bindings/ScriptFunctionCall.cpp:
+        (Deprecated::ScriptFunctionCall::call):
+        * heap/Heap.cpp:
+        (JSC::Heap::addCoreConstraints):
+        * inspector/InjectedScriptManager.cpp:
+        (Inspector::InjectedScriptManager::injectedScriptFor):
+        * inspector/JSGlobalObjectInspectorController.cpp:
+        (Inspector::JSGlobalObjectInspectorController::reportAPIException):
+        * interpreter/Interpreter.cpp:
+        (JSC::Interpreter::unwind):
+        (JSC::Interpreter::notifyDebuggerOfExceptionToBeThrown):
+        * jit/JITOperations.cpp:
+        (JSC::JSC_DEFINE_JIT_OPERATION):
+        * jsc.cpp:
+        (checkException):
+        * llint/LLIntSlowPaths.cpp:
+        (JSC::LLInt::LLINT_SLOW_PATH_DECL):
+        * runtime/ExceptionHelpers.cpp:
+        (JSC::TerminatedExecutionError::defaultValue): Deleted.
+        (JSC::createTerminatedExecutionException): Deleted.
+        (JSC::isTerminatedExecutionException): Deleted.
+        (JSC::throwTerminatedExecutionException): Deleted.
+        * runtime/ExceptionHelpers.h:
+        (): Deleted.
+        * runtime/JSObject.h:
+        (JSC::JSObject::get const):
+        * runtime/JSPromise.cpp:
+        (JSC::JSPromise::rejectWithCaughtException):
+        * runtime/VM.cpp:
+        (JSC::VM::VM):
+        (JSC::VM::ensureWatchdog):
+        (JSC::VM::ensureTerminationException):
+        (JSC::VM::throwTerminationException):
+        (JSC::VM::throwException):
+        * runtime/VM.h:
+        (JSC::VM::terminationException const):
+        (JSC::VM::isTerminationException const):
+        * runtime/VMTraps.cpp:
+        (JSC::VMTraps::handleTraps):
+
 2021-04-07  Yusuke Suzuki  <[email protected]>
 
         [JSC] Use FixedVector more in bytecode dir and JumpTable

Modified: trunk/Source/_javascript_Core/bindings/ScriptFunctionCall.cpp (275647 => 275648)


--- trunk/Source/_javascript_Core/bindings/ScriptFunctionCall.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/bindings/ScriptFunctionCall.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013-2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2021 Apple Inc. All rights reserved.
  * Copyright (C) 2009 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -127,7 +127,7 @@
 
     if (exception) {
         // Do not treat a terminated execution exception as having an exception. Just treat it as an empty result.
-        if (!isTerminatedExecutionException(vm, exception))
+        if (!vm.isTerminationException(exception))
             return makeUnexpected(exception);
         return { };
     }

Modified: trunk/Source/_javascript_Core/heap/Heap.cpp (275647 => 275648)


--- trunk/Source/_javascript_Core/heap/Heap.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/heap/Heap.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -2817,6 +2817,12 @@
                 SetRootMarkReasonScope rootScope(visitor, RootMarkReason::VMExceptions);
                 visitor.appendUnbarriered(m_vm.exception());
                 visitor.appendUnbarriered(m_vm.lastException());
+
+                // We're going to m_terminationException directly instead of going through
+                // the exception() getter because we want to assert in the getter that the
+                // TerminationException has been reified. Here, we don't care if it is
+                // reified or not.
+                visitor.appendUnbarriered(m_vm.m_terminationException);
             }
         })),
         ConstraintVolatility::GreyedByExecution);

Modified: trunk/Source/_javascript_Core/inspector/InjectedScriptManager.cpp (275647 => 275648)


--- trunk/Source/_javascript_Core/inspector/InjectedScriptManager.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/inspector/InjectedScriptManager.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2021 Apple Inc. All rights reserved.
  * Copyright (C) 2008 Matt Lilek <[email protected]>
  * Copyright (C) 2012 Google Inc. All rights reserved.
  *
@@ -188,7 +188,7 @@
         auto& error = createResult.error();
         ASSERT(error);
 
-        if (isTerminatedExecutionException(globalObject->vm(), error))
+        if (globalObject->vm().isTerminationException(error))
             return InjectedScript();
 
         unsigned line = 0;

Modified: trunk/Source/_javascript_Core/inspector/JSGlobalObjectInspectorController.cpp (275647 => 275648)


--- trunk/Source/_javascript_Core/inspector/JSGlobalObjectInspectorController.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/inspector/JSGlobalObjectInspectorController.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -172,7 +172,7 @@
 void JSGlobalObjectInspectorController::reportAPIException(JSGlobalObject* globalObject, Exception* exception)
 {
     VM& vm = globalObject->vm();
-    if (isTerminatedExecutionException(vm, exception))
+    if (vm.isTerminationException(exception))
         return;
 
     auto scope = DECLARE_CATCH_SCOPE(vm);

Modified: trunk/Source/_javascript_Core/interpreter/Interpreter.cpp (275647 => 275648)


--- trunk/Source/_javascript_Core/interpreter/Interpreter.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/interpreter/Interpreter.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2008-2021 Apple Inc. All rights reserved.
  * Copyright (C) 2008 Cameron Zwarich <[email protected]>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -607,7 +607,7 @@
 
     // Calculate an exception handler vPC, unwinding call frames as necessary.
     HandlerInfo* handler = nullptr;
-    UnwindFunctor functor(vm, callFrame, isTerminatedExecutionException(vm, exception), codeBlock, handler);
+    UnwindFunctor functor(vm, callFrame, vm.isTerminationException(exception), codeBlock, handler);
     StackVisitor::visit<StackVisitor::TerminateIfTopEntryFrameIsEmpty>(callFrame, vm, functor);
     if (vm.hasCheckpointOSRSideState())
         vm.popAllCheckpointOSRSideStateUntil(callFrame);
@@ -620,6 +620,8 @@
 
 void Interpreter::notifyDebuggerOfExceptionToBeThrown(VM& vm, JSGlobalObject* globalObject, CallFrame* callFrame, Exception* exception)
 {
+    ASSERT(!vm.isTerminationException(exception));
+
     Debugger* debugger = globalObject->debugger();
     if (debugger && debugger->needsExceptionCallbacks() && !exception->didNotifyInspectorOfThrow()) {
         // This code assumes that if the debugger is enabled then there is no inlining.
@@ -627,17 +629,11 @@
         // frames.
         // https://bugs.webkit.org/show_bug.cgi?id=121754
 
-        bool hasCatchHandler;
-        bool isTermination = isTerminatedExecutionException(vm, exception);
-        if (isTermination)
-            hasCatchHandler = false;
-        else {
-            GetCatchHandlerFunctor functor;
-            StackVisitor::visit(callFrame, vm, functor);
-            HandlerInfo* handler = functor.handler();
-            ASSERT(!handler || handler->isCatchHandler());
-            hasCatchHandler = !!handler;
-        }
+        GetCatchHandlerFunctor functor;
+        StackVisitor::visit(callFrame, vm, functor);
+        HandlerInfo* handler = functor.handler();
+        ASSERT(!handler || handler->isCatchHandler());
+        bool hasCatchHandler = !!handler;
 
         debugger->exception(globalObject, callFrame, exception->value(), hasCatchHandler);
     }

Modified: trunk/Source/_javascript_Core/jit/JITOperations.cpp (275647 => 275648)


--- trunk/Source/_javascript_Core/jit/JITOperations.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/jit/JITOperations.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -3519,7 +3519,7 @@
     auto scope = DECLARE_THROW_SCOPE(vm);
     RELEASE_ASSERT(!!scope.exception());
 
-    if (isTerminatedExecutionException(vm, scope.exception())) {
+    if (vm.isTerminationException(scope.exception())) {
         genericUnwind(vm, callFrame);
         return 1;
     }

Modified: trunk/Source/_javascript_Core/jsc.cpp (275647 => 275648)


--- trunk/Source/_javascript_Core/jsc.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/jsc.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -2940,7 +2940,21 @@
 {
     VM& vm = globalObject->vm();
 
-    if (options.m_treatWatchdogExceptionAsSuccess && value.inherits<TerminatedExecutionError>(vm)) {
+    auto isTerminationException = [&] (JSValue value) {
+        if (!value.isCell())
+            return false;
+
+        JSCell* valueCell = value.asCell();
+        vm.ensureTerminationException();
+        Exception* terminationException = vm.terminationException();
+        Exception* exception = jsDynamicCast<Exception*>(vm, valueCell);
+        if (exception)
+            return vm.isTerminationException(exception);
+        JSCell* terminationError = terminationException->value().asCell();
+        return valueCell == terminationError;
+    };
+
+    if (options.m_treatWatchdogExceptionAsSuccess && isTerminationException(value)) {
         ASSERT(hasException);
         return;
     }

Modified: trunk/Source/_javascript_Core/llint/LLIntSlowPaths.cpp (275647 => 275648)


--- trunk/Source/_javascript_Core/llint/LLIntSlowPaths.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/llint/LLIntSlowPaths.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2011-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -2188,7 +2188,7 @@
     UNUSED_PARAM(globalObject);
     RELEASE_ASSERT(!!throwScope.exception());
 
-    if (isTerminatedExecutionException(vm, throwScope.exception()))
+    if (vm.isTerminationException(throwScope.exception()))
         LLINT_RETURN_TWO(pc, bitwise_cast<void*>(static_cast<uintptr_t>(1)));
     LLINT_RETURN_TWO(pc, nullptr);
 }

Modified: trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp (275647 => 275648)


--- trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -39,30 +39,6 @@
 
 namespace JSC {
 
-STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(TerminatedExecutionError);
-
-const ClassInfo TerminatedExecutionError::s_info = { "TerminatedExecutionError", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(TerminatedExecutionError) };
-
-JSValue TerminatedExecutionError::defaultValue(const JSObject*, JSGlobalObject* globalObject, PreferredPrimitiveType hint)
-{
-    if (hint == PreferString)
-        return jsNontrivialString(globalObject->vm(), String("_javascript_ execution terminated."_s));
-    return JSValue(PNaN);
-}
-
-JSObject* createTerminatedExecutionException(VM* vm)
-{
-    return TerminatedExecutionError::create(*vm);
-}
-
-bool isTerminatedExecutionException(VM& vm, Exception* exception)
-{
-    if (!exception->value().isObject())
-        return false;
-
-    return exception->value().inherits<TerminatedExecutionError>(vm);
-}
-
 JSObject* createStackOverflowError(JSGlobalObject* globalObject)
 {
     auto* error = createRangeError(globalObject, "Maximum call stack size exceeded."_s);
@@ -385,11 +361,4 @@
     return throwException(globalObject, scope, createStackOverflowError(globalObject));
 }
 
-Exception* throwTerminatedExecutionException(JSGlobalObject* globalObject, ThrowScope& scope)
-{
-    VM& vm = globalObject->vm();
-    ErrorHandlingScope errorScope(vm);
-    return throwException(globalObject, scope, createTerminatedExecutionException(&vm));
-}
-
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/runtime/ExceptionHelpers.h (275647 => 275648)


--- trunk/Source/_javascript_Core/runtime/ExceptionHelpers.h	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/runtime/ExceptionHelpers.h	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2008-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -39,8 +39,6 @@
 
 String defaultSourceAppender(const String&, const String&, RuntimeType, ErrorInstance::SourceTextWhereErrorOccurred);
 
-JSObject* createTerminatedExecutionException(VM*);
-JS_EXPORT_PRIVATE bool isTerminatedExecutionException(VM&, Exception*);
 JS_EXPORT_PRIVATE JSObject* createError(JSGlobalObject*, JSValue, const String&, ErrorInstance::SourceAppender);
 JS_EXPORT_PRIVATE JSObject* createStackOverflowError(JSGlobalObject*);
 JSObject* createUndefinedVariableError(JSGlobalObject*, const Identifier&);
@@ -61,43 +59,5 @@
 JS_EXPORT_PRIVATE Exception* throwOutOfMemoryError(JSGlobalObject*, ThrowScope&);
 JS_EXPORT_PRIVATE Exception* throwOutOfMemoryError(JSGlobalObject*, ThrowScope&, const String&);
 JS_EXPORT_PRIVATE Exception* throwStackOverflowError(JSGlobalObject*, ThrowScope&);
-JS_EXPORT_PRIVATE Exception* throwTerminatedExecutionException(JSGlobalObject*, ThrowScope&);
 
-
-class TerminatedExecutionError final : public JSNonFinalObject {
-public:
-    using Base = JSNonFinalObject;
-    static constexpr unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
-
-    template<typename CellType, SubspaceAccess>
-    static IsoSubspace* subspaceFor(VM& vm)
-    {
-        STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(TerminatedExecutionError, Base);
-        return &vm.plainObjectSpace;
-    }
-
-    static TerminatedExecutionError* create(VM& vm)
-    {
-        TerminatedExecutionError* error = new (NotNull, allocateCell<TerminatedExecutionError>(vm.heap)) TerminatedExecutionError(vm);
-        error->finishCreation(vm);
-        return error;
-    }
-
-    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
-    {
-        return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
-    }
-
-    DECLARE_EXPORT_INFO;
-
-private:
-    explicit TerminatedExecutionError(VM& vm)
-        : JSNonFinalObject(vm, vm.terminatedExecutionErrorStructure.get())
-    {
-    }
-
-    static JSValue defaultValue(const JSObject*, JSGlobalObject*, PreferredPrimitiveType);
-
-};
-
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/runtime/JSObject.h (275647 => 275648)


--- trunk/Source/_javascript_Core/runtime/JSObject.h	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/runtime/JSObject.h	2021-04-08 00:30:15 UTC (rev 275648)
@@ -73,7 +73,6 @@
 struct HashTable;
 struct HashTableValue;
 
-JS_EXPORT_PRIVATE bool isTerminatedExecutionException(VM&, Exception*);
 JS_EXPORT_PRIVATE Exception* throwTypeError(JSGlobalObject*, ThrowScope&, const String&);
 extern JS_EXPORT_PRIVATE const ASCIILiteral NonExtensibleObjectPropertyDefineError;
 extern JS_EXPORT_PRIVATE const ASCIILiteral ReadonlyPropertyWriteError;
@@ -1497,7 +1496,7 @@
     PropertySlot slot(this, PropertySlot::InternalMethodType::Get);
     bool hasProperty = const_cast<JSObject*>(this)->getPropertySlot(globalObject, propertyName, slot);
 
-    EXCEPTION_ASSERT(!scope.exception() || isTerminatedExecutionException(vm, scope.exception()) || !hasProperty);
+    EXCEPTION_ASSERT(!scope.exception() || vm.isTerminationException(scope.exception()) || !hasProperty);
     RETURN_IF_EXCEPTION(scope, jsUndefined());
 
     if (hasProperty)
@@ -1513,7 +1512,7 @@
     PropertySlot slot(this, PropertySlot::InternalMethodType::Get);
     bool hasProperty = const_cast<JSObject*>(this)->getPropertySlot(globalObject, propertyName, slot);
 
-    EXCEPTION_ASSERT(!scope.exception() || isTerminatedExecutionException(vm, scope.exception()) || !hasProperty);
+    EXCEPTION_ASSERT(!scope.exception() || vm.isTerminationException(scope.exception()) || !hasProperty);
     RETURN_IF_EXCEPTION(scope, jsUndefined());
 
     if (hasProperty)

Modified: trunk/Source/_javascript_Core/runtime/JSPromise.cpp (275647 => 275648)


--- trunk/Source/_javascript_Core/runtime/JSPromise.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/runtime/JSPromise.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -228,7 +228,7 @@
     VM& vm = globalObject->vm();
     Exception* exception = scope.exception();
     ASSERT(exception);
-    if (UNLIKELY(isTerminatedExecutionException(vm, exception))) {
+    if (UNLIKELY(vm.isTerminationException(exception))) {
         scope.release();
         return this;
     }

Modified: trunk/Source/_javascript_Core/runtime/VM.cpp (275647 => 275648)


--- trunk/Source/_javascript_Core/runtime/VM.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/runtime/VM.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -432,7 +432,6 @@
     smallStrings.initializeCommonStrings(*this);
 
     propertyNames = new CommonIdentifiers(*this);
-    terminatedExecutionErrorStructure.set(*this, TerminatedExecutionError::createStructure(*this, nullptr, jsNull()));
     propertyNameEnumeratorStructure.set(*this, JSPropertyNameEnumerator::createStructure(*this, nullptr, jsNull()));
     getterSetterStructure.set(*this, GetterSetter::createStructure(*this, nullptr, jsNull()));
     customGetterSetterStructure.set(*this, CustomGetterSetter::createStructure(*this, nullptr, jsNull()));
@@ -741,8 +740,10 @@
 
 Watchdog& VM::ensureWatchdog()
 {
-    if (!m_watchdog)
+    if (!m_watchdog) {
         m_watchdog = adoptRef(new Watchdog(this));
+        ensureTerminationException();
+    }
     return *m_watchdog;
 }
 
@@ -762,6 +763,17 @@
 }
 #endif // ENABLE(SAMPLING_PROFILER)
 
+static SymbolImpl::StaticSymbolImpl terminationErrorSymbol { "TerminationError", SymbolImpl::s_flagIsPrivate };
+
+Exception* VM::ensureTerminationException()
+{
+    if (!m_terminationException) {
+        Symbol* terminationError = Symbol::create(*this, terminationErrorSymbol);
+        m_terminationException = Exception::create(*this, terminationError, Exception::DoNotCaptureStack);
+    }
+    return m_terminationException;
+}
+
 #if ENABLE(JIT)
 static ThunkGenerator thunkGeneratorForIntrinsic(Intrinsic intrinsic)
 {
@@ -946,8 +958,25 @@
     sourceProviderCacheMap.clear();
 }
 
-Exception* VM::throwException(JSGlobalObject* globalObject, Exception* exception)
+void VM::throwTerminationException()
 {
+    setException(terminationException());
+}
+
+Exception* VM::throwException(JSGlobalObject* globalObject, Exception* exceptionToThrow)
+{
+    // The TerminationException is not like ordinary exceptions that should be
+    // reported to the debugger. The fact that the TerminationException uses the
+    // exception handling mechanism is just a VM internal implementation detail.
+    // It is not meaningful to report it to the debugger as an exception.
+    if (isTerminationException(exceptionToThrow)) {
+        // Note: we can only get here is we're just re-throwing the TerminationException
+        // from C++ functions to propagate it. If we're throwing it for the first
+        // time, we would have gone through VM::throwTerminationException().
+        setException(exceptionToThrow);
+        return exceptionToThrow;
+    }
+
     CallFrame* throwOriginFrame = topJSCallFrame();
     if (!throwOriginFrame)
         throwOriginFrame = globalObject->deprecatedCallFrameForDebugger();
@@ -958,15 +987,15 @@
         CRASH();
     }
 
-    interpreter->notifyDebuggerOfExceptionToBeThrown(*this, globalObject, throwOriginFrame, exception);
+    interpreter->notifyDebuggerOfExceptionToBeThrown(*this, globalObject, throwOriginFrame, exceptionToThrow);
 
-    setException(exception);
+    setException(exceptionToThrow);
 
 #if ENABLE(EXCEPTION_SCOPE_VERIFICATION)
     m_nativeStackTraceOfLastThrow = StackTrace::captureStackTrace(Options::unexpectedExceptionStackTraceLimit());
     m_throwingThread = &Thread::current();
 #endif
-    return exception;
+    return exceptionToThrow;
 }
 
 Exception* VM::throwException(JSGlobalObject* globalObject, JSValue thrownValue)

Modified: trunk/Source/_javascript_Core/runtime/VM.h (275647 => 275648)


--- trunk/Source/_javascript_Core/runtime/VM.h	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/runtime/VM.h	2021-04-08 00:30:15 UTC (rev 275648)
@@ -338,6 +338,20 @@
     WeakRandom& random() { return m_random; }
     Integrity::Random& integrityRandom() { return m_integrityRandom; }
 
+    JS_EXPORT_PRIVATE Exception* ensureTerminationException();
+    Exception* terminationException() const
+    {
+        ASSERT(m_terminationException);
+        return m_terminationException;
+    }
+    bool isTerminationException(Exception* exception) const
+    {
+        ASSERT(exception);
+        return exception == m_terminationException;
+    }
+
+    void throwTerminationException();
+
 private:
     unsigned nextID();
 
@@ -664,7 +678,6 @@
 #endif
     Strong<Structure> structureStructure;
     Strong<Structure> structureRareDataStructure;
-    Strong<Structure> terminatedExecutionErrorStructure;
     Strong<Structure> stringStructure;
     Strong<Structure> propertyNameEnumeratorStructure;
     Strong<Structure> getterSetterStructure;
@@ -1078,6 +1091,7 @@
     bool needTrapHandling(VMTraps::Mask mask) { return m_traps.needTrapHandling(mask); }
     void* needTrapHandlingAddress() { return m_traps.needTrapHandlingAddress(); }
 
+    // These may be called concurrently from another thread.
     void notifyNeedDebuggerBreak() { m_traps.fireTrap(VMTraps::NeedDebuggerBreak); }
     void notifyNeedShellTimeoutCheck() { m_traps.fireTrap(VMTraps::NeedShellTimeoutCheck); }
     void notifyNeedTermination() { m_traps.fireTrap(VMTraps::NeedTermination); }
@@ -1186,6 +1200,7 @@
     void* m_lastStackTop { nullptr };
 
     Exception* m_exception { nullptr };
+    Exception* m_terminationException { nullptr };
     Exception* m_lastException { nullptr };
 #if ENABLE(EXCEPTION_SCOPE_VERIFICATION)
     ExceptionScope* m_topExceptionScope { nullptr };

Modified: trunk/Source/_javascript_Core/runtime/VMTraps.cpp (275647 => 275648)


--- trunk/Source/_javascript_Core/runtime/VMTraps.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/_javascript_Core/runtime/VMTraps.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -380,8 +380,7 @@
             FALLTHROUGH;
 
         case NeedTermination:
-            throwException(globalObject, scope, createTerminatedExecutionException(&vm));
-            return;
+            RELEASE_AND_RETURN(scope, vm.throwTerminationException());
 
         default:
             RELEASE_ASSERT_NOT_REACHED();

Modified: trunk/Source/WebCore/ChangeLog (275647 => 275648)


--- trunk/Source/WebCore/ChangeLog	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/WebCore/ChangeLog	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,3 +1,38 @@
+2021-04-07  Mark Lam  <[email protected]>
+
+        Rename and make the TerminationException a singleton.
+        https://bugs.webkit.org/show_bug.cgi?id=224295
+
+        Reviewed by Keith Miller.
+
+        In the WorkerOrWorkletScriptController constructor, we ensure the TerminationException
+        because workers need to support termination requests.
+
+        * bindings/js/JSDOMExceptionHandling.cpp:
+        (WebCore::reportException):
+        * bindings/js/JSDOMGlobalObject.cpp:
+        (WebCore::JSC_DEFINE_HOST_FUNCTION):
+        (WebCore::handleResponseOnStreamingAction):
+        * bindings/js/JSDOMPromise.cpp:
+        (WebCore::DOMPromise::whenPromiseIsSettled):
+        * bindings/js/JSDOMPromiseDeferred.cpp:
+        (WebCore::DeferredPromise::reject):
+        * bindings/js/JSEventListener.cpp:
+        (WebCore::JSEventListener::handleEvent):
+        * bindings/js/ReadableStream.cpp:
+        (WebCore::invokeReadableStreamFunction):
+        (WebCore::ReadableStream::lock):
+        (WebCore::checkReadableStream):
+        * bindings/js/ReadableStreamDefaultController.cpp:
+        (WebCore::invokeReadableStreamDefaultControllerFunction):
+        (WebCore::ReadableStreamDefaultController::error):
+        (WebCore::ReadableStreamDefaultController::enqueue):
+        * workers/WorkerOrWorkletScriptController.cpp:
+        (WebCore::WorkerOrWorkletScriptController::WorkerOrWorkletScriptController):
+        (WebCore::WorkerOrWorkletScriptController::evaluate):
+        (WebCore::WorkerOrWorkletScriptController::linkAndEvaluateModule):
+        (WebCore::WorkerOrWorkletScriptController::loadAndEvaluateModule):
+
 2021-04-07  Simon Fraser  <[email protected]>
 
         Remove RepaintLayoutRectsMap

Modified: trunk/Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp (275647 => 275648)


--- trunk/Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,6 +1,6 @@
 /*
  *  Copyright (C) 1999-2001 Harri Porten ([email protected])
- *  Copyright (C) 2004-2020 Apple Inc. All rights reserved.
+ *  Copyright (C) 2004-2021 Apple Inc. All rights reserved.
  *  Copyright (C) 2007 Samuel Weinig <[email protected]>
  *  Copyright (C) 2013 Michael Pruett <[email protected]>
  *
@@ -94,7 +94,7 @@
     auto scope = DECLARE_CATCH_SCOPE(vm);
 
     RELEASE_ASSERT(vm.currentThreadIsHoldingAPILock());
-    if (isTerminatedExecutionException(vm, exception))
+    if (vm.isTerminationException(exception))
         return;
 
     ErrorHandlingScope errorScope(lexicalGlobalObject->vm());

Modified: trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp (275647 => 275648)


--- trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -141,7 +141,7 @@
         code = AbortError;
     auto value = createDOMException(globalObject, code, message);
 
-    EXCEPTION_ASSERT(!scope.exception() || isTerminatedExecutionException(vm, scope.exception()));
+    EXCEPTION_ASSERT(!scope.exception() || vm.isTerminationException(scope.exception()));
 
     return JSValue::encode(value);
 }
@@ -410,7 +410,7 @@
                 auto scope = DECLARE_THROW_SCOPE(vm);
                 auto error = createDOMException(*globalObject, WTFMove(exception));
                 if (UNLIKELY(scope.exception())) {
-                    ASSERT(isTerminatedExecutionException(vm, scope.exception()));
+                    ASSERT(vm.isTerminationException(scope.exception()));
                     compiler->cancel();
                     return;
                 }

Modified: trunk/Source/WebCore/bindings/js/JSDOMPromise.cpp (275647 => 275648)


--- trunk/Source/WebCore/bindings/js/JSDOMPromise.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/WebCore/bindings/js/JSDOMPromise.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -57,7 +57,7 @@
     const JSC::Identifier& privateName = vm.propertyNames->builtinNames().thenPrivateName();
     auto thenFunction = promise->get(&lexicalGlobalObject, privateName);
 
-    EXCEPTION_ASSERT(!scope.exception() || isTerminatedExecutionException(lexicalGlobalObject.vm(), scope.exception()));
+    EXCEPTION_ASSERT(!scope.exception() || vm.isTerminationException(scope.exception()));
     if (scope.exception())
         return IsCallbackRegistered::No;
 
@@ -71,7 +71,7 @@
     ASSERT(callData.type != JSC::CallData::Type::None);
     call(&lexicalGlobalObject, thenFunction, callData, promise, arguments);
 
-    EXCEPTION_ASSERT(!scope.exception() || isTerminatedExecutionException(lexicalGlobalObject.vm(), scope.exception()));
+    EXCEPTION_ASSERT(!scope.exception() || vm.isTerminationException(scope.exception()));
     return scope.exception() ? IsCallbackRegistered::No : IsCallbackRegistered::Yes;
 }
 

Modified: trunk/Source/WebCore/bindings/js/JSDOMPromiseDeferred.cpp (275647 => 275648)


--- trunk/Source/WebCore/bindings/js/JSDOMPromiseDeferred.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/WebCore/bindings/js/JSDOMPromiseDeferred.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -129,7 +129,8 @@
     ASSERT(deferred());
     ASSERT(m_globalObject);
     auto& lexicalGlobalObject = *m_globalObject;
-    JSC::JSLockHolder locker(&lexicalGlobalObject);
+    JSC::VM& vm = lexicalGlobalObject.vm();
+    JSC::JSLockHolder locker(vm);
 
     if (exception.code() == ExistingExceptionError) {
         auto scope = DECLARE_CATCH_SCOPE(lexicalGlobalObject.vm());
@@ -143,10 +144,10 @@
         return;
     }
 
-    auto scope = DECLARE_THROW_SCOPE(lexicalGlobalObject.vm());
+    auto scope = DECLARE_THROW_SCOPE(vm);
     auto error = createDOMException(lexicalGlobalObject, WTFMove(exception));
     if (UNLIKELY(scope.exception())) {
-        ASSERT(isTerminatedExecutionException(lexicalGlobalObject.vm(), scope.exception()));
+        ASSERT(vm.isTerminationException(scope.exception()));
         return;
     }
 
@@ -162,10 +163,11 @@
     ASSERT(deferred());
     ASSERT(m_globalObject);
     auto& lexicalGlobalObject = *m_globalObject;
-    JSC::JSLockHolder locker(&lexicalGlobalObject);
+    JSC::VM& vm = lexicalGlobalObject.vm();
+    JSC::JSLockHolder locker(vm);
 
     if (ec == ExistingExceptionError) {
-        auto scope = DECLARE_CATCH_SCOPE(lexicalGlobalObject.vm());
+        auto scope = DECLARE_CATCH_SCOPE(vm);
 
         EXCEPTION_ASSERT(scope.exception());
 
@@ -176,10 +178,10 @@
         return;
     }
 
-    auto scope = DECLARE_THROW_SCOPE(lexicalGlobalObject.vm());
+    auto scope = DECLARE_THROW_SCOPE(vm);
     auto error = createDOMException(&lexicalGlobalObject, ec, message);
     if (UNLIKELY(scope.exception())) {
-        ASSERT(isTerminatedExecutionException(lexicalGlobalObject.vm(), scope.exception()));
+        ASSERT(vm.isTerminationException(scope.exception()));
         return;
     }
 

Modified: trunk/Source/WebCore/bindings/js/JSEventListener.cpp (275647 => 275648)


--- trunk/Source/WebCore/bindings/js/JSEventListener.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/WebCore/bindings/js/JSEventListener.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -193,7 +193,7 @@
     auto handleExceptionIfNeeded = [&] () -> bool {
         if (is<WorkerGlobalScope>(scriptExecutionContext)) {
             auto& scriptController = *downcast<WorkerGlobalScope>(scriptExecutionContext).script();
-            bool terminatorCausedException = (scope.exception() && isTerminatedExecutionException(vm, scope.exception()));
+            bool terminatorCausedException = (scope.exception() && vm.isTerminationException(scope.exception()));
             if (terminatorCausedException || scriptController.isTerminatingExecution())
                 scriptController.forbidExecution();
         }

Modified: trunk/Source/WebCore/bindings/js/ReadableStream.cpp (275647 => 275648)


--- trunk/Source/WebCore/bindings/js/ReadableStream.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/WebCore/bindings/js/ReadableStream.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -67,12 +67,12 @@
     JSC::JSLockHolder lock(vm);
 
     auto function = lexicalGlobalObject.get(&lexicalGlobalObject, identifier);
-    ASSERT(function.isCallable(lexicalGlobalObject.vm()));
+    ASSERT(function.isCallable(vm));
 
     auto scope = DECLARE_CATCH_SCOPE(vm);
     auto callData = JSC::getCallData(vm, function);
     auto result = call(&lexicalGlobalObject, function, callData, thisValue, arguments);
-    EXCEPTION_ASSERT(!scope.exception() || isTerminatedExecutionException(lexicalGlobalObject.vm(), scope.exception()));
+    EXCEPTION_ASSERT(!scope.exception() || vm.isTerminationException(scope.exception()));
     if (scope.exception())
         return { };
     return result;
@@ -131,7 +131,7 @@
     ASSERT(!args.hasOverflowed());
 
     JSC::construct(&lexicalGlobalObject, constructor, constructData, args);
-    EXCEPTION_ASSERT(!scope.exception() || isTerminatedExecutionException(lexicalGlobalObject.vm(), scope.exception()));
+    EXCEPTION_ASSERT(!scope.exception() || vm.isTerminationException(scope.exception()));
 }
 
 static inline bool checkReadableStream(JSDOMGlobalObject& globalObject, JSReadableStream* readableStream, JSC::JSValue function)
@@ -149,7 +149,7 @@
     ASSERT(callData.type != JSC::CallData::Type::None);
 
     auto result = call(&lexicalGlobalObject, function, callData, JSC::jsUndefined(), arguments);
-    EXCEPTION_ASSERT(!scope.exception() || isTerminatedExecutionException(lexicalGlobalObject.vm(), scope.exception()));
+    EXCEPTION_ASSERT(!scope.exception() || vm.isTerminationException(scope.exception()));
 
     return result.isTrue() || scope.exception();
 }

Modified: trunk/Source/WebCore/bindings/js/ReadableStreamDefaultController.cpp (275647 => 275648)


--- trunk/Source/WebCore/bindings/js/ReadableStreamDefaultController.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/WebCore/bindings/js/ReadableStreamDefaultController.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2016 Canon Inc.
- * Copyright (C) 2016-2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted, provided that the following conditions
@@ -50,7 +50,7 @@
     auto scope = DECLARE_CATCH_SCOPE(vm);
     auto callData = JSC::getCallData(vm, function);
     call(&lexicalGlobalObject, function, callData, JSC::jsUndefined(), arguments);
-    EXCEPTION_ASSERT(!scope.exception() || isTerminatedExecutionException(lexicalGlobalObject.vm(), scope.exception()));
+    EXCEPTION_ASSERT(!scope.exception() || vm.isTerminationException(scope.exception()));
     return !scope.exception();
 }
 
@@ -75,7 +75,7 @@
     auto value = createDOMException(&lexicalGlobalObject, exception.code(), exception.message());
 
     if (UNLIKELY(scope.exception())) {
-        ASSERT(isTerminatedExecutionException(lexicalGlobalObject.vm(), scope.exception()));
+        ASSERT(vm.isTerminationException(scope.exception()));
         return;
     }
 
@@ -83,7 +83,7 @@
     arguments.append(&jsController());
     arguments.append(value);
 
-    auto* clientData = static_cast<JSVMClientData*>(lexicalGlobalObject.vm().clientData);
+    auto* clientData = static_cast<JSVMClientData*>(vm.clientData);
     auto& privateName = clientData->builtinFunctions().readableStreamInternalsBuiltins().readableStreamDefaultControllerErrorPrivateName();
 
     invokeReadableStreamDefaultControllerFunction(globalObject(), privateName, arguments);
@@ -121,7 +121,7 @@
     auto value = toJS(&lexicalGlobalObject, &lexicalGlobalObject, chunk.get());
 
     if (UNLIKELY(scope.exception())) {
-        ASSERT(isTerminatedExecutionException(lexicalGlobalObject.vm(), scope.exception()));
+        ASSERT(vm.isTerminationException(scope.exception()));
         return false;
     }
 

Modified: trunk/Source/WebCore/workers/WorkerOrWorkletScriptController.cpp (275647 => 275648)


--- trunk/Source/WebCore/workers/WorkerOrWorkletScriptController.cpp	2021-04-08 00:24:53 UTC (rev 275647)
+++ trunk/Source/WebCore/workers/WorkerOrWorkletScriptController.cpp	2021-04-08 00:30:15 UTC (rev 275648)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2020 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008-2021 Apple Inc. All Rights Reserved.
  * Copyright (C) 2011, 2012 Google Inc. All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -67,6 +67,11 @@
     , m_globalScopeWrapper(*m_vm)
 {
     m_vm->heap.acquireAccess(); // It's not clear that we have good discipline for heap access, so turn it on permanently.
+    {
+        JSLockHolder lock(m_vm.get());
+        m_vm->ensureTerminationException();
+    }
+
     JSVMClientData::initNormalWorld(m_vm.get(), type);
 }
 
@@ -218,7 +223,7 @@
 
     JSExecState::profiledEvaluate(&globalObject, JSC::ProfilingReason::Other, sourceCode.jsSourceCode(), m_globalScopeWrapper->globalThis(), returnedException);
 
-    if ((returnedException && isTerminatedExecutionException(vm, returnedException)) || isTerminatingExecution()) {
+    if ((returnedException && vm.isTerminationException(returnedException)) || isTerminatingExecution()) {
         forbidExecution();
         return;
     }
@@ -351,7 +356,7 @@
 
     NakedPtr<JSC::Exception> returnedException;
     JSExecState::linkAndEvaluateModule(globalObject, Identifier::fromUid(vm, scriptFetcher.moduleKey()), jsUndefined(), returnedException);
-    if ((returnedException && isTerminatedExecutionException(vm, returnedException)) || isTerminatingExecution()) {
+    if ((returnedException && vm.isTerminationException(returnedException)) || isTerminatingExecution()) {
         forbidExecution();
         return;
     }
@@ -409,7 +414,7 @@
 
             NakedPtr<JSC::Exception> returnedException;
             JSExecState::linkAndEvaluateModule(*globalObject, moduleKey, jsUndefined(), returnedException);
-            if ((returnedException && isTerminatedExecutionException(vm, returnedException)) || context->script()->isTerminatingExecution()) {
+            if ((returnedException && vm.isTerminationException(returnedException)) || context->script()->isTerminatingExecution()) {
                 if (context->script())
                     context->script()->forbidExecution();
                 task->run(WTF::nullopt);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to