Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1 @@
spec: https://webassembly.github.io/spec/web-api/

View File

@ -0,0 +1,37 @@
const methods = [
"compileStreaming",
"instantiateStreaming",
];
for (const method of methods) {
promise_test(async t => {
const controller = new AbortController();
const signal = controller.signal;
controller.abort();
const request = fetch('../incrementer.wasm', { signal });
return promise_rejects_dom(t, 'AbortError', WebAssembly[method](request),
`${method} should reject`);
}, `${method}() on an already-aborted request should reject with AbortError`);
promise_test(async t => {
const controller = new AbortController();
const signal = controller.signal;
const request = fetch('../incrementer.wasm', { signal });
const promise = WebAssembly[method](request);
controller.abort();
return promise_rejects_dom(t, 'AbortError', promise, `${method} should reject`);
}, `${method}() synchronously followed by abort should reject with AbortError`);
promise_test(async t => {
const controller = new AbortController();
const signal = controller.signal;
return fetch('../incrementer.wasm', { signal })
.then(response => {
Promise.resolve().then(() => controller.abort());
return WebAssembly[method](response);
})
.catch(err => {
assert_equals(err.name, "AbortError");
});
}, `${method}() asynchronously racing with abort should succeed or reject with AbortError`);
}

View File

@ -0,0 +1,19 @@
// META: global=window,worker
// META: script=/wasm/jsapi/wasm-module-builder.js
for (const method of ["compileStreaming", "instantiateStreaming"]) {
promise_test(t => {
const buffer = new WasmModuleBuilder().toBuffer();
const argument = new Response(buffer, { headers: { "Content-Type": "application/wasm" } });
argument.arrayBuffer();
return promise_rejects_js(t, TypeError, WebAssembly[method](argument));
}, `${method} after consumption`);
promise_test(t => {
const buffer = new WasmModuleBuilder().toBuffer();
const argument = new Response(buffer, { headers: { "Content-Type": "application/wasm" } });
const promise = WebAssembly[method](argument);
argument.arrayBuffer();
return promise_rejects_js(t, TypeError, promise);
}, `${method} before consumption`);
}

View File

@ -0,0 +1,64 @@
// META: global=window,worker
// META: script=/wasm/jsapi/assertions.js
promise_test(t => {
const response = fetch("/wasm/incrementer.wasm").then(res => new Response(res.body));
return promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(response));
}, "Response with no Content-Type: compileStreaming");
promise_test(t => {
const response = fetch("/wasm/incrementer.wasm").then(res => new Response(res.body));
return promise_rejects_js(t, TypeError, WebAssembly.instantiateStreaming(response));
}, "Response with no Content-Type: instantiateStreaming");
const invalidContentTypes = [
"",
"application/javascript",
"application/octet-stream",
"text/wasm",
"application/wasm;",
"application/wasm;x",
"application/wasm;charset=UTF-8",
];
for (const contenttype of invalidContentTypes) {
promise_test(t => {
const response = fetch(`/wasm/incrementer.wasm?pipe=header(Content-Type,${encodeURIComponent(contenttype)})`);
return promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(response));
}, `Response with Content-Type ${format_value(contenttype)}: compileStreaming`);
promise_test(t => {
const response = fetch(`/wasm/incrementer.wasm?pipe=header(Content-Type,${encodeURIComponent(contenttype)})`);
return promise_rejects_js(t, TypeError, WebAssembly.instantiateStreaming(response));
}, `Response with Content-Type ${format_value(contenttype)}: instantiateStreaming`);
}
const validContentTypes = [
"application/wasm",
"APPLICATION/wasm",
"APPLICATION/WASM",
];
for (const contenttype of validContentTypes) {
promise_test(async t => {
const response = fetch(`/wasm/incrementer.wasm?pipe=header(Content-Type,${encodeURIComponent(contenttype)})`);
const module = await WebAssembly.compileStreaming(response);
assert_equals(Object.getPrototypeOf(module), WebAssembly.Module.prototype,
"prototype");
}, `Response with Content-Type ${format_value(contenttype)}: compileStreaming`);
promise_test(async t => {
const response = fetch(`/wasm/incrementer.wasm?pipe=header(Content-Type,${encodeURIComponent(contenttype)})`);
const result = await WebAssembly.instantiateStreaming(response);
assert_WebAssemblyInstantiatedSource(
result,
{
"increment": {
"kind": "function",
"name": "0",
"length": 1
}
}
);
}, `Response with Content-Type ${format_value(contenttype)}: instantiateStreaming`);
}

View File

@ -0,0 +1,20 @@
// META: global=window,worker
const invalidArguments = [
[() => new Response(undefined, { headers: { "Content-Type": "application/wasm" } }), "no body"],
[() => new Response("", { headers: { "Content-Type": "application/wasm" } }), "empty body"],
];
for (const method of ["compileStreaming", "instantiateStreaming"]) {
for (const [argumentFactory, name] of invalidArguments) {
promise_test(t => {
const argument = argumentFactory();
return promise_rejects_js(t, WebAssembly.CompileError, WebAssembly[method](argument));
}, `${method}: ${name}`);
promise_test(t => {
const argument = Promise.resolve(argumentFactory());
return promise_rejects_js(t, WebAssembly.CompileError, WebAssembly[method](argument));
}, `${method}: ${name} in a promise`);
}
}

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<title>Check execution of WebAssembly start function</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({allow_uncaught_exception: true});
const test_load = async_test(
"Importing a WebAssembly module should execute the start function.");
window.log = [];
window.addEventListener("error", ev => {
log.push(ev.message);
});
window.addEventListener("load", test_load.step_func_done(ev => {
assert_array_equals(log, ["executed"]);
}));
function unreachable() { log.push("unexpected"); }
</script>
<script type="module" src="./resources/execute-start.wasm" onerror="unreachable()""></script>

View File

@ -0,0 +1,17 @@
<!doctype html>
<title>Exported names from a WebAssembly module</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type=module>
setup({ single_test: true });
import * as mod from "./resources/exported-names.wasm";
assert_array_equals(Object.getOwnPropertyNames(mod).sort(),
["func", "glob", "mem", "tab"]);
assert_true(mod.func instanceof Function);
assert_true(mod.mem instanceof WebAssembly.Memory);
assert_true(mod.glob instanceof WebAssembly.Global);
assert_true(mod.tab instanceof WebAssembly.Table);
assert_throws_js(TypeError, () => { mod.func = 2; });
done();
</script>

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<title>Handling of importing invalid WebAssembly modules</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({allow_uncaught_exception: true});
window.log = [];
window.addEventListener("error", ev => log.push(ev.error));
const test_load = async_test(
"Test that imports of invalid WebAssembly modules leads to WebAssembly.CompileError on window.");
window.addEventListener("load", test_load.step_func_done(ev => {
assert_equals(log.length, 2);
assert_equals(log[0].constructor, WebAssembly.CompileError);
assert_equals(log[1].constructor, WebAssembly.CompileError);
}));
function unreachable() { log.push("unexpected"); }
</script>
<script type="module" src="./resources/invalid-bytecode.wasm" onerror="unreachable()"></script>
<script type="module" src="./resources/invalid-module.wasm" onerror="unreachable()"></script>

View File

@ -0,0 +1,38 @@
<!doctype html>
<title>Cyclic linking between JavaScript and WebAssembly (JS higher)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({allow_uncaught_exception: true});
const test_load = async_test(
"Check cyclic linking between JavaScript and WebAssembly where JavaScript is higher in the module graph.");
window.log = [];
window.addEventListener("error", ev => {
test_load.step(() => assert_equals(ev.error.constructor, WebAssembly.LinkError));
log.push(ev.message);
});
window.addEventListener("load", test_load.step_func_done(ev => {
assert_equals(log.length, 10);
assert_equals(log[1], 1);
assert_equals(log[3], 2);
assert_equals(log[5], 3);
assert_equals(log[7], 4);
assert_equals(log[9], 5);
}));
function unreachable() { log.push("unexpected"); }
</script>
<script type="module" src="./resources/js-wasm-cycle-value.js"
onerror="unreachable()" onload="log.push(1)"></script>
<script type="module" src="./resources/js-wasm-cycle-global.js"
onerror="unreachable()" onload="log.push(2)"></script>
<script type="module" src="./resources/js-wasm-cycle-memory.js"
onerror="unreachable()" onload="log.push(3)"></script>
<script type="module" src="./resources/js-wasm-cycle-table.js"
onerror="unreachable()" onload="log.push(4)"></script>
<script type="module" src="./resources/js-wasm-cycle-function-error.js"
onerror="unreachable()" onload="log.push(5)"></script>

View File

@ -0,0 +1,11 @@
<!doctype html>
<title>Check bindings in JavaScript and WebAssembly cycle (JS higher)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type=module>
setup({ single_test: true });
import { f } from "./resources/js-wasm-cycle.js";
assert_equals(f(), 24);
done();
</script>

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<title>Handling of importing invalid WebAssembly modules</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({allow_uncaught_exception: true});
window.log = [];
window.addEventListener("error", ev => log.push(ev.error));
const test_load = async_test(
"Test that imports of invalid WebAssembly modules leads to WebAssembly.CompileError on window.");
window.addEventListener("load", test_load.step_func_done(ev => {
assert_equals(log.length, 2);
assert_equals(log[0].constructor, WebAssembly.CompileError);
assert_equals(log[1].constructor, WebAssembly.CompileError);
}));
function unreachable() { log.push("unexpected"); }
</script>
<script type="module" src="./resources/invalid-bytecode.wasm" onerror="unreachable()"></script>
<script type="module" src="./resources/invalid-module.wasm" onerror="unreachable()"></script>

View File

@ -0,0 +1 @@
export { f } from "./resources/resolve-export.wasm";

View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>Check ResolveExport on invalid re-export from WebAssembly</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({allow_uncaught_exception: true});
const test_load = async_test(
"Re-export of missing Wasm export should result in SyntaxError.");
window.log = [];
window.addEventListener("error", ev => {
test_load.step(() => assert_equals(ev.error.constructor, SyntaxError));
log.push(ev.message);
});
window.addEventListener("load", test_load.step_func_done(ev => {
assert_equals(log[1], 1);
}));
function unreachable() { log.push("unexpected"); }
</script>
<script type="module" src="./resolve-export.js"
onerror="unreachable()" onload="log.push(1)"></script>

View File

@ -0,0 +1,2 @@
export const func = 42;
import { f } from "./js-wasm-cycle-function-error.wasm";

View File

@ -0,0 +1,2 @@
export const glob = new WebAssembly.Global({ value: "i32" }, 42);
import { f } from "./js-wasm-cycle-global.wasm";

View File

@ -0,0 +1,2 @@
export const mem = new WebAssembly.Memory({ initial: 10 });
import { f } from "./js-wasm-cycle-memory.wasm";

View File

@ -0,0 +1,2 @@
export const tab = new WebAssembly.Table({ element: "anyfunc" });
import { f } from "./js-wasm-cycle-table.wasm";

View File

@ -0,0 +1,2 @@
export const val = 42;
import { f } from "./js-wasm-cycle-value.wasm";

View File

@ -0,0 +1,13 @@
function f() { return 42; }
export { f };
import { mem, tab, glob, func } from "./js-wasm-cycle.wasm";
assert_true(glob instanceof WebAssembly.Global);
assert_equals(glob.valueOf(), 1);
assert_true(mem instanceof WebAssembly.Memory);
assert_true(tab instanceof WebAssembly.Table);
assert_true(func instanceof Function);
f = () => { return 24 };
assert_equals(func(), 42);

View File

@ -0,0 +1 @@
export function logExec() { log.push("executed"); }

View File

@ -0,0 +1 @@
export let f = 5;

View File

@ -0,0 +1 @@
export let g = 5;

View File

@ -0,0 +1 @@
export let m = 5;

View File

@ -0,0 +1 @@
export let t = 5;

View File

@ -0,0 +1,15 @@
import * as mod from "./wasm-js-cycle.wasm";
let jsGlob = new WebAssembly.Global({ value: "i32", mutable: true }, 42);
let jsMem = new WebAssembly.Memory({ initial: 10 });
let jsTab = new WebAssembly.Table({ initial: 10, element: "anyfunc" });
let jsFunc = () => { return 42; };
export { jsGlob, jsMem, jsTab, jsFunc };
export function mutateBindings() {
jsGlob = 0;
jsMem = 0;
jsTab = 0;
jsFunc = 0;
}

View File

@ -0,0 +1 @@
export function pm(x) { postMessage(x); }

View File

@ -0,0 +1 @@
import * as mod from "./worker.wasm"

Binary file not shown.

View File

@ -0,0 +1,14 @@
<!doctype html>
<title>Check import and export between WebAssembly modules</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type=module>
setup({ single_test: true });
window.log = [];
import { logExec } from "./resources/wasm-import-from-wasm.wasm";
logExec();
assert_equals(log.length, 1);
assert_equals(log[0], "executed");
done();
</script>

View File

@ -0,0 +1,34 @@
<!doctype html>
<title>Errors for imports of WebAssembly modules</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({allow_uncaught_exception: true});
const test_load = async_test(
"Invalid imports for WebAssembly modules should error.");
window.log = [];
window.addEventListener("error", ev => {
test_load.step(() => assert_equals(ev.error.constructor, WebAssembly.LinkError));
log.push(ev.message);
});
window.addEventListener("load", test_load.step_func_done(ev => {
assert_equals(log[1], 1);
assert_equals(log[3], 2);
assert_equals(log[5], 3);
assert_equals(log[7], 4);
}));
function unreachable() { log.push("unexpected"); }
</script>
<script type="module" src="./resources/wasm-import-func.wasm"
onerror="unreachable()" onload="log.push(1)"></script>
<script type="module" src="./resources/wasm-import-memory.wasm"
onerror="unreachable()" onload="log.push(2)"></script>
<script type="module" src="./resources/wasm-import-table.wasm"
onerror="unreachable()" onload="log.push(3)"></script>
<script type="module" src="./resources/wasm-import-global.wasm"
onerror="unreachable()" onload="log.push(4)"></script>

View File

@ -0,0 +1,32 @@
<!doctype html>
<title>Check bindings in JavaScript and WebAssembly cycle (Wasm higher)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type=module>
setup({ single_test: true });
import * as wasm from "./resources/wasm-js-cycle.wasm";
import * as js from "./resources/wasm-js-cycle.js";
js.mutateBindings();
assert_true(wasm.wasmGlob instanceof WebAssembly.Global);
assert_equals(wasm.wasmGlob.valueOf(), 24);
assert_true(wasm.wasmFunc instanceof Function);
assert_equals(wasm.wasmFunc(), 43);
assert_equals(wasm.incrementGlob(), 43);
const buf = new Int32Array(wasm.wasmMem.buffer);
assert_equals(buf[0], 0);
assert_equals(wasm.mutateMem(), 42);
assert_equals(buf[0], 42);
assert_equals(wasm.wasmTab.get(0), null);
const ref = wasm.mutateTab();
assert_true(ref instanceof Function);
assert_equals(wasm.wasmTab.get(0), ref);
done();
</script>

View File

@ -0,0 +1,26 @@
<!doctype html>
<title>Errors for linking WebAssembly module scripts</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({allow_uncaught_exception: true});
const test_load = async_test(
"Link errors for imports between WebAssembly modules should be reported.");
window.log = [];
window.addEventListener("error", ev => {
test_load.step(() => assert_equals(ev.error.constructor, WebAssembly.LinkError));
log.push(ev.message);
});
window.addEventListener("load", test_load.step_func_done(ev => {
assert_equals(log.length, 2);
assert_equals(log[1], 1);
}));
function unreachable() { log.push("unexpected"); }
</script>
<script type="module" src="./resources/wasm-import-error-from-wasm.wasm"
onerror="unreachable()" onload="log.push(1)"></script>

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<title>Testing import of WebAssembly from JavaScript worker</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type=module>
setup({ single_test: true });
const worker = new Worker("resources/worker.js", { type: "module" });
worker.onmessage = (msg) => {
assert_equals(msg.data, 42);
done();
}
</script>

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<title>Testing WebAssembly worker</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type=module>
setup({ single_test: true });
const worker = new Worker("resources/worker.wasm", { type: "module" });
worker.onmessage = (msg) => {
assert_equals(msg, 42);
done();
}
</script>

View File

@ -0,0 +1,29 @@
// META: global=window,worker
promise_test(async t => {
const db_name = "WebAssembly";
const obj_store = "store";
const module_key = "module";
await new Promise((resolve, reject) => {
const delete_request = indexedDB.deleteDatabase(db_name);
delete_request.onsuccess = resolve;
delete_request.onerror = reject;
});
const db = await new Promise((resolve, reject) => {
const open_request = indexedDB.open(db_name);
open_request.onupgradeneeded = function() {
open_request.result.createObjectStore(obj_store);
};
open_request.onsuccess = function() {
resolve(open_request.result);
};
open_request.onerror = reject;
});
const mod = await WebAssembly.compileStreaming(fetch('../incrementer.wasm'));
const tx = db.transaction(obj_store, 'readwrite');
const store = tx.objectStore(obj_store);
assert_throws_dom("DataCloneError", () => store.put(mod, module_key));
});

View File

@ -0,0 +1,10 @@
// META: script=/resources/WebIDLParser.js
// META: script=/resources/idlharness.js
"use strict";
idl_test(
["wasm-web-api"],
["wasm-js-api"],
idl_array => {}
);

View File

@ -0,0 +1,13 @@
// META: global=window,worker
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/bad-imports.js
test_bad_imports((name, error, build, ...args) => {
promise_test(t => {
const builder = new WasmModuleBuilder();
build(builder);
const buffer = builder.toBuffer();
const response = new Response(buffer, { "headers": { "Content-Type": "application/wasm" } });
return promise_rejects_js(t, error, WebAssembly.instantiateStreaming(response, ...args));
}, name);
});

View File

@ -0,0 +1,49 @@
// META: global=window,worker
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/assertions.js
// META: script=/wasm/jsapi/instanceTestFactory.js
let emptyModuleBinary;
setup(() => {
emptyModuleBinary = new WasmModuleBuilder().toBuffer();
});
for (const [name, fn] of instanceTestFactory) {
promise_test(async () => {
const { buffer, args, exports, verify } = fn();
const response = new Response(buffer, { "headers": { "Content-Type": "application/wasm" } });
const result = await WebAssembly.instantiateStreaming(response, ...args);
assert_WebAssemblyInstantiatedSource(result, exports);
verify(result.instance);
}, name);
}
promise_test(async () => {
const builder = new WasmModuleBuilder();
builder.addImportedGlobal("module", "global", kWasmI32);
const buffer = builder.toBuffer();
const response = new Response(buffer, { "headers": { "Content-Type": "application/wasm" } });
const order = [];
const imports = {
get module() {
order.push("module getter");
return {
get global() {
order.push("global getter");
return 0;
},
}
},
};
const expected = [
"module getter",
"global getter",
];
const p = WebAssembly.instantiateStreaming(response, imports);
assert_array_equals(order, []);
const result = await p;
assert_WebAssemblyInstantiatedSource(result, {});
assert_array_equals(order, expected);
}, "Synchronous options handling");

View File

@ -0,0 +1,28 @@
// META: global=window,worker
const invalidArguments = [
[undefined],
[null],
[true],
["test"],
[Symbol()],
[0],
[0.1],
[NaN],
[{}, "Empty object"],
[Response, "Response interface object"],
[Response.prototype, "Response interface prototype object"],
];
for (const method of ["compileStreaming", "instantiateStreaming"]) {
for (const [argument, name = format_value(argument)] of invalidArguments) {
promise_test(t => {
return promise_rejects_js(t, TypeError, WebAssembly[method](argument));
}, `${method}: ${name}`);
promise_test(t => {
const promise = Promise.resolve(argument);
return promise_rejects_js(t, TypeError, WebAssembly[method](argument));
}, `${method}: ${name} in a promise`);
}
}

View File

@ -0,0 +1,21 @@
// META: global=window,worker
// META: script=/wasm/jsapi/wasm-module-builder.js
let emptyModuleBinary;
setup(() => {
emptyModuleBinary = new WasmModuleBuilder().toBuffer();
});
for (const method of ["compileStreaming", "instantiateStreaming"]) {
promise_test(t => {
const buffer = new Uint8Array(Array.from(emptyModuleBinary).concat([0, 0]));
const response = new Response(buffer, { headers: { "Content-Type": "application/wasm" } });
return promise_rejects_js(t, WebAssembly.CompileError, WebAssembly[method](response));
}, `Invalid code (0x0000): ${method}`);
promise_test(t => {
const buffer = new Uint8Array(Array.from(emptyModuleBinary).concat([0xCA, 0xFE]));
const response = new Response(buffer, { headers: { "Content-Type": "application/wasm" } });
return promise_rejects_js(t, WebAssembly.CompileError, WebAssembly[method](response));
}, `Invalid code (0xCAFE): ${method}`);
}

View File

@ -0,0 +1,24 @@
// META: global=window,worker
// META: script=/wasm/jsapi/wasm-module-builder.js
["compileStreaming", "instantiateStreaming"].forEach(method => {
promise_test(async t => {
const buffer = new WasmModuleBuilder().toBuffer();
const argument = new Response(buffer, { headers: { "Content-Type": "test/test" } });
argument.headers.set("Content-Type", "application/wasm");
// This should resolve successfully
await WebAssembly[method](argument);
// Ensure body can only be read once
return promise_rejects_js(t, TypeError, argument.blob());
}, `${method} with Content-Type set late`);
promise_test(async t => {
const buffer = new WasmModuleBuilder().toBuffer();
const argument = new Response(buffer, { headers: { "Content-Type": "application/wasm" } });
argument.headers.delete("Content-Type");
// Ensure Wasm cannot be created
await promise_rejects_js(t, TypeError, WebAssembly[method](argument));
// This should resolve successfully
await argument.arrayBuffer();
}, `${method} with Content-Type removed late`);
});

View File

@ -0,0 +1,15 @@
// META: global=window,worker
for (const method of ["compileStreaming", "instantiateStreaming"]) {
promise_test(t => {
const url = "http://{{domains[www]}}:{{ports[http][0]}}/wasm/incrementer.wasm";
const response = fetch(url, { "mode": "no-cors" });
return promise_rejects_js(t, TypeError, WebAssembly[method](response));
}, `Opaque response: ${method}`);
promise_test(t => {
const url = "/fetch/api/resources/redirect.py?redirect_status=301&location=/wasm/incrementer.wasm";
const response = fetch(url, { "mode": "no-cors", "redirect": "manual" });
return promise_rejects_js(t, TypeError, WebAssembly[method](response));
}, `Opaque redirect response: ${method}`);
}

View File

@ -0,0 +1,9 @@
// META: global=window,worker
for (const method of ["compileStreaming", "instantiateStreaming"]) {
promise_test(t => {
const error = { "name": "custom error" };
const promise = Promise.reject(error);
return promise_rejects_exactly(t, error, WebAssembly[method](promise));
}, `${method}`);
}

Binary file not shown.

View File

@ -0,0 +1,2 @@
Content-Type: application/wasm
Cache-Control: max-age=3600

View File

@ -0,0 +1,2 @@
Content-Type: text/css
Cache-Control: max-age=3600

View File

@ -0,0 +1,21 @@
// META: global=window,worker
const statuses = [
0,
300,
400,
404,
500,
600,
700,
999,
];
for (const method of ["compileStreaming", "instantiateStreaming"]) {
for (const status of statuses) {
promise_test(t => {
const response = fetch(`status.py?status=${status}`);
return promise_rejects_js(t, TypeError, WebAssembly[method](response));
}, `Response with status ${status}: ${method}`);
}
}

View File

@ -0,0 +1,115 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>WebAssembly.compileStreaming</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script>
promise_test(async function() {
const response = await fetch('resources/incrementer.wasm');
const module = await WebAssembly.compileStreaming(response);
assert_true(module instanceof WebAssembly.Module);
}, "compileStreaming using resolved response");
promise_test(async function() {
const response = await fetch('resources/incrementer.wasm');
const module = await WebAssembly.compileStreaming(response);
const instance = new WebAssembly.Instance(module);
assert_true(instance instanceof WebAssembly.Instance);
}, "compileStreaming using resolved response and check instantiate");
promise_test(async function() {
const result = fetch('resources/incrementer.wasm');
const module = await WebAssembly.compileStreaming(result);
const instance = new WebAssembly.Instance(module);
assert_true(instance instanceof WebAssembly.Instance);
}, "compileStreaming using promise response from fetch and check instantiate");
promise_test(async function(t) {
const result = fetch('resources/incrementer.wrong_mime_type.wasm');
await promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(result));
}, "compileStreaming raise error if wrong mime type");
promise_test(async function(t) {
const result = fetch('resources/incrementer.no_mime_type.wasm?pipe=header(Content-Type,)');
await promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(result));
}, "compileStreaming raise error if no mime type");
promise_test(async function(t) {
const result = fetch('webapi/status.py?status=404');
await promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(result));
}, "compileStreaming raise error if 404 status");
const getWasmUrl = fileName => {
const host_info = get_host_info();
const url = host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT + '/wasm/webapi/';
return url + fileName + "?pipe=header(Access-Control-Allow-Origin,*)";
};
promise_test(async function() {
const result = fetch(getWasmUrl('resources/incrementer.wasm'), {"mode": "cors"} );
const module = await WebAssembly.compileStreaming(result);
assert_true(module instanceof WebAssembly.Module);
}, "compileStreaming check CORS");
promise_test(async function(t) {
const result = fetch(getWasmUrl('resources/incrementer.wasm'), {"mode": "no-cors"} );
await promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(result));
}, "compileStreaming raise error if no-cors");
promise_test(async function() {
const v = await fetch('resources/incrementer.wasm');
const buffer = await v.arrayBuffer();
const response = new Response(buffer, { headers: { "Content-Type" : "application/wasm" }});
const module = await WebAssembly.compileStreaming(response);
assert_true(module instanceof WebAssembly.Module);
}, "compileStreaming receive promise with response created from ArrayBuffer");
promise_test(async function() {
const v = await fetch('resources/incrementer.wasm');
const buffer = await v.arrayBuffer();
const stream = new ReadableStream({
start(controller) {
(async () => {
await Promise.resolve().then(() => controller.enqueue(new Uint8Array(buffer.slice(0, 20))));
await Promise.resolve().then(() => controller.enqueue(new Uint8Array(buffer.slice(20, buffer.byteLength))));
await Promise.resolve().then(() => controller.close());
})();
}
});
const response = new Response(stream, { headers: { "Content-Type" : "application/wasm" }});
const module = await WebAssembly.compileStreaming(response);
assert_true(module instanceof WebAssembly.Module);
}, "compileStreaming using ReadableStream with Uint8Array chunks");
promise_test(async function(t) {
const v = await fetch('resources/incrementer.wasm');
const buffer = await v.arrayBuffer();
const stream = new ReadableStream({
start(controller) {
// Enqueuing an ArrayBuffer rather a Uint8Array per
// https://streams.spec.whatwg.org/#read-loop
controller.enqueue(buffer);
controller.close();
}
});
const response = new Response(stream, { headers: { "Content-Type" : "application/wasm" }});
await promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(response));
}, "compileStreaming using ReadableStream with ArrayBuffer chunk");
promise_test(async function() {
const response = await fetch('resources/incrementer.wasm');
const 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) {
const response = await fetch('resources/incrementer.wasm');
const blob = await response.blob();
const 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>

View File

@ -0,0 +1,115 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>WebAssembly.instantiateStreaming</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script>
promise_test(async function() {
const response = await fetch('resources/incrementer.wasm');
const { instance, module } = await WebAssembly.instantiateStreaming(response);
assert_true(instance instanceof WebAssembly.Instance);
assert_true(module instanceof WebAssembly.Module);
}, "instantiateStreaming using resolved response");
promise_test(async function() {
const response = await fetch('resources/incrementer.wasm');
const { instance } = await WebAssembly.instantiateStreaming(response);
assert_true(instance instanceof WebAssembly.Instance);
}, "instantiateStreaming using resolved response and check instantiate");
promise_test(async function() {
const result = fetch('resources/incrementer.wasm');
const { instance } = await WebAssembly.instantiateStreaming(result);
assert_true(instance instanceof WebAssembly.Instance);
}, "instantiateStreaming using promise response from fetch and check instantiate");
promise_test(async function(t) {
const result = fetch('resources/incrementer.wrong_mime_type.wasm');
await promise_rejects_js(t, TypeError, WebAssembly.instantiateStreaming(result));
}, "instantiateStreaming raise error if wrong mime type");
promise_test(async function(t) {
const result = fetch('resources/incrementer.no_mime_type.wasm?pipe=header(Content-Type,)');
await promise_rejects_js(t, TypeError, WebAssembly.instantiateStreaming(result));
}, "instantiateStreaming raise error if no mime type");
promise_test(async function(t) {
const result = fetch('webapi/status.py?status=404');
await promise_rejects_js(t, TypeError, WebAssembly.instantiateStreaming(result));
}, "instantiateStreaming raise error if 404 status");
const getWasmUrl = fileName => {
const host_info = get_host_info();
const url = host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT + '/wasm/webapi/';
return url + fileName + "?pipe=header(Access-Control-Allow-Origin,*)";
};
promise_test(async function() {
const result = fetch(getWasmUrl('resources/incrementer.wasm'), {"mode": "cors"} );
const { instance } = await WebAssembly.instantiateStreaming(result);
assert_true(instance instanceof WebAssembly.Instance);
}, "instantiateStreaming check CORS");
promise_test(async function(t) {
const result = fetch(getWasmUrl('resources/incrementer.wasm'), {"mode": "no-cors"} );
await promise_rejects_js(t, TypeError, WebAssembly.instantiateStreaming(result));
}, "instantiateStreaming raise error if no-cors");
promise_test(async function() {
const v = await fetch('resources/incrementer.wasm');
const buffer = await v.arrayBuffer();
const response = new Response(buffer, { headers: { "Content-Type" : "application/wasm" }});
const { instance } = await WebAssembly.instantiateStreaming(response);
assert_true(instance instanceof WebAssembly.Instance);
}, "instantiateStreaming receive promise with response created from ArrayBuffer");
promise_test(async function() {
const v = await fetch('resources/incrementer.wasm');
const buffer = await v.arrayBuffer();
const stream = new ReadableStream({
start(controller) {
(async () => {
await Promise.resolve().then(() => controller.enqueue(new Uint8Array(buffer.slice(0, 20))));
await Promise.resolve().then(() => controller.enqueue(new Uint8Array(buffer.slice(20, buffer.byteLength))));
await Promise.resolve().then(() => controller.close());
})();
}
});
const response = new Response(stream, { headers: { "Content-Type" : "application/wasm" }});
const { instance } = await WebAssembly.instantiateStreaming(response);
assert_true(instance instanceof WebAssembly.Instance);
}, "instantiateStreaming using ReadableStream with Uint8Array chunks");
promise_test(async function(t) {
const v = await fetch('resources/incrementer.wasm');
const buffer = await v.arrayBuffer();
const stream = new ReadableStream({
start(controller) {
// Enqueuing an ArrayBuffer rather a Uint8Array per
// https://streams.spec.whatwg.org/#read-loop
controller.enqueue(buffer);
controller.close();
}
});
const response = new Response(stream, { headers: { "Content-Type" : "application/wasm" }});
await promise_rejects_js(t, TypeError, WebAssembly.instantiateStreaming(response));
}, "instantiateStreaming using ReadableStream with ArrayBuffer chunk");
promise_test(async function() {
const response = await fetch('resources/incrementer.wasm');
const 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) {
const response = await fetch('resources/incrementer.wasm');
const blob = await response.blob();
const 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>