Title: [266177] trunk
Revision
266177
Author
[email protected]
Date
2020-08-26 11:07:35 -0700 (Wed, 26 Aug 2020)

Log Message

Abort pipeTo based on AbortSignal
https://bugs.webkit.org/show_bug.cgi?id=215448

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

* web-platform-tests/streams/piping/abort.any-expected.txt:
* web-platform-tests/streams/piping/abort.any.worker-expected.txt:
* web-platform-tests/streams/piping/close-propagation-forward.any-expected.txt:
* web-platform-tests/streams/piping/close-propagation-forward.any.worker-expected.txt:
* web-platform-tests/streams/piping/error-propagation-forward.any-expected.txt:
* web-platform-tests/streams/piping/error-propagation-forward.any.worker-expected.txt:
* web-platform-tests/streams/piping/flow-control.any-expected.txt:
* web-platform-tests/streams/piping/flow-control.any.worker-expected.txt:

Source/WebCore:

* CMakeLists.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* Modules/streams/ReadableStreamInternals.js:
(readableStreamPipeToWritableStream):
(pipeToFinalize):
* Modules/streams/WritableStream.js:
(initializeWritableStream):
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSDOMGlobalObject.cpp:
(WebCore::makeDOMExceptionForBuiltins):
(WebCore::whenSignalAborted):
(WebCore::JSDOMGlobalObject::addBuiltinGlobals):
* bindings/js/WebCoreBuiltinNames.h:
* dom/AbortAlgorithm.h: Copied from Source/WebCore/dom/AbortSignal.idl.
* dom/AbortAlgorithm.idl: Copied from Source/WebCore/dom/AbortSignal.idl.
* dom/AbortSignal.cpp:
(WebCore::AbortSignal::whenSignalAborted):
* dom/AbortSignal.h:
* dom/AbortSignal.idl:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (266176 => 266177)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-08-26 18:07:35 UTC (rev 266177)
@@ -1,3 +1,19 @@
+2020-08-26  Youenn Fablet  <[email protected]>
+
+        Abort pipeTo based on AbortSignal
+        https://bugs.webkit.org/show_bug.cgi?id=215448
+
+        Reviewed by Alex Christensen.
+
+        * web-platform-tests/streams/piping/abort.any-expected.txt:
+        * web-platform-tests/streams/piping/abort.any.worker-expected.txt:
+        * web-platform-tests/streams/piping/close-propagation-forward.any-expected.txt:
+        * web-platform-tests/streams/piping/close-propagation-forward.any.worker-expected.txt:
+        * web-platform-tests/streams/piping/error-propagation-forward.any-expected.txt:
+        * web-platform-tests/streams/piping/error-propagation-forward.any.worker-expected.txt:
+        * web-platform-tests/streams/piping/flow-control.any-expected.txt:
+        * web-platform-tests/streams/piping/flow-control.any.worker-expected.txt:
+
 2020-08-26  Oriol Brufau  <[email protected]>
 
         [css-grid] Set available column space before grid items prelayout

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/abort.any-expected.txt (266176 => 266177)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/abort.any-expected.txt	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/abort.any-expected.txt	2020-08-26 18:07:35 UTC (rev 266177)
@@ -6,20 +6,20 @@
 PASS a signal argument 'true' should cause pipeTo() to reject 
 PASS a signal argument '-1' should cause pipeTo() to reject 
 FAIL a signal argument '[object AbortSignal]' should cause pipeTo() to reject promise_rejects_js: pipeTo should reject function "function () { throw e }" threw "failed to abort" with type "string", not an object
-FAIL an aborted signal should cause the writable stream to reject with an AbortError promise_rejects_dom: pipeTo should reject function "function () { throw e }" threw "failed to abort" with type "string", not an object
-FAIL all the AbortError objects should be the same object promise_test: Unhandled rejection with value: "failed to abort"
-FAIL preventCancel should prevent canceling the readable promise_rejects_dom: pipeTo should reject function "function () { throw e }" threw "failed to abort" with type "string", not an object
-FAIL preventAbort should prevent aborting the readable promise_rejects_dom: pipeTo should reject function "function () { throw e }" threw "failed to abort" with type "string", not an object
-FAIL preventCancel and preventAbort should prevent canceling the readable and aborting the readable promise_rejects_dom: pipeTo should reject function "function () { throw e }" threw "failed to abort" with type "string", not an object
-FAIL abort should prevent further reads assert_unreached: Should have rejected: pipeTo should reject Reached unreachable code
-FAIL all pending writes should complete on abort assert_unreached: Should have rejected: pipeTo should reject Reached unreachable code
-FAIL a rejection from underlyingSource.cancel() should be returned by pipeTo() promise_rejects_exactly: pipeTo should reject function "function () { throw e }" threw "failed to abort" but we expected it to throw object "error1: error1"
+PASS an aborted signal should cause the writable stream to reject with an AbortError 
+PASS all the AbortError objects should be the same object 
+PASS preventCancel should prevent canceling the readable 
+PASS preventAbort should prevent aborting the readable 
+PASS preventCancel and preventAbort should prevent canceling the readable and aborting the readable 
+PASS abort should prevent further reads 
+PASS all pending writes should complete on abort 
+PASS a rejection from underlyingSource.cancel() should be returned by pipeTo() 
 PASS a rejection from underlyingSink.abort() should be returned by pipeTo() 
-FAIL a rejection from underlyingSink.abort() should be preferred to one from underlyingSource.cancel() assert_array_equals: abort() should be called before cancel() lengths differ, expected array ["abort", "cancel"] length 2, got ["abort"] length 1
-FAIL abort signal takes priority over closed readable assert_unreached: Should have rejected: pipeTo should reject Reached unreachable code
-FAIL abort signal takes priority over errored readable promise_rejects_dom: pipeTo should reject function "function () { throw e }" threw object "error1: error1" that is not a DOMException AbortError: property "code" is equal to undefined, expected 20
-FAIL abort signal takes priority over closed writable promise_rejects_dom: pipeTo should reject function "function () { throw e }" threw object "TypeError: closing is propagated backward" that is not a DOMException AbortError: property "code" is equal to undefined, expected 20
-FAIL abort signal takes priority over errored writable promise_rejects_dom: pipeTo should reject function "function () { throw e }" threw object "error1: error1" that is not a DOMException AbortError: property "code" is equal to undefined, expected 20
+PASS a rejection from underlyingSink.abort() should be preferred to one from underlyingSource.cancel() 
+PASS abort signal takes priority over closed readable 
+PASS abort signal takes priority over errored readable 
+PASS abort signal takes priority over closed writable 
+PASS abort signal takes priority over errored writable 
 PASS abort should do nothing after the readable is closed 
 PASS abort should do nothing after the readable is errored 
 PASS abort should do nothing after the readable is errored, even with pending writes 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/abort.any.worker-expected.txt (266176 => 266177)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/abort.any.worker-expected.txt	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/abort.any.worker-expected.txt	2020-08-26 18:07:35 UTC (rev 266177)
@@ -6,20 +6,20 @@
 PASS a signal argument 'true' should cause pipeTo() to reject 
 PASS a signal argument '-1' should cause pipeTo() to reject 
 FAIL a signal argument '[object AbortSignal]' should cause pipeTo() to reject promise_rejects_js: pipeTo should reject function "function () { throw e }" threw "failed to abort" with type "string", not an object
-FAIL an aborted signal should cause the writable stream to reject with an AbortError promise_rejects_dom: pipeTo should reject function "function () { throw e }" threw "failed to abort" with type "string", not an object
-FAIL all the AbortError objects should be the same object promise_test: Unhandled rejection with value: "failed to abort"
-FAIL preventCancel should prevent canceling the readable promise_rejects_dom: pipeTo should reject function "function () { throw e }" threw "failed to abort" with type "string", not an object
-FAIL preventAbort should prevent aborting the readable promise_rejects_dom: pipeTo should reject function "function () { throw e }" threw "failed to abort" with type "string", not an object
-FAIL preventCancel and preventAbort should prevent canceling the readable and aborting the readable promise_rejects_dom: pipeTo should reject function "function () { throw e }" threw "failed to abort" with type "string", not an object
-FAIL abort should prevent further reads assert_unreached: Should have rejected: pipeTo should reject Reached unreachable code
-FAIL all pending writes should complete on abort assert_unreached: Should have rejected: pipeTo should reject Reached unreachable code
-FAIL a rejection from underlyingSource.cancel() should be returned by pipeTo() promise_rejects_exactly: pipeTo should reject function "function () { throw e }" threw "failed to abort" but we expected it to throw object "error1: error1"
+PASS an aborted signal should cause the writable stream to reject with an AbortError 
+PASS all the AbortError objects should be the same object 
+PASS preventCancel should prevent canceling the readable 
+PASS preventAbort should prevent aborting the readable 
+PASS preventCancel and preventAbort should prevent canceling the readable and aborting the readable 
+PASS abort should prevent further reads 
+PASS all pending writes should complete on abort 
+PASS a rejection from underlyingSource.cancel() should be returned by pipeTo() 
 PASS a rejection from underlyingSink.abort() should be returned by pipeTo() 
-FAIL a rejection from underlyingSink.abort() should be preferred to one from underlyingSource.cancel() assert_array_equals: abort() should be called before cancel() lengths differ, expected array ["abort", "cancel"] length 2, got ["abort"] length 1
-FAIL abort signal takes priority over closed readable assert_unreached: Should have rejected: pipeTo should reject Reached unreachable code
-FAIL abort signal takes priority over errored readable promise_rejects_dom: pipeTo should reject function "function () { throw e }" threw object "error1: error1" that is not a DOMException AbortError: property "code" is equal to undefined, expected 20
-FAIL abort signal takes priority over closed writable promise_rejects_dom: pipeTo should reject function "function () { throw e }" threw object "TypeError: closing is propagated backward" that is not a DOMException AbortError: property "code" is equal to undefined, expected 20
-FAIL abort signal takes priority over errored writable promise_rejects_dom: pipeTo should reject function "function () { throw e }" threw object "error1: error1" that is not a DOMException AbortError: property "code" is equal to undefined, expected 20
+PASS a rejection from underlyingSink.abort() should be preferred to one from underlyingSource.cancel() 
+PASS abort signal takes priority over closed readable 
+PASS abort signal takes priority over errored readable 
+PASS abort signal takes priority over closed writable 
+PASS abort signal takes priority over errored writable 
 PASS abort should do nothing after the readable is closed 
 PASS abort should do nothing after the readable is errored 
 PASS abort should do nothing after the readable is errored, even with pending writes 

Modified: trunk/Source/WebCore/CMakeLists.txt (266176 => 266177)


--- trunk/Source/WebCore/CMakeLists.txt	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/Source/WebCore/CMakeLists.txt	2020-08-26 18:07:35 UTC (rev 266177)
@@ -721,6 +721,7 @@
 
     css/WebKitCSSMatrix.idl
 
+    dom/AbortAlgorithm.idl
     dom/AbortController.idl
     dom/AbortSignal.idl
     dom/AnimationEvent.idl

Modified: trunk/Source/WebCore/ChangeLog (266176 => 266177)


--- trunk/Source/WebCore/ChangeLog	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/Source/WebCore/ChangeLog	2020-08-26 18:07:35 UTC (rev 266177)
@@ -1,3 +1,33 @@
+2020-08-26  Youenn Fablet  <[email protected]>
+
+        Abort pipeTo based on AbortSignal
+        https://bugs.webkit.org/show_bug.cgi?id=215448
+
+        Reviewed by Alex Christensen.
+
+        * CMakeLists.txt:
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources-output.xcfilelist:
+        * DerivedSources.make:
+        * Modules/streams/ReadableStreamInternals.js:
+        (readableStreamPipeToWritableStream):
+        (pipeToFinalize):
+        * Modules/streams/WritableStream.js:
+        (initializeWritableStream):
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSDOMGlobalObject.cpp:
+        (WebCore::makeDOMExceptionForBuiltins):
+        (WebCore::whenSignalAborted):
+        (WebCore::JSDOMGlobalObject::addBuiltinGlobals):
+        * bindings/js/WebCoreBuiltinNames.h:
+        * dom/AbortAlgorithm.h: Copied from Source/WebCore/dom/AbortSignal.idl.
+        * dom/AbortAlgorithm.idl: Copied from Source/WebCore/dom/AbortSignal.idl.
+        * dom/AbortSignal.cpp:
+        (WebCore::AbortSignal::whenSignalAborted):
+        * dom/AbortSignal.h:
+        * dom/AbortSignal.idl:
+
 2020-08-26  Jer Noble  <[email protected]>
 
         [Mac,EME] Netflix.com shows HDCP error for all streams

Modified: trunk/Source/WebCore/DerivedSources-input.xcfilelist (266176 => 266177)


--- trunk/Source/WebCore/DerivedSources-input.xcfilelist	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/Source/WebCore/DerivedSources-input.xcfilelist	2020-08-26 18:07:35 UTC (rev 266177)
@@ -635,6 +635,7 @@
 $(PROJECT_DIR)/css/typedom/TypedOMCSSStyleValue.idl
 $(PROJECT_DIR)/css/typedom/TypedOMCSSUnitValue.idl
 $(PROJECT_DIR)/css/typedom/TypedOMCSSUnparsedValue.idl
+$(PROJECT_DIR)/dom/AbortAlgorithm.idl
 $(PROJECT_DIR)/dom/AbortController.idl
 $(PROJECT_DIR)/dom/AbortSignal.idl
 $(PROJECT_DIR)/dom/AnimationEvent.idl

Modified: trunk/Source/WebCore/DerivedSources-output.xcfilelist (266176 => 266177)


--- trunk/Source/WebCore/DerivedSources-output.xcfilelist	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/Source/WebCore/DerivedSources-output.xcfilelist	2020-08-26 18:07:35 UTC (rev 266177)
@@ -33,6 +33,8 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/InternalSettingsGenerated.idl
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSANGLEInstancedArrays.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSANGLEInstancedArrays.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSAbortAlgorithm.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSAbortAlgorithm.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSAbortController.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSAbortController.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSAbortSignal.cpp

Modified: trunk/Source/WebCore/DerivedSources.make (266176 => 266177)


--- trunk/Source/WebCore/DerivedSources.make	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/Source/WebCore/DerivedSources.make	2020-08-26 18:07:35 UTC (rev 266177)
@@ -672,6 +672,7 @@
     $(WebCore)/css/typedom/TypedOMCSSUnitValue.idl \
     $(WebCore)/css/typedom/TypedOMCSSUnparsedValue.idl \
     $(WebCore)/css/WebKitCSSMatrix.idl \
+    $(WebCore)/dom/AbortAlgorithm.idl \
     $(WebCore)/dom/AbortController.idl \
     $(WebCore)/dom/AbortSignal.idl \
     $(WebCore)/dom/AnimationEvent.idl \

Modified: trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js (266176 => 266177)


--- trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js	2020-08-26 18:07:35 UTC (rev 266177)
@@ -156,6 +156,7 @@
 
     @putByIdDirectPrivate(source, "disturbed", true);
 
+    pipeState.finalized = false;
     pipeState.shuttingDown = false;
     pipeState.promiseCapability = @newPromiseCapability(@Promise);
     pipeState.pendingReadPromiseCapability = @newPromiseCapability(@Promise);
@@ -162,8 +163,41 @@
     pipeState.pendingReadPromiseCapability.@resolve.@call();
     pipeState.pendingWritePromise = @Promise.@resolve();
 
-    // FIXME: Support signal.
+    if (signal !== @undefined) {
+        const algorithm = () => {
+            if (pipeState.finalized)
+                return;
 
+            const error = @makeDOMException("AbortError", "abort pipeTo from signal");
+
+            @pipeToShutdownWithAction(pipeState, () => {
+                const shouldAbortDestination = !pipeState.preventAbort && @getByIdDirectPrivate(pipeState.destination, "state") === "writable";
+                const promiseDestination = shouldAbortDestination ? @writableStreamAbort(pipeState.destination, error) : @Promise.@resolve();
+
+                const shouldAbortSource = !pipeState.preventCancel && @getByIdDirectPrivate(pipeState.source, "state") === @streamReadable;
+                const promiseSource = shouldAbortSource ? @readableStreamCancel(pipeState.source, error) : @Promise.@resolve();
+
+                let promiseCapability = @newPromiseCapability(@Promise);
+                let shouldWait = true;
+                let handleResolvedPromise = () => {
+                    if (shouldWait) {
+                        shouldWait = false;
+                        return;
+                    }
+                    promiseCapability.@resolve.@call();
+                }
+                let handleRejectedPromise = (e) => {
+                    promiseCapability.@reject.@call(@undefined, e);
+                }
+                promiseDestination.@then(handleResolvedPromise, handleRejectedPromise);
+                promiseSource.@then(handleResolvedPromise, handleRejectedPromise);
+                return promiseCapability.@promise;
+            }, error);
+        };
+        if (@whenSignalAborted(signal, algorithm))
+            return pipeState.promiseCapability.@promise;
+    }
+
     @pipeToErrorsMustBePropagatedForward(pipeState);
     @pipeToErrorsMustBePropagatedBackward(pipeState);
     @pipeToClosingMustBePropagatedForward(pipeState);
@@ -343,7 +377,8 @@
     @writableStreamDefaultWriterRelease(pipeState.writer);
     @readableStreamReaderGenericRelease(pipeState.reader);
 
-    // FIXME: Implement signal support.
+    // Instead of removing the abort algorithm as per spec, we make it a no-op which is equivalent.
+    pipeState.finalized = true;
 
     if (arguments.length > 1)
         pipeState.promiseCapability.@reject.@call(@undefined, arguments[1]);

Modified: trunk/Source/WebCore/Sources.txt (266176 => 266177)


--- trunk/Source/WebCore/Sources.txt	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/Source/WebCore/Sources.txt	2020-08-26 18:07:35 UTC (rev 266177)
@@ -2616,6 +2616,7 @@
 // FIXME: We should probably move these into ${DerivedSources}/bindings/js/ so they get bundled with the custom bindings.
 
 JSANGLEInstancedArrays.cpp
+JSAbortAlgorithm.cpp
 JSAbortController.cpp
 JSAbortSignal.cpp
 JSAbstractWorker.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (266176 => 266177)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-08-26 18:07:35 UTC (rev 266177)
@@ -7576,6 +7576,8 @@
 		4186BD46214072B60001826F /* RTCRtpTransceiverBackend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCRtpTransceiverBackend.h; sourceTree = "<group>"; };
 		4186BD4B2140A8050001826F /* LibWebRTCRtpTransceiverBackend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCRtpTransceiverBackend.h; path = libwebrtc/LibWebRTCRtpTransceiverBackend.h; sourceTree = "<group>"; };
 		4186BD4D2140B9E80001826F /* LibWebRTCRtpTransceiverBackend.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibWebRTCRtpTransceiverBackend.cpp; path = libwebrtc/LibWebRTCRtpTransceiverBackend.cpp; sourceTree = "<group>"; };
+		418807DF24E4558300DDAF94 /* AbortAlgorithm.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = AbortAlgorithm.idl; sourceTree = "<group>"; };
+		418807E124E458C300DDAF94 /* AbortAlgorithm.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AbortAlgorithm.h; sourceTree = "<group>"; };
 		41885B9111B6FDA6003383BB /* FormSubmission.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FormSubmission.h; sourceTree = "<group>"; };
 		41885B9211B6FDA6003383BB /* FormSubmission.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormSubmission.cpp; sourceTree = "<group>"; };
 		418938AF2429F9AB007FDC41 /* RetrieveRecordsOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RetrieveRecordsOptions.h; sourceTree = "<group>"; };
@@ -28946,6 +28948,8 @@
 				CE2616A4187E65C1007955F3 /* ios */,
 				2D5036661BCDDDC400E20BB3 /* mac */,
 				51ECC3E42005831F00483EAE /* messageports */,
+				418807E124E458C300DDAF94 /* AbortAlgorithm.h */,
+				418807DF24E4558300DDAF94 /* AbortAlgorithm.idl */,
 				7CD0E2B61F80A4820016A4CE /* AbortController.cpp */,
 				7CD0E2B51F80A4820016A4CE /* AbortController.h */,
 				7CD0E2B71F80A4820016A4CE /* AbortController.idl */,

Modified: trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp (266176 => 266177)


--- trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp	2020-08-26 18:07:35 UTC (rev 266177)
@@ -29,6 +29,8 @@
 
 #include "DOMWindow.h"
 #include "Document.h"
+#include "JSAbortAlgorithm.h"
+#include "JSAbortSignal.h"
 #include "JSDOMPromiseDeferred.h"
 #include "JSDOMWindow.h"
 #include "JSEventListener.h"
@@ -56,8 +58,10 @@
 
 EncodedJSValue JSC_HOST_CALL makeThisTypeErrorForBuiltins(JSGlobalObject*, CallFrame*);
 EncodedJSValue JSC_HOST_CALL makeGetterTypeErrorForBuiltins(JSGlobalObject*, CallFrame*);
+EncodedJSValue JSC_HOST_CALL makeDOMExceptionForBuiltins(JSGlobalObject*, CallFrame*);
 EncodedJSValue JSC_HOST_CALL isReadableByteStreamAPIEnabled(JSGlobalObject*, CallFrame*);
 EncodedJSValue JSC_HOST_CALL isWritableStreamAPIEnabled(JSGlobalObject*, CallFrame*);
+EncodedJSValue JSC_HOST_CALL whenSignalAborted(JSGlobalObject*, CallFrame*);
 
 const ClassInfo JSDOMGlobalObject::s_info = { "DOMGlobalObject", &JSGlobalObject::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMGlobalObject) };
 
@@ -107,6 +111,30 @@
     return JSValue::encode(error);
 }
 
+EncodedJSValue JSC_HOST_CALL makeDOMExceptionForBuiltins(JSGlobalObject* globalObject, CallFrame* callFrame)
+{
+    ASSERT(callFrame);
+    ASSERT(callFrame->argumentCount() == 2);
+
+    auto& vm = globalObject->vm();
+    auto scope = DECLARE_CATCH_SCOPE(vm);
+
+    auto codeValue = callFrame->uncheckedArgument(0).getString(globalObject);
+    scope.assertNoException();
+
+    auto message = callFrame->uncheckedArgument(1).getString(globalObject);
+    scope.assertNoException();
+
+    ExceptionCode code { TypeError };
+    if (codeValue == "AbortError")
+        code = AbortError;
+    auto value = createDOMException(globalObject, code, message);
+
+    EXCEPTION_ASSERT(!scope.exception() || isTerminatedExecutionException(vm, scope.exception()));
+
+    return JSValue::encode(value);
+}
+
 EncodedJSValue JSC_HOST_CALL isReadableByteStreamAPIEnabled(JSGlobalObject*, CallFrame*)
 {
     return JSValue::encode(jsBoolean(RuntimeEnabledFeatures::sharedFeatures().readableByteStreamAPIEnabled()));
@@ -117,6 +145,23 @@
     return JSValue::encode(jsBoolean(RuntimeEnabledFeatures::sharedFeatures().writableStreamAPIEnabled()));
 }
 
+EncodedJSValue JSC_HOST_CALL whenSignalAborted(JSGlobalObject* globalObject, CallFrame* callFrame)
+{
+    ASSERT(callFrame);
+    ASSERT(callFrame->argumentCount() == 2);
+
+    auto& vm = globalObject->vm();
+    auto* abortSignal = jsDynamicCast<JSAbortSignal*>(vm, callFrame->uncheckedArgument(0));
+    if (UNLIKELY(!abortSignal))
+        return JSValue::encode(JSValue(JSC::JSValue::JSFalse));
+
+    auto* jsDOMGlobalObject = JSC::jsCast<JSDOMGlobalObject*>(globalObject);
+    Ref<AbortAlgorithm> abortAlgorithm = JSAbortAlgorithm::create(callFrame->uncheckedArgument(1).getObject(), jsDOMGlobalObject);
+
+    bool result = AbortSignal::whenSignalAborted(abortSignal->wrapped(), WTFMove(abortAlgorithm));
+    return JSValue::encode(result ? JSValue(JSC::JSValue::JSTrue) : JSValue(JSC::JSValue::JSFalse));
+}
+
 void JSDOMGlobalObject::addBuiltinGlobals(VM& vm)
 {
     m_builtinInternalFunctions.initialize(*this);
@@ -127,6 +172,10 @@
             JSFunction::create(vm, this, 2, String(), makeThisTypeErrorForBuiltins), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().makeGetterTypeErrorPrivateName(),
             JSFunction::create(vm, this, 2, String(), makeGetterTypeErrorForBuiltins), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
+        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().makeDOMExceptionPrivateName(),
+            JSFunction::create(vm, this, 2, String(), makeDOMExceptionForBuiltins), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
+        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().whenSignalAbortedPrivateName(),
+            JSFunction::create(vm, this, 2, String(), whenSignalAborted), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().cloneArrayBufferPrivateName(),
             JSFunction::create(vm, this, 3, String(), cloneArrayBuffer), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().structuredCloneArrayBufferPrivateName(),

Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (266176 => 266177)


--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2020-08-26 18:07:35 UTC (rev 266177)
@@ -332,6 +332,7 @@
     macro(isSecureContext) \
     macro(localStreams) \
     macro(location) \
+    macro(makeDOMException) \
     macro(makeGetterTypeError) \
     macro(makeThisTypeError) \
     macro(matchingElementInFlatTree) \
@@ -423,6 +424,7 @@
     macro(webkitIndexedDB) \
     macro(webkitOfflineAudioContext) \
     macro(webkitOscillatorNode) \
+    macro(whenSignalAborted) \
     macro(window) \
     macro(writableStreamAPIEnabled) \
     macro(writeAlgorithm) \

Copied: trunk/Source/WebCore/dom/AbortAlgorithm.h (from rev 266176, trunk/Source/WebCore/dom/AbortSignal.idl) (0 => 266177)


--- trunk/Source/WebCore/dom/AbortAlgorithm.h	                        (rev 0)
+++ trunk/Source/WebCore/dom/AbortAlgorithm.h	2020-08-26 18:07:35 UTC (rev 266177)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2020 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 "ActiveDOMCallback.h"
+#include "CallbackResult.h"
+#include <wtf/ThreadSafeRefCounted.h>
+
+namespace WebCore {
+
+class AbortAlgorithm : public ThreadSafeRefCounted<AbortAlgorithm>, public ActiveDOMCallback {
+public:
+    using ActiveDOMCallback::ActiveDOMCallback;
+
+    virtual CallbackResult<void> handleEvent() = 0;
+};
+
+} // namespace WebCore
+

Copied: trunk/Source/WebCore/dom/AbortAlgorithm.idl (from rev 266176, trunk/Source/WebCore/dom/AbortSignal.idl) (0 => 266177)


--- trunk/Source/WebCore/dom/AbortAlgorithm.idl	                        (rev 0)
+++ trunk/Source/WebCore/dom/AbortAlgorithm.idl	2020-08-26 18:07:35 UTC (rev 266177)
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+[
+] callback AbortAlgorithm = void ();

Modified: trunk/Source/WebCore/dom/AbortSignal.cpp (266176 => 266177)


--- trunk/Source/WebCore/dom/AbortSignal.cpp	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/Source/WebCore/dom/AbortSignal.cpp	2020-08-26 18:07:35 UTC (rev 266177)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "AbortSignal.h"
 
+#include "AbortAlgorithm.h"
 #include "Event.h"
 #include "EventNames.h"
 #include "ScriptExecutionContext.h"
@@ -84,4 +85,16 @@
     });
 }
 
+bool AbortSignal::whenSignalAborted(AbortSignal& signal, Ref<AbortAlgorithm>&& algorithm)
+{
+    if (signal.aborted()) {
+        algorithm->handleEvent();
+        return true;
+    }
+    signal.addAlgorithm([algorithm = WTFMove(algorithm)]() mutable {
+        algorithm->handleEvent();
+    });
+    return false;
 }
+
+}

Modified: trunk/Source/WebCore/dom/AbortSignal.h (266176 => 266177)


--- trunk/Source/WebCore/dom/AbortSignal.h	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/Source/WebCore/dom/AbortSignal.h	2020-08-26 18:07:35 UTC (rev 266177)
@@ -27,6 +27,7 @@
 
 #include "ContextDestructionObserver.h"
 #include "EventTarget.h"
+#include "JSDOMPromiseDeferred.h"
 #include <wtf/Function.h>
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
@@ -34,6 +35,7 @@
 
 namespace WebCore {
 
+class AbortAlgorithm;
 class ScriptExecutionContext;
 
 class AbortSignal final : public RefCounted<AbortSignal>, public EventTargetWithInlineData, public CanMakeWeakPtr<AbortSignal>, private ContextDestructionObserver {
@@ -41,6 +43,8 @@
 public:
     static Ref<AbortSignal> create(ScriptExecutionContext&);
 
+    static bool whenSignalAborted(AbortSignal&, Ref<AbortAlgorithm>&&);
+
     void abort();
 
     bool aborted() const { return m_aborted; }
@@ -48,7 +52,7 @@
     using RefCounted::ref;
     using RefCounted::deref;
 
-    using Algorithm = WTF::Function<void()>;
+    using Algorithm = Function<void()>;
     void addAlgorithm(Algorithm&& algorithm) { m_algorithms.append(WTFMove(algorithm)); }
 
     void follow(AbortSignal&);

Modified: trunk/Source/WebCore/dom/AbortSignal.idl (266176 => 266177)


--- trunk/Source/WebCore/dom/AbortSignal.idl	2020-08-26 17:57:06 UTC (rev 266176)
+++ trunk/Source/WebCore/dom/AbortSignal.idl	2020-08-26 18:07:35 UTC (rev 266177)
@@ -29,7 +29,8 @@
     PrivateIdentifier,
     PublicIdentifier
 ] interface AbortSignal : EventTarget {
+    [ PrivateIdentifier ] static void whenSignalAborted(AbortSignal object, AbortAlgorithm algorithm);
+
     readonly attribute boolean aborted;
-
     attribute EventHandler onabort;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to