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,85 @@
// META: global=window,dedicatedworker,jsshell
// META: script=/wasm/jsapi/wasm-module-builder.js
function assert_Module(module) {
assert_equals(Object.getPrototypeOf(module), WebAssembly.Module.prototype,
"Prototype");
assert_true(Object.isExtensible(module), "Extensibility");
}
let emptyModuleBinary;
setup(() => {
emptyModuleBinary = new WasmModuleBuilder().toBuffer();
});
promise_test(t => {
return promise_rejects_js(t, TypeError, WebAssembly.compile());
}, "Missing argument");
promise_test(t => {
const invalidArguments = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
ArrayBuffer,
ArrayBuffer.prototype,
Array.from(emptyModuleBinary),
];
return Promise.all(invalidArguments.map(argument => {
return promise_rejects_js(t, TypeError, WebAssembly.compile(argument),
`compile(${format_value(argument)})`);
}));
}, "Invalid arguments");
promise_test(() => {
const fn = WebAssembly.compile;
const thisValues = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
WebAssembly,
];
return Promise.all(thisValues.map(thisValue => {
return fn.call(thisValue, emptyModuleBinary).then(assert_Module);
}));
}, "Branding");
test(() => {
const promise = WebAssembly.compile(emptyModuleBinary);
assert_equals(Object.getPrototypeOf(promise), Promise.prototype, "prototype");
assert_true(Object.isExtensible(promise), "extensibility");
}, "Promise type");
promise_test(t => {
const buffer = new Uint8Array();
return promise_rejects_js(t, WebAssembly.CompileError, WebAssembly.compile(buffer));
}, "Empty buffer");
promise_test(t => {
const buffer = new Uint8Array(Array.from(emptyModuleBinary).concat([0, 0]));
return promise_rejects_js(t, WebAssembly.CompileError, WebAssembly.compile(buffer));
}, "Invalid code");
promise_test(() => {
return WebAssembly.compile(emptyModuleBinary).then(assert_Module);
}, "Result type");
promise_test(() => {
return WebAssembly.compile(emptyModuleBinary, {}).then(assert_Module);
}, "Stray argument");
promise_test(() => {
const buffer = new WasmModuleBuilder().toBuffer();
assert_equals(buffer[0], 0);
const promise = WebAssembly.compile(buffer);
buffer[0] = 1;
return promise.then(assert_Module);
}, "Changing the buffer");

View File

@ -0,0 +1,22 @@
// META: global=window,dedicatedworker,jsshell
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/bad-imports.js
test_bad_imports((name, error, build, ...arguments) => {
promise_test(t => {
const builder = new WasmModuleBuilder();
build(builder);
const buffer = builder.toBuffer();
const module = new WebAssembly.Module(buffer);
return promise_rejects_js(t, error, WebAssembly.instantiate(module, ...arguments));
}, `WebAssembly.instantiate(module): ${name}`);
});
test_bad_imports((name, error, build, ...arguments) => {
promise_test(t => {
const builder = new WasmModuleBuilder();
build(builder);
const buffer = builder.toBuffer();
return promise_rejects_js(t, error, WebAssembly.instantiate(buffer, ...arguments));
}, `WebAssembly.instantiate(buffer): ${name}`);
});

View File

@ -0,0 +1,152 @@
// META: global=window,dedicatedworker,jsshell
// 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();
});
promise_test(t => {
return promise_rejects_js(t, TypeError, WebAssembly.instantiate());
}, "Missing arguments");
promise_test(() => {
const fn = WebAssembly.instantiate;
const thisValues = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
WebAssembly,
];
return Promise.all(thisValues.map(thisValue => {
return fn.call(thisValue, emptyModuleBinary).then(assert_WebAssemblyInstantiatedSource);
}));
}, "Branding");
promise_test(t => {
const invalidArguments = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
WebAssembly.Module,
WebAssembly.Module.prototype,
ArrayBuffer,
ArrayBuffer.prototype,
Array.from(emptyModuleBinary),
];
return Promise.all(invalidArguments.map(argument => {
return promise_rejects_js(t, TypeError, WebAssembly.instantiate(argument),
`instantiate(${format_value(argument)})`);
}));
}, "Invalid arguments");
test(() => {
const promise = WebAssembly.instantiate(emptyModuleBinary);
assert_equals(Object.getPrototypeOf(promise), Promise.prototype, "prototype");
assert_true(Object.isExtensible(promise), "extensibility");
}, "Promise type");
for (const [name, fn] of instanceTestFactory) {
promise_test(() => {
const { buffer, args, exports, verify } = fn();
return WebAssembly.instantiate(buffer, ...args).then(result => {
assert_WebAssemblyInstantiatedSource(result, exports);
verify(result.instance);
});
}, `${name}: BufferSource argument`);
promise_test(() => {
const { buffer, args, exports, verify } = fn();
const module = new WebAssembly.Module(buffer);
return WebAssembly.instantiate(module, ...args).then(instance => {
assert_Instance(instance, exports);
verify(instance);
});
}, `${name}: Module argument`);
}
promise_test(() => {
const builder = new WasmModuleBuilder();
builder.addImportedGlobal("module", "global", kWasmI32);
const buffer = builder.toBuffer();
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.instantiate(buffer, imports);
assert_array_equals(order, []);
return p.then(result => {
assert_WebAssemblyInstantiatedSource(result);
assert_array_equals(order, expected);
});
}, "Synchronous options handling: Buffer argument");
promise_test(() => {
const builder = new WasmModuleBuilder();
builder.addImportedGlobal("module", "global", kWasmI32);
const buffer = builder.toBuffer();
const module = new WebAssembly.Module(buffer);
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.instantiate(module, imports);
assert_array_equals(order, expected);
return p.then(instance => assert_Instance(instance, {}));
}, "Synchronous options handling: Module argument");
promise_test(t => {
const buffer = new Uint8Array();
return promise_rejects_js(t, WebAssembly.CompileError, WebAssembly.instantiate(buffer));
}, "Empty buffer");
promise_test(t => {
const buffer = new Uint8Array(Array.from(emptyModuleBinary).concat([0, 0]));
return promise_rejects_js(t, WebAssembly.CompileError, WebAssembly.instantiate(buffer));
}, "Invalid code");
promise_test(() => {
const buffer = new WasmModuleBuilder().toBuffer();
assert_equals(buffer[0], 0);
const promise = WebAssembly.instantiate(buffer);
buffer[0] = 1;
return promise.then(assert_WebAssemblyInstantiatedSource);
}, "Changing the buffer");

View File

@ -0,0 +1,149 @@
// META: global=window,dedicatedworker,jsshell
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/assertions.js
const type_if_fi = makeSig([kWasmF64, kWasmI32], [kWasmI32, kWasmF64]);
promise_test(async () => {
const builder = new WasmModuleBuilder();
builder
.addFunction("swap", type_if_fi)
.addBody([
kExprLocalGet, 1,
kExprLocalGet, 0,
kExprReturn,
])
.exportFunc();
const buffer = builder.toBuffer();
const result = await WebAssembly.instantiate(buffer);
const swapped = result.instance.exports.swap(4.2, 7);
assert_true(Array.isArray(swapped));
assert_equals(Object.getPrototypeOf(swapped), Array.prototype);
assert_array_equals(swapped, [7, 4.2]);
}, "multiple return values from wasm to js");
promise_test(async () => {
const builder = new WasmModuleBuilder();
const swap = builder
.addFunction("swap", type_if_fi)
.addBody([
kExprLocalGet, 1,
kExprLocalGet, 0,
kExprReturn,
]);
builder
.addFunction("callswap", kSig_i_v)
.addBody([
...wasmF64Const(4.2),
...wasmI32Const(7),
kExprCallFunction, swap.index,
kExprDrop,
kExprReturn,
])
.exportFunc();
const buffer = builder.toBuffer();
const result = await WebAssembly.instantiate(buffer);
const swapped = result.instance.exports.callswap();
assert_equals(swapped, 7);
}, "multiple return values inside wasm");
promise_test(async () => {
const builder = new WasmModuleBuilder();
const fnIndex = builder.addImport("module", "fn", type_if_fi);
builder
.addFunction("callfn", kSig_i_v)
.addBody([
...wasmF64Const(4.2),
...wasmI32Const(7),
kExprCallFunction, fnIndex,
kExprDrop,
kExprReturn,
])
.exportFunc();
const buffer = builder.toBuffer();
const actual = [];
const imports = {
"module": {
fn(f32, i32) {
assert_equals(f32, 4.2);
assert_equals(i32, 7);
const result = [2, 7.3];
let i = 0;
return {
get [Symbol.iterator]() {
actual.push("@@iterator getter");
return function iterator() {
actual.push("@@iterator call");
return {
get next() {
actual.push("next getter");
return function next(...args) {
assert_array_equals(args, []);
let j = ++i;
actual.push(`next call ${j}`);
if (j > result.length) {
return {
get done() {
actual.push(`done call ${j}`);
return true;
}
};
}
return {
get done() {
actual.push(`done call ${j}`);
return false;
},
get value() {
actual.push(`value call ${j}`);
return {
get valueOf() {
actual.push(`valueOf get ${j}`);
return function() {
actual.push(`valueOf call ${j}`);
return result[j - 1];
};
}
};
}
};
};
}
};
}
},
};
},
}
};
const { instance } = await WebAssembly.instantiate(buffer, imports);
const result = instance.exports.callfn();
assert_equals(result, 2);
assert_array_equals(actual, [
"@@iterator getter",
"@@iterator call",
"next getter",
"next call 1",
"done call 1",
"value call 1",
"next call 2",
"done call 2",
"value call 2",
"next call 3",
"done call 3",
"valueOf get 1",
"valueOf call 1",
"valueOf get 2",
"valueOf call 2",
]);
}, "multiple return values from js to wasm");

View File

@ -0,0 +1,42 @@
// META: global=window,dedicatedworker,jsshell
"use strict";
// https://webidl.spec.whatwg.org/#es-namespaces
// https://webassembly.github.io/spec/js-api/#namespacedef-webassembly
test(() => {
assert_own_property(WebAssembly, Symbol.toStringTag);
const propDesc = Object.getOwnPropertyDescriptor(WebAssembly, Symbol.toStringTag);
assert_equals(propDesc.value, "WebAssembly", "value");
assert_equals(propDesc.writable, false, "writable");
assert_equals(propDesc.enumerable, false, "enumerable");
assert_equals(propDesc.configurable, true, "configurable");
}, "@@toStringTag exists on the namespace object with the appropriate descriptor");
test(() => {
assert_equals(WebAssembly.toString(), "[object WebAssembly]");
assert_equals(Object.prototype.toString.call(WebAssembly), "[object WebAssembly]");
}, "Object.prototype.toString applied to the namespace object");
test(t => {
assert_own_property(WebAssembly, Symbol.toStringTag, "Precondition: @@toStringTag on the namespace object");
t.add_cleanup(() => {
Object.defineProperty(WebAssembly, Symbol.toStringTag, { value: "WebAssembly" });
});
Object.defineProperty(WebAssembly, Symbol.toStringTag, { value: "Test" });
assert_equals(WebAssembly.toString(), "[object Test]");
assert_equals(Object.prototype.toString.call(WebAssembly), "[object Test]");
}, "Object.prototype.toString applied after modifying the namespace object's @@toStringTag");
test(t => {
assert_own_property(WebAssembly, Symbol.toStringTag, "Precondition: @@toStringTag on the namespace object");
t.add_cleanup(() => {
Object.defineProperty(WebAssembly, Symbol.toStringTag, { value: "WebAssembly" });
});
assert_true(delete WebAssembly[Symbol.toStringTag]);
assert_equals(WebAssembly.toString(), "[object Object]");
assert_equals(Object.prototype.toString.call(WebAssembly), "[object Object]");
}, "Object.prototype.toString applied after deleting @@toStringTag");

View File

@ -0,0 +1,99 @@
// META: global=window,dedicatedworker,jsshell
// META: script=/wasm/jsapi/wasm-module-builder.js
let emptyModuleBinary;
setup(() => {
emptyModuleBinary = new WasmModuleBuilder().toBuffer();
});
test(() => {
assert_throws_js(TypeError, () => WebAssembly.validate());
}, "Missing argument");
test(() => {
const invalidArguments = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
ArrayBuffer,
ArrayBuffer.prototype,
Array.from(emptyModuleBinary),
];
for (const argument of invalidArguments) {
assert_throws_js(TypeError, () => WebAssembly.validate(argument),
`validate(${format_value(argument)})`);
}
}, "Invalid arguments");
test(() => {
const fn = WebAssembly.validate;
const thisValues = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
WebAssembly,
];
for (const thisValue of thisValues) {
assert_true(fn.call(thisValue, emptyModuleBinary), `this=${format_value(thisValue)}`);
}
}, "Branding");
const modules = [
// Incomplete header.
[[], false],
[[0x00], false],
[[0x00, 0x61], false],
[[0x00, 0x61, 0x73], false],
[[0x00, 0x61, 0x73, 0x6d], false],
[[0x00, 0x61, 0x73, 0x6d, 0x01], false],
[[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00], false],
[[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00], false],
// Complete header.
[[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00], true],
// Invalid version.
[[0x00, 0x61, 0x73, 0x6d, 0x00, 0x00, 0x00, 0x00], false],
[[0x00, 0x61, 0x73, 0x6d, 0x02, 0x00, 0x00, 0x00], false],
// Nameless custom section.
[[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00], false],
// Custom section with empty name.
[[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00], true],
// Custom section with name "a".
[[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x61], true],
];
const bufferTypes = [
Uint8Array,
Int8Array,
Uint16Array,
Int16Array,
Uint32Array,
Int32Array,
];
for (const [module, expected] of modules) {
const name = module.map(n => n.toString(16)).join(" ");
for (const bufferType of bufferTypes) {
if (module.length % bufferType.BYTES_PER_ELEMENT === 0) {
test(() => {
const bytes = new Uint8Array(module);
const moduleBuffer = new bufferType(bytes.buffer);
assert_equals(WebAssembly.validate(moduleBuffer), expected);
}, `Validating module [${name}] in ${bufferType.name}`);
}
}
}
test(() => {
assert_true(WebAssembly.validate(emptyModuleBinary, {}));
}, "Stray argument");