Title: [272221] trunk
Revision
272221
Author
[email protected]
Date
2021-02-02 10:30:42 -0800 (Tue, 02 Feb 2021)

Log Message

WebAssembly: add support for stream APIs - _javascript_ API: Implement loading for the Blob type
https://bugs.webkit.org/show_bug.cgi?id=184886

Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

* web-platform-tests/wasm/wasm_stream_compile_test-expected.txt:
* web-platform-tests/wasm/wasm_stream_compile_test.html:
* web-platform-tests/wasm/wasm_stream_instantiate_test-expected.txt:
* web-platform-tests/wasm/wasm_stream_instantiate_test.html:

Source/WebCore:

This patch adds compileStreaming / instantiateStreaming with FetchResponse created from Blob.
We materialize ReadableStream to load Blob for now. In the future, if more efficient way is
implemented, we will switch to that.
More complex FormData is not supported, tracked in https://bugs.webkit.org/show_bug.cgi?id=221248.

* bindings/js/JSDOMGlobalObject.cpp:
(WebCore::handleResponseOnStreamingAction):

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (272220 => 272221)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-02-02 18:23:40 UTC (rev 272220)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-02-02 18:30:42 UTC (rev 272221)
@@ -1,3 +1,15 @@
+2021-02-02  Yusuke Suzuki  <[email protected]>
+
+        WebAssembly: add support for stream APIs - _javascript_ API: Implement loading for the Blob type
+        https://bugs.webkit.org/show_bug.cgi?id=184886
+
+        Reviewed by Youenn Fablet.
+
+        * web-platform-tests/wasm/wasm_stream_compile_test-expected.txt:
+        * web-platform-tests/wasm/wasm_stream_compile_test.html:
+        * web-platform-tests/wasm/wasm_stream_instantiate_test-expected.txt:
+        * web-platform-tests/wasm/wasm_stream_instantiate_test.html:
+
 2021-02-02  Rob Buis  <[email protected]>
 
         Support aspect-ratio on <body> in quirks mode

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/wasm_stream_compile_test-expected.txt (272220 => 272221)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/wasm_stream_compile_test-expected.txt	2021-02-02 18:23:40 UTC (rev 272220)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/wasm_stream_compile_test-expected.txt	2021-02-02 18:30:42 UTC (rev 272221)
@@ -9,4 +9,8 @@
 PASS compileStreaming raise error if no-cors
 PASS compileStreaming receive promise with response created from ArrayBuffer
 PASS compileStreaming receive response that deliver data by chunks as bufferArray
+PASS compileStreaming using blob
+FAIL compileStreaming using FormData promise_rejects_js: function "function () { throw e }" threw object "TypeError: FormData is not supported" ("TypeError") expected instance of function "function CompileError() {
+    [native code]
+}" ("CompileError")
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/wasm_stream_compile_test.html (272220 => 272221)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/wasm_stream_compile_test.html	2021-02-02 18:23:40 UTC (rev 272220)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/wasm_stream_compile_test.html	2021-02-02 18:30:42 UTC (rev 272221)
@@ -105,5 +105,21 @@
       .then(stream => WebAssembly.compileStreaming(new Response(stream, { headers: { "Content-Type" : "application/wasm" }})));
     assert_true(module instanceof WebAssembly.Module);
   }, "compileStreaming receive response that deliver data by chunks as bufferArray");
+
+  promise_test(async function() {
+      var response = await fetch('resources/incrementer.wasm');
+      var blob = await response.blob();
+      const module = await WebAssembly.compileStreaming(new Response(blob, { headers: { "Content-Type" : "application/wasm" }}));
+      assert_true(module instanceof WebAssembly.Module);
+  }, "compileStreaming using blob");
+
+  promise_test(async function(t) {
+      var response = await fetch('resources/incrementer.wasm');
+      var blob = await response.blob();
+      var formData = new FormData;
+      formData.append('blob', blob);
+      formData.append('blob2', "Hello");
+      await promise_rejects_js(t, WebAssembly.CompileError, WebAssembly.compileStreaming(new Response(formData, { headers: { "Content-Type" : "application/wasm" }})));
+  }, "compileStreaming using FormData");
 </script>
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/wasm_stream_instantiate_test-expected.txt (272220 => 272221)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/wasm_stream_instantiate_test-expected.txt	2021-02-02 18:23:40 UTC (rev 272220)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/wasm_stream_instantiate_test-expected.txt	2021-02-02 18:30:42 UTC (rev 272221)
@@ -9,4 +9,8 @@
 PASS instantiateStreaming raise error if no-cors
 PASS instantiateStreaming receive promise with response created from ArrayBuffer
 PASS instantiateStreaming receive response that deliver data by chunks as bufferArray
+PASS instantiateStreaming using blob
+FAIL instantiateStreaming using FormData promise_rejects_js: function "function () { throw e }" threw object "TypeError: FormData is not supported" ("TypeError") expected instance of function "function CompileError() {
+    [native code]
+}" ("CompileError")
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/wasm_stream_instantiate_test.html (272220 => 272221)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/wasm_stream_instantiate_test.html	2021-02-02 18:23:40 UTC (rev 272220)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/wasm_stream_instantiate_test.html	2021-02-02 18:30:42 UTC (rev 272221)
@@ -103,4 +103,21 @@
       .then(stream => WebAssembly.instantiateStreaming(new Response(stream, { headers: { "Content-Type" : "application/wasm" }})));
     assert_true(instance instanceof WebAssembly.Instance);
   }, "instantiateStreaming receive response that deliver data by chunks as bufferArray");
+
+  promise_test(async function() {
+      var response = await fetch('resources/incrementer.wasm');
+      var blob = await response.blob();
+      const { instance, module } = await WebAssembly.instantiateStreaming(new Response(blob, { headers: { "Content-Type" : "application/wasm" }}));
+      assert_true(instance instanceof WebAssembly.Instance);
+      assert_true(module instanceof WebAssembly.Module);
+  }, "instantiateStreaming using blob");
+
+  promise_test(async function(t) {
+      var response = await fetch('resources/incrementer.wasm');
+      var blob = await response.blob();
+      var formData = new FormData;
+      formData.append('blob', blob);
+      formData.append('blob2', "Hello");
+      await promise_rejects_js(t, WebAssembly.CompileError, WebAssembly.instantiateStreaming(new Response(formData, { headers: { "Content-Type" : "application/wasm" }})));
+  }, "instantiateStreaming using FormData");
 </script>

Modified: trunk/Source/WebCore/ChangeLog (272220 => 272221)


--- trunk/Source/WebCore/ChangeLog	2021-02-02 18:23:40 UTC (rev 272220)
+++ trunk/Source/WebCore/ChangeLog	2021-02-02 18:30:42 UTC (rev 272221)
@@ -1,3 +1,18 @@
+2021-02-02  Yusuke Suzuki  <[email protected]>
+
+        WebAssembly: add support for stream APIs - _javascript_ API: Implement loading for the Blob type
+        https://bugs.webkit.org/show_bug.cgi?id=184886
+
+        Reviewed by Youenn Fablet.
+
+        This patch adds compileStreaming / instantiateStreaming with FetchResponse created from Blob.
+        We materialize ReadableStream to load Blob for now. In the future, if more efficient way is
+        implemented, we will switch to that.
+        More complex FormData is not supported, tracked in https://bugs.webkit.org/show_bug.cgi?id=221248.
+
+        * bindings/js/JSDOMGlobalObject.cpp:
+        (WebCore::handleResponseOnStreamingAction):
+
 2021-02-02  Chris Dumez  <[email protected]>
 
         Promote debug assertion to release assertion in cookiesForURL()

Modified: trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp (272220 => 272221)


--- trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp	2021-02-02 18:23:40 UTC (rev 272220)
+++ trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp	2021-02-02 18:30:42 UTC (rev 272221)
@@ -339,6 +339,15 @@
         return jsCast<JSC::JSPromise*>(deferred->promise());
     }
 
+    // FIXME: for efficiency, we should load blobs directly instead of going through the readableStream path.
+    if (inputResponse->isBlobBody()) {
+        auto streamOrException = inputResponse->readableStream(*globalObject);
+        if (UNLIKELY(streamOrException.hasException())) {
+            deferred->reject(streamOrException.releaseException());
+            return jsCast<JSC::JSPromise*>(deferred->promise());
+        }
+    }
+
     auto compiler = JSC::Wasm::StreamingCompiler::create(vm, compilerMode, globalObject, jsCast<JSC::JSPromise*>(deferred->promise()), importObject);
 
     if (inputResponse->isBodyReceivedByChunk()) {
@@ -387,8 +396,9 @@
             compiler->finalize(globalObject);
             return;
         }
-        // FIXME: http://webkit.org/b/184886> Implement loading for the Blob type
-        compiler->fail(globalObject, createTypeError(globalObject, "Blob is not supported"_s));
+        // FIXME: Support FormData loading.
+        // https://bugs.webkit.org/show_bug.cgi?id=221248
+        compiler->fail(globalObject, createDOMException(*globalObject, Exception { NotSupportedError, "Not implemented"_s  }));
     }, [&](Ref<SharedBuffer>& buffer) {
         compiler->addBytes(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
         compiler->finalize(globalObject);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to