haikuwebkit/JSTests/wasm
Yusuke Suzuki 907efddb43 [JSC] Remove already-shipped wasm option flags
https://bugs.webkit.org/show_bug.cgi?id=229386

Reviewed by Ross Kirsling.

JSTests:

* wasm/references/element_active_mod.js:
* wasm/references/element_parsing.js:
* wasm/references/externref_globals.js:
* wasm/references/externref_modules.js:
* wasm/references/externref_table.js:
* wasm/references/externref_table_import.js:
* wasm/references/func_ref.js:
* wasm/references/globals.js:
* wasm/references/is_null.js:
* wasm/references/memory_copy.js:
* wasm/references/memory_copy_shared.js:
* wasm/references/memory_fill_shared.js:
* wasm/references/multitable.js:
* wasm/references/parse_unreachable.js:
* wasm/references/table_js_api.js:
* wasm/references/table_misc.js:
* wasm/references/validation.js:
* wasm/stress/immutable-globals.js:
* wasm/stress/local-ref.js:
* wasm/stress/mutable-globals.js:
* wasm/stress/table-grow-table-size.js:

Source/JavaScriptCore:

This patch removes some wasm option flags which are already shipped.

* runtime/OptionsList.h:
* wasm/WasmFormat.h:
(JSC::Wasm::isValueType):
* wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::parseExpression):
(JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression):
* wasm/WasmOperations.cpp:
(JSC::Wasm::JSC_DEFINE_JIT_OPERATION):
* wasm/WasmParser.h:
(JSC::Wasm::Parser<SuccessType>::parseBlockSignature):
* wasm/WasmSectionParser.cpp:
(JSC::Wasm::SectionParser::parseType):
(JSC::Wasm::SectionParser::parseElement):
(JSC::Wasm::SectionParser::parseData):
(JSC::Wasm::SectionParser::parseDataCount):
* wasm/js/JSWebAssembly.cpp:
(JSC::JSWebAssembly::finishCreation):
* wasm/js/WebAssemblyGlobalConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/WebAssemblyTableConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/WebAssemblyTablePrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):

Tools:

* Scripts/run-jsc-stress-tests:

LayoutTests:

* workers/wasm-references.html:

Canonical link: https://commits.webkit.org/240821@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281438 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-08-23 06:28:16 +00:00
..
function-references [WASM-Function-References] Add support for (ref null? $t) type constructor 2021-06-25 02:23:28 +00:00
function-tests Unreviewed, reverting r271186. 2021-01-27 19:19:57 +00:00
fuzz Align %TypedArray% constructor behavior with spec 2020-12-08 21:02:48 +00:00
js-api JSTests: 2021-04-02 21:10:28 +00:00
lowExecutableMemory
modules
multi-value-spec-tests
noJIT
ref-spec-harness [WASM-References] Add support for type annotated select 2020-12-15 10:17:53 +00:00
references [JSC] Remove already-shipped wasm option flags 2021-08-23 06:28:16 +00:00
references-spec-tests [WASM-References] Add linking tests 2021-01-08 17:02:41 +00:00
regress WebAssembly: update wabt.js 2020-11-13 08:36:26 +00:00
self-test
spec-harness [WASM-References] Add table.init 2020-12-11 19:04:22 +00:00
spec-tests [JSC] Remove already-shipped wasm option flags 2021-08-23 06:28:16 +00:00
stress [JSC] Remove already-shipped wasm option flags 2021-08-23 06:28:16 +00:00
threads-spec-tests [JSC] wasm atomic wait offset is not index 2021-03-14 18:19:00 +00:00
tier-up
wast-tests
Builder.js [WASM-References] Add support for active mods in element section 2020-12-02 10:43:22 +00:00
Builder_WebAssemblyBinary.js [WASM-References] Add support for active mods in element section 2020-12-02 10:43:22 +00:00
LowLevelBinary.js [WASM-References] Support imm for ref.null 2020-11-12 11:59:44 +00:00
README.md Clean up SourceProvider and add caller relative load script to jsc.cpp 2020-07-13 17:35:35 +00:00
WASM.js [WASM-References] Support imm for ref.null 2020-11-12 11:59:44 +00:00
assert.js
import-spec-tests.rb
libwabt.js WebAssembly: update wabt.js 2020-11-13 08:36:26 +00:00
ref-spec-harness.js [WASM-References] Add support for type annotated select 2020-12-15 10:17:53 +00:00
spec-harness.js Clean up SourceProvider and add caller relative load script to jsc.cpp 2020-07-13 17:35:35 +00:00
test.sh
utilities.js
wabt-wrapper.js WebAssembly: update wabt.js 2020-11-13 08:36:26 +00:00
wasm.json [WASM-Function-References] Add support for (ref null? $t) type constructor 2021-06-25 02:23:28 +00:00

README.md

wasmjs: JavaScript tooling for WebAssembly

wasmjs is a self-contained collection of JavaScript tools which can create and manipulate WebAssembly representations and binaries. At its core is wasm.json, a JSON decription of the WebAssembly format and other interesting facts about WebAssembly as used by the Webkit project (such as the names of associated JavaScriptCore B3 opcodes).

wasmjs requires modern JavaScript features such as ES6 modules, which is acceptable because WebAssembly is itself contemporary to these other features.

Builder API

The current core API of wasmjs is the Builder API from Builder.js. It is used to build WebAssembly modules, and assemble them to valid .wasm binaries (held in an ArrayBuffer). The Builder is a small DSL which looks similar to the WebAssembly binary format. Each section is declared through a property on the Builder object, and each declaration returns a proxy object which has properties specific to that section. Proxies are "popped" back by invoking their .End() property.

The Code section has properties for each WebAssembly opcode. Opcode which create a scope can be nested using a lambda.

A simple example:

import Builder from './Builder.js';

const builder = new Builder();

// Construct the equivalent of: (module (func "answer" (i32.const 42) (return)))
builder
    // Declare a Type section, which the builder will auto-fill as functions are defined.
    .Type().End()
    // Declare a Function section, which the builder will auto-fill as functions are defined.
    .Function().End()
    .Export()
        // Export the "answer" function (defined below) to JavaScript.
        .Function("answer")
    .End()
    .Code()
        // The "answer" function takes an i32 parameters, and returns an i32.
        .Function("answer", { params: ["i32"], ret: "i32" })
            // Create a block returning an i32, whose body is the enclosed lambda.
            .Block("i32", b => b
                .GetLocal(0) // Parameters are in the same index space as locals.
                .I32Const(0) // Generate an i32 constant.
                .I32Eq()     // A comparison, using the two values currently on the stack.
                .If("i32")   // Consume the comparison result, returning an i32.
                    .I32Const(42)
                .Else()
                    .I32Const(1)
                .End()
            )
            .Return() // Return the top of the stack: the value returned by the block.
        .End() // End the current function.
    .End(); // End the Code section.

// Create an ArrayBuffer which is a valid WebAssembly `.wasm` file.
const bin = builder.WebAssembly().get();

// Use the standard WebAssembly JavaScript API to compile the module, and instantiate it.
const module = new WebAssembly.Module(bin);
const instance = new WebAssembly.Instance(module);

// Invoke the compiled WebAssembly function.
const result0 = instance.exports.answer(0);
if (result0 !== 42)
    throw new Error(`Expected 42, got ${result0}.`);

const result1 = instance.exports.answer(1);
if (result1 !== 1)
    throw new Error(`Expected 1, got ${result1}.`);

Testing

  • self-test tests wasmjs itself.
  • js-api tests the WebAssembly JavaScript API.
  • function-tests tests the WebAssembly compiler's implementation.

All tests can be executed using:

JSSHELL=/path/to/my/js-shell test.sh

They can also be executed by using WebKit's run-javascriptcore-tests tool:

./Tools/Scripts/run-javascriptcore-tests --release --filter wasm -arch x86_64