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: https://github.com/WebAssembly/wabt/blob/49b7984544ddaf14d5e2f1ad9115dad7e9a2b299/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:
Steve Kinney authored and Anna Henningsen committed 2017-11-15 19:50:54 +01:00
1 parent 7d8fe7df91
commit 74e7a4a041
3 files changed
+22

No files matched your search

+4
View File
@@ -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
View File
Binary file not shown.
+18
View 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.',
);
});