haikuwebkit/LayoutTests/js/dom/promise-stack-overflow.html

49 lines
962 B
HTML
Raw Permalink Normal View History

[JSC] Remove JSPromiseDeferred 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. Canonical link: https://commits.webkit.org/216917@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@251691 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-10-29 01:37:12 +00:00
<!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>