summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2017-02-14 11:27:26 +0100
committerMichaël Zasso <targos@protonmail.com>2017-02-22 15:55:42 +0100
commit7a77daf24344db7942e34c962b0f1ee729ab7af5 (patch)
treee7cbe7bf4e2f4b802a8f5bc18336c546cd6a0d7f /deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js
parent5f08871ee93ea739148cc49e0f7679e33c70295a (diff)
downloadnode-new-7a77daf24344db7942e34c962b0f1ee729ab7af5.tar.gz
deps: update V8 to 5.6.326.55
PR-URL: https://github.com/nodejs/node/pull/10992 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js')
-rw-r--r--deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js94
1 files changed, 49 insertions, 45 deletions
diff --git a/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js b/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js
index b1a2309770..30bbe4ac93 100644
--- a/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js
+++ b/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js
@@ -9,40 +9,44 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
var debug = true;
+function instantiate(buffer, ffi) {
+ return new WebAssembly.Instance(WebAssembly.Module(buffer), ffi);
+}
+
(function BasicTest() {
- var module = new WasmModuleBuilder();
- module.addMemory(1, 2, false);
- module.addFunction("foo", kSig_i)
+ let builder = new WasmModuleBuilder();
+ builder.addMemory(1, 2, false);
+ builder.addFunction("foo", kSig_i_v)
.addBody([kExprI8Const, 11])
.exportAs("blarg");
- var buffer = module.toBuffer(debug);
- var instance = Wasm.instantiateModule(buffer);
+ var buffer = builder.toBuffer(debug);
+ var instance = instantiate(buffer);
assertEquals(11, instance.exports.blarg());
})();
(function ImportTest() {
- var module = new WasmModuleBuilder();
- var index = module.addImport("print", makeSig_v_x(kAstI32));
- module.addFunction("foo", kSig_v_v)
+ let builder = new WasmModuleBuilder();
+ var index = builder.addImport("print", makeSig_v_x(kAstI32));
+ builder.addFunction("foo", kSig_v_v)
.addBody([kExprI8Const, 13, kExprCallFunction, index])
.exportAs("main");
- var buffer = module.toBuffer(debug);
- var instance = Wasm.instantiateModule(buffer, {print: print});
+ var buffer = builder.toBuffer(debug);
+ var instance = instantiate(buffer, {print: print});
print("should print 13! ");
instance.exports.main();
})();
(function LocalsTest() {
- var module = new WasmModuleBuilder();
- module.addFunction(undefined, kSig_i_i)
+ let builder = new WasmModuleBuilder();
+ builder.addFunction(undefined, kSig_i_i)
.addLocals({i32_count: 1})
.addBody([kExprGetLocal, 0, kExprSetLocal, 1, kExprGetLocal, 1])
.exportAs("main");
- var buffer = module.toBuffer(debug);
- var instance = Wasm.instantiateModule(buffer);
+ var buffer = builder.toBuffer(debug);
+ var instance = instantiate(buffer);
assertEquals(19, instance.exports.main(19));
assertEquals(27777, instance.exports.main(27777));
})();
@@ -57,72 +61,72 @@ var debug = true;
];
for (p of types) {
- var module = new WasmModuleBuilder();
- module.addFunction(undefined, makeSig_r_x(p.type, p.type))
+ let builder = new WasmModuleBuilder();
+ builder.addFunction(undefined, makeSig_r_x(p.type, p.type))
.addLocals(p.locals)
.addBody([kExprGetLocal, 0, kExprSetLocal, 1, kExprGetLocal, 1])
.exportAs("main");
- var buffer = module.toBuffer(debug);
- var instance = Wasm.instantiateModule(buffer);
+ var buffer = builder.toBuffer(debug);
+ var instance = instantiate(buffer);
assertEquals(19, instance.exports.main(19));
assertEquals(27777, instance.exports.main(27777));
}
})();
(function CallTest() {
- var module = new WasmModuleBuilder();
- module.addFunction("add", kSig_i_ii)
+ let builder = new WasmModuleBuilder();
+ builder.addFunction("add", kSig_i_ii)
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add]);
- module.addFunction("main", kSig_i_ii)
+ builder.addFunction("main", kSig_i_ii)
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprCallFunction, 0])
.exportAs("main");
- var instance = module.instantiate();
+ var instance = builder.instantiate();
assertEquals(44, instance.exports.main(11, 33));
assertEquals(7777, instance.exports.main(2222, 5555));
})();
(function IndirectCallTest() {
- var module = new WasmModuleBuilder();
- module.addFunction("add", kSig_i_ii)
+ let builder = new WasmModuleBuilder();
+ builder.addFunction("add", kSig_i_ii)
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add]);
- module.addFunction("main", kSig_i_iii)
+ builder.addFunction("main", kSig_i_iii)
.addBody([kExprGetLocal,
- 1, kExprGetLocal, 2, kExprGetLocal, 0, kExprCallIndirect, 0])
+ 1, kExprGetLocal, 2, kExprGetLocal, 0, kExprCallIndirect, 0, kTableZero])
.exportAs("main");
- module.appendToTable([0]);
+ builder.appendToTable([0]);
- var instance = module.instantiate();
+ var instance = builder.instantiate();
assertEquals(44, instance.exports.main(0, 11, 33));
assertEquals(7777, instance.exports.main(0, 2222, 5555));
assertThrows(function() { instance.exports.main(1, 1, 1); });
})();
(function DataSegmentTest() {
- var module = new WasmModuleBuilder();
- module.addMemory(1, 1, false);
- module.addFunction("load", kSig_i_i)
+ let builder = new WasmModuleBuilder();
+ builder.addMemory(1, 1, false);
+ builder.addFunction("load", kSig_i_i)
.addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
.exportAs("load");
- module.addDataSegment(0, [9, 9, 9, 9], true);
+ builder.addDataSegment(0, [9, 9, 9, 9]);
- var buffer = module.toBuffer(debug);
- var instance = Wasm.instantiateModule(buffer);
+ var buffer = builder.toBuffer(debug);
+ var instance = instantiate(buffer);
assertEquals(151587081, instance.exports.load(0));
})();
(function BasicTestWithUint8Array() {
- var module = new WasmModuleBuilder();
- module.addMemory(1, 2, false);
- module.addFunction("foo", kSig_i)
+ let builder = new WasmModuleBuilder();
+ builder.addMemory(1, 2, false);
+ builder.addFunction("foo", kSig_i_v)
.addBody([kExprI8Const, 17])
.exportAs("blarg");
- var buffer = module.toBuffer(debug);
+ var buffer = builder.toBuffer(debug);
var array = new Uint8Array(buffer);
- var instance = Wasm.instantiateModule(array);
+ var instance = instantiate(array);
assertEquals(17, instance.exports.blarg());
var kPad = 5;
@@ -135,19 +139,19 @@ var debug = true;
for (var i = 0; i < array2.byteLength; i++) {
array2[i] = array[i];
}
- var instance = Wasm.instantiateModule(array2);
+ var instance = instantiate(array2);
assertEquals(17, instance.exports.blarg());
})();
(function ImportTestTwoLevel() {
- var module = new WasmModuleBuilder();
- var index = module.addImportWithModule("mod", "print", makeSig_v_x(kAstI32));
- module.addFunction("foo", kSig_v_v)
+ let builder = new WasmModuleBuilder();
+ var index = builder.addImportWithModule("mod", "print", makeSig_v_x(kAstI32));
+ builder.addFunction("foo", kSig_v_v)
.addBody([kExprI8Const, 19, kExprCallFunction, index])
.exportAs("main");
- var buffer = module.toBuffer(debug);
- var instance = Wasm.instantiateModule(buffer, {mod: {print: print}});
+ var buffer = builder.toBuffer(debug);
+ var instance = instantiate(buffer, {mod: {print: print}});
print("should print 19! ");
instance.exports.main();
})();