Skip to content

Commit

Permalink
Enable shadowrealm testing for wasm api (tests with dependencies)
Browse files Browse the repository at this point in the history
Supports tests that have helper dependencies. Exposes wasm-local helper functions
  • Loading branch information
rwaldron authored and Ms2ger committed Sep 15, 2023
1 parent 5623804 commit e0c0429
Show file tree
Hide file tree
Showing 44 changed files with 56 additions and 43 deletions.
5 changes: 5 additions & 0 deletions wasm/jsapi/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function assert_function_name(fn, name, description) {
assert_true(propdesc.configurable, "configurable", `${description} name should be configurable`);
assert_equals(propdesc.value, name, `${description} name should be ${name}`);
}
globalThis.assert_function_name = assert_function_name;

function assert_function_length(fn, length, description) {
const propdesc = Object.getOwnPropertyDescriptor(fn, "length");
Expand All @@ -15,6 +16,7 @@ function assert_function_length(fn, length, description) {
assert_true(propdesc.configurable, "configurable", `${description} length should be configurable`);
assert_equals(propdesc.value, length, `${description} length should be ${length}`);
}
globalThis.assert_function_length = assert_function_length;

function assert_exported_function(fn, { name, length }, description) {
if (WebAssembly.Function === undefined) {
Expand All @@ -28,6 +30,7 @@ function assert_exported_function(fn, { name, length }, description) {
assert_function_name(fn, name, description);
assert_function_length(fn, length, description);
}
globalThis.assert_exported_function = assert_exported_function;

function assert_Instance(instance, expected_exports) {
assert_equals(Object.getPrototypeOf(instance), WebAssembly.Instance.prototype,
Expand Down Expand Up @@ -77,6 +80,7 @@ function assert_Instance(instance, expected_exports) {
}
}
}
globalThis.assert_Instance = assert_Instance;

function assert_WebAssemblyInstantiatedSource(actual, expected_exports={}) {
assert_equals(Object.getPrototypeOf(actual), Object.prototype,
Expand All @@ -98,3 +102,4 @@ function assert_WebAssemblyInstantiatedSource(actual, expected_exports={}) {
assert_true(instance.configurable, "instance: configurable");
assert_Instance(instance.value, expected_exports);
}
globalThis.assert_WebAssemblyInstantiatedSource = assert_WebAssemblyInstantiatedSource;
1 change: 1 addition & 0 deletions wasm/jsapi/bad-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,4 @@ function test_bad_imports(t) {
});
}
}
globalThis.test_bad_imports = test_bad_imports;
2 changes: 1 addition & 1 deletion wasm/jsapi/constructor/compile.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js

function assert_Module(module) {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/constructor/instantiate-bad-imports.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/bad-imports.js

Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/constructor/instantiate.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/assertions.js
// META: script=/wasm/jsapi/instanceTestFactory.js
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/constructor/multi-value.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/assertions.js

Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/constructor/validate.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js

let emptyModuleBinary;
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/exception/basic.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,worker,jsshell
// META: global=window,worker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js

function assert_throws_wasm(fn, message) {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/exception/constructor.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js

test(() => {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/exception/getArg.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/memory/assertions.js

test(() => {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/exception/identity.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js
// META: script=/wasm/jsapi/wasm-module-builder.js

Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/exception/is.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/memory/assertions.js

test(() => {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/function/call.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js

function addxy(x, y) {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/function/constructor.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js

function addxy(x, y) {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/function/table.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js

function testfunc(n) {}
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/function/type.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js

function addNumbers(x, y, z) {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/global/constructor.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js

function assert_Global(actual, expected) {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/global/type.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js

function assert_type(argument) {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/instance/constructor-bad-imports.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/bad-imports.js

Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/instance/constructor-caching.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js

function getExports() {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/instance/constructor.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/assertions.js
// META: script=/wasm/jsapi/instanceTestFactory.js
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/instance/exports.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js

let emptyModuleBinary;
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/instance/toString.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js

test(() => {
Expand Down
2 changes: 2 additions & 0 deletions wasm/jsapi/instanceTestFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,3 +759,5 @@ const instanceTestFactory = [
}
],
];

globalThis.instanceTestFactory = instanceTestFactory;
2 changes: 1 addition & 1 deletion wasm/jsapi/interface.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js

function test_operations(object, object_name, operations) {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/memory/constructor-shared.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js
// META: script=/wasm/jsapi/memory/assertions.js

Expand Down
4 changes: 2 additions & 2 deletions wasm/jsapi/memory/constructor-types.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js
// META: script=/wasm/jsapi/memory/assertions.js

Expand All @@ -17,4 +17,4 @@ test(() => {
const argument = { minimum: 4 };
const memory = new WebAssembly.Memory(argument);
assert_Memory(memory, { "size": 4 });
}, "Non-zero minimum");
}, "Non-zero minimum");
2 changes: 1 addition & 1 deletion wasm/jsapi/memory/constructor.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js
// META: script=/wasm/jsapi/memory/assertions.js

Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/memory/grow.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/memory/assertions.js

test(() => {
Expand Down
4 changes: 2 additions & 2 deletions wasm/jsapi/memory/type.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js

function assert_type(argument) {
Expand Down Expand Up @@ -34,4 +34,4 @@ test(() => {

test(() => {
assert_type({ "minimum": 0, "maximum": 10, "shared": true});
}, "shared memory");
}, "shared memory");
2 changes: 1 addition & 1 deletion wasm/jsapi/module/constructor.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/assertions.js

Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/module/customSections.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js

function assert_ArrayBuffer(buffer, expected) {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/module/exports.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js

let emptyModuleBinary;
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/module/imports.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js

function assert_ModuleImportDescriptor(import_, expected) {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/module/toString.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js

test(() => {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/prototypes.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js
// META: script=/wasm/jsapi/wasm-module-builder.js

Expand Down
4 changes: 2 additions & 2 deletions wasm/jsapi/table/constructor-types.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js
// META: script=/wasm/jsapi/table/assertions.js

Expand All @@ -17,4 +17,4 @@ test(() => {
const argument = { "element": "anyfunc", "minimum": 5 };
const table = new WebAssembly.Table(argument);
assert_Table(table, { "length": 5 });
}, "Non-zero minimum");
}, "Non-zero minimum");
2 changes: 1 addition & 1 deletion wasm/jsapi/table/constructor.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/assertions.js
// META: script=/wasm/jsapi/table/assertions.js
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/table/get-set.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=assertions.js

Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/table/grow.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=assertions.js

Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/table/type.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js

function assert_type(argument) {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/tag/constructor.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js

test(() => {
Expand Down
2 changes: 1 addition & 1 deletion wasm/jsapi/tag/type.tentative.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/assertions.js

function assert_type(argument) {
Expand Down
5 changes: 5 additions & 0 deletions wasm/jsapi/wasm-module-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@ class WasmModuleBuilder {
return new WebAssembly.Module(this.toBuffer(debug));
}
}
globalThis.WasmModuleBuilder = WasmModuleBuilder;

function wasmSignedLeb(val, max_len = 5) {
let res = [];
Expand All @@ -1300,10 +1301,12 @@ function wasmSignedLeb(val, max_len = 5) {
throw new Error(
'Leb value <' + val + '> exceeds maximum length of ' + max_len);
}
globalThis.wasmSignedLeb = wasmSignedLeb;

function wasmI32Const(val) {
return [kExprI32Const, ...wasmSignedLeb(val, 5)];
}
globalThis.wasmI32Const = wasmI32Const;

function wasmF32Const(f) {
// Write in little-endian order at offset 0.
Expand All @@ -1312,6 +1315,7 @@ function wasmF32Const(f) {
kExprF32Const, byte_view[0], byte_view[1], byte_view[2], byte_view[3]
];
}
globalThis.wasmI32Const = wasmI32Const;

function wasmF64Const(f) {
// Write in little-endian order at offset 0.
Expand All @@ -1321,3 +1325,4 @@ function wasmF64Const(f) {
byte_view[3], byte_view[4], byte_view[5], byte_view[6], byte_view[7]
];
}
globalThis.wasmF64Const = wasmF64Const;

0 comments on commit e0c0429

Please sign in to comment.