Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1751)

Unified Diff: test/mjsunit/wasm/calls.js

Issue 1504713014: Initial import of v8-native WASM. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/wasm/asm-wasm.js ('k') | test/mjsunit/wasm/compile-run-basic.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/wasm/calls.js
diff --git a/test/mjsunit/wasm/calls.js b/test/mjsunit/wasm/calls.js
new file mode 100644
index 0000000000000000000000000000000000000000..41d2529e253f98e35397ea0d58133e5500d51ed2
--- /dev/null
+++ b/test/mjsunit/wasm/calls.js
@@ -0,0 +1,143 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+load("test/mjsunit/wasm/wasm-constants.js");
+
+var module = (function () {
+ var kBodySize = 5;
+ var kNameOffset = 21 + kBodySize + 1;
+
+ return WASM.instantiateModule(bytes(
+ // -- memory
+ kDeclMemory,
+ 12, 12, 1,
+ // -- signatures
+ kDeclSignatures, 1,
+ 2, kAstI32, kAstI32, kAstI32, // int, int -> int
+ // -- functions
+ kDeclFunctions, 1,
+ kDeclFunctionName | kDeclFunctionExport,
+ 0, 0,
+ kNameOffset, 0, 0, 0, // name offset
+ kBodySize, 0,
+ // -- body
+ kExprI32Sub, // --
+ kExprGetLocal, 0, // --
+ kExprGetLocal, 1, // --
+ kDeclEnd,
+ 's', 'u', 'b', 0 // name
+ ));
+})();
+
+// Check the module exists.
+assertFalse(module === undefined);
+assertFalse(module === null);
+assertFalse(module === 0);
+assertEquals("object", typeof module);
+
+// Check the memory is an ArrayBuffer.
+var mem = module.memory;
+assertFalse(mem === undefined);
+assertFalse(mem === null);
+assertFalse(mem === 0);
+assertEquals("object", typeof mem);
+assertTrue(mem instanceof ArrayBuffer);
+for (var i = 0; i < 4; i++) {
+ module.memory = 0; // should be ignored
+ assertEquals(mem, module.memory);
+}
+
+assertEquals(4096, module.memory.byteLength);
+
+// Check the properties of the sub function.
+assertEquals("function", typeof module.sub);
+
+assertEquals(-55, module.sub(33, 88));
+assertEquals(-55555, module.sub(33333, 88888));
+assertEquals(-5555555, module.sub(3333333, 8888888));
+
+
+var module = (function() {
+ var kBodySize = 1;
+ var kNameOffset2 = 19 + kBodySize + 1;
+
+ return WASM.instantiateModule(bytes(
+ // -- memory
+ kDeclMemory,
+ 12, 12, 1,
+ // -- signatures
+ kDeclSignatures, 1,
+ 0, kAstStmt, // signature: void -> void
+ // -- functions
+ kDeclFunctions, 1,
+ kDeclFunctionName | kDeclFunctionExport,
+ 0, 0, // signature index
+ kNameOffset2, 0, 0, 0, // name offset
+ kBodySize, 0,
+ kExprNop, // body
+ kDeclEnd,
+ 'n', 'o', 'p', 0 // name
+ ));
+})();
+
+// Check the module exists.
+assertFalse(module === undefined);
+assertFalse(module === null);
+assertFalse(module === 0);
+assertEquals("object", typeof module);
+
+// Check the memory is an ArrayBuffer.
+var mem = module.memory;
+assertFalse(mem === undefined);
+assertFalse(mem === null);
+assertFalse(mem === 0);
+assertEquals("object", typeof mem);
+assertTrue(mem instanceof ArrayBuffer);
+for (var i = 0; i < 4; i++) {
+ module.memory = 0; // should be ignored
+ assertEquals(mem, module.memory);
+}
+
+assertEquals(4096, module.memory.byteLength);
+
+// Check the properties of the sub function.
+assertFalse(module.nop === undefined);
+assertFalse(module.nop === null);
+assertFalse(module.nop === 0);
+assertEquals("function", typeof module.nop);
+
+assertEquals(undefined, module.nop());
+
+(function testLt() {
+ var kBodySize = 5;
+ var kNameOffset = 21 + kBodySize + 1;
+
+ var data = bytes(
+ // -- memory
+ kDeclMemory,
+ 12, 12, 1,
+ // -- signatures
+ kDeclSignatures, 1,
+ 2, kAstI32, kAstF64, kAstF64, // (f64,f64)->int
+ // -- functions
+ kDeclFunctions, 1,
+ kDeclFunctionName | kDeclFunctionExport,
+ 0, 0, // signature index
+ kNameOffset, 0, 0, 0, // name offset
+ kBodySize, 0,
+ // -- body
+ kExprF64Lt, // --
+ kExprGetLocal, 0, // --
+ kExprGetLocal, 1, // --
+ kDeclEnd,
+ 'f', 'l', 't', 0 // name
+ );
+
+ var module = WASM.instantiateModule(data);
+
+ assertEquals("function", typeof module.flt);
+ assertEquals(1, module.flt(-2, -1));
+ assertEquals(0, module.flt(7.3, 7.1));
+ assertEquals(1, module.flt(7.1, 7.3));
+})();
« no previous file with comments | « test/mjsunit/wasm/asm-wasm.js ('k') | test/mjsunit/wasm/compile-run-basic.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698