[JSC] Remove JSPromiseDeferred
authorysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Oct 2019 01:37:12 +0000 (01:37 +0000)
committerysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Oct 2019 01:37:12 +0000 (01:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=203400

Reviewed by Keith Miller.

Source/JavaScriptCore:

This patch optimizes the existing Promise usage in C++. We remove JSPromiseDeferred and JSInternalPromiseDeferred, use JSPromise and JSInternalPromise directly.
JSC now offers first `resolve` and `reject` operations to `JSPromise` without separating `resolve` and `reject` function from `JSPromise`. Then, we do not need
to have a tuple of these functions and promise, and we can just use `JSPromise::resolve` and `JSPromise::reject`. This removes unnecessary function allocations
and cell allocation for JSPromiseDeferred and makes API simple.

* API/JSAPIGlobalObject.mm:
(JSC::JSAPIGlobalObject::moduleLoaderImportModule):
(JSC::JSAPIGlobalObject::moduleLoaderFetch):
(JSC::JSAPIGlobalObject::loadAndEvaluateJSScriptModule):
* API/JSObjectRef.cpp:
(JSObjectMakeDeferredPromise):
* CMakeLists.txt:
* JavaScriptCore.xcodeproj/project.pbxproj:
* Sources.txt:
* jsc.cpp:
(GlobalObject::moduleLoaderImportModule):
(GlobalObject::moduleLoaderFetch):
(runJSC):
* runtime/Completion.cpp:
(JSC::rejectPromise):
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::newPromiseCapabilityFunction const):
(JSC::JSGlobalObject::resolvePromiseFunction const):
(JSC::JSGlobalObject::rejectPromiseFunction const):
(JSC::JSGlobalObject::numberProtoToStringFunction const):
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::globalFuncImportModule):
* runtime/JSInternalPromise.h:
* runtime/JSInternalPromiseDeferred.cpp: Removed.
* runtime/JSInternalPromiseDeferred.h: Removed.
* runtime/JSModuleLoader.cpp:
(JSC::JSModuleLoader::importModule):
(JSC::JSModuleLoader::resolve):
(JSC::JSModuleLoader::fetch):
(JSC::moduleLoaderParseModule):
* runtime/JSPromise.cpp:
(JSC::JSPromise::flags const):
(JSC::JSPromise::isHandled const):
(JSC::JSPromise::createDeferredData):
(JSC::JSPromise::resolvedPromise):
(JSC::callFunction):
(JSC::JSPromise::resolve):
(JSC::JSPromise::reject):
* runtime/JSPromise.h:
* runtime/JSPromiseDeferred.cpp: Removed.
* runtime/JSPromiseDeferred.h: Removed.
* runtime/PromiseTimer.cpp: Renamed from Source/JavaScriptCore/runtime/PromiseDeferredTimer.cpp.
(JSC::PromiseTimer::PromiseTimer):
(JSC::PromiseTimer::doWork):
(JSC::PromiseTimer::runRunLoop):
(JSC::PromiseTimer::addPendingPromise):
(JSC::PromiseTimer::hasPendingPromise):
(JSC::PromiseTimer::hasDependancyInPendingPromise):
(JSC::PromiseTimer::cancelPendingPromise):
(JSC::PromiseTimer::scheduleWorkSoon):
* runtime/PromiseTimer.h: Renamed from Source/JavaScriptCore/runtime/PromiseDeferredTimer.h.
(JSC::PromiseTimer::create):
* runtime/StringRecursionChecker.h:
* runtime/VM.cpp:
(JSC::VM::VM):
(JSC::VM::~VM):
* runtime/VM.h:
* wasm/js/JSWebAssembly.cpp:
(JSC::reject):
(JSC::webAssemblyModuleValidateAsyncInternal):
(JSC::webAssemblyCompileFunc):
(JSC::resolve):
(JSC::JSWebAssembly::webAssemblyModuleValidateAsync):
(JSC::instantiate):
(JSC::compileAndInstantiate):
(JSC::JSWebAssembly::instantiate):
(JSC::webAssemblyModuleInstantinateAsyncInternal):
(JSC::JSWebAssembly::webAssemblyModuleInstantinateAsync):
(JSC::webAssemblyInstantiateFunc):
(JSC::webAssemblyCompileStreamingInternal):
(JSC::webAssemblyInstantiateStreamingInternal):
* wasm/js/JSWebAssembly.h:
* wasm/js/JSWebAssemblyCodeBlock.h:

Source/WebCore:

This patch removes PromiseExecutionScope. This assumed that promise operation cannot fail in main thread. But this is
wrong since any JS call can fail due to stack-overflow error. This patch makes things more robust by handling errors correctly.
And we remove JSPromiseDeferred and use JSPromise instead.

* bindings/js/JSCustomElementRegistryCustom.cpp:
(WebCore::whenDefinedPromise):
(WebCore::JSCustomElementRegistry::whenDefined):
* bindings/js/JSDOMConvertPromise.h:
(WebCore::Converter<IDLPromise<T>>::convert):
* bindings/js/JSDOMGlobalObject.cpp:
* bindings/js/JSDOMOperationReturningPromise.h:
(WebCore::IDLOperationReturningPromise::call):
(WebCore::IDLOperationReturningPromise::callStatic):
* bindings/js/JSDOMPromiseDeferred.cpp:
(WebCore::DeferredPromise::promise const):
(WebCore::DeferredPromise::callFunction):
(WebCore::DeferredPromise::whenSettled):
(WebCore::rejectPromiseWithExceptionIfAny):
(WebCore::createDeferredPromise):
* bindings/js/JSDOMPromiseDeferred.h:
(WebCore::DeferredPromise::create):
(WebCore::DeferredPromise::DeferredPromise):
(WebCore::DeferredPromise::deferred const):
(WebCore::DeferredPromise::resolve):
(WebCore::DeferredPromise::reject):
(WebCore::DOMPromiseDeferredBase::DOMPromiseDeferredBase):
(WebCore::DOMPromiseDeferredBase::operator=):
(WebCore::DOMPromiseDeferredBase::reject):
(WebCore::DOMPromiseDeferredBase::rejectType):
(WebCore::DOMPromiseDeferredBase::promise const):
(WebCore::DOMPromiseDeferredBase::whenSettled):
(WebCore::DOMPromiseDeferred::resolve):
(WebCore::DOMPromiseDeferred<void>::resolve):
(WebCore::callPromiseFunction):
* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::moduleLoaderFetch):
(WebCore::JSDOMWindowBase::moduleLoaderImportModule):
(WebCore::tryAllocate):
(WebCore::isResponseCorrect):
(WebCore::handleResponseOnStreamingAction):
(WebCore::JSDOMWindowBase::compileStreaming):
(WebCore::JSDOMWindowBase::instantiateStreaming):
* bindings/js/JSDOMWindowBase.h:
* bindings/js/ScriptModuleLoader.cpp:
(WebCore::ScriptModuleLoader::fetch):
(WebCore::rejectPromise):
* bindings/js/WorkerScriptController.cpp:
(WebCore::WorkerScriptController::addTimerSetNotification):
(WebCore::WorkerScriptController::removeTimerSetNotification):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateOperationTrampolineDefinition):
* bindings/scripts/test/JS/JSTestGlobalObject.cpp:
(WebCore::jsTestGlobalObjectInstanceFunctionCalculateSecretResult):
* bindings/scripts/test/JS/JSTestNode.cpp:
(WebCore::jsTestNodePrototypeFunctionTestWorkerPromise):
(WebCore::jsTestNodePrototypeFunctionCalculateSecretResult):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::jsTestObjPrototypeFunctionCalculateSecretResult):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunction):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgument):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithException):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgument):
(WebCore::jsTestObjPrototypeFunctionTestPromiseOverloadedFunction):
(WebCore::jsTestObjConstructorFunctionTestStaticPromiseFunction):
(WebCore::jsTestObjConstructorFunctionTestStaticPromiseFunctionWithException):
(WebCore::jsTestObjPrototypeFunctionTestCustomPromiseFunction):
(WebCore::jsTestObjConstructorFunctionTestStaticCustomPromiseFunction):
* workers/WorkerRunLoop.cpp:
* worklets/WorkletScriptController.cpp:

LayoutTests:

* js/dom/promise-stack-overflow-expected.txt: Added.
* js/dom/promise-stack-overflow.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@251691 268f45cc-cd09-0410-ab3c-d52691b4dbfc

46 files changed:
LayoutTests/ChangeLog
LayoutTests/js/dom/promise-stack-overflow-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/promise-stack-overflow.html [new file with mode: 0644]
Source/JavaScriptCore/API/JSAPIGlobalObject.mm
Source/JavaScriptCore/API/JSObjectRef.cpp
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/Sources.txt
Source/JavaScriptCore/jsc.cpp
Source/JavaScriptCore/runtime/Completion.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.h
Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
Source/JavaScriptCore/runtime/JSInternalPromise.h
Source/JavaScriptCore/runtime/JSInternalPromiseDeferred.cpp [deleted file]
Source/JavaScriptCore/runtime/JSInternalPromiseDeferred.h [deleted file]
Source/JavaScriptCore/runtime/JSModuleLoader.cpp
Source/JavaScriptCore/runtime/JSPromise.cpp
Source/JavaScriptCore/runtime/JSPromise.h
Source/JavaScriptCore/runtime/JSPromiseDeferred.cpp [deleted file]
Source/JavaScriptCore/runtime/JSPromiseDeferred.h [deleted file]
Source/JavaScriptCore/runtime/PromiseTimer.cpp [moved from Source/JavaScriptCore/runtime/PromiseDeferredTimer.cpp with 76% similarity]
Source/JavaScriptCore/runtime/PromiseTimer.h [moved from Source/JavaScriptCore/runtime/PromiseDeferredTimer.h with 72% similarity]
Source/JavaScriptCore/runtime/VM.cpp
Source/JavaScriptCore/runtime/VM.h
Source/JavaScriptCore/wasm/js/JSWebAssembly.cpp
Source/JavaScriptCore/wasm/js/JSWebAssembly.h
Source/JavaScriptCore/wasm/js/JSWebAssemblyCodeBlock.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSCustomElementRegistryCustom.cpp
Source/WebCore/bindings/js/JSDOMConvertPromise.h
Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
Source/WebCore/bindings/js/JSDOMOperationReturningPromise.h
Source/WebCore/bindings/js/JSDOMPromiseDeferred.cpp
Source/WebCore/bindings/js/JSDOMPromiseDeferred.h
Source/WebCore/bindings/js/JSDOMWindowBase.cpp
Source/WebCore/bindings/js/JSDOMWindowBase.h
Source/WebCore/bindings/js/ScriptModuleLoader.cpp
Source/WebCore/bindings/js/WorkerScriptController.cpp
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSTestGlobalObject.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestNode.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
Source/WebCore/workers/WorkerRunLoop.cpp
Source/WebCore/worklets/WorkletScriptController.cpp

index 4cc79af..4bec39a 100644 (file)
@@ -1,3 +1,13 @@
+2019-10-28  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        [JSC] Remove JSPromiseDeferred
+        https://bugs.webkit.org/show_bug.cgi?id=203400
+
+        Reviewed by Keith Miller.
+
+        * js/dom/promise-stack-overflow-expected.txt: Added.
+        * js/dom/promise-stack-overflow.html: Added.
+
 2019-10-28  Simon Fraser  <simon.fraser@apple.com>
 
         Update css/css-text-decor WPT
diff --git a/LayoutTests/js/dom/promise-stack-overflow-expected.txt b/LayoutTests/js/dom/promise-stack-overflow-expected.txt
new file mode 100644 (file)
index 0000000..bb15f25
--- /dev/null
@@ -0,0 +1,10 @@
+Test Promise operation does not crash with stack-overflow.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS stackOverflowHappens is true
+PASS stackOverflowDoesNotHappen is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/dom/promise-stack-overflow.html b/LayoutTests/js/dom/promise-stack-overflow.html
new file mode 100644 (file)
index 0000000..2aee41c
--- /dev/null
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description('Test Promise operation does not crash with stack-overflow.');
+
+var count = 0;
+function checkCount(passed)
+{
+    count++;
+    if (passed === count) {
+        fetch("./promise-stack-overflow.html");
+        return;
+    }
+    checkCount(passed);
+}
+try {
+    checkCount(0);
+} catch {
+}
+count = 0;
+try {
+    checkCount(0);
+} catch {
+}
+var stackOverflowHappens = false;
+var stackOverflowDoesNotHappen = false;
+var target = count;
+for (var i = -100; i < 100; ++i) {
+    try {
+        count = 0;
+        checkCount(target - i);
+        stackOverflowDoesNotHappen = true;
+    } catch {
+        stackOverflowHappens = true;
+    }
+}
+shouldBeTrue('stackOverflowHappens');
+shouldBeTrue('stackOverflowDoesNotHappen');
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index f619bda..c74aca0 100644 (file)
 #import "Exception.h"
 #import "JSContextInternal.h"
 #import "JSInternalPromise.h"
-#import "JSInternalPromiseDeferred.h"
 #import "JSModuleLoader.h"
 #import "JSNativeStdFunction.h"
-#import "JSPromiseDeferred.h"
+#import "JSPromise.h"
 #import "JSScriptInternal.h"
 #import "JSSourceCode.h"
 #import "JSValueInternal.h"
@@ -129,9 +128,12 @@ JSInternalPromise* JSAPIGlobalObject::moduleLoaderImportModule(JSGlobalObject* g
     auto scope = DECLARE_CATCH_SCOPE(vm);
     auto reject = [&] (JSValue exception) -> JSInternalPromise* {
         scope.clearException();
-        auto* promise = JSInternalPromiseDeferred::tryCreate(globalObject);
+        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, exception);
         scope.clearException();
-        return promise->reject(globalObject, exception);
+        return promise;
     };
 
     auto import = [&] (URL& url) {
@@ -164,20 +166,23 @@ JSInternalPromise* JSAPIGlobalObject::moduleLoaderFetch(JSGlobalObject* globalOb
     ASSERT(globalObject == globalObject);
     JSContext *context = [JSContext contextWithJSGlobalContextRef:toGlobalRef(globalObject)];
 
-    JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::tryCreate(globalObject);
-    RETURN_IF_EXCEPTION(scope, nullptr);
+    JSInternalPromise* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
 
     Identifier moduleKey = key.toPropertyKey(globalObject);
     if (UNLIKELY(scope.exception())) {
         JSValue exception = scope.exception();
         scope.clearException();
-        return deferred->reject(globalObject, exception);
+        promise->reject(globalObject, exception);
+        scope.clearException();
+        return promise;
     }
 
-    if (UNLIKELY(![context moduleLoaderDelegate]))
-        return deferred->reject(globalObject, createError(globalObject, "No module loader provided."));
+    if (UNLIKELY(![context moduleLoaderDelegate])) {
+        promise->reject(globalObject, createError(globalObject, "No module loader provided."));
+        return promise;
+    }
 
-    auto deferredPromise = Strong<JSInternalPromiseDeferred>(vm, deferred);
+    auto strongPromise = Strong<JSInternalPromise>(vm, promise);
     auto* resolve = JSNativeStdFunction::create(vm, globalObject, 1, "resolve", [=] (JSGlobalObject* globalObject, CallFrame* callFrame) {
         // This captures the globalObject but that's ok because our structure keeps it alive anyway.
         VM& vm = globalObject->vm();
@@ -187,8 +192,7 @@ JSInternalPromise* JSAPIGlobalObject::moduleLoaderFetch(JSGlobalObject* globalOb
         MarkedArgumentBuffer args;
 
         auto rejectPromise = [&] (String message) {
-            args.append(createTypeError(globalObject, message));
-            call(globalObject, deferredPromise->JSPromiseDeferred::reject(), args, "This should never be seen...");
+            strongPromise.get()->reject(globalObject, createTypeError(globalObject, message));
             return encodedJSUndefined();
         };
 
@@ -206,25 +210,21 @@ JSInternalPromise* JSAPIGlobalObject::moduleLoaderFetch(JSGlobalObject* globalOb
         if (UNLIKELY(Identifier::fromString(vm, oldModuleKey) != moduleKey))
             return rejectPromise(makeString("The same JSScript was provided for two different identifiers, previously: ", oldModuleKey, " and now: ", moduleKey.string()));
 
-        args.append(source);
-        call(globalObject, deferredPromise->JSPromiseDeferred::resolve(), args, "This should never be seen...");
+        strongPromise.get()->resolve(globalObject, source);
         return encodedJSUndefined();
     });
 
     auto* reject = JSNativeStdFunction::create(vm, globalObject, 1, "reject", [=] (JSGlobalObject*, CallFrame* callFrame) {
-        MarkedArgumentBuffer args;
-        args.append(callFrame->argument(0));
-
-        call(globalObject, deferredPromise->JSPromiseDeferred::reject(), args, "This should never be seen...");
+        strongPromise.get()->reject(globalObject, callFrame->argument(0));
         return encodedJSUndefined();
     });
 
     [[context moduleLoaderDelegate] context:context fetchModuleForIdentifier:[::JSValue valueWithJSValueRef:toRef(globalObject, key) inContext:context] withResolveHandler:[::JSValue valueWithJSValueRef:toRef(globalObject, resolve) inContext:context] andRejectHandler:[::JSValue valueWithJSValueRef:toRef(globalObject, reject) inContext:context]];
     if (context.exception) {
-        deferred->reject(globalObject, toJS(globalObject, [context.exception JSValueRef]));
+        promise->reject(globalObject, toJS(globalObject, [context.exception JSValueRef]));
         context.exception = nil;
     }
-    return deferred->promise();
+    return promise;
 }
 
 JSObject* JSAPIGlobalObject::moduleLoaderCreateImportMetaProperties(JSGlobalObject* globalObject, JSModuleLoader*, JSValue key, JSModuleRecord*, JSValue)
@@ -277,10 +277,10 @@ JSValue JSAPIGlobalObject::loadAndEvaluateJSScriptModule(const JSLockHolder&, JS
     Identifier key = Identifier::fromString(vm, String { [[script sourceURL] absoluteString] });
     JSInternalPromise* promise = importModule(this, key, jsUndefined(), jsUndefined());
     RETURN_IF_EXCEPTION(scope, { });
-    auto result = JSPromiseDeferred::tryCreate(this);
-    RETURN_IF_EXCEPTION(scope, { });
+    auto* result = JSPromise::create(vm, this->promiseStructure());
     result->resolve(this, promise);
-    return result->promise();
+    RETURN_IF_EXCEPTION(scope, { });
+    return result;
 }
 
 }
index 4a7edb5..b4bfefe 100644 (file)
@@ -47,7 +47,6 @@
 #include "JSGlobalObject.h"
 #include "JSObject.h"
 #include "JSPromise.h"
-#include "JSPromiseDeferred.h"
 #include "JSRetainPtr.h"
 #include "JSString.h"
 #include "JSValueRef.h"
@@ -289,7 +288,7 @@ JSObjectRef JSObjectMakeDeferredPromise(JSContextRef ctx, JSObjectRef* resolve,
     JSLockHolder locker(globalObject);
     auto scope = DECLARE_CATCH_SCOPE(vm);
 
-    JSPromiseDeferred::DeferredData data = JSPromiseDeferred::createDeferredData(globalObject, globalObject->promiseConstructor());
+    JSPromise::DeferredData data = JSPromise::createDeferredData(globalObject, globalObject->promiseConstructor());
     if (handleExceptionIfNeeded(scope, ctx, exception) == ExceptionStatus::DidThrow)
         return nullptr;
 
index 4823817..f14b876 100644 (file)
@@ -874,7 +874,6 @@ set(JavaScriptCore_PRIVATE_FRAMEWORK_HEADERS
     runtime/JSImmutableButterfly.h
     runtime/JSInternalFieldObjectImpl.h
     runtime/JSInternalPromise.h
-    runtime/JSInternalPromiseDeferred.h
     runtime/JSMicrotask.h
     runtime/JSLock.h
     runtime/JSMap.h
@@ -888,7 +887,6 @@ set(JavaScriptCore_PRIVATE_FRAMEWORK_HEADERS
     runtime/JSObjectInlines.h
     runtime/JSPromise.h
     runtime/JSPromiseConstructor.h
-    runtime/JSPromiseDeferred.h
     runtime/JSPropertyNameEnumerator.h
     runtime/JSProxy.h
     runtime/JSRunLoopTimer.h
@@ -931,7 +929,7 @@ set(JavaScriptCore_PRIVATE_FRAMEWORK_HEADERS
     runtime/ParseInt.h
     runtime/PrivateName.h
     runtime/ProgramExecutable.h
-    runtime/PromiseDeferredTimer.h
+    runtime/PromiseTimer.h
     runtime/PropertyDescriptor.h
     runtime/PropertyMapHashTable.h
     runtime/PropertyName.h
index 45248fc..763d4fc 100644 (file)
@@ -1,3 +1,92 @@
+2019-10-28  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        [JSC] Remove JSPromiseDeferred
+        https://bugs.webkit.org/show_bug.cgi?id=203400
+
+        Reviewed by Keith Miller.
+
+        This patch optimizes the existing Promise usage in C++. We remove JSPromiseDeferred and JSInternalPromiseDeferred, use JSPromise and JSInternalPromise directly.
+        JSC now offers first `resolve` and `reject` operations to `JSPromise` without separating `resolve` and `reject` function from `JSPromise`. Then, we do not need
+        to have a tuple of these functions and promise, and we can just use `JSPromise::resolve` and `JSPromise::reject`. This removes unnecessary function allocations
+        and cell allocation for JSPromiseDeferred and makes API simple.
+
+        * API/JSAPIGlobalObject.mm:
+        (JSC::JSAPIGlobalObject::moduleLoaderImportModule):
+        (JSC::JSAPIGlobalObject::moduleLoaderFetch):
+        (JSC::JSAPIGlobalObject::loadAndEvaluateJSScriptModule):
+        * API/JSObjectRef.cpp:
+        (JSObjectMakeDeferredPromise):
+        * CMakeLists.txt:
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * Sources.txt:
+        * jsc.cpp:
+        (GlobalObject::moduleLoaderImportModule):
+        (GlobalObject::moduleLoaderFetch):
+        (runJSC):
+        * runtime/Completion.cpp:
+        (JSC::rejectPromise):
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init):
+        (JSC::JSGlobalObject::visitChildren):
+        * runtime/JSGlobalObject.h:
+        (JSC::JSGlobalObject::newPromiseCapabilityFunction const):
+        (JSC::JSGlobalObject::resolvePromiseFunction const):
+        (JSC::JSGlobalObject::rejectPromiseFunction const):
+        (JSC::JSGlobalObject::numberProtoToStringFunction const):
+        * runtime/JSGlobalObjectFunctions.cpp:
+        (JSC::globalFuncImportModule):
+        * runtime/JSInternalPromise.h:
+        * runtime/JSInternalPromiseDeferred.cpp: Removed.
+        * runtime/JSInternalPromiseDeferred.h: Removed.
+        * runtime/JSModuleLoader.cpp:
+        (JSC::JSModuleLoader::importModule):
+        (JSC::JSModuleLoader::resolve):
+        (JSC::JSModuleLoader::fetch):
+        (JSC::moduleLoaderParseModule):
+        * runtime/JSPromise.cpp:
+        (JSC::JSPromise::flags const):
+        (JSC::JSPromise::isHandled const):
+        (JSC::JSPromise::createDeferredData):
+        (JSC::JSPromise::resolvedPromise):
+        (JSC::callFunction):
+        (JSC::JSPromise::resolve):
+        (JSC::JSPromise::reject):
+        * runtime/JSPromise.h:
+        * runtime/JSPromiseDeferred.cpp: Removed.
+        * runtime/JSPromiseDeferred.h: Removed.
+        * runtime/PromiseTimer.cpp: Renamed from Source/JavaScriptCore/runtime/PromiseDeferredTimer.cpp.
+        (JSC::PromiseTimer::PromiseTimer):
+        (JSC::PromiseTimer::doWork):
+        (JSC::PromiseTimer::runRunLoop):
+        (JSC::PromiseTimer::addPendingPromise):
+        (JSC::PromiseTimer::hasPendingPromise):
+        (JSC::PromiseTimer::hasDependancyInPendingPromise):
+        (JSC::PromiseTimer::cancelPendingPromise):
+        (JSC::PromiseTimer::scheduleWorkSoon):
+        * runtime/PromiseTimer.h: Renamed from Source/JavaScriptCore/runtime/PromiseDeferredTimer.h.
+        (JSC::PromiseTimer::create):
+        * runtime/StringRecursionChecker.h:
+        * runtime/VM.cpp:
+        (JSC::VM::VM):
+        (JSC::VM::~VM):
+        * runtime/VM.h:
+        * wasm/js/JSWebAssembly.cpp:
+        (JSC::reject):
+        (JSC::webAssemblyModuleValidateAsyncInternal):
+        (JSC::webAssemblyCompileFunc):
+        (JSC::resolve):
+        (JSC::JSWebAssembly::webAssemblyModuleValidateAsync):
+        (JSC::instantiate):
+        (JSC::compileAndInstantiate):
+        (JSC::JSWebAssembly::instantiate):
+        (JSC::webAssemblyModuleInstantinateAsyncInternal):
+        (JSC::JSWebAssembly::webAssemblyModuleInstantinateAsync):
+        (JSC::webAssemblyInstantiateFunc):
+        (JSC::webAssemblyCompileStreamingInternal):
+        (JSC::webAssemblyInstantiateStreamingInternal):
+        * wasm/js/JSWebAssembly.h:
+        * wasm/js/JSWebAssemblyCodeBlock.h:
+
 2019-10-28  Adrian Perez de Castro  <aperez@igalia.com>
 
         [GTK][WPE] Fix various non-unified build issues introduced since r251436
index c7fe3a3..9fcad7c 100644 (file)
                5333BBDD2110F7E1007618EC /* DFGSpeculativeJIT64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86880F4C14353B2100B08D42 /* DFGSpeculativeJIT64.cpp */; };
                5341FC721DAC343C00E7E4D7 /* B3WasmBoundsCheckValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 5341FC711DAC343C00E7E4D7 /* B3WasmBoundsCheckValue.h */; };
                534638711E70CF3D00F12AC1 /* JSRunLoopTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 534638701E70CF3D00F12AC1 /* JSRunLoopTimer.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               534638751E70DDEC00F12AC1 /* PromiseDeferredTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 534638741E70DDEC00F12AC1 /* PromiseDeferredTimer.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               534638751E70DDEC00F12AC1 /* PromiseTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 534638741E70DDEC00F12AC1 /* PromiseTimer.h */; settings = {ATTRIBUTES = (Private, ); }; };
                53486BB71C1795C300F6F3AF /* JSTypedArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 53486BB61C1795C300F6F3AF /* JSTypedArray.h */; settings = {ATTRIBUTES = (Public, ); }; };
                534902851C7276B70012BCB8 /* TypedArrayCTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 534902821C7242C80012BCB8 /* TypedArrayCTest.cpp */; };
                534C457C1BC72411007476A7 /* JSTypedArrayViewConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = 534C457B1BC72411007476A7 /* JSTypedArrayViewConstructor.h */; };
                79FC8A081E32E9F000D88F0E /* DFGRegisteredStructure.h in Headers */ = {isa = PBXBuildFile; fileRef = 79FC8A071E32E9F000D88F0E /* DFGRegisteredStructure.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7A9774A8206B82E4008D03D0 /* JSWeakValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A9774A7206B82C9008D03D0 /* JSWeakValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7BC547D31B6959A100959B58 /* WasmFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC547D21B69599B00959B58 /* WasmFormat.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               7C008CDB187124BB00955C24 /* JSPromiseDeferred.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C008CD9187124BB00955C24 /* JSPromiseDeferred.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7C008CE7187631B600955C24 /* Microtask.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C008CE5187631B600955C24 /* Microtask.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7C184E1B17BEDBD3007CB63A /* JSPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C184E1917BEDBD3007CB63A /* JSPromise.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7C184E1F17BEE22E007CB63A /* JSPromisePrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C184E1D17BEE22E007CB63A /* JSPromisePrototype.h */; };
                E33F50751B8421C000413856 /* JSInternalPromisePrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = E33F50731B8421C000413856 /* JSInternalPromisePrototype.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E33F50791B84225700413856 /* JSInternalPromiseConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = E33F50771B84225700413856 /* JSInternalPromiseConstructor.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E33F50811B8429A400413856 /* JSInternalPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = E33F507F1B8429A400413856 /* JSInternalPromise.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               E33F50851B8437A000413856 /* JSInternalPromiseDeferred.h in Headers */ = {isa = PBXBuildFile; fileRef = E33F50831B8437A000413856 /* JSInternalPromiseDeferred.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E33F50871B8449EF00413856 /* JSInternalPromiseConstructor.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = E33F50861B8449EF00413856 /* JSInternalPromiseConstructor.lut.h */; };
                E3400EC122A1CC7B009DED54 /* FunctionExecutableInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = E3400EC022A1CC78009DED54 /* FunctionExecutableInlines.h */; };
                E34E657520668EAA00FB81AC /* ParseHash.h in Headers */ = {isa = PBXBuildFile; fileRef = E34E657320668E8D00FB81AC /* ParseHash.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5341FC711DAC343C00E7E4D7 /* B3WasmBoundsCheckValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3WasmBoundsCheckValue.h; path = b3/B3WasmBoundsCheckValue.h; sourceTree = "<group>"; };
                534638701E70CF3D00F12AC1 /* JSRunLoopTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSRunLoopTimer.h; sourceTree = "<group>"; };
                534638721E70D01500F12AC1 /* JSRunLoopTimer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSRunLoopTimer.cpp; sourceTree = "<group>"; };
-               534638741E70DDEC00F12AC1 /* PromiseDeferredTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PromiseDeferredTimer.h; sourceTree = "<group>"; };
-               534638761E71E06E00F12AC1 /* PromiseDeferredTimer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PromiseDeferredTimer.cpp; sourceTree = "<group>"; };
+               534638741E70DDEC00F12AC1 /* PromiseTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PromiseTimer.h; sourceTree = "<group>"; };
+               534638761E71E06E00F12AC1 /* PromiseTimer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PromiseTimer.cpp; sourceTree = "<group>"; };
                53486BB61C1795C300F6F3AF /* JSTypedArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTypedArray.h; sourceTree = "<group>"; };
                53486BBA1C18E84500F6F3AF /* JSTypedArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArray.cpp; sourceTree = "<group>"; };
                534902821C7242C80012BCB8 /* TypedArrayCTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TypedArrayCTest.cpp; path = API/tests/TypedArrayCTest.cpp; sourceTree = "<group>"; };
                7A9774A6206B828C008D03D0 /* JSWeakValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWeakValue.cpp; sourceTree = "<group>"; };
                7A9774A7206B82C9008D03D0 /* JSWeakValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWeakValue.h; sourceTree = "<group>"; };
                7BC547D21B69599B00959B58 /* WasmFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmFormat.h; sourceTree = "<group>"; };
-               7C008CD8187124BB00955C24 /* JSPromiseDeferred.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPromiseDeferred.cpp; sourceTree = "<group>"; };
-               7C008CD9187124BB00955C24 /* JSPromiseDeferred.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPromiseDeferred.h; sourceTree = "<group>"; };
                7C008CE5187631B600955C24 /* Microtask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Microtask.h; sourceTree = "<group>"; };
                7C184E1817BEDBD3007CB63A /* JSPromise.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPromise.cpp; sourceTree = "<group>"; };
                7C184E1917BEDBD3007CB63A /* JSPromise.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPromise.h; sourceTree = "<group>"; };
                E33F50771B84225700413856 /* JSInternalPromiseConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSInternalPromiseConstructor.h; sourceTree = "<group>"; };
                E33F507E1B8429A400413856 /* JSInternalPromise.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSInternalPromise.cpp; sourceTree = "<group>"; };
                E33F507F1B8429A400413856 /* JSInternalPromise.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSInternalPromise.h; sourceTree = "<group>"; };
-               E33F50821B8437A000413856 /* JSInternalPromiseDeferred.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSInternalPromiseDeferred.cpp; sourceTree = "<group>"; };
-               E33F50831B8437A000413856 /* JSInternalPromiseDeferred.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSInternalPromiseDeferred.h; sourceTree = "<group>"; };
                E33F50861B8449EF00413856 /* JSInternalPromiseConstructor.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSInternalPromiseConstructor.lut.h; sourceTree = "<group>"; };
                E33F50881B844A1A00413856 /* InternalPromiseConstructor.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = InternalPromiseConstructor.js; sourceTree = "<group>"; };
                E3400EC022A1CC78009DED54 /* FunctionExecutableInlines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FunctionExecutableInlines.h; sourceTree = "<group>"; };
                                0F2B66B317B6B5AB00A7AE3F /* GenericTypedArrayViewInlines.h */,
                                14788EE521501B2900A561C8 /* GetPutInfo.cpp */,
                                796465681B952FF0003059EE /* GetPutInfo.h */,
-                               FE1D6D6E236258FE007A5C26 /* GetVM.h */,
                                BC02E9B80E184545000F9297 /* GetterSetter.cpp */,
                                BC337BDE0E1AF0B80076918A /* GetterSetter.h */,
+                               FE1D6D6E236258FE007A5C26 /* GetVM.h */,
                                E355D38E2244686C008F1AD6 /* GlobalExecutable.cpp */,
                                E355D38D2244686B008F1AD6 /* GlobalExecutable.h */,
                                79A0907D1D768465008B889B /* HashMapImpl.cpp */,
                                E33F507F1B8429A400413856 /* JSInternalPromise.h */,
                                E33F50761B84225700413856 /* JSInternalPromiseConstructor.cpp */,
                                E33F50771B84225700413856 /* JSInternalPromiseConstructor.h */,
-                               E33F50821B8437A000413856 /* JSInternalPromiseDeferred.cpp */,
-                               E33F50831B8437A000413856 /* JSInternalPromiseDeferred.h */,
                                E33F50721B8421C000413856 /* JSInternalPromisePrototype.cpp */,
                                E33F50731B8421C000413856 /* JSInternalPromisePrototype.h */,
                                14DA818F0D99FD2000B0A4FB /* JSLexicalEnvironment.cpp */,
                                7C184E1917BEDBD3007CB63A /* JSPromise.h */,
                                7C184E2017BEE240007CB63A /* JSPromiseConstructor.cpp */,
                                7C184E2117BEE240007CB63A /* JSPromiseConstructor.h */,
-                               7C008CD8187124BB00955C24 /* JSPromiseDeferred.cpp */,
-                               7C008CD9187124BB00955C24 /* JSPromiseDeferred.h */,
                                7C184E1C17BEE22E007CB63A /* JSPromisePrototype.cpp */,
                                7C184E1D17BEE22E007CB63A /* JSPromisePrototype.h */,
                                2A05ABD31961DF2400341750 /* JSPropertyNameEnumerator.cpp */,
                                868916A9155F285400CB2B9A /* PrivateName.h */,
                                147341DF1DC2CE9600AA29BA /* ProgramExecutable.cpp */,
                                147341D31DC02E6D00AA29BA /* ProgramExecutable.h */,
-                               534638761E71E06E00F12AC1 /* PromiseDeferredTimer.cpp */,
-                               534638741E70DDEC00F12AC1 /* PromiseDeferredTimer.h */,
+                               534638761E71E06E00F12AC1 /* PromiseTimer.cpp */,
+                               534638741E70DDEC00F12AC1 /* PromiseTimer.h */,
                                A7FB60A3103F7DC20017A286 /* PropertyDescriptor.cpp */,
                                A7FB604B103F5EAB0017A286 /* PropertyDescriptor.h */,
                                BC95437C0EBA70FD0072B6D3 /* PropertyMapHashTable.h */,
                                0F63945515D07057006A597C /* ArrayProfile.h in Headers */,
                                BC18C3E70E16F5CD00B34460 /* ArrayPrototype.h in Headers */,
                                0FB7F39615ED8E4600F167B2 /* ArrayStorage.h in Headers */,
+                               FE1D6D7123625AB1007A5C26 /* ArrayStorageInlines.h in Headers */,
                                9688CB150ED12B4E001D649F /* AssemblerBuffer.h in Headers */,
                                86D3B2C510156BDE002865E7 /* AssemblerBufferWithConstantPool.h in Headers */,
                                43C392AB1C3BEB0500241F53 /* AssemblerCommon.h in Headers */,
                                0FEC85041BDACDAC0080FF74 /* B3BlockWorklist.h in Headers */,
                                DCFDFBD91D1F5D9B00FE3D72 /* B3BottomProvider.h in Headers */,
                                0F6B8AE31C4EFE1700969052 /* B3BreakCriticalEdges.h in Headers */,
-                               FE1D6D752362649F007A5C26 /* ProtoCallFrameInlines.h in Headers */,
                                DC9A0C201D2D9CB30085124E /* B3CaseCollection.h in Headers */,
                                DC9A0C1F1D2D9CB10085124E /* B3CaseCollectionInlines.h in Headers */,
                                0F338DFA1BE96AA80013C88F /* B3CCallValue.h in Headers */,
                                0F338E1E1BF286EA0013C88F /* B3LowerMacros.h in Headers */,
                                4319DA041C1BE40D001D260B /* B3LowerMacrosAfterOptimizations.h in Headers */,
                                0FEC851E1BDACDAC0080FF74 /* B3LowerToAir.h in Headers */,
-                               FE1D6D6D2362544B007A5C26 /* RegisterInlines.h in Headers */,
                                43AB26C61C1A535900D82AE6 /* B3MathExtras.h in Headers */,
                                0FEC85201BDACDAC0080FF74 /* B3MemoryValue.h in Headers */,
                                0F2C63C41E69EF9400C13839 /* B3MemoryValueInlines.h in Headers */,
                                0F0332C418B01763005F979A /* GetByIdVariant.h in Headers */,
                                7964656A1B952FF0003059EE /* GetPutInfo.h in Headers */,
                                534E03581E53BF2F00213F64 /* GetterSetterAccessCase.h in Headers */,
+                               FE1D6D6F236258FE007A5C26 /* GetVM.h in Headers */,
                                0FEC3C5B1F33A48900F59B6C /* GigacageAlignedMemoryAllocator.h in Headers */,
                                14AD910E1DCA92940014F9FE /* GlobalCodeBlock.h in Headers */,
                                E355D38F22446877008F1AD6 /* GlobalExecutable.h in Headers */,
                                0F32BD111BB34F190093A57F /* HeapHelperPool.h in Headers */,
                                C2DA778318E259990066FCB6 /* HeapInlines.h in Headers */,
                                2AD8932B17E3868F00668276 /* HeapIterationScope.h in Headers */,
-                               FE1D6D7123625AB1007A5C26 /* ArrayStorageInlines.h in Headers */,
                                A5339EC91BB4B4600054F005 /* HeapObserver.h in Headers */,
                                A5398FAB1C750DA40060A963 /* HeapProfiler.h in Headers */,
                                A54C2AB11C6544F200A18D78 /* HeapSnapshot.h in Headers */,
                                E33F50811B8429A400413856 /* JSInternalPromise.h in Headers */,
                                E33F50791B84225700413856 /* JSInternalPromiseConstructor.h in Headers */,
                                E33F50871B8449EF00413856 /* JSInternalPromiseConstructor.lut.h in Headers */,
-                               E33F50851B8437A000413856 /* JSInternalPromiseDeferred.h in Headers */,
                                E33F50751B8421C000413856 /* JSInternalPromisePrototype.h in Headers */,
                                A503FA1E188E0FB000110F14 /* JSJavaScriptCallFramePrototype.h in Headers */,
                                BC18C4160E16F5CD00B34460 /* JSLexicalEnvironment.h in Headers */,
                                7C184E1B17BEDBD3007CB63A /* JSPromise.h in Headers */,
                                7C184E2317BEE240007CB63A /* JSPromiseConstructor.h in Headers */,
                                996B731E1BDA08EF00331B84 /* JSPromiseConstructor.lut.h in Headers */,
-                               7C008CDB187124BB00955C24 /* JSPromiseDeferred.h in Headers */,
                                7C184E1F17BEE22E007CB63A /* JSPromisePrototype.h in Headers */,
                                996B731F1BDA08EF00331B84 /* JSPromisePrototype.lut.h in Headers */,
                                2A05ABD61961DF2400341750 /* JSPropertyNameEnumerator.h in Headers */,
                                DC605B601CE26EA700593718 /* ProfilerUID.h in Headers */,
                                14AD91101DCA92940014F9FE /* ProgramCodeBlock.h in Headers */,
                                147341D41DC02E6D00AA29BA /* ProgramExecutable.h in Headers */,
-                               534638751E70DDEC00F12AC1 /* PromiseDeferredTimer.h in Headers */,
+                               534638751E70DDEC00F12AC1 /* PromiseTimer.h in Headers */,
                                0FD3E40E1B618B6600C80E1E /* PropertyCondition.h in Headers */,
                                A7FB61001040C38B0017A286 /* PropertyDescriptor.h in Headers */,
                                BC95437D0EBA70FD0072B6D3 /* PropertyMapHashTable.h in Headers */,
                                BC18C4550E16F5CD00B34460 /* PropertySlot.h in Headers */,
                                0FB7F39C15ED8E4600F167B2 /* PropertyStorage.h in Headers */,
                                BC18C4560E16F5CD00B34460 /* Protect.h in Headers */,
+                               FE1D6D752362649F007A5C26 /* ProtoCallFrameInlines.h in Headers */,
                                0F74B93B1F89614800B935D3 /* PrototypeKey.h in Headers */,
                                534E03561E53BEDE00213F64 /* ProxyableAccessCase.h in Headers */,
                                79B00CBD1C6AB07E0088C65D /* ProxyConstructor.h in Headers */,
                                BCD202C40E1706A7002C7E82 /* RegExpPrototype.h in Headers */,
                                BC18C45D0E16F5CD00B34460 /* Register.h in Headers */,
                                E328C6C91DA432F900D255FD /* RegisterAtOffset.h in Headers */,
-                               FE1D6D6F236258FE007A5C26 /* GetVM.h in Headers */,
                                E328C6C81DA4306100D255FD /* RegisterAtOffsetList.h in Headers */,
                                969A072B0ED1CE6900F1F681 /* RegisterID.h in Headers */,
                                9688CB160ED12B4E001D6499 /* RegisterInfo.h in Headers */,
+                               FE1D6D6D2362544B007A5C26 /* RegisterInlines.h in Headers */,
                                623A37EC1B87A7C000754209 /* RegisterMap.h in Headers */,
                                0FC314121814559100033232 /* RegisterSet.h in Headers */,
                                0FD0E5F01E46BF250006AB08 /* RegisterState.h in Headers */,
index c328fba..d1ce45d 100644 (file)
@@ -833,7 +833,6 @@ runtime/JSGlobalObjectFunctions.cpp
 runtime/JSImmutableButterfly.cpp
 runtime/JSInternalPromise.cpp
 runtime/JSInternalPromiseConstructor.cpp
-runtime/JSInternalPromiseDeferred.cpp
 runtime/JSInternalPromisePrototype.cpp
 runtime/JSLexicalEnvironment.cpp
 runtime/JSLock.cpp
@@ -850,7 +849,6 @@ runtime/JSONObject.cpp
 runtime/JSObject.cpp
 runtime/JSPromise.cpp
 runtime/JSPromiseConstructor.cpp
-runtime/JSPromiseDeferred.cpp
 runtime/JSPromisePrototype.cpp
 runtime/JSPropertyNameEnumerator.cpp
 runtime/JSProxy.cpp
@@ -907,7 +905,7 @@ runtime/ObjectToStringAdaptiveStructureWatchpoint.cpp
 runtime/Operations.cpp
 runtime/Options.cpp
 runtime/ProgramExecutable.cpp
-runtime/PromiseDeferredTimer.cpp
+runtime/PromiseTimer.cpp
 runtime/PropertyDescriptor.cpp
 runtime/PropertySlot.cpp
 runtime/PropertyTable.cpp
index 626fdeb..0df2818 100644 (file)
@@ -47,7 +47,6 @@
 #include "JSCInlines.h"
 #include "JSFunction.h"
 #include "JSInternalPromise.h"
-#include "JSInternalPromiseDeferred.h"
 #include "JSLock.h"
 #include "JSModuleLoader.h"
 #include "JSNativeStdFunction.h"
@@ -61,7 +60,7 @@
 #include "ObjectConstructor.h"
 #include "ParserError.h"
 #include "ProfilerDatabase.h"
-#include "PromiseDeferredTimer.h"
+#include "PromiseTimer.h"
 #include "ProtoCallFrame.h"
 #include "ReleaseHeapAccessScope.h"
 #include "SamplingProfiler.h"
@@ -826,15 +825,14 @@ JSInternalPromise* GlobalObject::moduleLoaderImportModule(JSGlobalObject* global
     VM& vm = globalObject->vm();
     auto throwScope = DECLARE_THROW_SCOPE(vm);
 
-    auto* deferred = JSInternalPromiseDeferred::tryCreate(globalObject);
-    RETURN_IF_EXCEPTION(throwScope, nullptr);
+    auto* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
 
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
     auto reject = [&] (JSValue rejectionReason) {
         catchScope.clearException();
-        auto result = deferred->reject(globalObject, rejectionReason);
+        promise->reject(globalObject, rejectionReason);
         catchScope.clearException();
-        return result;
+        return promise;
     };
 
     if (sourceOrigin.isNull())
@@ -1161,16 +1159,14 @@ static bool fetchModuleFromLocalFileSystem(const String& fileName, Vector& buffe
 JSInternalPromise* GlobalObject::moduleLoaderFetch(JSGlobalObject* globalObject, JSModuleLoader*, JSValue key, JSValue, JSValue)
 {
     VM& vm = globalObject->vm();
-    auto throwScope = DECLARE_THROW_SCOPE(vm);
-    JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::tryCreate(globalObject);
-    RETURN_IF_EXCEPTION(throwScope, nullptr);
+    JSInternalPromise* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
 
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
     auto reject = [&] (JSValue rejectionReason) {
         catchScope.clearException();
-        auto result = deferred->reject(globalObject, rejectionReason);
+        promise->reject(globalObject, rejectionReason);
         catchScope.clearException();
-        return result;
+        return promise;
     };
 
     String moduleKey = key.toWTFString(globalObject);
@@ -1192,18 +1188,18 @@ JSInternalPromise* GlobalObject::moduleLoaderFetch(JSGlobalObject* globalObject,
             catchScope.releaseAssertNoException();
             auto sourceCode = JSSourceCode::create(vm, WTFMove(source));
             catchScope.releaseAssertNoException();
-            auto result = deferred->resolve(globalObject, sourceCode);
+            promise->resolve(globalObject, sourceCode);
             catchScope.clearException();
-            return result;
+            return promise;
         }
     }
 #endif
 
     auto sourceCode = JSSourceCode::create(vm, jscSource(stringFromUTF(buffer), SourceOrigin { moduleKey }, WTFMove(moduleURL), TextPosition(), SourceProviderSourceType::Module));
     catchScope.releaseAssertNoException();
-    auto result = deferred->resolve(globalObject, sourceCode);
+    promise->resolve(globalObject, sourceCode);
     catchScope.clearException();
-    return result;
+    return promise;
 }
 
 JSObject* GlobalObject::moduleLoaderCreateImportMetaProperties(JSGlobalObject* globalObject, JSModuleLoader*, JSValue key, JSModuleRecord*, JSValue)
@@ -3003,7 +2999,7 @@ int runJSC(const CommandLine& options, bool isWorker, const Func& func)
         func(vm, globalObject, success);
         vm.drainMicrotasks();
     }
-    vm.promiseDeferredTimer->runRunLoop();
+    vm.promiseTimer->runRunLoop();
     {
         JSLockHolder locker(vm);
         if (options.m_interactive && success)
index 003eabf..a7bdf52 100644 (file)
@@ -34,7 +34,6 @@
 #include "JSCInlines.h"
 #include "JSGlobalObject.h"
 #include "JSInternalPromise.h"
-#include "JSInternalPromiseDeferred.h"
 #include "JSLock.h"
 #include "JSModuleLoader.h"
 #include "JSModuleRecord.h"
@@ -193,11 +192,9 @@ static JSInternalPromise* rejectPromise(JSGlobalObject* globalObject)
     scope.assertNoException();
     JSValue exception = scope.exception()->value();
     scope.clearException();
-    JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::tryCreate(globalObject);
-    scope.releaseAssertNoException();
-    deferred->reject(globalObject, exception);
-    scope.releaseAssertNoException();
-    return deferred->promise();
+    JSInternalPromise* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
+    promise->reject(globalObject, exception);
+    return promise;
 }
 
 JSInternalPromise* loadAndEvaluateModule(JSGlobalObject* globalObject, Symbol* moduleId, JSValue parameters, JSValue scriptFetcher)
index 3587aa6..9e09fbb 100644 (file)
@@ -543,7 +543,6 @@ void JSGlobalObject::init(VM& vm)
             init.set(JSFunction::create(init.vm, promiseConstructorResolveCodeGenerator(init.vm), init.owner));
         });
 
-    m_newPromiseCapabilityFunction.set(vm, this, JSFunction::create(vm, promiseOperationsNewPromiseCapabilityCodeGenerator(vm), this));
     m_functionProtoHasInstanceSymbolFunction.set(vm, this, hasInstanceSymbolFunction);
     m_throwTypeErrorGetterSetter.initLater(
         [] (const Initializer<GetterSetter>& init) {
@@ -980,6 +979,10 @@ capitalName ## Constructor* lowerName ## Constructor = featureFlag ? capitalName
     JSObject* setIteratorPrototype = SetIteratorPrototype::create(vm, this, SetIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
     setIteratorConstructorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, setIteratorPrototype);
 
+    m_newPromiseCapabilityFunction.set(vm, this, newPromiseCapabilityPrivateFunction);
+    m_resolvePromiseFunction.set(vm, this, resolvePromisePrivateFunction);
+    m_rejectPromiseFunction.set(vm, this, rejectPromisePrivateFunction);
+
     GlobalPropertyInfo staticGlobals[] = {
 #define INIT_PRIVATE_GLOBAL(varName, funcName, code) GlobalPropertyInfo(vm.propertyNames->builtinNames().funcName ## PrivateName(), varName ## PrivateFunction, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         JSC_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(INIT_PRIVATE_GLOBAL)
@@ -1706,10 +1709,12 @@ void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
     thisObject->m_evalFunction.visit(visitor);
     thisObject->m_iteratorProtocolFunction.visit(visitor);
     thisObject->m_promiseResolveFunction.visit(visitor);
+    visitor.append(thisObject->m_newPromiseCapabilityFunction);
+    visitor.append(thisObject->m_resolvePromiseFunction);
+    visitor.append(thisObject->m_rejectPromiseFunction);
     visitor.append(thisObject->m_promiseProtoThenFunction);
     visitor.append(thisObject->m_objectProtoValueOfFunction);
     visitor.append(thisObject->m_numberProtoToStringFunction);
-    visitor.append(thisObject->m_newPromiseCapabilityFunction);
     visitor.append(thisObject->m_functionProtoHasInstanceSymbolFunction);
     thisObject->m_throwTypeErrorGetterSetter.visit(visitor);
     visitor.append(thisObject->m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter);
index 081a6aa..248708d 100644 (file)
@@ -33,7 +33,7 @@
 #include "JSArrayBufferPrototype.h"
 #include "JSClassRef.h"
 #include "JSGlobalLexicalEnvironment.h"
-#include "JSPromiseDeferred.h"
+#include "JSPromise.h"
 #include "JSSegmentedVariableObject.h"
 #include "JSWeakObjectMapRefInternal.h"
 #include "LazyProperty.h"
@@ -226,10 +226,10 @@ struct GlobalObjectMethodTable {
     typedef String (*DefaultLanguageFunctionPtr)();
     DefaultLanguageFunctionPtr defaultLanguage;
 
-    typedef void (*CompileStreamingPtr)(JSGlobalObject*, JSPromiseDeferred*, JSValue);
+    typedef void (*CompileStreamingPtr)(JSGlobalObject*, JSPromise*, JSValue);
     CompileStreamingPtr compileStreaming;
 
-    typedef void (*InstantiateStreamingPtr)(JSGlobalObject*, JSPromiseDeferred*, JSValue, JSObject*);
+    typedef void (*InstantiateStreamingPtr)(JSGlobalObject*, JSPromise*, JSValue, JSObject*);
     InstantiateStreamingPtr instantiateStreaming;
 };
 
@@ -305,10 +305,12 @@ public:
     LazyProperty<JSGlobalObject, JSFunction> m_evalFunction;
     LazyProperty<JSGlobalObject, JSFunction> m_iteratorProtocolFunction;
     LazyProperty<JSGlobalObject, JSFunction> m_promiseResolveFunction;
+    WriteBarrier<JSFunction> m_newPromiseCapabilityFunction;
+    WriteBarrier<JSFunction> m_resolvePromiseFunction;
+    WriteBarrier<JSFunction> m_rejectPromiseFunction;
     WriteBarrier<JSFunction> m_promiseProtoThenFunction;
     WriteBarrier<JSFunction> m_objectProtoValueOfFunction;
     WriteBarrier<JSFunction> m_numberProtoToStringFunction;
-    WriteBarrier<JSFunction> m_newPromiseCapabilityFunction;
     WriteBarrier<JSFunction> m_functionProtoHasInstanceSymbolFunction;
     LazyProperty<JSGlobalObject, GetterSetter> m_throwTypeErrorGetterSetter;
     WriteBarrier<JSObject> m_regExpProtoExec;
@@ -620,11 +622,13 @@ public:
     JSFunction* arrayProtoToStringFunction() const { return m_arrayProtoToStringFunction.get(this); }
     JSFunction* arrayProtoValuesFunction() const { return m_arrayProtoValuesFunction.get(this); }
     JSFunction* iteratorProtocolFunction() const { return m_iteratorProtocolFunction.get(this); }
+    JSFunction* newPromiseCapabilityFunction() const { return m_newPromiseCapabilityFunction.get(); }
     JSFunction* promiseResolveFunction() const { return m_promiseResolveFunction.get(this); }
+    JSFunction* resolvePromiseFunction() const { return m_resolvePromiseFunction.get(); }
+    JSFunction* rejectPromiseFunction() const { return m_rejectPromiseFunction.get(); }
     JSFunction* promiseProtoThenFunction() const { return m_promiseProtoThenFunction.get(); }
     JSFunction* objectProtoValueOfFunction() const { return m_objectProtoValueOfFunction.get(); }
     JSFunction* numberProtoToStringFunction() const { return m_numberProtoToStringFunction.get(); }
-    JSFunction* newPromiseCapabilityFunction() const { return m_newPromiseCapabilityFunction.get(); }
     JSFunction* functionProtoHasInstanceSymbolFunction() const { return m_functionProtoHasInstanceSymbolFunction.get(); }
     JSObject* regExpProtoExecFunction() const { return m_regExpProtoExec.get(); }
     JSObject* regExpProtoSymbolReplaceFunction() const { return m_regExpProtoSymbolReplace.get(); }
index ad6b934..b8113dc 100644 (file)
@@ -39,7 +39,6 @@
 #include "JSInternalPromise.h"
 #include "JSModuleLoader.h"
 #include "JSPromise.h"
-#include "JSPromiseDeferred.h"
 #include "JSString.h"
 #include "Lexer.h"
 #include "LiteralParser.h"
@@ -807,17 +806,15 @@ EncodedJSValue JSC_HOST_CALL globalFuncBuiltinDescribe(JSGlobalObject* globalObj
 EncodedJSValue JSC_HOST_CALL globalFuncImportModule(JSGlobalObject* globalObject, CallFrame* callFrame)
 {
     VM& vm = globalObject->vm();
-    auto throwScope = DECLARE_THROW_SCOPE(vm);
 
-    auto* promise = JSPromiseDeferred::tryCreate(globalObject);
-    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+    auto* promise = JSPromise::create(vm, globalObject->promiseStructure());
 
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
     auto reject = [&] (JSValue rejectionReason) {
         catchScope.clearException();
         promise->reject(globalObject, rejectionReason);
         catchScope.clearException();
-        return JSValue::encode(promise->promise());
+        return JSValue::encode(promise);
     };
 
     auto sourceOrigin = callFrame->callerSourceOrigin(vm);
@@ -835,7 +832,7 @@ EncodedJSValue JSC_HOST_CALL globalFuncImportModule(JSGlobalObject* globalObject
     promise->resolve(globalObject, internalPromise);
 
     catchScope.clearException();
-    return JSValue::encode(promise->promise());
+    return JSValue::encode(promise);
 }
 
 EncodedJSValue JSC_HOST_CALL globalFuncPropertyIsEnumerable(JSGlobalObject* globalObject, CallFrame* callFrame)
index 9c154b1..8e7df5e 100644 (file)
@@ -43,7 +43,7 @@ class JSInternalPromise final : public JSPromise {
 public:
     typedef JSPromise Base;
 
-    static JSInternalPromise* create(VM&, Structure*);
+    JS_EXPORT_PRIVATE static JSInternalPromise* create(VM&, Structure*);
     static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
 
     DECLARE_EXPORT_INFO;
diff --git a/Source/JavaScriptCore/runtime/JSInternalPromiseDeferred.cpp b/Source/JavaScriptCore/runtime/JSInternalPromiseDeferred.cpp
deleted file mode 100644 (file)
index 4384843..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "JSInternalPromiseDeferred.h"
-
-#include "BuiltinNames.h"
-#include "Error.h"
-#include "Exception.h"
-#include "JSCInlines.h"
-#include "JSInternalPromise.h"
-#include "JSInternalPromiseConstructor.h"
-
-namespace JSC {
-
-const ClassInfo JSInternalPromiseDeferred::s_info = { "JSInternalPromiseDeferred", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSInternalPromiseDeferred) };
-
-JSInternalPromiseDeferred* JSInternalPromiseDeferred::tryCreate(JSGlobalObject* globalObject)
-{
-    VM& vm = globalObject->vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-
-    DeferredData data = createDeferredData(globalObject, globalObject->internalPromiseConstructor());
-    RETURN_IF_EXCEPTION(scope, nullptr);
-
-    JSInternalPromiseDeferred* result = new (NotNull, allocateCell<JSInternalPromiseDeferred>(vm.heap)) JSInternalPromiseDeferred(vm);
-    result->finishCreation(vm, data.promise, data.resolve, data.reject);
-    return result;
-}
-
-JSInternalPromiseDeferred::JSInternalPromiseDeferred(VM& vm)
-    : Base(vm, vm.internalPromiseDeferredStructure.get())
-{
-}
-
-JSInternalPromise* JSInternalPromiseDeferred::promise() const
-{
-    return jsCast<JSInternalPromise*>(Base::promise());
-}
-
-JSInternalPromise* JSInternalPromiseDeferred::resolve(JSGlobalObject* globalObject, JSValue value)
-{
-    Base::resolve(globalObject, value);
-    return promise();
-}
-
-JSInternalPromise* JSInternalPromiseDeferred::reject(JSGlobalObject* globalObject, JSValue reason)
-{
-    Base::reject(globalObject, reason);
-    return promise();
-}
-
-JSInternalPromise* JSInternalPromiseDeferred::reject(JSGlobalObject* globalObject, Exception* reason)
-{
-    return reject(globalObject, reason->value());
-}
-
-} // namespace JSC
diff --git a/Source/JavaScriptCore/runtime/JSInternalPromiseDeferred.h b/Source/JavaScriptCore/runtime/JSInternalPromiseDeferred.h
deleted file mode 100644 (file)
index eb9909c..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2015-2019 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include "JSPromiseDeferred.h"
-
-namespace JSC {
-
-class JSInternalPromise;
-
-class JSInternalPromiseDeferred final : public JSPromiseDeferred {
-public:
-    typedef JSPromiseDeferred Base;
-    static constexpr unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
-
-    JS_EXPORT_PRIVATE static JSInternalPromiseDeferred* tryCreate(JSGlobalObject*);
-
-    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
-    {
-        return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info());
-    }
-
-    DECLARE_EXPORT_INFO;
-
-    JS_EXPORT_PRIVATE JSInternalPromise* promise() const;
-    JS_EXPORT_PRIVATE JSInternalPromise* resolve(JSGlobalObject*, JSValue);
-    JS_EXPORT_PRIVATE JSInternalPromise* reject(JSGlobalObject*, JSValue);
-    JS_EXPORT_PRIVATE JSInternalPromise* reject(JSGlobalObject*, Exception*);
-
-private:
-    JSInternalPromiseDeferred(VM&);
-};
-
-} // namespace JSC
index 57c8403..64dd3e6 100644 (file)
@@ -35,7 +35,6 @@
 #include "JSCInlines.h"
 #include "JSGlobalObjectFunctions.h"
 #include "JSInternalPromise.h"
-#include "JSInternalPromiseDeferred.h"
 #include "JSMap.h"
 #include "JSModuleEnvironment.h"
 #include "JSModuleNamespaceObject.h"
@@ -262,21 +261,20 @@ JSInternalPromise* JSModuleLoader::importModule(JSGlobalObject* globalObject, JS
     if (globalObject->globalObjectMethodTable()->moduleLoaderImportModule)
         RELEASE_AND_RETURN(throwScope, globalObject->globalObjectMethodTable()->moduleLoaderImportModule(globalObject, this, moduleName, parameters, referrer));
 
-    auto* deferred = JSInternalPromiseDeferred::tryCreate(globalObject);
-    RETURN_IF_EXCEPTION(throwScope, nullptr);
+    auto* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
 
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
     auto moduleNameString = moduleName->value(globalObject);
     if (UNLIKELY(catchScope.exception())) {
         JSValue exception = catchScope.exception()->value();
         catchScope.clearException();
-        deferred->reject(globalObject, exception);
+        promise->reject(globalObject, exception);
         catchScope.clearException();
-        return deferred->promise();
+        return promise;
     }
-    deferred->reject(globalObject, createError(globalObject, makeString("Could not import the module '", moduleNameString, "'.")));
+    promise->reject(globalObject, createError(globalObject, makeString("Could not import the module '", moduleNameString, "'.")));
     catchScope.clearException();
-    return deferred->promise();
+    return promise;
 }
 
 Identifier JSModuleLoader::resolveSync(JSGlobalObject* globalObject, JSValue name, JSValue referrer, JSValue scriptFetcher)
@@ -292,10 +290,8 @@ Identifier JSModuleLoader::resolveSync(JSGlobalObject* globalObject, JSValue nam
 JSInternalPromise* JSModuleLoader::resolve(JSGlobalObject* globalObject, JSValue name, JSValue referrer, JSValue scriptFetcher)
 {
     VM& vm = globalObject->vm();
-    auto throwScope = DECLARE_THROW_SCOPE(vm);
 
-    JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::tryCreate(globalObject);
-    RETURN_IF_EXCEPTION(throwScope, nullptr);
+    auto* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
 
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
 
@@ -303,13 +299,13 @@ JSInternalPromise* JSModuleLoader::resolve(JSGlobalObject* globalObject, JSValue
     if (UNLIKELY(catchScope.exception())) {
         JSValue exception = catchScope.exception();
         catchScope.clearException();
-        auto result = deferred->reject(globalObject, exception);
+        promise->reject(globalObject, exception);
         catchScope.clearException();
-        return result;
+        return promise;
     }
-    auto result = deferred->resolve(globalObject, identifierToJSValue(vm, moduleKey));
+    promise->resolve(globalObject, identifierToJSValue(vm, moduleKey));
     catchScope.clearException();
-    return result;
+    return promise;
 }
 
 JSInternalPromise* JSModuleLoader::fetch(JSGlobalObject* globalObject, JSValue key, JSValue parameters, JSValue scriptFetcher)
@@ -323,8 +319,7 @@ JSInternalPromise* JSModuleLoader::fetch(JSGlobalObject* globalObject, JSValue k
     if (globalObject->globalObjectMethodTable()->moduleLoaderFetch)
         RELEASE_AND_RETURN(throwScope, globalObject->globalObjectMethodTable()->moduleLoaderFetch(globalObject, this, key, parameters, scriptFetcher));
 
-    JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::tryCreate(globalObject);
-    RETURN_IF_EXCEPTION(throwScope, nullptr);
+    auto* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
 
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
 
@@ -332,13 +327,13 @@ JSInternalPromise* JSModuleLoader::fetch(JSGlobalObject* globalObject, JSValue k
     if (UNLIKELY(catchScope.exception())) {
         JSValue exception = catchScope.exception()->value();
         catchScope.clearException();
-        deferred->reject(globalObject, exception);
+        promise->reject(globalObject, exception);
         catchScope.clearException();
-        return deferred->promise();
+        return promise;
     }
-    deferred->reject(globalObject, createError(globalObject, makeString("Could not open the module '", moduleKey, "'.")));
+    promise->reject(globalObject, createError(globalObject, makeString("Could not open the module '", moduleKey, "'.")));
     catchScope.clearException();
-    return deferred->promise();
+    return promise;
 }
 
 JSObject* JSModuleLoader::createImportMetaProperties(JSGlobalObject* globalObject, JSValue key, JSModuleRecord* moduleRecord, JSValue scriptFetcher)
@@ -385,17 +380,15 @@ JSModuleNamespaceObject* JSModuleLoader::getModuleNamespaceObject(JSGlobalObject
 EncodedJSValue JSC_HOST_CALL moduleLoaderParseModule(JSGlobalObject* globalObject, CallFrame* callFrame)
 {
     VM& vm = globalObject->vm();
-    auto throwScope = DECLARE_THROW_SCOPE(vm);
 
-    JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::tryCreate(globalObject);
-    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+    auto* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
 
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
     auto reject = [&] (JSValue rejectionReason) {
         catchScope.clearException();
-        auto result = deferred->reject(globalObject, rejectionReason);
+        promise->reject(globalObject, rejectionReason);
         catchScope.clearException();
-        return JSValue::encode(result);
+        return JSValue::encode(promise);
     };
 
     const Identifier moduleKey = callFrame->argument(0).toPropertyKey(globalObject);
@@ -408,7 +401,7 @@ EncodedJSValue JSC_HOST_CALL moduleLoaderParseModule(JSGlobalObject* globalObjec
 
 #if ENABLE(WEBASSEMBLY)
     if (sourceCode.provider()->sourceType() == SourceProviderSourceType::WebAssembly)
-        return JSValue::encode(JSWebAssembly::instantiate(globalObject, deferred, moduleKey, jsSourceCode));
+        return JSValue::encode(JSWebAssembly::instantiate(globalObject, promise, moduleKey, jsSourceCode));
 #endif
 
     CodeProfiling profile(sourceCode);
@@ -425,9 +418,9 @@ EncodedJSValue JSC_HOST_CALL moduleLoaderParseModule(JSGlobalObject* globalObjec
     if (UNLIKELY(catchScope.exception()))
         return reject(catchScope.exception());
 
-    auto result = deferred->resolve(globalObject, moduleAnalyzer.analyze(*moduleProgramNode));
+    promise->resolve(globalObject, moduleAnalyzer.analyze(*moduleProgramNode));
     catchScope.clearException();
-    return JSValue::encode(result);
+    return JSValue::encode(promise);
 }
 
 EncodedJSValue JSC_HOST_CALL moduleLoaderRequestedModules(JSGlobalObject* globalObject, CallFrame* callFrame)
index b018c37..3e6999f 100644 (file)
@@ -32,6 +32,7 @@
 #include "JSInternalFieldObjectImplInlines.h"
 #include "JSPromiseConstructor.h"
 #include "Microtask.h"
+#include "PromiseTimer.h"
 
 namespace JSC {
 
@@ -83,30 +84,107 @@ JSValue JSPromise::result(VM& vm) const
     return internalField(static_cast<unsigned>(Field::ReactionsOrResult)).get();
 }
 
-bool JSPromise::isHandled(VM&) const
+uint32_t JSPromise::flags() const
 {
     JSValue value = internalField(static_cast<unsigned>(Field::Flags)).get();
-    uint32_t flags = value.asUInt32AsAnyInt();
-    return flags & isHandledFlag;
+    return value.asUInt32AsAnyInt();
+}
+
+bool JSPromise::isHandled(VM&) const
+{
+    return flags() & isHandledFlag;
 }
 
-JSPromise* JSPromise::resolve(JSGlobalObject* globalObject, JSValue value)
+JSPromise::DeferredData JSPromise::createDeferredData(JSGlobalObject* globalObject, JSPromiseConstructor* promiseConstructor)
 {
-    auto& vm = globalObject->vm();
+    VM& vm = globalObject->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
 
-    auto* promiseResolveFunction = globalObject->promiseResolveFunction();
+    JSFunction* newPromiseCapabilityFunction = globalObject->newPromiseCapabilityFunction();
     CallData callData;
-    auto callType = JSC::getCallData(vm, promiseResolveFunction, callData);
+    CallType callType = JSC::getCallData(globalObject->vm(), newPromiseCapabilityFunction, callData);
     ASSERT(callType != CallType::None);
 
     MarkedArgumentBuffer arguments;
-    arguments.append(value);
+    arguments.append(promiseConstructor);
     ASSERT(!arguments.hasOverflowed());
-    auto result = call(globalObject, promiseResolveFunction, callType, callData, globalObject->promiseConstructor(), arguments);
+    JSValue deferred = call(globalObject, newPromiseCapabilityFunction, callType, callData, jsUndefined(), arguments);
+    RETURN_IF_EXCEPTION(scope, { });
+
+    DeferredData result;
+    result.promise = jsCast<JSPromise*>(deferred.get(globalObject, vm.propertyNames->builtinNames().promisePrivateName()));
+    RETURN_IF_EXCEPTION(scope, { });
+    result.resolve = jsCast<JSFunction*>(deferred.get(globalObject, vm.propertyNames->builtinNames().resolvePrivateName()));
+    RETURN_IF_EXCEPTION(scope, { });
+    result.reject = jsCast<JSFunction*>(deferred.get(globalObject, vm.propertyNames->builtinNames().rejectPrivateName()));
+    RETURN_IF_EXCEPTION(scope, { });
+
+    return result;
+}
+
+JSPromise* JSPromise::resolvedPromise(JSGlobalObject* globalObject, JSValue value)
+{
+    VM& vm = globalObject->vm();
+    auto scope = DECLARE_THROW_SCOPE(vm);
+
+    JSFunction* function = globalObject->promiseResolveFunction();
+    CallData callData;
+    CallType callType = JSC::getCallData(vm, function, callData);
+    ASSERT(callType != CallType::None);
+
+    MarkedArgumentBuffer arguments;
+    arguments.append(value);
+    auto result = call(globalObject, function, callType, callData, globalObject->promiseConstructor(), arguments);
     RETURN_IF_EXCEPTION(scope, nullptr);
     ASSERT(result.inherits<JSPromise>(vm));
     return jsCast<JSPromise*>(result);
 }
 
+static inline void callFunction(JSGlobalObject* globalObject, JSValue function, JSPromise* promise, JSValue value)
+{
+    CallData callData;
+    CallType callType = getCallData(globalObject->vm(), function, callData);
+    ASSERT(callType != CallType::None);
+
+    MarkedArgumentBuffer arguments;
+    arguments.append(promise);
+    arguments.append(value);
+    ASSERT(!arguments.hasOverflowed());
+
+    call(globalObject, function, callType, callData, jsUndefined(), arguments);
+}
+
+void JSPromise::resolve(JSGlobalObject* lexicalGlobalObject, JSValue value)
+{
+    VM& vm = lexicalGlobalObject->vm();
+    auto scope = DECLARE_THROW_SCOPE(vm);
+    uint32_t flags = this->flags();
+    if (!(flags & isFirstResolvingFunctionCalledFlag)) {
+        internalField(static_cast<unsigned>(Field::Flags)).set(vm, this, jsNumber(flags | isFirstResolvingFunctionCalledFlag));
+        JSGlobalObject* globalObject = this->globalObject(vm);
+        callFunction(lexicalGlobalObject, globalObject->resolvePromiseFunction(), this, value);
+        RETURN_IF_EXCEPTION(scope, void());
+    }
+    vm.promiseTimer->cancelPendingPromise(this);
+}
+
+void JSPromise::reject(JSGlobalObject* lexicalGlobalObject, JSValue value)
+{
+    VM& vm = lexicalGlobalObject->vm();
+    auto scope = DECLARE_THROW_SCOPE(vm);
+    uint32_t flags = this->flags();
+    if (!(flags & isFirstResolvingFunctionCalledFlag)) {
+        internalField(static_cast<unsigned>(Field::Flags)).set(vm, this, jsNumber(flags | isFirstResolvingFunctionCalledFlag));
+        JSGlobalObject* globalObject = this->globalObject(vm);
+        callFunction(lexicalGlobalObject, globalObject->rejectPromiseFunction(), this, value);
+        RETURN_IF_EXCEPTION(scope, void());
+    }
+    vm.promiseTimer->cancelPendingPromise(this);
+}
+
+void JSPromise::reject(JSGlobalObject* lexicalGlobalObject, Exception* reason)
+{
+    reject(lexicalGlobalObject, reason->value());
+}
+
 } // namespace JSC
index a48c13c..63400e3 100644 (file)
 
 namespace JSC {
 
+class JSPromiseConstructor;
 class JSPromise : public JSInternalFieldObjectImpl<2> {
 public:
     using Base = JSInternalFieldObjectImpl<2>;
 
-    static JSPromise* create(VM&, Structure*);
+    JS_EXPORT_PRIVATE static JSPromise* create(VM&, Structure*);
     static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
 
     DECLARE_EXPORT_INFO;
@@ -57,13 +58,28 @@ public:
     JS_EXPORT_PRIVATE JSValue result(VM&) const;
     JS_EXPORT_PRIVATE bool isHandled(VM&) const;
 
-    JS_EXPORT_PRIVATE static JSPromise* resolve(JSGlobalObject*, JSValue);
+    JS_EXPORT_PRIVATE static JSPromise* resolvedPromise(JSGlobalObject*, JSValue);
+
+    JS_EXPORT_PRIVATE void resolve(JSGlobalObject*, JSValue);
+    JS_EXPORT_PRIVATE void reject(JSGlobalObject*, JSValue);
+    JS_EXPORT_PRIVATE void reject(JSGlobalObject*, Exception*);
+
+    struct DeferredData {
+        WTF_FORBID_HEAP_ALLOCATION;
+    public:
+        JSPromise* promise { nullptr };
+        JSFunction* resolve { nullptr };
+        JSFunction* reject { nullptr };
+    };
+    static DeferredData createDeferredData(JSGlobalObject*, JSPromiseConstructor*);
 
     static void visitChildren(JSCell*, SlotVisitor&);
 
 protected:
     JSPromise(VM&, Structure*);
     void finishCreation(VM&);
+
+    uint32_t flags() const;
 };
 
 } // namespace JSC
diff --git a/Source/JavaScriptCore/runtime/JSPromiseDeferred.cpp b/Source/JavaScriptCore/runtime/JSPromiseDeferred.cpp
deleted file mode 100644 (file)
index b5e7161..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "JSPromiseDeferred.h"
-
-#include "BuiltinNames.h"
-#include "Error.h"
-#include "Exception.h"
-#include "JSCInlines.h"
-#include "JSObjectInlines.h"
-#include "JSPromise.h"
-#include "JSPromiseConstructor.h"
-#include "PromiseDeferredTimer.h"
-
-namespace JSC {
-
-const ClassInfo JSPromiseDeferred::s_info = { "JSPromiseDeferred", nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(JSPromiseDeferred) };
-
-JSPromiseDeferred::DeferredData JSPromiseDeferred::createDeferredData(JSGlobalObject* globalObject, JSPromiseConstructor* promiseConstructor)
-{
-    VM& vm = globalObject->vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-
-    JSFunction* newPromiseCapabilityFunction = globalObject->newPromiseCapabilityFunction();
-    CallData callData;
-    CallType callType = JSC::getCallData(globalObject->vm(), newPromiseCapabilityFunction, callData);
-    ASSERT(callType != CallType::None);
-
-    MarkedArgumentBuffer arguments;
-    arguments.append(promiseConstructor);
-    ASSERT(!arguments.hasOverflowed());
-    JSValue deferred = call(globalObject, newPromiseCapabilityFunction, callType, callData, jsUndefined(), arguments);
-    RETURN_IF_EXCEPTION(scope, { });
-
-    DeferredData result;
-    result.promise = jsCast<JSPromise*>(deferred.get(globalObject, vm.propertyNames->builtinNames().promisePrivateName()));
-    RETURN_IF_EXCEPTION(scope, { });
-    result.resolve = jsCast<JSFunction*>(deferred.get(globalObject, vm.propertyNames->builtinNames().resolvePrivateName()));
-    RETURN_IF_EXCEPTION(scope, { });
-    result.reject = jsCast<JSFunction*>(deferred.get(globalObject, vm.propertyNames->builtinNames().rejectPrivateName()));
-    RETURN_IF_EXCEPTION(scope, { });
-
-    return result;
-}
-
-JSPromiseDeferred* JSPromiseDeferred::tryCreate(JSGlobalObject* globalObject)
-{
-    VM& vm = globalObject->vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-
-    DeferredData data = createDeferredData(globalObject, globalObject->promiseConstructor());
-    RETURN_IF_EXCEPTION(scope, { });
-    return JSPromiseDeferred::create(vm, data.promise, data.resolve, data.reject);
-}
-
-JSPromiseDeferred* JSPromiseDeferred::create(VM& vm, JSPromise* promise, JSFunction* resolve, JSFunction* reject)
-{
-    JSPromiseDeferred* deferred = new (NotNull, allocateCell<JSPromiseDeferred>(vm.heap)) JSPromiseDeferred(vm);
-    deferred->finishCreation(vm, promise, resolve, reject);
-    return deferred;
-}
-
-JSPromiseDeferred::JSPromiseDeferred(VM& vm)
-    : JSPromiseDeferred(vm, vm.promiseDeferredStructure.get())
-{
-}
-
-JSPromiseDeferred::JSPromiseDeferred(VM& vm, Structure* structure)
-    : Base(vm, structure)
-{
-}
-
-static inline void callFunction(JSGlobalObject* globalObject, JSValue function, JSValue value)
-{
-    CallData callData;
-    CallType callType = getCallData(globalObject->vm(), function, callData);
-    ASSERT(callType != CallType::None);
-
-    MarkedArgumentBuffer arguments;
-    arguments.append(value);
-    ASSERT(!arguments.hasOverflowed());
-
-    call(globalObject, function, callType, callData, jsUndefined(), arguments);
-}
-
-void JSPromiseDeferred::resolve(JSGlobalObject* globalObject, JSValue value)
-{
-    callFunction(globalObject, m_resolve.get(), value);
-    bool wasPending = globalObject->vm().promiseDeferredTimer->cancelPendingPromise(this);
-    ASSERT_UNUSED(wasPending, wasPending == m_promiseIsAsyncPending);
-}
-
-void JSPromiseDeferred::reject(JSGlobalObject* globalObject, JSValue reason)
-{
-    callFunction(globalObject, m_reject.get(), reason);
-    bool wasPending = globalObject->vm().promiseDeferredTimer->cancelPendingPromise(this);
-    ASSERT_UNUSED(wasPending, wasPending == m_promiseIsAsyncPending);
-}
-
-void JSPromiseDeferred::reject(JSGlobalObject* globalObject, Exception* reason)
-{
-    reject(globalObject, reason->value());
-}
-
-void JSPromiseDeferred::finishCreation(VM& vm, JSPromise* promise, JSFunction* resolve, JSFunction* reject)
-{
-    Base::finishCreation(vm);
-    m_promise.set(vm, this, promise);
-    m_resolve.set(vm, this, resolve);
-    m_reject.set(vm, this, reject);
-}
-
-void JSPromiseDeferred::visitChildren(JSCell* cell, SlotVisitor& visitor)
-{
-    JSPromiseDeferred* thisObject = jsCast<JSPromiseDeferred*>(cell);
-    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
-
-    Base::visitChildren(thisObject, visitor);
-
-    visitor.append(thisObject->m_promise);
-    visitor.append(thisObject->m_resolve);
-    visitor.append(thisObject->m_reject);
-}
-
-} // namespace JSC
diff --git a/Source/JavaScriptCore/runtime/JSPromiseDeferred.h b/Source/JavaScriptCore/runtime/JSPromiseDeferred.h
deleted file mode 100644 (file)
index a9cfa9b..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2013-2019 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include "JSCast.h"
-#include "JSPromise.h"
-#include "Structure.h"
-
-namespace JSC {
-
-class Exception;
-class JSPromiseConstructor;
-class JSFunction;
-
-class JSPromiseDeferred : public JSCell {
-public:
-    typedef JSCell Base;
-    static constexpr unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
-
-    struct DeferredData {
-        WTF_FORBID_HEAP_ALLOCATION;
-    public:
-        JSPromise* promise { nullptr };
-        JSFunction* resolve { nullptr };
-        JSFunction* reject { nullptr };
-    };
-    static DeferredData createDeferredData(JSGlobalObject*, JSPromiseConstructor*);
-
-    JS_EXPORT_PRIVATE static JSPromiseDeferred* tryCreate(JSGlobalObject*);
-    JS_EXPORT_PRIVATE static JSPromiseDeferred* create(VM&, JSPromise*, JSFunction* resolve, JSFunction* reject);
-
-    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
-    {
-        return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info());
-    }
-
-    DECLARE_EXPORT_INFO;
-
-    JSPromise* promise() const { return m_promise.get(); }
-    JSFunction* resolve() const { return m_resolve.get(); }
-    JSFunction* reject() const { return m_reject.get(); }
-
-    JS_EXPORT_PRIVATE void resolve(JSGlobalObject*, JSValue);
-    JS_EXPORT_PRIVATE void reject(JSGlobalObject*, JSValue);
-    JS_EXPORT_PRIVATE void reject(JSGlobalObject*, Exception*);
-
-#ifndef NDEBUG
-    void promiseAsyncPending() { m_promiseIsAsyncPending = true; }
-#endif
-
-protected:
-    JSPromiseDeferred(VM&, Structure*);
-    void finishCreation(VM&, JSPromise*, JSFunction* resolve, JSFunction* reject);
-    static void visitChildren(JSCell*, SlotVisitor&);
-
-private:
-    JSPromiseDeferred(VM&);
-
-#ifndef NDEBUG
-    bool m_promiseIsAsyncPending { false };
-#endif
-
-    WriteBarrier<JSPromise> m_promise;
-    WriteBarrier<JSFunction> m_resolve;
-    WriteBarrier<JSFunction> m_reject;
-};
-
-} // namespace JSC
@@ -24,9 +24,9 @@
  */
 
 #include "config.h"
-#include "PromiseDeferredTimer.h"
+#include "PromiseTimer.h"
 
-#include "JSPromiseDeferred.h"
+#include "JSPromise.h"
 #include "StrongInlines.h"
 #include "VM.h"
 #include <wtf/Locker.h>
 
 namespace JSC {
 
-namespace PromiseDeferredTimerInternal {
+namespace PromiseTimerInternal {
 static constexpr bool verbose = false;
 }
 
-PromiseDeferredTimer::PromiseDeferredTimer(VM& vm)
+PromiseTimer::PromiseTimer(VM& vm)
     : Base(vm)
 {
 }
 
-void PromiseDeferredTimer::doWork(VM& vm)
+void PromiseTimer::doWork(VM& vm)
 {
     ASSERT(vm.currentThreadIsHoldingAPILock());
     m_taskLock.lock();
@@ -55,7 +55,7 @@ void PromiseDeferredTimer::doWork(VM& vm)
 
     while (!m_tasks.isEmpty()) {
         auto [ticket, task] = m_tasks.takeLast();
-        dataLogLnIf(PromiseDeferredTimerInternal::verbose, "Doing work on promise: ", RawPointer(ticket));
+        dataLogLnIf(PromiseTimerInternal::verbose, "Doing work on promise: ", RawPointer(ticket));
 
         // We may have already canceled these promises.
         if (m_pendingPromises.contains(ticket)) {
@@ -82,7 +82,7 @@ void PromiseDeferredTimer::doWork(VM& vm)
     m_taskLock.unlock();
 }
 
-void PromiseDeferredTimer::runRunLoop()
+void PromiseTimer::runRunLoop()
 {
     ASSERT(!m_apiLock->vm()->currentThreadIsHoldingAPILock());
 #if USE(CF)
@@ -98,7 +98,7 @@ void PromiseDeferredTimer::runRunLoop()
     }
 }
 
-void PromiseDeferredTimer::addPendingPromise(VM& vm, JSPromiseDeferred* ticket, Vector<Strong<JSCell>>&& dependencies)
+void PromiseTimer::addPendingPromise(VM& vm, JSPromise* ticket, Vector<Strong<JSCell>>&& dependencies)
 {
     ASSERT(vm.currentThreadIsHoldingAPILock());
     for (unsigned i = 0; i < dependencies.size(); ++i)
@@ -106,26 +106,22 @@ void PromiseDeferredTimer::addPendingPromise(VM& vm, JSPromiseDeferred* ticket,
 
     auto result = m_pendingPromises.add(ticket, Vector<Strong<JSCell>>());
     if (result.isNewEntry) {
-        dataLogLnIf(PromiseDeferredTimerInternal::verbose, "Adding new pending promise: ", RawPointer(ticket));
+        dataLogLnIf(PromiseTimerInternal::verbose, "Adding new pending promise: ", RawPointer(ticket));
         dependencies.append(Strong<JSCell>(vm, ticket));
         result.iterator->value = WTFMove(dependencies);
     } else {
-        dataLogLnIf(PromiseDeferredTimerInternal::verbose, "Adding new dependencies for promise: ", RawPointer(ticket));
+        dataLogLnIf(PromiseTimerInternal::verbose, "Adding new dependencies for promise: ", RawPointer(ticket));
         result.iterator->value.appendVector(dependencies);
     }
-
-#ifndef NDEBUG
-    ticket->promiseAsyncPending();
-#endif
 }
 
-bool PromiseDeferredTimer::hasPendingPromise(JSPromiseDeferred* ticket)
+bool PromiseTimer::hasPendingPromise(JSPromise* ticket)
 {
     ASSERT(ticket->vm().currentThreadIsHoldingAPILock());
     return m_pendingPromises.contains(ticket);
 }
 
-bool PromiseDeferredTimer::hasDependancyInPendingPromise(JSPromiseDeferred* ticket, JSCell* dependency)
+bool PromiseTimer::hasDependancyInPendingPromise(JSPromise* ticket, JSCell* dependency)
 {
     ASSERT(ticket->vm().currentThreadIsHoldingAPILock());
     ASSERT(m_pendingPromises.contains(ticket));
@@ -134,18 +130,18 @@ bool PromiseDeferredTimer::hasDependancyInPendingPromise(JSPromiseDeferred* tick
     return result.contains(dependency);
 }
 
-bool PromiseDeferredTimer::cancelPendingPromise(JSPromiseDeferred* ticket)
+bool PromiseTimer::cancelPendingPromise(JSPromise* ticket)
 {
     ASSERT(ticket->vm().currentThreadIsHoldingAPILock());
     bool result = m_pendingPromises.remove(ticket);
 
     if (result)
-        dataLogLnIf(PromiseDeferredTimerInternal::verbose, "Canceling promise: ", RawPointer(ticket));
+        dataLogLnIf(PromiseTimerInternal::verbose, "Canceling promise: ", RawPointer(ticket));
 
     return result;
 }
 
-void PromiseDeferredTimer::scheduleWorkSoon(JSPromiseDeferred* ticket, Task&& task)
+void PromiseTimer::scheduleWorkSoon(JSPromise* ticket, Task&& task)
 {
     LockHolder locker(m_taskLock);
     m_tasks.append(std::make_tuple(ticket, WTFMove(task)));
 
 namespace JSC {
 
-class JSPromiseDeferred;
+class JSPromise;
 class VM;
 class JSCell;
 
-class PromiseDeferredTimer : public JSRunLoopTimer {
+class PromiseTimer : public JSRunLoopTimer {
 public:
     using Base = JSRunLoopTimer;
 
     void doWork(VM&) override;
 
-    void addPendingPromise(VM&, JSPromiseDeferred*, Vector<Strong<JSCell>>&& dependencies);
-    JS_EXPORT_PRIVATE bool hasPendingPromise(JSPromiseDeferred* ticket);
-    JS_EXPORT_PRIVATE bool hasDependancyInPendingPromise(JSPromiseDeferred* ticket, JSCell* dependency);
-    // JSPromiseDeferred should handle canceling when the promise is resolved or rejected.
-    bool cancelPendingPromise(JSPromiseDeferred*);
+    void addPendingPromise(VM&, JSPromise*, Vector<Strong<JSCell>>&& dependencies);
+    JS_EXPORT_PRIVATE bool hasPendingPromise(JSPromise* ticket);
+    JS_EXPORT_PRIVATE bool hasDependancyInPendingPromise(JSPromise* ticket, JSCell* dependency);
+    // JSPromise should handle canceling when the promise is resolved or rejected.
+    bool cancelPendingPromise(JSPromise*);
 
     using Task = Function<void()>;
-    void scheduleWorkSoon(JSPromiseDeferred*, Task&&);
+    void scheduleWorkSoon(JSPromise*, Task&&);
 
     void stopRunningTasks() { m_runTasks = false; }
 
     JS_EXPORT_PRIVATE void runRunLoop();
 
-    static Ref<PromiseDeferredTimer> create(VM& vm)
+    static Ref<PromiseTimer> create(VM& vm)
     {
-        return adoptRef(*new PromiseDeferredTimer(vm));
+        return adoptRef(*new PromiseTimer(vm));
     }
 
 private:
-    PromiseDeferredTimer(VM&);
+    PromiseTimer(VM&);
 
-    HashMap<JSPromiseDeferred*, Vector<Strong<JSCell>>> m_pendingPromises;
+    HashMap<JSPromise*, Vector<Strong<JSCell>>> m_pendingPromises;
     Lock m_taskLock;
     bool m_runTasks { true };
     bool m_shouldStopRunLoopWhenAllPromisesFinish { false };
     bool m_currentlyRunningTask { false };
-    Vector<std::tuple<JSPromiseDeferred*, Task>> m_tasks;
+    Vector<std::tuple<JSPromise*, Task>> m_tasks;
 };
 
 } // namespace JSC
index 84f5711..4559aa7 100644 (file)
 #include "JSFunction.h"
 #include "JSGlobalObjectFunctions.h"
 #include "JSImmutableButterfly.h"
-#include "JSInternalPromiseDeferred.h"
+#include "JSInternalPromise.h"
 #include "JSLock.h"
 #include "JSMap.h"
 #include "JSMapIterator.h"
-#include "JSPromiseDeferred.h"
+#include "JSPromise.h"
 #include "JSPropertyNameEnumerator.h"
 #include "JSScriptFetchParameters.h"
 #include "JSScriptFetcher.h"
 #include "ProfilerDatabase.h"
 #include "ProgramCodeBlock.h"
 #include "ProgramExecutable.h"
-#include "PromiseDeferredTimer.h"
+#include "PromiseTimer.h"
 #include "PropertyMapHashTable.h"
 #include "ProxyRevoke.h"
 #include "RandomizingFuzzerAgent.h"
@@ -294,7 +294,7 @@ VM::VM(VMType vmType, HeapType heapType)
     , clientData(0)
     , topEntryFrame(nullptr)
     , topCallFrame(CallFrame::noCaller())
-    , promiseDeferredTimer(PromiseDeferredTimer::create(*this))
+    , promiseTimer(PromiseTimer::create(*this))
     , m_atomStringTable(vmType == Default ? Thread::current().atomStringTable() : new AtomStringTable)
     , propertyNames(nullptr)
     , emptyList(new ArgList)
@@ -379,8 +379,6 @@ VM::VM(VMType vmType, HeapType heapType)
     propertyTableStructure.set(*this, PropertyTable::createStructure(*this, 0, jsNull()));
     functionRareDataStructure.set(*this, FunctionRareData::createStructure(*this, 0, jsNull()));
     exceptionStructure.set(*this, Exception::createStructure(*this, 0, jsNull()));
-    promiseDeferredStructure.set(*this, JSPromiseDeferred::createStructure(*this, 0, jsNull()));
-    internalPromiseDeferredStructure.set(*this, JSInternalPromiseDeferred::createStructure(*this, 0, jsNull()));
     nativeStdFunctionCellStructure.set(*this, NativeStdFunctionCell::createStructure(*this, 0, jsNull()));
     programCodeBlockStructure.set(*this, ProgramCodeBlock::createStructure(*this, 0, jsNull()));
     moduleProgramCodeBlockStructure.set(*this, ModuleProgramCodeBlock::createStructure(*this, 0, jsNull()));
@@ -490,7 +488,7 @@ VM::~VM()
     auto destructionLocker = holdLock(s_destructionLock.read());
     
     Gigacage::removePrimitiveDisableCallback(primitiveGigacageDisabledCallback, this);
-    promiseDeferredTimer->stopRunningTasks();
+    promiseTimer->stopRunningTasks();
 #if ENABLE(WEBASSEMBLY)
     if (Wasm::Worklist* worklist = Wasm::existingWorklistOrNull())
         worklist->stopAllPlansForContext(wasmContext);
index 857ca91..4616fb2 100644 (file)
@@ -132,7 +132,7 @@ class JSWebAssemblyCodeBlockHeapCellType;
 class JSWebAssemblyInstance;
 class LLIntOffsetsExtractor;
 class NativeExecutable;
-class PromiseDeferredTimer;
+class PromiseTimer;
 class RegExp;
 class RegExpCache;
 class Register;
@@ -536,8 +536,6 @@ public:
     Strong<Structure> propertyTableStructure;
     Strong<Structure> functionRareDataStructure;
     Strong<Structure> exceptionStructure;
-    Strong<Structure> promiseDeferredStructure;
-    Strong<Structure> internalPromiseDeferredStructure;
     Strong<Structure> nativeStdFunctionCellStructure;
     Strong<Structure> programCodeBlockStructure;
     Strong<Structure> moduleProgramCodeBlockStructure;
@@ -556,7 +554,7 @@ public:
     Strong<JSCell> m_sentinelSetBucket;
     Strong<JSCell> m_sentinelMapBucket;
 
-    Ref<PromiseDeferredTimer> promiseDeferredTimer;
+    Ref<PromiseTimer> promiseTimer;
     
     JSCell* currentlyDestructingCallbackObject;
     const ClassInfo* currentlyDestructingCallbackObjectClassInfo { nullptr };
index 8371cdf..1090883 100644 (file)
 #include "JSCBuiltins.h"
 #include "JSCInlines.h"
 #include "JSModuleNamespaceObject.h"
-#include "JSPromiseDeferred.h"
+#include "JSPromise.h"
 #include "JSToWasm.h"
 #include "JSWebAssemblyHelpers.h"
 #include "JSWebAssemblyInstance.h"
 #include "JSWebAssemblyModule.h"
 #include "ObjectConstructor.h"
 #include "Options.h"
-#include "PromiseDeferredTimer.h"
+#include "PromiseTimer.h"
 #include "StrongInlines.h"
 #include "ThrowScope.h"
 #include "WasmBBQPlan.h"
@@ -124,7 +124,7 @@ JSWebAssembly::JSWebAssembly(VM& vm, Structure* structure)
 {
 }
 
-static void reject(JSGlobalObject* globalObject, CatchScope& catchScope, JSPromiseDeferred* promise)
+static void reject(JSGlobalObject* globalObject, CatchScope& catchScope, JSPromise* promise)
 {
     Exception* exception = catchScope.exception();
     ASSERT(exception);
@@ -133,17 +133,17 @@ static void reject(JSGlobalObject* globalObject, CatchScope& catchScope, JSPromi
     CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, void());
 }
 
-static void webAssemblyModuleValidateAsyncInternal(JSGlobalObject* globalObject, JSPromiseDeferred* promise, Vector<uint8_t>&& source)
+static void webAssemblyModuleValidateAsyncInternal(JSGlobalObject* globalObject, JSPromise* promise, Vector<uint8_t>&& source)
 {
     VM& vm = globalObject->vm();
 
     Vector<Strong<JSCell>> dependencies;
     dependencies.append(Strong<JSCell>(vm, globalObject));
 
-    vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
+    vm.promiseTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
 
     Wasm::Module::validateAsync(&vm.wasmContext, WTFMove(source), createSharedTask<Wasm::Module::CallbackType>([promise, globalObject, &vm] (Wasm::Module::ValidationResult&& result) mutable {
-        vm.promiseDeferredTimer->scheduleWorkSoon(promise, [promise, globalObject, result = WTFMove(result), &vm] () mutable {
+        vm.promiseTimer->scheduleWorkSoon(promise, [promise, globalObject, result = WTFMove(result), &vm] () mutable {
             auto scope = DECLARE_CATCH_SCOPE(vm);
             JSValue module = JSWebAssemblyModule::createStub(vm, globalObject, globalObject->webAssemblyModuleStructure(), WTFMove(result));
             if (UNLIKELY(scope.exception())) {
@@ -162,7 +162,7 @@ static EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(JSGlobalObject* globa
     VM& vm = globalObject->vm();
     auto throwScope = DECLARE_THROW_SCOPE(vm);
 
-    JSPromiseDeferred* promise = JSPromiseDeferred::tryCreate(globalObject);
+    auto* promise = JSPromise::create(vm, globalObject->promiseStructure());
     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
     {
@@ -174,12 +174,12 @@ static EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(JSGlobalObject* globa
         else
             webAssemblyModuleValidateAsyncInternal(globalObject, promise, WTFMove(source));
 
-        return JSValue::encode(promise->promise());
+        return JSValue::encode(promise);
     }
 }
 
 enum class Resolve { WithInstance, WithModuleRecord, WithModuleAndInstance };
-static void resolve(VM& vm, JSGlobalObject* globalObject, JSPromiseDeferred* promise, JSWebAssemblyInstance* instance, JSWebAssemblyModule* module, JSObject* importObject, Ref<Wasm::CodeBlock>&& codeBlock, Resolve resolveKind, Wasm::CreationMode creationMode)
+static void resolve(VM& vm, JSGlobalObject* globalObject, JSPromise* promise, JSWebAssemblyInstance* instance, JSWebAssemblyModule* module, JSObject* importObject, Ref<Wasm::CodeBlock>&& codeBlock, Resolve resolveKind, Wasm::CreationMode creationMode)
 {
     auto scope = DECLARE_CATCH_SCOPE(vm);
     instance->finalizeCreation(vm, globalObject, WTFMove(codeBlock), importObject, creationMode);
@@ -201,7 +201,7 @@ static void resolve(VM& vm, JSGlobalObject* globalObject, JSPromiseDeferred* pro
     CLEAR_AND_RETURN_IF_EXCEPTION(scope, void());
 }
 
-void JSWebAssembly::webAssemblyModuleValidateAsync(JSGlobalObject* globalObject, JSPromiseDeferred* promise, Vector<uint8_t>&& source)
+void JSWebAssembly::webAssemblyModuleValidateAsync(JSGlobalObject* globalObject, JSPromise* promise, Vector<uint8_t>&& source)
 {
     VM& vm = globalObject->vm();
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
@@ -209,7 +209,7 @@ void JSWebAssembly::webAssemblyModuleValidateAsync(JSGlobalObject* globalObject,
     CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, void());
 }
 
-static void instantiate(VM& vm, JSGlobalObject* globalObject, JSPromiseDeferred* promise, JSWebAssemblyModule* module, JSObject* importObject, const Identifier& moduleKey, Resolve resolveKind, Wasm::CreationMode creationMode)
+static void instantiate(VM& vm, JSGlobalObject* globalObject, JSPromise* promise, JSWebAssemblyModule* module, JSObject* importObject, const Identifier& moduleKey, Resolve resolveKind, Wasm::CreationMode creationMode)
 {
     auto scope = DECLARE_CATCH_SCOPE(vm);
     // In order to avoid potentially recompiling a module. We first gather all the import/memory information prior to compiling code.
@@ -220,18 +220,18 @@ static void instantiate(VM& vm, JSGlobalObject* globalObject, JSPromiseDeferred*
     // The instance keeps the module alive.
     dependencies.append(Strong<JSCell>(vm, instance));
     dependencies.append(Strong<JSCell>(vm, importObject));
-    vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
+    vm.promiseTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
     // Note: This completion task may or may not get called immediately.
     module->module().compileAsync(&vm.wasmContext, instance->memoryMode(), createSharedTask<Wasm::CodeBlock::CallbackType>([promise, instance, module, importObject, resolveKind, creationMode, &vm] (Ref<Wasm::CodeBlock>&& refCodeBlock) mutable {
         RefPtr<Wasm::CodeBlock> codeBlock = WTFMove(refCodeBlock);
-        vm.promiseDeferredTimer->scheduleWorkSoon(promise, [promise, instance, module, importObject, resolveKind, creationMode, &vm, codeBlock = WTFMove(codeBlock)] () mutable {
+        vm.promiseTimer->scheduleWorkSoon(promise, [promise, instance, module, importObject, resolveKind, creationMode, &vm, codeBlock = WTFMove(codeBlock)] () mutable {
             JSGlobalObject* globalObject = instance->globalObject();
             resolve(vm, globalObject, promise, instance, module, importObject, codeBlock.releaseNonNull(), resolveKind, creationMode);
         });
     }), &Wasm::createJSToWasmWrapper, &Wasm::operationWasmToJSException);
 }
 
-static void compileAndInstantiate(VM& vm, JSGlobalObject* globalObject, JSPromiseDeferred* promise, const Identifier& moduleKey, JSValue buffer, JSObject* importObject, Resolve resolveKind, Wasm::CreationMode creationMode)
+static void compileAndInstantiate(VM& vm, JSGlobalObject* globalObject, JSPromise* promise, const Identifier& moduleKey, JSValue buffer, JSObject* importObject, Resolve resolveKind, Wasm::CreationMode creationMode)
 {
     auto scope = DECLARE_CATCH_SCOPE(vm);
 
@@ -239,13 +239,13 @@ static void compileAndInstantiate(VM& vm, JSGlobalObject* globalObject, JSPromis
     Vector<Strong<JSCell>> dependencies;
     dependencies.append(Strong<JSCell>(vm, importObject));
     dependencies.append(Strong<JSCell>(vm, moduleKeyCell));
-    vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
+    vm.promiseTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
 
     Vector<uint8_t> source = createSourceBufferFromValue(vm, globalObject, buffer);
     RETURN_IF_EXCEPTION(scope, reject(globalObject, scope, promise));
 
     Wasm::Module::validateAsync(&vm.wasmContext, WTFMove(source), createSharedTask<Wasm::Module::CallbackType>([promise, importObject, moduleKeyCell, globalObject, resolveKind, creationMode, &vm] (Wasm::Module::ValidationResult&& result) mutable {
-        vm.promiseDeferredTimer->scheduleWorkSoon(promise, [promise, importObject, moduleKeyCell, globalObject, result = WTFMove(result), resolveKind, creationMode, &vm] () mutable {
+        vm.promiseTimer->scheduleWorkSoon(promise, [promise, importObject, moduleKeyCell, globalObject, result = WTFMove(result), resolveKind, creationMode, &vm] () mutable {
             auto scope = DECLARE_CATCH_SCOPE(vm);
             JSWebAssemblyModule* module = JSWebAssemblyModule::createStub(vm, globalObject, globalObject->webAssemblyModuleStructure(), WTFMove(result));
             if (UNLIKELY(scope.exception()))
@@ -260,24 +260,24 @@ static void compileAndInstantiate(VM& vm, JSGlobalObject* globalObject, JSPromis
     }));
 }
 
-JSValue JSWebAssembly::instantiate(JSGlobalObject* globalObject, JSPromiseDeferred* promise, const Identifier& moduleKey, JSValue argument)
+JSValue JSWebAssembly::instantiate(JSGlobalObject* globalObject, JSPromise* promise, const Identifier& moduleKey, JSValue argument)
 {
     VM& vm = globalObject->vm();
     compileAndInstantiate(vm, globalObject, promise, moduleKey, argument, nullptr, Resolve::WithModuleRecord, Wasm::CreationMode::FromModuleLoader);
-    return promise->promise();
+    return promise;
 }
 
-static void webAssemblyModuleInstantinateAsyncInternal(JSGlobalObject* globalObject, JSPromiseDeferred* promise, Vector<uint8_t>&& source, JSObject* importObject)
+static void webAssemblyModuleInstantinateAsyncInternal(JSGlobalObject* globalObject, JSPromise* promise, Vector<uint8_t>&& source, JSObject* importObject)
 {
     VM& vm = globalObject->vm();
 
     Vector<Strong<JSCell>> dependencies;
     dependencies.append(Strong<JSCell>(vm, importObject));
     dependencies.append(Strong<JSCell>(vm, globalObject));
-    vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
+    vm.promiseTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
 
     Wasm::Module::validateAsync(&vm.wasmContext, WTFMove(source), createSharedTask<Wasm::Module::CallbackType>([promise, importObject, globalObject, &vm] (Wasm::Module::ValidationResult&& result) mutable {
-        vm.promiseDeferredTimer->scheduleWorkSoon(promise, [promise, importObject, globalObject, result = WTFMove(result), &vm] () mutable {
+        vm.promiseTimer->scheduleWorkSoon(promise, [promise, importObject, globalObject, result = WTFMove(result), &vm] () mutable {
             auto scope = DECLARE_CATCH_SCOPE(vm);
             JSWebAssemblyModule* module = JSWebAssemblyModule::createStub(vm, globalObject, globalObject->webAssemblyModuleStructure(), WTFMove(result));
             if (UNLIKELY(scope.exception()))
@@ -289,7 +289,7 @@ static void webAssemblyModuleInstantinateAsyncInternal(JSGlobalObject* globalObj
     }));
 }
 
-void JSWebAssembly::webAssemblyModuleInstantinateAsync(JSGlobalObject* globalObject, JSPromiseDeferred* promise, Vector<uint8_t>&& source, JSObject* importedObject)
+void JSWebAssembly::webAssemblyModuleInstantinateAsync(JSGlobalObject* globalObject, JSPromise* promise, Vector<uint8_t>&& source, JSObject* importedObject)
 {
     VM& vm = globalObject->vm();
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
@@ -300,11 +300,8 @@ void JSWebAssembly::webAssemblyModuleInstantinateAsync(JSGlobalObject* globalObj
 static EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(JSGlobalObject* globalObject, CallFrame* callFrame)
 {
     VM& vm = globalObject->vm();
-    auto throwScope = DECLARE_THROW_SCOPE(vm);
-
-    JSPromiseDeferred* promise = JSPromiseDeferred::tryCreate(globalObject);
-    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
+    auto* promise = JSPromise::create(vm, globalObject->promiseStructure());
     {
         auto catchScope = DECLARE_CATCH_SCOPE(vm);
 
@@ -313,7 +310,7 @@ static EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(JSGlobalObject* g
         if (UNLIKELY(!importArgument.isUndefined() && !importObject)) {
             promise->reject(globalObject, createTypeError(globalObject,
                 "second argument to WebAssembly.instantiate must be undefined or an Object"_s, defaultSourceAppender, runtimeTypeForValue(vm, importArgument)));
-            CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, JSValue::encode(promise->promise()));
+            CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, JSValue::encode(promise));
         } else {
             JSValue firstArgument = callFrame->argument(0);
             if (auto* module = jsDynamicCast<JSWebAssemblyModule*>(vm, firstArgument))
@@ -322,7 +319,7 @@ static EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(JSGlobalObject* g
                 compileAndInstantiate(vm, globalObject, promise, JSWebAssemblyInstance::createPrivateModuleKey(), firstArgument, importObject, Resolve::WithModuleAndInstance, Wasm::CreationMode::FromJS);
         }
 
-        return JSValue::encode(promise->promise());
+        return JSValue::encode(promise);
     }
 }
 
@@ -344,11 +341,11 @@ EncodedJSValue JSC_HOST_CALL webAssemblyCompileStreamingInternal(JSGlobalObject*
     VM& vm = globalObject->vm();
     auto catchScope = DECLARE_CATCH_SCOPE(vm);
 
-    JSPromiseDeferred* promise = JSPromiseDeferred::tryCreate(globalObject);
+    auto* promise = JSPromise::create(vm, globalObject->promiseStructure());
 
     Vector<Strong<JSCell>> dependencies;
     dependencies.append(Strong<JSCell>(vm, globalObject));
-    vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
+    vm.promiseTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
 
     if (globalObject->globalObjectMethodTable()->compileStreaming)
         globalObject->globalObjectMethodTable()->compileStreaming(globalObject, promise, callFrame->argument(0));
@@ -357,18 +354,16 @@ EncodedJSValue JSC_HOST_CALL webAssemblyCompileStreamingInternal(JSGlobalObject*
         ASSERT_NOT_REACHED();
     }
 
-    CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, JSValue::encode(promise->promise()));
+    CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, JSValue::encode(promise));
 
-    return JSValue::encode(promise->promise());
+    return JSValue::encode(promise);
 }
 
 EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateStreamingInternal(JSGlobalObject* globalObject, CallFrame* callFrame)
 {
     VM& vm = globalObject->vm();
-    auto throwScope = DECLARE_THROW_SCOPE(vm);
 
-    JSPromiseDeferred* promise = JSPromiseDeferred::tryCreate(globalObject);
-    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+    auto* promise = JSPromise::create(vm, globalObject->promiseStructure());
     {
         auto catchScope = DECLARE_CATCH_SCOPE(vm);
 
@@ -377,13 +372,13 @@ EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateStreamingInternal(JSGlobalObj
         if (UNLIKELY(!importArgument.isUndefined() && !importObject)) {
             promise->reject(globalObject, createTypeError(globalObject,
                 "second argument to WebAssembly.instantiateStreaming must be undefined or an Object"_s, defaultSourceAppender, runtimeTypeForValue(vm, importArgument)));
-            CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, JSValue::encode(promise->promise()));
+            CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, JSValue::encode(promise));
         } else {
             if (globalObject->globalObjectMethodTable()->instantiateStreaming) {
                 Vector<Strong<JSCell>> dependencies;
                 dependencies.append(Strong<JSCell>(vm, globalObject));
                 dependencies.append(Strong<JSCell>(vm, importObject));
-                vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
+                vm.promiseTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
 
                 // FIXME: <http://webkit.org/b/184888> if there's an importObject and it contains a Memory, then we can compile the module with the right memory type (fast or not) by looking at the memory's type.
                 globalObject->globalObjectMethodTable()->instantiateStreaming(globalObject, promise, callFrame->argument(0), importObject);
@@ -392,9 +387,9 @@ EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateStreamingInternal(JSGlobalObj
                 ASSERT_NOT_REACHED();
             }
         }
-        CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, JSValue::encode(promise->promise()));
+        CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, JSValue::encode(promise));
 
-        return JSValue::encode(promise->promise());
+        return JSValue::encode(promise);
     }
 }
 
index 1277db1..29e773d 100644 (file)
@@ -28,7 +28,7 @@
 #if ENABLE(WEBASSEMBLY)
 
 #include "JSObject.h"
-#include "JSPromiseDeferred.h"
+#include "JSPromise.h"
 
 namespace JSC {
 
@@ -42,9 +42,9 @@ public:
 
     DECLARE_INFO;
 
-    JS_EXPORT_PRIVATE static void webAssemblyModuleValidateAsync(JSGlobalObject*, JSPromiseDeferred*, Vector<uint8_t>&&);
-    JS_EXPORT_PRIVATE static void webAssemblyModuleInstantinateAsync(JSGlobalObject*, JSPromiseDeferred*, Vector<uint8_t>&&, JSObject*);
-    static JSValue instantiate(JSGlobalObject*, JSPromiseDeferred*, const Identifier&, JSValue);
+    JS_EXPORT_PRIVATE static void webAssemblyModuleValidateAsync(JSGlobalObject*, JSPromise*, Vector<uint8_t>&&);
+    JS_EXPORT_PRIVATE static void webAssemblyModuleInstantinateAsync(JSGlobalObject*, JSPromise*, Vector<uint8_t>&&, JSObject*);
+    static JSValue instantiate(JSGlobalObject*, JSPromise*, const Identifier&, JSValue);
 
 protected:
     void finishCreation(VM&, JSGlobalObject*);
index 58a0682..48949bf 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "CallLinkInfo.h"
 #include "JSCast.h"
-#include "PromiseDeferredTimer.h"
+#include "PromiseTimer.h"
 #include "Structure.h"
 #include "WasmCallee.h"
 #include "WasmFormat.h"
index ecbfe26..1ba3a1d 100644 (file)
@@ -1,3 +1,80 @@
+2019-10-28  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        [JSC] Remove JSPromiseDeferred
+        https://bugs.webkit.org/show_bug.cgi?id=203400
+
+        Reviewed by Keith Miller.
+
+        This patch removes PromiseExecutionScope. This assumed that promise operation cannot fail in main thread. But this is
+        wrong since any JS call can fail due to stack-overflow error. This patch makes things more robust by handling errors correctly.
+        And we remove JSPromiseDeferred and use JSPromise instead.
+
+        * bindings/js/JSCustomElementRegistryCustom.cpp:
+        (WebCore::whenDefinedPromise):
+        (WebCore::JSCustomElementRegistry::whenDefined):
+        * bindings/js/JSDOMConvertPromise.h:
+        (WebCore::Converter<IDLPromise<T>>::convert):
+        * bindings/js/JSDOMGlobalObject.cpp:
+        * bindings/js/JSDOMOperationReturningPromise.h:
+        (WebCore::IDLOperationReturningPromise::call):
+        (WebCore::IDLOperationReturningPromise::callStatic):
+        * bindings/js/JSDOMPromiseDeferred.cpp:
+        (WebCore::DeferredPromise::promise const):
+        (WebCore::DeferredPromise::callFunction):
+        (WebCore::DeferredPromise::whenSettled):
+        (WebCore::rejectPromiseWithExceptionIfAny):
+        (WebCore::createDeferredPromise):
+        * bindings/js/JSDOMPromiseDeferred.h:
+        (WebCore::DeferredPromise::create):
+        (WebCore::DeferredPromise::DeferredPromise):
+        (WebCore::DeferredPromise::deferred const):
+        (WebCore::DeferredPromise::resolve):
+        (WebCore::DeferredPromise::reject):
+        (WebCore::DOMPromiseDeferredBase::DOMPromiseDeferredBase):
+        (WebCore::DOMPromiseDeferredBase::operator=):
+        (WebCore::DOMPromiseDeferredBase::reject):
+        (WebCore::DOMPromiseDeferredBase::rejectType):
+        (WebCore::DOMPromiseDeferredBase::promise const):
+        (WebCore::DOMPromiseDeferredBase::whenSettled):
+        (WebCore::DOMPromiseDeferred::resolve):
+        (WebCore::DOMPromiseDeferred<void>::resolve):
+        (WebCore::callPromiseFunction):
+        * bindings/js/JSDOMWindowBase.cpp:
+        (WebCore::JSDOMWindowBase::moduleLoaderFetch):
+        (WebCore::JSDOMWindowBase::moduleLoaderImportModule):
+        (WebCore::tryAllocate):
+        (WebCore::isResponseCorrect):
+        (WebCore::handleResponseOnStreamingAction):
+        (WebCore::JSDOMWindowBase::compileStreaming):
+        (WebCore::JSDOMWindowBase::instantiateStreaming):
+        * bindings/js/JSDOMWindowBase.h:
+        * bindings/js/ScriptModuleLoader.cpp:
+        (WebCore::ScriptModuleLoader::fetch):
+        (WebCore::rejectPromise):
+        * bindings/js/WorkerScriptController.cpp:
+        (WebCore::WorkerScriptController::addTimerSetNotification):
+        (WebCore::WorkerScriptController::removeTimerSetNotification):
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateOperationTrampolineDefinition):
+        * bindings/scripts/test/JS/JSTestGlobalObject.cpp:
+        (WebCore::jsTestGlobalObjectInstanceFunctionCalculateSecretResult):
+        * bindings/scripts/test/JS/JSTestNode.cpp:
+        (WebCore::jsTestNodePrototypeFunctionTestWorkerPromise):
+        (WebCore::jsTestNodePrototypeFunctionCalculateSecretResult):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::jsTestObjPrototypeFunctionCalculateSecretResult):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunction):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgument):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithException):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgument):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseOverloadedFunction):
+        (WebCore::jsTestObjConstructorFunctionTestStaticPromiseFunction):
+        (WebCore::jsTestObjConstructorFunctionTestStaticPromiseFunctionWithException):
+        (WebCore::jsTestObjPrototypeFunctionTestCustomPromiseFunction):
+        (WebCore::jsTestObjConstructorFunctionTestStaticCustomPromiseFunction):
+        * workers/WorkerRunLoop.cpp:
+        * worklets/WorkletScriptController.cpp:
+
 2019-10-28  Adrian Perez de Castro  <aperez@igalia.com>
 
         [GTK][WPE] Fix various non-unified build issues introduced since r251436
index 81282c1..9342acb 100644 (file)
@@ -175,7 +175,7 @@ JSValue JSCustomElementRegistry::define(JSGlobalObject& lexicalGlobalObject, Cal
 }
 
 // https://html.spec.whatwg.org/#dom-customelementregistry-whendefined
-static JSValue whenDefinedPromise(JSGlobalObject& lexicalGlobalObject, CallFrame& callFrame, JSDOMGlobalObject& globalObject, CustomElementRegistry& registry, JSPromiseDeferred& promiseDeferred)
+static JSValue whenDefinedPromise(JSGlobalObject& lexicalGlobalObject, CallFrame& callFrame, JSDOMGlobalObject& globalObject, CustomElementRegistry& registry, JSPromise& promise)
 {
     auto scope = DECLARE_THROW_SCOPE(lexicalGlobalObject.vm());
 
@@ -191,12 +191,12 @@ static JSValue whenDefinedPromise(JSGlobalObject& lexicalGlobalObject, CallFrame
     }
 
     if (registry.findInterface(localName)) {
-        DeferredPromise::create(globalObject, promiseDeferred)->resolve();
-        return promiseDeferred.promise();
+        DeferredPromise::create(globalObject, promise)->resolve();
+        return &promise;
     }
 
     auto result = registry.promiseMap().ensure(localName, [&] {
-        return DeferredPromise::create(globalObject, promiseDeferred);
+        return DeferredPromise::create(globalObject, promise);
     });
 
     return result.iterator->value->promise();
@@ -207,14 +207,13 @@ JSValue JSCustomElementRegistry::whenDefined(JSGlobalObject& lexicalGlobalObject
     auto scope = DECLARE_CATCH_SCOPE(lexicalGlobalObject.vm());
 
     ASSERT(globalObject());
-    auto promiseDeferred = JSPromiseDeferred::tryCreate(globalObject());
-    RELEASE_ASSERT(promiseDeferred);
-    JSValue promise = whenDefinedPromise(lexicalGlobalObject, callFrame, *globalObject(), wrapped(), *promiseDeferred);
+    auto* result = JSPromise::create(lexicalGlobalObject.vm(), lexicalGlobalObject.promiseStructure());
+    JSValue promise = whenDefinedPromise(lexicalGlobalObject, callFrame, *globalObject(), wrapped(), *result);
 
     if (UNLIKELY(scope.exception())) {
-        rejectPromiseWithExceptionIfAny(lexicalGlobalObject, *globalObject(), *promiseDeferred);
+        rejectPromiseWithExceptionIfAny(lexicalGlobalObject, *globalObject(), *result);
         scope.assertNoException();
-        return promiseDeferred->promise();
+        return result;
     }
 
     return promise;
index 3ea2372..5fc0a87 100644 (file)
@@ -46,7 +46,7 @@ template<typename T> struct Converter<IDLPromise<T>> : DefaultConverter<IDLPromi
 
         // 1. Let resolve be the original value of %Promise%.resolve.
         // 2. Let promise be the result of calling resolve with %Promise% as the this value and V as the single argument value.
-        auto* promise = JSC::JSPromise::resolve(globalObject, value);
+        auto* promise = JSC::JSPromise::resolvedPromise(globalObject, value);
         if (scope.exception()) {
             exceptionThrower(lexicalGlobalObject, scope);
             return nullptr;
index 72ed893..60a34cf 100644 (file)
@@ -48,7 +48,6 @@
 #include <JavaScriptCore/BuiltinNames.h>
 #include <JavaScriptCore/CodeBlock.h>
 #include <JavaScriptCore/JSInternalPromise.h>
-#include <JavaScriptCore/JSInternalPromiseDeferred.h>
 #include <JavaScriptCore/StructureInlines.h>
 
 namespace WebCore {
index 0ff7471..83aa392 100644 (file)
@@ -35,10 +35,10 @@ public:
     using Operation = JSC::EncodedJSValue(JSC::JSGlobalObject*, JSC::CallFrame*, ClassParameter, Ref<DeferredPromise>&&, JSC::ThrowScope&);
     using StaticOperation = JSC::EncodedJSValue(JSC::JSGlobalObject*, JSC::CallFrame*, Ref<DeferredPromise>&&, JSC::ThrowScope&);
 
-    template<Operation operation, PromiseExecutionScope executionScope, CastedThisErrorBehavior shouldThrow = CastedThisErrorBehavior::RejectPromise>
+    template<Operation operation, CastedThisErrorBehavior shouldThrow = CastedThisErrorBehavior::RejectPromise>
     static JSC::EncodedJSValue call(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, const char* operationName)
     {
-        return JSC::JSValue::encode(callPromiseFunction<executionScope>(lexicalGlobalObject, callFrame, [&operationName] (JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, Ref<DeferredPromise>&& promise) {
+        return JSC::JSValue::encode(callPromiseFunction(lexicalGlobalObject, callFrame, [&operationName] (JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, Ref<DeferredPromise>&& promise) {
             auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(&lexicalGlobalObject));
             
             auto* thisObject = IDLOperation<JSClass>::cast(lexicalGlobalObject, callFrame);
@@ -71,10 +71,10 @@ public:
         return operation(&lexicalGlobalObject, &callFrame, thisObject, throwScope);
     }
 
-    template<StaticOperation operation, PromiseExecutionScope executionScope, CastedThisErrorBehavior shouldThrow = CastedThisErrorBehavior::RejectPromise>
+    template<StaticOperation operation, CastedThisErrorBehavior shouldThrow = CastedThisErrorBehavior::RejectPromise>
     static JSC::EncodedJSValue callStatic(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, const char*)
     {
-        return JSC::JSValue::encode(callPromiseFunction<executionScope>(lexicalGlobalObject, callFrame, [] (JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, Ref<DeferredPromise>&& promise) {
+        return JSC::JSValue::encode(callPromiseFunction(lexicalGlobalObject, callFrame, [] (JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, Ref<DeferredPromise>&& promise) {
             auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(&lexicalGlobalObject));
             
             // FIXME: We should refactor the binding generated code to use references for lexicalGlobalObject.
index 30344dc..2266122 100644 (file)
@@ -40,30 +40,24 @@ using namespace JSC;
 JSC::JSValue DeferredPromise::promise() const
 {
     ASSERT(deferred());
-    return deferred()->promise();
+    return deferred();
 }
 
-void DeferredPromise::callFunction(JSGlobalObject& lexicalGlobalObject, JSValue function, JSValue resolution)
+void DeferredPromise::callFunction(JSGlobalObject& lexicalGlobalObject, ResolveMode mode, JSValue resolution)
 {
     if (!canInvokeCallback())
         return;
 
-    VM& vm = lexicalGlobalObject.vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-
-    CallData callData;
-    CallType callType = getCallData(vm, function, callData);
-    ASSERT(callType != CallType::None);
-
-    MarkedArgumentBuffer arguments;
-    arguments.append(resolution);
-    ASSERT(!arguments.hasOverflowed());
-
-    call(&lexicalGlobalObject, function, callType, callData, jsUndefined(), arguments);
-
-    // DeferredPromise should only be used by internal implementations that are well behaved.
-    // In practice, the only exception we should ever see here is the TerminatedExecutionException.
-    EXCEPTION_ASSERT_UNUSED(scope, !scope.exception() || isTerminatedExecutionException(vm, scope.exception()));
+    // FIXME: We could have error since any JS call can throw stack-overflow errors.
+    // https://bugs.webkit.org/show_bug.cgi?id=203402
+    switch (mode) {
+    case ResolveMode::Resolve:
+        deferred()->resolve(&lexicalGlobalObject, resolution);
+        break;
+    case ResolveMode::Reject:
+        deferred()->reject(&lexicalGlobalObject, resolution);
+        break;
+    }
 
     if (m_mode == Mode::ClearPromiseOnResolve)
         clear();
@@ -71,7 +65,7 @@ void DeferredPromise::callFunction(JSGlobalObject& lexicalGlobalObject, JSValue
 
 void DeferredPromise::whenSettled(Function<void()>&& callback)
 {
-    DOMPromise::whenPromiseIsSettled(globalObject(), deferred()->promise(), WTFMove(callback));
+    DOMPromise::whenPromiseIsSettled(globalObject(), deferred(), WTFMove(callback));
 }
 
 void DeferredPromise::reject()
@@ -175,7 +169,7 @@ void DeferredPromise::reject(const JSC::PrivateName& privateName)
     reject(*lexicalGlobalObject, JSC::Symbol::create(lexicalGlobalObject->vm(), privateName.uid()));
 }
 
-void rejectPromiseWithExceptionIfAny(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, JSPromiseDeferred& promiseDeferred)
+void rejectPromiseWithExceptionIfAny(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, JSPromise& promise)
 {
     VM& vm = lexicalGlobalObject.vm();
     auto scope = DECLARE_CATCH_SCOPE(vm);
@@ -186,15 +180,14 @@ void rejectPromiseWithExceptionIfAny(JSC::JSGlobalObject& lexicalGlobalObject, J
     JSValue error = scope.exception()->value();
     scope.clearException();
 
-    DeferredPromise::create(globalObject, promiseDeferred)->reject<IDLAny>(error);
+    DeferredPromise::create(globalObject, promise)->reject<IDLAny>(error);
 }
 
 Ref<DeferredPromise> createDeferredPromise(JSC::JSGlobalObject&, JSDOMWindow& domWindow)
 {
-    JSC::JSPromiseDeferred* deferred = JSC::JSPromiseDeferred::tryCreate(&domWindow);
-    // deferred can only be null in workers.
-    RELEASE_ASSERT(deferred);
-    return DeferredPromise::create(domWindow, *deferred);
+    auto* promise = JSPromise::create(domWindow.vm(), domWindow.promiseStructure());
+    RELEASE_ASSERT(promise);
+    return DeferredPromise::create(domWindow, *promise);
 }
 
 JSC::EncodedJSValue createRejectedPromiseWithTypeError(JSC::JSGlobalObject& lexicalGlobalObject, const String& errorMessage, RejectedPromiseWithTypeErrorCause cause)
index 6697b73..f0a1e7e 100644 (file)
 #include "JSDOMConvert.h"
 #include "JSDOMGuardedObject.h"
 #include <JavaScriptCore/CatchScope.h>
-#include <JavaScriptCore/JSPromiseDeferred.h>
+#include <JavaScriptCore/JSPromise.h>
 
 namespace WebCore {
 
 class JSDOMWindow;
 
-class DeferredPromise : public DOMGuarded<JSC::JSPromiseDeferred> {
+class DeferredPromise : public DOMGuarded<JSC::JSPromise> {
 public:
     enum class Mode {
         ClearPromiseOnResolve,
@@ -44,13 +44,13 @@ public:
 
     static RefPtr<DeferredPromise> create(JSDOMGlobalObject& globalObject, Mode mode = Mode::ClearPromiseOnResolve)
     {
-        auto* promiseDeferred = JSC::JSPromiseDeferred::tryCreate(&globalObject);
-        if (!promiseDeferred)
-            return nullptr;
-        return adoptRef(new DeferredPromise(globalObject, *promiseDeferred, mode));
+        JSC::VM& vm = JSC::getVM(&globalObject);
+        auto* promise = JSC::JSPromise::create(vm, globalObject.promiseStructure());
+        ASSERT(promise);
+        return adoptRef(new DeferredPromise(globalObject, *promise, mode));
     }
 
-    static Ref<DeferredPromise> create(JSDOMGlobalObject& globalObject, JSC::JSPromiseDeferred& deferred, Mode mode = Mode::ClearPromiseOnResolve)
+    static Ref<DeferredPromise> create(JSDOMGlobalObject& globalObject, JSC::JSPromise& deferred, Mode mode = Mode::ClearPromiseOnResolve)
     {
         return adoptRef(*new DeferredPromise(globalObject, deferred, mode));
     }
@@ -149,18 +149,19 @@ public:
     void whenSettled(Function<void()>&&);
 
 private:
-    DeferredPromise(JSDOMGlobalObject& globalObject, JSC::JSPromiseDeferred& deferred, Mode mode)
-        : DOMGuarded<JSC::JSPromiseDeferred>(globalObject, deferred)
+    DeferredPromise(JSDOMGlobalObject& globalObject, JSC::JSPromise& deferred, Mode mode)
+        : DOMGuarded<JSC::JSPromise>(globalObject, deferred)
         , m_mode(mode)
     {
     }
 
-    JSC::JSPromiseDeferred* deferred() const { return guarded(); }
+    JSC::JSPromise* deferred() const { return guarded(); }
 
-    WEBCORE_EXPORT void callFunction(JSC::JSGlobalObject&, JSC::JSValue function, JSC::JSValue resolution);
+    enum class ResolveMode { Resolve, Reject };
+    WEBCORE_EXPORT void callFunction(JSC::JSGlobalObject&, ResolveMode, JSC::JSValue resolution);
 
-    void resolve(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue resolution) { callFunction(lexicalGlobalObject, deferred()->resolve(), resolution); }
-    void reject(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue resolution) { callFunction(lexicalGlobalObject, deferred()->reject(), resolution); }
+    void resolve(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue resolution) { callFunction(lexicalGlobalObject, ResolveMode::Resolve, resolution); }
+    void reject(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue resolution) { callFunction(lexicalGlobalObject, ResolveMode::Reject, resolution); }
 
     Mode m_mode;
 };
@@ -169,58 +170,58 @@ class DOMPromiseDeferredBase {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     DOMPromiseDeferredBase(Ref<DeferredPromise>&& genericPromise)
-        : m_promiseDeferred(WTFMove(genericPromise))
+        : m_promise(WTFMove(genericPromise))
     {
     }
 
     DOMPromiseDeferredBase(DOMPromiseDeferredBase&& promise)
-        : m_promiseDeferred(WTFMove(promise.m_promiseDeferred))
+        : m_promise(WTFMove(promise.m_promise))
     {
     }
 
     DOMPromiseDeferredBase(const DOMPromiseDeferredBase& other)
-        : m_promiseDeferred(other.m_promiseDeferred.copyRef())
+        : m_promise(other.m_promise.copyRef())
     {
     }
 
     DOMPromiseDeferredBase& operator=(const DOMPromiseDeferredBase& other)
     {
-        m_promiseDeferred = other.m_promiseDeferred.copyRef();
+        m_promise = other.m_promise.copyRef();
         return *this;
     }
 
     DOMPromiseDeferredBase& operator=(DOMPromiseDeferredBase&& other)
     {
-        m_promiseDeferred = WTFMove(other.m_promiseDeferred);
+        m_promise = WTFMove(other.m_promise);
         return *this;
     }
 
     void reject()
     {
-        m_promiseDeferred->reject();
+        m_promise->reject();
     }
 
     template<typename... ErrorType> 
     void reject(ErrorType&&... error)
     {
-        m_promiseDeferred->reject(std::forward<ErrorType>(error)...);
+        m_promise->reject(std::forward<ErrorType>(error)...);
     }
 
     template<typename IDLType>
     void rejectType(typename IDLType::ParameterType value)
     {
-        m_promiseDeferred->reject<IDLType>(std::forward<typename IDLType::ParameterType>(value));
+        m_promise->reject<IDLType>(std::forward<typename IDLType::ParameterType>(value));
     }
 
-    JSC::JSValue promise() const { return m_promiseDeferred->promise(); };
+    JSC::JSValue promise() const { return m_promise->promise(); };
 
     void whenSettled(Function<void()>&& function)
     {
-        m_promiseDeferred->whenSettled(WTFMove(function));
+        m_promise->whenSettled(WTFMove(function));
     }
 
 protected:
-    Ref<DeferredPromise> m_promiseDeferred;
+    Ref<DeferredPromise> m_promise;
 };
 
 template<typename IDLType> 
@@ -233,7 +234,7 @@ public:
 
     void resolve(typename IDLType::ParameterType value)
     { 
-        m_promiseDeferred->resolve<IDLType>(std::forward<typename IDLType::ParameterType>(value));
+        m_promise->resolve<IDLType>(std::forward<typename IDLType::ParameterType>(value));
     }
 
     void settle(ExceptionOr<typename IDLType::ParameterType>&& result)
@@ -255,7 +256,7 @@ public:
 
     void resolve()
     { 
-        m_promiseDeferred->resolve();
+        m_promise->resolve();
     }
 
     void settle(ExceptionOr<void>&& result)
@@ -274,53 +275,49 @@ Ref<DeferredPromise> createDeferredPromise(JSC::JSGlobalObject&, JSDOMWindow&);
 void fulfillPromiseWithJSON(Ref<DeferredPromise>&&, const String&);
 void fulfillPromiseWithArrayBuffer(Ref<DeferredPromise>&&, ArrayBuffer*);
 void fulfillPromiseWithArrayBuffer(Ref<DeferredPromise>&&, const void*, size_t);
-WEBCORE_EXPORT void rejectPromiseWithExceptionIfAny(JSC::JSGlobalObject&, JSDOMGlobalObject&, JSC::JSPromiseDeferred&);
+WEBCORE_EXPORT void rejectPromiseWithExceptionIfAny(JSC::JSGlobalObject&, JSDOMGlobalObject&, JSC::JSPromise&);
 
 enum class RejectedPromiseWithTypeErrorCause { NativeGetter, InvalidThis };
 JSC::EncodedJSValue createRejectedPromiseWithTypeError(JSC::JSGlobalObject&, const String&, RejectedPromiseWithTypeErrorCause);
 
 using PromiseFunction = void(JSC::JSGlobalObject&, JSC::CallFrame&, Ref<DeferredPromise>&&);
 
-enum class PromiseExecutionScope { WindowOnly, WindowOrWorker };
-
-template<PromiseFunction promiseFunction, PromiseExecutionScope executionScope>
+template<PromiseFunction promiseFunction>
 inline JSC::JSValue callPromiseFunction(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame)
 {
     JSC::VM& vm = JSC::getVM(&lexicalGlobalObject);
     auto scope = DECLARE_CATCH_SCOPE(vm);
 
     auto& globalObject = callerGlobalObject(lexicalGlobalObject, callFrame);
-    JSC::JSPromiseDeferred* promiseDeferred = JSC::JSPromiseDeferred::tryCreate(&globalObject);
-
-    // promiseDeferred can be null when terminating a Worker abruptly.
-    if (executionScope == PromiseExecutionScope::WindowOrWorker && !promiseDeferred)
-        return JSC::jsUndefined();
+    auto* promise = JSC::JSPromise::create(vm, globalObject.promiseStructure());
+    ASSERT(promise);
 
-    promiseFunction(lexicalGlobalObject, callFrame, DeferredPromise::create(globalObject, *promiseDeferred));
+    promiseFunction(lexicalGlobalObject, callFrame, DeferredPromise::create(globalObject, *promise));
 
-    rejectPromiseWithExceptionIfAny(lexicalGlobalObject, globalObject, *promiseDeferred);
-    EXCEPTION_ASSERT_UNUSED(scope, !scope.exception());
-    return promiseDeferred->promise();
+    rejectPromiseWithExceptionIfAny(lexicalGlobalObject, globalObject, *promise);
+    // FIXME: We could have error since any JS call can throw stack-overflow errors.
+    // https://bugs.webkit.org/show_bug.cgi?id=203402
+    RETURN_IF_EXCEPTION(scope, JSC::jsUndefined());
+    return promise;
 }
 
-template<PromiseExecutionScope executionScope, typename PromiseFunctor>
+template<typename PromiseFunctor>
 inline JSC::JSValue callPromiseFunction(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, PromiseFunctor functor)
 {
     JSC::VM& vm = JSC::getVM(&lexicalGlobalObject);
     auto scope = DECLARE_CATCH_SCOPE(vm);
 
     auto& globalObject = callerGlobalObject(lexicalGlobalObject, callFrame);
-    JSC::JSPromiseDeferred* promiseDeferred = JSC::JSPromiseDeferred::tryCreate(&globalObject);
-
-    // promiseDeferred can be null when terminating a Worker abruptly.
-    if (executionScope == PromiseExecutionScope::WindowOrWorker && !promiseDeferred)
-        return JSC::jsUndefined();
+    auto* promise = JSC::JSPromise::create(vm, globalObject.promiseStructure());
+    ASSERT(promise);
 
-    functor(lexicalGlobalObject, callFrame, DeferredPromise::create(globalObject, *promiseDeferred));
+    functor(lexicalGlobalObject, callFrame, DeferredPromise::create(globalObject, *promise));
 
-    rejectPromiseWithExceptionIfAny(lexicalGlobalObject, globalObject, *promiseDeferred);
-    EXCEPTION_ASSERT_UNUSED(scope, !scope.exception());
-    return promiseDeferred->promise();
+    rejectPromiseWithExceptionIfAny(lexicalGlobalObject, globalObject, *promise);
+    // FIXME: We could have error since any JS call can throw stack-overflow errors.
+    // https://bugs.webkit.org/show_bug.cgi?id=203402
+    RETURN_IF_EXCEPTION(scope, JSC::jsUndefined());
+    return promise;
 }
 
 using BindingPromiseFunction = JSC::EncodedJSValue(JSC::JSGlobalObject*, JSC::CallFrame*, Ref<DeferredPromise>&&);
@@ -330,10 +327,10 @@ inline void bindingPromiseFunctionAdapter(JSC::JSGlobalObject& lexicalGlobalObje
     bindingFunction(&lexicalGlobalObject, &callFrame, WTFMove(promise));
 }
 
-template<BindingPromiseFunction bindingPromiseFunction, PromiseExecutionScope executionScope>
+template<BindingPromiseFunction bindingPromiseFunction>
 inline JSC::JSValue callPromiseFunction(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame)
 {
-    return callPromiseFunction<bindingPromiseFunctionAdapter<bindingPromiseFunction>, executionScope>(lexicalGlobalObject, callFrame);
+    return callPromiseFunction<bindingPromiseFunctionAdapter<bindingPromiseFunction>>(lexicalGlobalObject, callFrame);
 }
 
 } // namespace WebCore
index dc387d5..57dc31b 100644 (file)
 #include "WebCoreJSClientData.h"
 #include <JavaScriptCore/CodeBlock.h>
 #include <JavaScriptCore/JSInternalPromise.h>
-#include <JavaScriptCore/JSInternalPromiseDeferred.h>
 #include <JavaScriptCore/JSWebAssembly.h>
 #include <JavaScriptCore/Microtask.h>
-#include <JavaScriptCore/PromiseDeferredTimer.h>
+#include <JavaScriptCore/PromiseTimer.h>
 #include <JavaScriptCore/StrongInlines.h>
 #include <wtf/Language.h>
 #include <wtf/MainThread.h>
@@ -317,9 +316,10 @@ JSC::JSInternalPromise* JSDOMWindowBase::moduleLoaderFetch(JSC::JSGlobalObject*
     JSDOMWindowBase* thisObject = JSC::jsCast<JSDOMWindowBase*>(globalObject);
     if (RefPtr<Document> document = thisObject->wrapped().document())
         RELEASE_AND_RETURN(scope, document->moduleLoader().fetch(globalObject, moduleLoader, moduleKey, parameters, scriptFetcher));
-    JSC::JSInternalPromiseDeferred* deferred = JSC::JSInternalPromiseDeferred::tryCreate(globalObject);
-    RETURN_IF_EXCEPTION(scope, nullptr);
-    RELEASE_AND_RETURN(scope, deferred->reject(globalObject, jsUndefined()));
+    JSC::JSInternalPromise* promise = JSC::JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
+    scope.release();
+    promise->reject(globalObject, jsUndefined());
+    return promise;
 }
 
 JSC::JSValue JSDOMWindowBase::moduleLoaderEvaluate(JSC::JSGlobalObject* globalObject, JSC::JSModuleLoader* moduleLoader, JSC::JSValue moduleKey, JSC::JSValue moduleRecord, JSC::JSValue scriptFetcher)
@@ -337,9 +337,10 @@ JSC::JSInternalPromise* JSDOMWindowBase::moduleLoaderImportModule(JSC::JSGlobalO
     JSDOMWindowBase* thisObject = JSC::jsCast<JSDOMWindowBase*>(globalObject);
     if (RefPtr<Document> document = thisObject->wrapped().document())
         RELEASE_AND_RETURN(scope, document->moduleLoader().importModule(globalObject, moduleLoader, moduleName, parameters, sourceOrigin));
-    JSC::JSInternalPromiseDeferred* deferred = JSC::JSInternalPromiseDeferred::tryCreate(globalObject);
-    RETURN_IF_EXCEPTION(scope, nullptr);
-    RELEASE_AND_RETURN(scope, deferred->reject(globalObject, jsUndefined()));
+    JSC::JSInternalPromise* promise = JSC::JSInternalPromise::create(vm, globalObject->internalPromiseStructure());
+    scope.release();
+    promise->reject(globalObject, jsUndefined());
+    return promise;
 }
 
 JSC::JSObject* JSDOMWindowBase::moduleLoaderCreateImportMetaProperties(JSC::JSGlobalObject* globalObject, JSC::JSModuleLoader* moduleLoader, JSC::JSValue moduleKey, JSC::JSModuleRecord* moduleRecord, JSC::JSValue scriptFetcher)
@@ -351,7 +352,7 @@ JSC::JSObject* JSDOMWindowBase::moduleLoaderCreateImportMetaProperties(JSC::JSGl
 }
 
 #if ENABLE(WEBASSEMBLY)
-static Optional<Vector<uint8_t>> tryAllocate(JSC::JSGlobalObject* lexicalGlobalObject, JSC::JSPromiseDeferred* promise, const char* data, size_t byteSize)
+static Optional<Vector<uint8_t>> tryAllocate(JSC::JSGlobalObject* lexicalGlobalObject, JSC::JSPromise* promise, const char* data, size_t byteSize)
 {
     Vector<uint8_t> arrayBuffer;
     if (!arrayBuffer.tryReserveCapacity(byteSize)) {
@@ -365,7 +366,7 @@ static Optional<Vector<uint8_t>> tryAllocate(JSC::JSGlobalObject* lexicalGlobalO
     return arrayBuffer;
 }
 
-static bool isResponseCorrect(JSC::JSGlobalObject* lexicalGlobalObject, FetchResponse* inputResponse, JSC::JSPromiseDeferred* promise)
+static bool isResponseCorrect(JSC::JSGlobalObject* lexicalGlobalObject, FetchResponse* inputResponse, JSC::JSPromise* promise)
 {
     bool isResponseCorsSameOrigin = inputResponse->type() == ResourceResponse::Type::Basic || inputResponse->type() == ResourceResponse::Type::Cors || inputResponse->type() == ResourceResponse::Type::Default;
 
@@ -388,7 +389,7 @@ static bool isResponseCorrect(JSC::JSGlobalObject* lexicalGlobalObject, FetchRes
     return true;
 }
 
-static void handleResponseOnStreamingAction(JSC::JSGlobalObject* globalObject, FetchResponse* inputResponse, JSC::JSPromiseDeferred* promise, Function<void(JSC::JSGlobalObject* lexicalGlobalObject, const char* data, size_t byteSize)>&& actionCallback)
+static void handleResponseOnStreamingAction(JSC::JSGlobalObject* globalObject, FetchResponse* inputResponse, JSC::JSPromise* promise, Function<void(JSC::JSGlobalObject* lexicalGlobalObject, const char* data, size_t byteSize)>&& actionCallback)
 {
     if (!isResponseCorrect(globalObject, inputResponse, promise))
         return;
@@ -433,14 +434,14 @@ static void handleResponseOnStreamingAction(JSC::JSGlobalObject* globalObject, F
     });
 }
 
-void JSDOMWindowBase::compileStreaming(JSC::JSGlobalObject* globalObject, JSC::JSPromiseDeferred* promise, JSC::JSValue source)
+void JSDOMWindowBase::compileStreaming(JSC::JSGlobalObject* globalObject, JSC::JSPromise* promise, JSC::JSValue source)
 {
     ASSERT(source);
 
     VM& vm = globalObject->vm();
 
-    ASSERT(vm.promiseDeferredTimer->hasPendingPromise(promise));
-    ASSERT(vm.promiseDeferredTimer->hasDependancyInPendingPromise(promise, globalObject));
+    ASSERT(vm.promiseTimer->hasPendingPromise(promise));
+    ASSERT(vm.promiseTimer->hasDependancyInPendingPromise(promise, globalObject));
 
     if (auto inputResponse = JSFetchResponse::toWrapped(vm, source)) {
         handleResponseOnStreamingAction(globalObject, inputResponse, promise, [promise] (JSC::JSGlobalObject* lexicalGlobalObject, const char* data, size_t byteSize) mutable {
@@ -451,15 +452,15 @@ void JSDOMWindowBase::compileStreaming(JSC::JSGlobalObject* globalObject, JSC::J
         promise->reject(globalObject, createTypeError(globalObject, "first argument must be an Response or Promise for Response"_s));
 }
 
-void JSDOMWindowBase::instantiateStreaming(JSC::JSGlobalObject* globalObject, JSC::JSPromiseDeferred* promise, JSC::JSValue source, JSC::JSObject* importedObject)
+void JSDOMWindowBase::instantiateStreaming(JSC::JSGlobalObject* globalObject, JSC::JSPromise* promise, JSC::JSValue source, JSC::JSObject* importedObject)
 {
     ASSERT(source);
 
     VM& vm = globalObject->vm();
 
-    ASSERT(vm.promiseDeferredTimer->hasPendingPromise(promise));
-    ASSERT(vm.promiseDeferredTimer->hasDependancyInPendingPromise(promise, globalObject));
-    ASSERT(vm.promiseDeferredTimer->hasDependancyInPendingPromise(promise, importedObject));
+    ASSERT(vm.promiseTimer->hasPendingPromise(promise));
+    ASSERT(vm.promiseTimer->hasDependancyInPendingPromise(promise, globalObject));
+    ASSERT(vm.promiseTimer->hasDependancyInPendingPromise(promise, importedObject));
 
     if (auto inputResponse = JSFetchResponse::toWrapped(vm, source)) {
         handleResponseOnStreamingAction(globalObject, inputResponse, promise, [promise, importedObject] (JSC::JSGlobalObject* lexicalGlobalObject, const char* data, size_t byteSize) mutable {
index 6a0f7d7..598c11b 100644 (file)
@@ -98,8 +98,8 @@ private:
     static JSC::JSObject* moduleLoaderCreateImportMetaProperties(JSC::JSGlobalObject*, JSC::JSModuleLoader*, JSC::JSValue, JSC::JSModuleRecord*, JSC::JSValue);
 
 #if ENABLE(WEBASSEMBLY)
-    static void compileStreaming(JSC::JSGlobalObject*, JSC::JSPromiseDeferred*, JSC::JSValue);
-    static void instantiateStreaming(JSC::JSGlobalObject*, JSC::JSPromiseDeferred*, JSC::JSValue, JSC::JSObject*);
+    static void compileStreaming(JSC::JSGlobalObject*, JSC::JSPromise*, JSC::JSValue);
+    static void instantiateStreaming(JSC::JSGlobalObject*, JSC::JSPromise*, JSC::JSValue, JSC::JSObject*);
 #endif
 
     RefPtr<DOMWindow> m_wrapped;
index d6ef7c0..b3f06ac 100644 (file)
@@ -43,7 +43,6 @@
 #include "WebCoreJSClientData.h"
 #include <JavaScriptCore/Completion.h>
 #include <JavaScriptCore/JSInternalPromise.h>
-#include <JavaScriptCore/JSInternalPromiseDeferred.h>
 #include <JavaScriptCore/JSModuleRecord.h>
 #include <JavaScriptCore/JSScriptFetchParameters.h>
 #include <JavaScriptCore/JSScriptFetcher.h>
@@ -147,17 +146,17 @@ JSC::JSInternalPromise* ScriptModuleLoader::fetch(JSC::JSGlobalObject* jsGlobalO
     ASSERT(JSC::jsDynamicCast<JSC::JSScriptFetcher*>(vm, scriptFetcher));
 
     auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(jsGlobalObject);
-    auto* jsPromise = JSC::JSInternalPromiseDeferred::tryCreate(&globalObject);
+    auto* jsPromise = JSC::JSInternalPromise::create(vm, globalObject.internalPromiseStructure());
     RELEASE_ASSERT(jsPromise);
     auto deferred = DeferredPromise::create(globalObject, *jsPromise);
     if (moduleKeyValue.isSymbol()) {
         deferred->reject(TypeError, "Symbol module key should be already fulfilled with the inlined resource."_s);
-        return jsPromise->promise();
+        return jsPromise;
     }
 
     if (!moduleKeyValue.isString()) {
         deferred->reject(TypeError, "Module key is not Symbol or String."_s);
-        return jsPromise->promise();
+        return jsPromise;
     }
 
     // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script
@@ -165,7 +164,7 @@ JSC::JSInternalPromise* ScriptModuleLoader::fetch(JSC::JSGlobalObject* jsGlobalO
     URL completedURL(URL(), asString(moduleKeyValue)->value(jsGlobalObject));
     if (!completedURL.isValid()) {
         deferred->reject(TypeError, "Module key is a valid URL."_s);
-        return jsPromise->promise();
+        return jsPromise;
     }
 
     RefPtr<ModuleFetchParameters> topLevelFetchParameters;
@@ -178,10 +177,10 @@ JSC::JSInternalPromise* ScriptModuleLoader::fetch(JSC::JSGlobalObject* jsGlobalO
         loader->clearClient();
         m_loaders.remove(WTFMove(loader));
         rejectToPropagateNetworkError(deferred.get(), ModuleFetchFailureKind::WasErrored, "Importing a module script failed."_s);
-        return jsPromise->promise();
+        return jsPromise;
     }
 
-    return jsPromise->promise();
+    return jsPromise;
 }
 
 URL ScriptModuleLoader::moduleURL(JSC::JSGlobalObject& jsGlobalObject, JSC::JSValue moduleKeyValue)
@@ -216,11 +215,11 @@ JSC::JSValue ScriptModuleLoader::evaluate(JSC::JSGlobalObject* jsGlobalObject, J
 
 static JSC::JSInternalPromise* rejectPromise(JSDOMGlobalObject& globalObject, ExceptionCode ec, ASCIILiteral message)
 {
-    auto* jsPromise = JSC::JSInternalPromiseDeferred::tryCreate(&globalObject);
+    auto* jsPromise = JSInternalPromise::create(globalObject.vm(), globalObject.internalPromiseStructure());
     RELEASE_ASSERT(jsPromise);
     auto deferred = DeferredPromise::create(globalObject, *jsPromise);
     deferred->reject(ec, WTFMove(message));
-    return jsPromise->promise();
+    return jsPromise;
 }
 
 JSC::JSInternalPromise* ScriptModuleLoader::importModule(JSC::JSGlobalObject* jsGlobalObject, JSC::JSModuleLoader*, JSC::JSString* moduleName, JSC::JSValue parameters, const JSC::SourceOrigin& sourceOrigin)
index 08616e2..2eafb81 100644 (file)
@@ -42,7 +42,7 @@
 #include <JavaScriptCore/GCActivityCallback.h>
 #include <JavaScriptCore/JSCInlines.h>
 #include <JavaScriptCore/JSLock.h>
-#include <JavaScriptCore/PromiseDeferredTimer.h>
+#include <JavaScriptCore/PromiseTimer.h>
 #include <JavaScriptCore/StrongInlines.h>
 
 namespace WebCore {
@@ -250,7 +250,7 @@ void WorkerScriptController::addTimerSetNotification(JSC::JSRunLoopTimer::TimerN
 
     processTimer(m_vm->heap.fullActivityCallback());
     processTimer(m_vm->heap.edenActivityCallback());
-    processTimer(m_vm->promiseDeferredTimer.ptr());
+    processTimer(m_vm->promiseTimer.ptr());
 }
 
 void WorkerScriptController::removeTimerSetNotification(JSC::JSRunLoopTimer::TimerNotificationCallback callback)
@@ -263,7 +263,7 @@ void WorkerScriptController::removeTimerSetNotification(JSC::JSRunLoopTimer::Tim
 
     processTimer(m_vm->heap.fullActivityCallback());
     processTimer(m_vm->heap.edenActivityCallback());
-    processTimer(m_vm->promiseDeferredTimer.ptr());
+    processTimer(m_vm->promiseTimer.ptr());
 }
 
 void WorkerScriptController::attachDebugger(JSC::Debugger* debugger)
index 5d5908d..e0f4605 100644 (file)
@@ -5197,7 +5197,6 @@ sub GenerateOperationTrampolineDefinition
 
     my @callFunctionTemplateArguments = ();
     push(@callFunctionTemplateArguments, $functionBodyName);
-    push(@callFunctionTemplateArguments, "PromiseExecutionScope::${exposureScope}") if $hasPromiseReturnType && !$operation->extendedAttributes->{ReturnsOwnPromise};
     push(@callFunctionTemplateArguments, "CastedThisErrorBehavior::Assert") if ($operation->extendedAttributes->{PrivateIdentifier} and not $operation->extendedAttributes->{PublicIdentifier});
 
     push(@$outputArray, "EncodedJSValue JSC_HOST_CALL ${functionName}(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)\n");
index 7729bfa..f5acb1a 100644 (file)
@@ -2685,7 +2685,7 @@ static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionCalculateSec
 
 EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionCalculateSecretResult(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
 {
-    return IDLOperationReturningPromise<JSTestGlobalObject>::call<jsTestGlobalObjectInstanceFunctionCalculateSecretResultBody, PromiseExecutionScope::WindowOnly>(*lexicalGlobalObject, *callFrame, "calculateSecretResult");
+    return IDLOperationReturningPromise<JSTestGlobalObject>::call<jsTestGlobalObjectInstanceFunctionCalculateSecretResultBody>(*lexicalGlobalObject, *callFrame, "calculateSecretResult");
 }
 
 static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionGetSecretBooleanBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSTestGlobalObject>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
index 86f92a3..3925c42 100644 (file)
@@ -306,7 +306,7 @@ static inline JSC::EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromiseBo
 
 EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionTestWorkerPromise(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
 {
-    return IDLOperationReturningPromise<JSTestNode>::call<jsTestNodePrototypeFunctionTestWorkerPromiseBody, PromiseExecutionScope::WindowOrWorker>(*lexicalGlobalObject, *callFrame, "testWorkerPromise");
+    return IDLOperationReturningPromise<JSTestNode>::call<jsTestNodePrototypeFunctionTestWorkerPromiseBody>(*lexicalGlobalObject, *callFrame, "testWorkerPromise");
 }
 
 static inline JSC::EncodedJSValue jsTestNodePrototypeFunctionCalculateSecretResultBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperationReturningPromise<JSTestNode>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
@@ -321,7 +321,7 @@ static inline JSC::EncodedJSValue jsTestNodePrototypeFunctionCalculateSecretResu
 
 EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionCalculateSecretResult(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
 {
-    return IDLOperationReturningPromise<JSTestNode>::call<jsTestNodePrototypeFunctionCalculateSecretResultBody, PromiseExecutionScope::WindowOrWorker>(*lexicalGlobalObject, *callFrame, "calculateSecretResult");
+    return IDLOperationReturningPromise<JSTestNode>::call<jsTestNodePrototypeFunctionCalculateSecretResultBody>(*lexicalGlobalObject, *callFrame, "calculateSecretResult");
 }
 
 static inline JSC::EncodedJSValue jsTestNodePrototypeFunctionGetSecretBooleanBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSTestNode>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
index 2830e7a..d76ed9f 100644 (file)
@@ -5629,7 +5629,7 @@ static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionCalculateSecretResul
 
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionCalculateSecretResult(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
 {
-    return IDLOperationReturningPromise<JSTestObj>::call<jsTestObjPrototypeFunctionCalculateSecretResultBody, PromiseExecutionScope::WindowOrWorker>(*lexicalGlobalObject, *callFrame, "calculateSecretResult");
+    return IDLOperationReturningPromise<JSTestObj>::call<jsTestObjPrototypeFunctionCalculateSecretResultBody>(*lexicalGlobalObject, *callFrame, "calculateSecretResult");
 }
 
 static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionGetSecretBooleanBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSTestObj>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
@@ -8379,7 +8379,7 @@ static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionB
 
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunction(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
 {
-    return IDLOperationReturningPromise<JSTestObj>::call<jsTestObjPrototypeFunctionTestPromiseFunctionBody, PromiseExecutionScope::WindowOrWorker>(*lexicalGlobalObject, *callFrame, "testPromiseFunction");
+    return IDLOperationReturningPromise<JSTestObj>::call<jsTestObjPrototypeFunctionTestPromiseFunctionBody>(*lexicalGlobalObject, *callFrame, "testPromiseFunction");
 }
 
 static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperationReturningPromise<JSTestObj>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
@@ -8398,7 +8398,7 @@ static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionW
 
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgument(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
 {
-    return IDLOperationReturningPromise<JSTestObj>::call<jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentBody, PromiseExecutionScope::WindowOrWorker>(*lexicalGlobalObject, *callFrame, "testPromiseFunctionWithFloatArgument");
+    return IDLOperationReturningPromise<JSTestObj>::call<jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentBody>(*lexicalGlobalObject, *callFrame, "testPromiseFunctionWithFloatArgument");
 }
 
 static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperationReturningPromise<JSTestObj>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
@@ -8413,7 +8413,7 @@ static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionW
 
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithException(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
 {
-    return IDLOperationReturningPromise<JSTestObj>::call<jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionBody, PromiseExecutionScope::WindowOrWorker>(*lexicalGlobalObject, *callFrame, "testPromiseFunctionWithException");
+    return IDLOperationReturningPromise<JSTestObj>::call<jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionBody>(*lexicalGlobalObject, *callFrame, "testPromiseFunctionWithException");
 }
 
 static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperationReturningPromise<JSTestObj>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
@@ -8430,7 +8430,7 @@ static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionW
 
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgument(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
 {
-    return IDLOperationReturningPromise<JSTestObj>::call<jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentBody, PromiseExecutionScope::WindowOrWorker>(*lexicalGlobalObject, *callFrame, "testPromiseFunctionWithOptionalIntArgument");
+    return IDLOperationReturningPromise<JSTestObj>::call<jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentBody>(*lexicalGlobalObject, *callFrame, "testPromiseFunctionWithOptionalIntArgument");
 }
 
 static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperationReturningPromise<JSTestObj>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
@@ -8478,7 +8478,7 @@ static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloade
 
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseOverloadedFunction(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
 {
-    return IDLOperationReturningPromise<JSTestObj>::call<jsTestObjPrototypeFunctionTestPromiseOverloadedFunctionOverloadDispatcher, PromiseExecutionScope::WindowOrWorker>(*lexicalGlobalObject, *callFrame, "testPromiseOverloadedFunction");
+    return IDLOperationReturningPromise<JSTestObj>::call<jsTestObjPrototypeFunctionTestPromiseOverloadedFunctionOverloadDispatcher>(*lexicalGlobalObject, *callFrame, "testPromiseOverloadedFunction");
 }
 
 static inline JSC::EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseFunctionBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
@@ -8492,7 +8492,7 @@ static inline JSC::EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseF
 
 EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionTestStaticPromiseFunction(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
 {
-    return IDLOperationReturningPromise<JSTestObj>::callStatic<jsTestObjConstructorFunctionTestStaticPromiseFunctionBody, PromiseExecutionScope::WindowOrWorker>(*lexicalGlobalObject, *callFrame, "testStaticPromiseFunction");
+    return IDLOperationReturningPromise<JSTestObj>::callStatic<jsTestObjConstructorFunctionTestStaticPromiseFunctionBody>(*lexicalGlobalObject, *callFrame, "testStaticPromiseFunction");
 }
 
 static inline JSC::EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
@@ -8506,7 +8506,7 @@ static inline JSC::EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseF
 
 EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionTestStaticPromiseFunctionWithException(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
 {
-    return IDLOperationReturningPromise<JSTestObj>::callStatic<jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionBody, PromiseExecutionScope::WindowOrWorker>(*lexicalGlobalObject, *callFrame, "testStaticPromiseFunctionWithException");
+    return IDLOperationReturningPromise<JSTestObj>::callStatic<jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionBody>(*lexicalGlobalObject, *callFrame, "testStaticPromiseFunctionWithException");
 }
 
 static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionTestCustomPromiseFunctionBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperationReturningPromise<JSTestObj>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
@@ -8519,7 +8519,7 @@ static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionTestCustomPromiseFun
 
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestCustomPromiseFunction(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
 {
-    return IDLOperationReturningPromise<JSTestObj>::call<jsTestObjPrototypeFunctionTestCustomPromiseFunctionBody, PromiseExecutionScope::WindowOrWorker>(*lexicalGlobalObject, *callFrame, "testCustomPromiseFunction");
+    return IDLOperationReturningPromise<JSTestObj>::call<jsTestObjPrototypeFunctionTestCustomPromiseFunctionBody>(*lexicalGlobalObject, *callFrame, "testCustomPromiseFunction");
 }
 
 static inline JSC::EncodedJSValue jsTestObjConstructorFunctionTestStaticCustomPromiseFunctionBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
@@ -8532,7 +8532,7 @@ static inline JSC::EncodedJSValue jsTestObjConstructorFunctionTestStaticCustomPr
 
 EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionTestStaticCustomPromiseFunction(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
 {
-    return IDLOperationReturningPromise<JSTestObj>::callStatic<jsTestObjConstructorFunctionTestStaticCustomPromiseFunctionBody, PromiseExecutionScope::WindowOrWorker>(*lexicalGlobalObject, *callFrame, "testStaticCustomPromiseFunction");
+    return IDLOperationReturningPromise<JSTestObj>::callStatic<jsTestObjConstructorFunctionTestStaticCustomPromiseFunctionBody>(*lexicalGlobalObject, *callFrame, "testStaticCustomPromiseFunction");
 }
 
 static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionTestCustomReturnsOwnPromiseFunctionBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperationReturningPromise<JSTestObj>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
index bfac959..ec07ac4 100644 (file)
@@ -38,7 +38,7 @@
 #include "WorkerRunLoop.h"
 #include "WorkerGlobalScope.h"
 #include "WorkerThread.h"
-#include <JavaScriptCore/PromiseDeferredTimer.h>
+#include <JavaScriptCore/PromiseTimer.h>
 
 #if USE(GLIB)
 #include <glib.h>
index 37f1ddd..59e60c5 100644 (file)
@@ -41,7 +41,7 @@
 #include <JavaScriptCore/ExceptionHelpers.h>
 #include <JavaScriptCore/GCActivityCallback.h>
 #include <JavaScriptCore/JSLock.h>
-#include <JavaScriptCore/PromiseDeferredTimer.h>
+#include <JavaScriptCore/PromiseTimer.h>
 #include <JavaScriptCore/StrongInlines.h>
 
 namespace WebCore {