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,13 @@
// 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) => {
test(() => {
const builder = new WasmModuleBuilder();
build(builder);
const buffer = builder.toBuffer();
const module = new WebAssembly.Module(buffer);
assert_throws_js(error, () => new WebAssembly.Instance(module, ...arguments));
}, `new WebAssembly.Instance(module): ${name}`);
});

View File

@ -0,0 +1,54 @@
// META: global=window,dedicatedworker,jsshell
// META: script=/wasm/jsapi/wasm-module-builder.js
function getExports() {
const builder = new WasmModuleBuilder();
builder
.addFunction("fn", kSig_v_d)
.addBody([])
.exportFunc();
builder.setTableBounds(1);
builder.addExportOfKind("table", kExternalTable, 0);
builder.addGlobal(kWasmI32, false).exportAs("global");
builder.addMemory(4, 8, true);
const buffer = builder.toBuffer();
const module = new WebAssembly.Module(buffer);
const instance = new WebAssembly.Instance(module);
return instance.exports;
}
test(() => {
const exports = getExports();
const builder = new WasmModuleBuilder();
const functionIndex = builder.addImport("module", "imported", kSig_v_d);
builder.addExport("exportedFunction", functionIndex);
const globalIndex = builder.addImportedGlobal("module", "global", kWasmI32);
builder.addExportOfKind("exportedGlobal", kExternalGlobal, globalIndex);
builder.addImportedMemory("module", "memory", 4);
builder.exportMemoryAs("exportedMemory");
const tableIndex = builder.addImportedTable("module", "table", 1);
builder.addExportOfKind("exportedTable", kExternalTable, tableIndex);
const buffer = builder.toBuffer();
const module = new WebAssembly.Module(buffer);
const instance = new WebAssembly.Instance(module, {
"module": {
"imported": exports.fn,
"global": exports.global,
"memory": exports.memory,
"table": exports.table,
}
});
assert_equals(instance.exports.exportedFunction, exports.fn);
assert_equals(instance.exports.exportedGlobal, exports.global);
assert_equals(instance.exports.exportedMemory, exports.memory);
assert_equals(instance.exports.exportedTable, exports.table);
});

View File

@ -0,0 +1,54 @@
// 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();
});
test(() => {
assert_function_name(WebAssembly.Instance, "Instance", "WebAssembly.Instance");
}, "name");
test(() => {
assert_function_length(WebAssembly.Instance, 1, "WebAssembly.Instance");
}, "length");
test(() => {
assert_throws_js(TypeError, () => new WebAssembly.Instance());
}, "No arguments");
test(() => {
const invalidArguments = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
WebAssembly.Module,
WebAssembly.Module.prototype,
];
for (const argument of invalidArguments) {
assert_throws_js(TypeError, () => new WebAssembly.Instance(argument),
`new Instance(${format_value(argument)})`);
}
}, "Non-Module arguments");
test(() => {
const module = new WebAssembly.Module(emptyModuleBinary);
assert_throws_js(TypeError, () => WebAssembly.Instance(module));
}, "Calling");
for (const [name, fn] of instanceTestFactory) {
test(() => {
const { buffer, args, exports, verify } = fn();
const module = new WebAssembly.Module(buffer);
const instance = new WebAssembly.Instance(module, ...args);
assert_Instance(instance, exports);
verify(instance);
}, name);
}

View File

@ -0,0 +1,66 @@
// META: global=window,dedicatedworker,jsshell
// META: script=/wasm/jsapi/wasm-module-builder.js
let emptyModuleBinary;
setup(() => {
emptyModuleBinary = new WasmModuleBuilder().toBuffer();
});
test(() => {
const thisValues = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
WebAssembly.Instance,
WebAssembly.Instance.prototype,
];
const desc = Object.getOwnPropertyDescriptor(WebAssembly.Instance.prototype, "exports");
assert_equals(typeof desc, "object");
const getter = desc.get;
assert_equals(typeof getter, "function");
assert_equals(typeof desc.set, "undefined");
for (const thisValue of thisValues) {
assert_throws_js(TypeError, () => getter.call(thisValue), `this=${format_value(thisValue)}`);
}
}, "Branding");
test(() => {
const module = new WebAssembly.Module(emptyModuleBinary);
const instance = new WebAssembly.Instance(module);
const exports = instance.exports;
const desc = Object.getOwnPropertyDescriptor(WebAssembly.Instance.prototype, "exports");
assert_equals(typeof desc, "object");
const getter = desc.get;
assert_equals(typeof getter, "function");
assert_equals(getter.call(instance, {}), exports);
}, "Stray argument");
test(() => {
const module = new WebAssembly.Module(emptyModuleBinary);
const instance = new WebAssembly.Instance(module);
const exports = instance.exports;
instance.exports = {};
assert_equals(instance.exports, exports, "Should not change the exports");
}, "Setting (sloppy mode)");
test(() => {
const module = new WebAssembly.Module(emptyModuleBinary);
const instance = new WebAssembly.Instance(module);
const exports = instance.exports;
assert_throws_js(TypeError, () => {
"use strict";
instance.exports = {};
});
assert_equals(instance.exports, exports, "Should not change the exports");
}, "Setting (strict mode)");

View File

@ -0,0 +1,19 @@
// META: global=window,dedicatedworker,jsshell
// META: script=/wasm/jsapi/wasm-module-builder.js
test(() => {
const emptyModuleBinary = new WasmModuleBuilder().toBuffer();
const module = new WebAssembly.Module(emptyModuleBinary);
const instance = new WebAssembly.Instance(module);
assert_class_string(instance, "WebAssembly.Instance");
}, "Object.prototype.toString on an Instance");
test(() => {
assert_own_property(WebAssembly.Instance.prototype, Symbol.toStringTag);
const propDesc = Object.getOwnPropertyDescriptor(WebAssembly.Instance.prototype, Symbol.toStringTag);
assert_equals(propDesc.value, "WebAssembly.Instance", "value");
assert_equals(propDesc.configurable, true, "configurable");
assert_equals(propDesc.enumerable, false, "enumerable");
assert_equals(propDesc.writable, false, "writable");
}, "@@toStringTag exists on the prototype with the appropriate descriptor");