test: add basic WebAssembly test
Tests a basic WebAssembly module that adds two numbers.
wasm example from the WebAssembly/wabt repo licensed
Apache 2.0.
Refs: 49b7984544/demo/wat2wasm/examples.js (L27-L32)
PR-URL: https://github.com/nodejs/node/pull/16760
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
This commit is contained in:
parent
7d8fe7df91
commit
74e7a4a041
@ -15,3 +15,7 @@ rules:
|
||||
inspector-check: error
|
||||
## common module is mandatory in tests
|
||||
required-modules: [error, common]
|
||||
|
||||
# Global scoped methods and vars
|
||||
globals:
|
||||
WebAssembly: false
|
||||
|
BIN
test/fixtures/test.wasm
vendored
Normal file
BIN
test/fixtures/test.wasm
vendored
Normal file
Binary file not shown.
18
test/parallel/test-wasm-simple.js
Normal file
18
test/parallel/test-wasm-simple.js
Normal file
@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
|
||||
const assert = require('assert');
|
||||
const fixtures = require('../common/fixtures');
|
||||
|
||||
const buffer = fixtures.readSync('test.wasm');
|
||||
|
||||
assert.ok(WebAssembly.validate(buffer), 'Buffer should be valid WebAssembly');
|
||||
|
||||
WebAssembly.instantiate(buffer, {}).then((results) => {
|
||||
assert.strictEqual(
|
||||
results.instance.exports.addTwo(10, 20),
|
||||
30,
|
||||
'Exported function should add two numbers.',
|
||||
);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user