Title: [280627] trunk
Revision
280627
Author
shvaikal...@gmail.com
Date
2021-08-03 21:49:52 -0700 (Tue, 03 Aug 2021)

Log Message

ReadableStream's pipeTo() and pipeThrough() don't properly check for AbortSignal
https://bugs.webkit.org/show_bug.cgi?id=227693

Reviewed by Sam Weinig.

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/pipe-through.any-expected.txt:
* web-platform-tests/streams/piping/pipe-through.any.worker-expected.txt:

Source/WebCore:

This patch introduces @isAbortSignal global private function to replace `instanceof`
checks that a) were false positive for `Object.create(AbortSignal.prototype)` and
b) observably performed [[GetPrototypeOf]] and Symbol.hasInstance lookup / call.

Aligns WebKit with Blink and the spec (https://heycam.github.io/webidl/#implements).

Test: imported/w3c/web-platform-tests/streams/piping/abort.any.js

* Modules/streams/ReadableStream.js:
(pipeThrough):
(pipeTo):
* Modules/streams/ReadableStreamInternals.js:
(readableStreamPipeToWritableStream):
* bindings/js/JSDOMGlobalObject.cpp:
(WebCore::JSC_DEFINE_HOST_FUNCTION):
(WebCore::JSDOMGlobalObject::addBuiltinGlobals):
* bindings/js/WebCoreBuiltinNames.h:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (280626 => 280627)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-08-04 01:37:22 UTC (rev 280626)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-08-04 04:49:52 UTC (rev 280627)
@@ -1,3 +1,15 @@
+2021-08-03  Alexey Shvayka  <shvaikal...@gmail.com>
+
+        ReadableStream's pipeTo() and pipeThrough() don't properly check for AbortSignal
+        https://bugs.webkit.org/show_bug.cgi?id=227693
+
+        Reviewed by Sam Weinig.
+
+        * web-platform-tests/streams/piping/abort.any-expected.txt:
+        * web-platform-tests/streams/piping/abort.any.worker-expected.txt:
+        * web-platform-tests/streams/piping/pipe-through.any-expected.txt:
+        * web-platform-tests/streams/piping/pipe-through.any.worker-expected.txt:
+
 2021-08-03  Ryan Haddad  <ryanhad...@apple.com>
 
         Unreviewed, reverting r280531 and r280589.

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


--- trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/abort.any-expected.txt	2021-08-04 01:37:22 UTC (rev 280626)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/abort.any-expected.txt	2021-08-04 04:49:52 UTC (rev 280627)
@@ -5,7 +5,7 @@
 PASS a signal argument 'AbortSignal' should cause pipeTo() to reject
 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
+PASS a signal argument '[object AbortSignal]' should cause pipeTo() to reject
 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

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


--- trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/abort.any.worker-expected.txt	2021-08-04 01:37:22 UTC (rev 280626)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/abort.any.worker-expected.txt	2021-08-04 04:49:52 UTC (rev 280627)
@@ -5,7 +5,7 @@
 PASS a signal argument 'AbortSignal' should cause pipeTo() to reject
 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
+PASS a signal argument '[object AbortSignal]' should cause pipeTo() to reject
 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

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/pipe-through.any-expected.txt (280626 => 280627)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/pipe-through.any-expected.txt	2021-08-04 01:37:22 UTC (rev 280626)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/pipe-through.any-expected.txt	2021-08-04 04:49:52 UTC (rev 280627)
@@ -32,7 +32,7 @@
 PASS invalid values of signal should throw; specifically 'NaN'
 PASS invalid values of signal should throw; specifically 'true'
 PASS invalid values of signal should throw; specifically 'AbortSignal'
-FAIL invalid values of signal should throw; specifically '[object AbortSignal]' assert_throws_js: pipeThrough should throw function "() => rs.pipeThrough(uninterestingReadableWritablePair(), { signal })" did not throw
+PASS invalid values of signal should throw; specifically '[object AbortSignal]'
 PASS pipeThrough should accept a real AbortSignal
 PASS pipeThrough should throw if this is locked
 PASS pipeThrough should throw if writable is locked

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/pipe-through.any.worker-expected.txt (280626 => 280627)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/pipe-through.any.worker-expected.txt	2021-08-04 01:37:22 UTC (rev 280626)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/streams/piping/pipe-through.any.worker-expected.txt	2021-08-04 04:49:52 UTC (rev 280627)
@@ -32,7 +32,7 @@
 PASS invalid values of signal should throw; specifically 'NaN'
 PASS invalid values of signal should throw; specifically 'true'
 PASS invalid values of signal should throw; specifically 'AbortSignal'
-FAIL invalid values of signal should throw; specifically '[object AbortSignal]' assert_throws_js: pipeThrough should throw function "() => rs.pipeThrough(uninterestingReadableWritablePair(), { signal })" did not throw
+PASS invalid values of signal should throw; specifically '[object AbortSignal]'
 PASS pipeThrough should accept a real AbortSignal
 PASS pipeThrough should throw if this is locked
 PASS pipeThrough should throw if writable is locked

Modified: trunk/Source/WebCore/ChangeLog (280626 => 280627)


--- trunk/Source/WebCore/ChangeLog	2021-08-04 01:37:22 UTC (rev 280626)
+++ trunk/Source/WebCore/ChangeLog	2021-08-04 04:49:52 UTC (rev 280627)
@@ -1,3 +1,28 @@
+2021-08-03  Alexey Shvayka  <shvaikal...@gmail.com>
+
+        ReadableStream's pipeTo() and pipeThrough() don't properly check for AbortSignal
+        https://bugs.webkit.org/show_bug.cgi?id=227693
+
+        Reviewed by Sam Weinig.
+
+        This patch introduces @isAbortSignal global private function to replace `instanceof`
+        checks that a) were false positive for `Object.create(AbortSignal.prototype)` and
+        b) observably performed [[GetPrototypeOf]] and Symbol.hasInstance lookup / call.
+
+        Aligns WebKit with Blink and the spec (https://heycam.github.io/webidl/#implements).
+
+        Test: imported/w3c/web-platform-tests/streams/piping/abort.any.js
+
+        * Modules/streams/ReadableStream.js:
+        (pipeThrough):
+        (pipeTo):
+        * Modules/streams/ReadableStreamInternals.js:
+        (readableStreamPipeToWritableStream):
+        * bindings/js/JSDOMGlobalObject.cpp:
+        (WebCore::JSC_DEFINE_HOST_FUNCTION):
+        (WebCore::JSDOMGlobalObject::addBuiltinGlobals):
+        * bindings/js/WebCoreBuiltinNames.h:
+
 2021-08-03  Ryan Haddad  <ryanhad...@apple.com>
 
         Unreviewed, reverting r280531 and r280589.

Modified: trunk/Source/WebCore/Modules/streams/ReadableStream.js (280626 => 280627)


--- trunk/Source/WebCore/Modules/streams/ReadableStream.js	2021-08-04 01:37:22 UTC (rev 280626)
+++ trunk/Source/WebCore/Modules/streams/ReadableStream.js	2021-08-04 04:49:52 UTC (rev 280627)
@@ -139,7 +139,7 @@
             preventClose = !!options["preventClose"];
 
             signal = options["signal"];
-            if (signal !== @undefined && !(signal instanceof @AbortSignal))
+            if (signal !== @undefined && !@isAbortSignal(signal))
                 throw @makeTypeError("options.signal must be AbortSignal");
         }
 
@@ -192,7 +192,7 @@
                 return @Promise.@reject(e);
             }
 
-            if (signal !== @undefined && !(signal instanceof @AbortSignal))
+            if (signal !== @undefined && !@isAbortSignal(signal))
                 return @Promise.@reject(@makeTypeError("options.signal must be AbortSignal"));
         }
 

Modified: trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js (280626 => 280627)


--- trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js	2021-08-04 01:37:22 UTC (rev 280626)
+++ trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js	2021-08-04 04:49:52 UTC (rev 280627)
@@ -144,7 +144,7 @@
     @assert(@isWritableStream(destination));
     @assert(!@isReadableStreamLocked(source));
     @assert(!@isWritableStreamLocked(destination));
-    @assert(signal === @undefined || signal instanceof @AbortSignal);
+    @assert(signal === @undefined || @isAbortSignal(signal));
 
     if (@getByIdDirectPrivate(source, "underlyingByteSource") !== @undefined)
         return @Promise.@reject("Piping of readable by strean is not supported");

Modified: trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp (280626 => 280627)


--- trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp	2021-08-04 01:37:22 UTC (rev 280626)
+++ trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp	2021-08-04 04:49:52 UTC (rev 280627)
@@ -73,6 +73,7 @@
 JSC_DECLARE_HOST_FUNCTION(isReadableByteStreamAPIEnabled);
 JSC_DECLARE_HOST_FUNCTION(isWritableStreamAPIEnabled);
 JSC_DECLARE_HOST_FUNCTION(whenSignalAborted);
+JSC_DECLARE_HOST_FUNCTION(isAbortSignal);
 
 const ClassInfo JSDOMGlobalObject::s_info = { "DOMGlobalObject", &JSGlobalObject::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMGlobalObject) };
 
@@ -179,6 +180,12 @@
     return JSValue::encode(result ? JSValue(JSC::JSValue::JSTrue) : JSValue(JSC::JSValue::JSFalse));
 }
 
+JSC_DEFINE_HOST_FUNCTION(isAbortSignal, (JSGlobalObject* globalObject, CallFrame* callFrame))
+{
+    ASSERT(callFrame->argumentCount() == 1);
+    return JSValue::encode(jsBoolean(callFrame->uncheckedArgument(0).inherits<JSAbortSignal>(globalObject->vm())));
+}
+
 SUPPRESS_ASAN void JSDOMGlobalObject::addBuiltinGlobals(VM& vm)
 {
     m_builtinInternalFunctions.initialize(*this);
@@ -206,6 +213,7 @@
         JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().streamWritablePrivateName(), jsNumber(6), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().readableByteStreamAPIEnabledPrivateName(), JSFunction::create(vm, this, 0, String(), isReadableByteStreamAPIEnabled), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().writableStreamAPIEnabledPrivateName(), JSFunction::create(vm, this, 0, String(), isWritableStreamAPIEnabled), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
+        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().isAbortSignalPrivateName(), JSFunction::create(vm, this, 1, String(), isAbortSignal), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
     };
     addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
 }

Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (280626 => 280627)


--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2021-08-04 01:37:22 UTC (rev 280626)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2021-08-04 04:49:52 UTC (rev 280627)
@@ -347,6 +347,7 @@
     macro(inFlightWriteRequest) \
     macro(indexedDB) \
     macro(initializeWith) \
+    macro(isAbortSignal) \
     macro(isDisturbed) \
     macro(isLoading) \
     macro(isSecureContext) \
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to