Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: third_party/WebKit/LayoutTests/http/tests/wasm_streaming/wasm_response_apis.js

Issue 2826283003: [wasm] Tests for Response instantiate APIs (Closed)
Patch Set: fix Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/wasm_streaming/wasm_response_apis.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/http/tests/wasm_streaming/wasm_response_apis.js
diff --git a/third_party/WebKit/LayoutTests/http/tests/wasm_streaming/wasm_response_apis.js b/third_party/WebKit/LayoutTests/http/tests/wasm_streaming/wasm_response_apis.js
index e8b8f9212c2132b41514cea58cd6b8fc56170d61..26d6e3bd071433461320312ce05afa8dfb97ff50 100644
--- a/third_party/WebKit/LayoutTests/http/tests/wasm_streaming/wasm_response_apis.js
+++ b/third_party/WebKit/LayoutTests/http/tests/wasm_streaming/wasm_response_apis.js
@@ -23,13 +23,19 @@ function NegativeTestStreamedCompilePromise() {
e => assert_true(e instanceof TypeError));
}
-function BlankResponse() {
+function CompileBlankResponse() {
return WebAssembly.compile(new Response())
.then(assert_unreached,
e => assert_true(e instanceof TypeError));
}
-function FromArrayBuffer() {
+function InstantiateBlankResponse() {
+ return WebAssembly.instantiate(new Response())
+ .then(assert_unreached,
+ e => assert_true(e instanceof TypeError));
+}
+
+function CompileFromArrayBuffer() {
return fetch(incrementer_url)
.then(r => r.arrayBuffer())
.then(arr => new Response(arr))
@@ -38,7 +44,7 @@ function FromArrayBuffer() {
.then(i => assert_equals(6, i.exports.increment(5)));
}
-function FromInvalidArrayBuffer() {
+function CompileFromInvalidArrayBuffer() {
var arr = new ArrayBuffer(10);
var view = new Uint8Array(arr);
for (var i = 0; i < view.length; ++i) view[i] = i;
@@ -47,3 +53,89 @@ function FromInvalidArrayBuffer() {
.then(assert_unreached,
e => assert_true(e instanceof Error));
}
+
+function InstantiateFromInvalidArrayBuffer() {
+ var arr = new ArrayBuffer(10);
+ var view = new Uint8Array(arr);
+ for (var i = 0; i < view.length; ++i) view[i] = i;
+
+ return WebAssembly.instantiate(new Response(arr))
+ .then(assert_unreached,
+ e => assert_true(e instanceof Error));
+}
+
+function TestStreamedInstantiate() {
+ return fetch(incrementer_url)
+ .then(WebAssembly.instantiate)
+ .then(pair => assert_equals(5, pair.instance.exports.increment(4)));
+}
+
+function InstantiateFromArrayBuffer() {
+ return fetch(incrementer_url)
+ .then(response => response.arrayBuffer())
+ .then(WebAssembly.instantiate)
+ .then(pair => assert_equals(5, pair.instance.exports.increment(4)));
+}
+
+function TestShortFormStreamedInstantiate() {
+ return WebAssembly.instantiate(fetch(incrementer_url))
+ .then(pair => assert_equals(5, pair.instance.exports.increment(4)));
+}
+
+function InstantiateFromInvalidArrayBuffer() {
+ var arr = new ArrayBuffer(10);
+ var view = new Uint8Array(arr);
+ for (var i = 0; i < view.length; ++i) view[i] = i;
+
+ return WebAssembly.compile(new Response(arr))
+ .then(assert_unreached,
+ e => assert_true(e instanceof Error));
+}
+
+function buildImportingModuleBytes() {
+ var builder = new WasmModuleBuilder();
+ builder.addImportedMemory("", "memory", 1);
+ var kSig_v_i = makeSig([kWasmI32], []);
+ var signature = builder.addType(kSig_v_i);
+ builder.addImport("", "some_value", kSig_i_v);
+ builder.addImport("", "writer", signature);
+
+ builder.addFunction("main", kSig_i_i)
+ .addBody([
+ kExprGetLocal, 0,
+ kExprI32LoadMem, 0, 0,
+ kExprI32Const, 1,
+ kExprCallIndirect, signature, kTableZero,
+ kExprGetLocal,0,
+ kExprI32LoadMem,0, 0,
+ kExprCallFunction, 0,
+ kExprI32Add
+ ]).exportFunc();
+
+ // writer(mem[i]);
+ // return mem[i] + some_value();
+ builder.addFunction("_wrap_writer", signature)
+ .addBody([
+ kExprGetLocal, 0,
+ kExprCallFunction, 1]);
+ builder.appendToTable([2, 3]);
+
+ var wire_bytes = builder.toBuffer();
+ return wire_bytes;
+}
+
+function TestInstantiateComplexModule() {
+ var mem_1 = new WebAssembly.Memory({initial: 1});
+ var view_1 = new Int32Array(mem_1.buffer);
+ view_1[0] = 42;
+ var outval_1;
+
+ var ffi = {"":
+ {some_value: () => 1,
+ writer: (x) => outval_1 = x ,
+ memory: mem_1}
+ };
+ return Promise.resolve(buildImportingModuleBytes())
+ .then(b => WebAssembly.instantiate(b, ffi))
+ .then(pair => assert_true(pair.instance instanceof WebAssembly.Instance));
+}
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/wasm_streaming/wasm_response_apis.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698