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:
Steve Kinney 2017-11-04 16:08:37 -06:00 committed by Anna Henningsen
parent 7d8fe7df91
commit 74e7a4a041
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
3 changed files with 22 additions and 0 deletions

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
test/fixtures/test.wasm vendored Normal file

Binary file not shown.

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.',
);
});