/* Copyright 2021 Mozilla Foundation * *LicensedundertheApacheLicense,Version2.0(the"License"); *youmaynotusethisfileexceptincompliancewiththeLicense. *YoumayobtainacopyoftheLicenseat * *http://www.apache.org/licenses/LICENSE-2.0 * *Unlessrequiredbyapplicablelaworagreedtoinwriting,software *distributedundertheLicenseisdistributedonan"ASIS"BASIS, *WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied. *SeetheLicenseforthespecificlanguagegoverningpermissionsand *limitationsundertheLicense.
*/
if (!wasmIsSupported()) {
quit();
}
function partialOobWriteMayWritePartialData() {
let arm_native = getBuildConfiguration("arm") && !getBuildConfiguration("arm-simulator");
let arm64_native = getBuildConfiguration("arm64") && !getBuildConfiguration("arm64-simulator");
let riscv64_native = getBuildConfiguration("riscv64") && !getBuildConfiguration("riscv64-simulator"); return arm_native || arm64_native || riscv64_native;
}
function bytes(type, bytes) { var typedBuffer = new Uint8Array(bytes); return wasmGlobalFromArrayBuffer(type, typedBuffer.buffer);
} function value(type, value) { returnnew WebAssembly.Global({
value: type,
mutable: false,
}, value);
}
function i8x16(elements) {
let typedBuffer = new Uint8Array(elements); return wasmGlobalFromArrayBuffer("v128", typedBuffer.buffer);
} function i16x8(elements) {
let typedBuffer = new Uint16Array(elements); return wasmGlobalFromArrayBuffer("v128", typedBuffer.buffer);
} function i32x4(elements) {
let typedBuffer = new Uint32Array(elements); return wasmGlobalFromArrayBuffer("v128", typedBuffer.buffer);
} function i64x2(elements) {
let typedBuffer = new BigUint64Array(elements); return wasmGlobalFromArrayBuffer("v128", typedBuffer.buffer);
} function f32x4(elements) {
let typedBuffer = new Float32Array(elements); return wasmGlobalFromArrayBuffer("v128", typedBuffer.buffer);
} function f64x2(elements) {
let typedBuffer = new Float64Array(elements); return wasmGlobalFromArrayBuffer("v128", typedBuffer.buffer);
}
function either(...arr) { returnnew EitherVariants(arr);
}
test(refGlobal) { try { new WebAssembly.Global({value: this.type}, refGlobal.value); returntrue;
} catch (err) {
assertEq(err instanceof TypeError, true, `wrong type of error when creating global: ${err}`);
assertEq(!!err.message.match(/can only pass/), true, `wrong type of error when creating global: ${err}`); returnfalse;
}
}
}
// ref.extern values created by spec tests will be JS objects of the form // { [externsym]: <number> }. Other externref values are possible to observe // if extern.convert_any is used.
let externsym = Symbol("externref"); function externref(s) { return { [externsym]: s };
}
class ExternRefResult {
constructor(n) { this.n = n;
}
test(global) { // the global's value can either be an externref or just a plain old JS number
let result = global.value; if (typeof global.value === "object" && externsym in global.value) {
result = global.value[externsym];
} return result === this.n;
}
}
// ref.host values created by spectests will be whatever the JS API does to // convert the given value to anyref. It should implicitly be like any.convert_extern. function hostref(v) { const { internalizeNum } = new WebAssembly.Instance( new WebAssembly.Module(wasmTextToBinary(`(module
(func (import"test""coerce") (param i32) (result anyref))
(func (export "internalizeNum") (param i32) (result anyref)
(call 0 (local.get 0))
)
)`)),
{ "test": { "coerce": x => x } },
).exports; return internalizeNum(v);
}
class HostRefResult {
constructor(n) { this.n = n;
}
formatExpected() { return `ref.host ${this.n}`;
}
test(externrefGlobal) {
assertEq(externsym in externrefGlobal.value, true, `HostRefResult only works with externref inputs`); return externrefGlobal.value[externsym] === this.n;
}
}
function module(source) {
let bytecode = wasmTextToBinary(source);
let module = new WebAssembly.Module(bytecode); return module;
}
function instantiate(source) {
let bytecode = wasmTextToBinary(source);
let module = new WebAssembly.Module(bytecode);
let instance = new WebAssembly.Instance(module, linkage); return instance.exports;
}
function instantiateFromModule(module) {
let instance = new WebAssembly.Instance(module, linkage); return instance.exports;
}
function register(instance, name) {
linkage[name] = instance;
}
function invoke(instance, field, params) {
let func = instance[field];
assertEq(func instanceofFunction, true, "expected a function"); return wasmLosslessInvoke(func, ...params);
}
function get(instance, field) {
let global = instance[field];
assertEq(
global instanceof WebAssembly.Global, true, "expected a WebAssembly.Global",
); return global;
}
function assert_suspension(thunk, message) { // TODO: basically a duplicate of assert_trap, not sure what this actually // is supposed to be.
assert_trap(thunk, message);
}
function assert_unlinkable(thunk, message) { try {
thunk(); thrownew Error(`got no error`);
} catch (err) { // Allow type errors only when they pertain to imports if (err instanceof TypeError && err.message.match(/import object field.*is not a/)) { return;
}
// Allow link errors and compile errors generally (we do not really care // about the specifics) if (err instanceof WebAssembly.LinkError || err instanceof WebAssembly.CompileError) { return;
}
function compareResults(results, expected) { if (results.length !== expected.length) { returnfalse;
} for (let i in results) { if (expected[i] instanceof EitherVariants) { return expected[i].matches(results[i]);
} if (!compareResult(results[i], expected[i])) { returnfalse;
}
} returntrue;
}
constructor(sharedModule, sharedModuleName, code) { this._coord = new Int32Array(new SharedArrayBuffer(4*2));
setSharedObject(this._coord.buffer);
evalInWorker(` const _coord = new Int32Array(getSharedObject());
${readRelativeToScript("harness.js")}
function setState(state) {
Atomics.store(_coord, ${this.LOC_STATE}, state);
} function waitForState(expected) { while (Atomics.load(_coord, ${this.LOC_STATE}) !== expected) {}
} function receive() {
waitForState(${this.STATE_SENDING_VALUE}); const x = getSharedObject();
setState(${this.STATE_GOT_VALUE}); return x;
}
// Tell main thread we are ready
setState(${this.STATE_WORKER_READY});
// Get shared module's exports from main thread. (We do this one at a // time for reasons explained below.) const ${sharedModuleName} = {};
${Object.keys(sharedModule ?? {}).map(name =>
`${sharedModuleName}["${name}"] = receive();`
)}
waitForState(${this.STATE_RUN_CODE});
// Wait for worker to spawn this.waitForState(this.STATE_WORKER_READY);
// Send shared module exports to worker. We send values one at a time // because setGlobalObject can only take very specific objects, like wasm // memories, not generic objects like the whole exports object. for (const exportedValue of Object.values(sharedModule ?? {})) { this.send(exportedValue);
}
// Give the worker the all-clear to execute its workload this.setState(this.STATE_RUN_CODE);
}
wait() { this.waitForState(this.STATE_DONE); if (Atomics.load(this._coord, this.LOC_DID_ERROR)) { thrownew Error("Error in worker code. Note that line numbers will not be helpful because of how the harness is loaded.");
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-08-26)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.