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

Unified Diff: test/mjsunit/wasm/indirect-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/ffi-error.js ('k') | test/mjsunit/wasm/instantiate-module-basic.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/wasm/indirect-calls.js
diff --git a/test/mjsunit/wasm/indirect-calls.js b/test/mjsunit/wasm/indirect-calls.js
new file mode 100644
index 0000000000000000000000000000000000000000..948504cc51e773731cad2d4c77ae4e1ef83eed8e
--- /dev/null
+++ b/test/mjsunit/wasm/indirect-calls.js
@@ -0,0 +1,71 @@
+// 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 kFuncWithBody = 9;
+ var kFuncImported = 7;
+ var kBodySize1 = 5;
+ var kBodySize2 = 8;
+ var kFuncTableSize = 8;
+ var kSubOffset = 13 + kFuncWithBody + kBodySize1 + kFuncImported + kFuncWithBody + kBodySize2 + kFuncTableSize + 1;
+ var kAddOffset = kSubOffset + 4;
+ var kMainOffset = kAddOffset + 4;
+
+ var ffi = new Object();
+ ffi.add = (function(a, b) { return a + b | 0; });
+
+ return WASM.instantiateModule(bytes(
+ // -- signatures
+ kDeclSignatures, 2,
+ 2, kAstI32, kAstI32, kAstI32, // int, int -> int
+ 3, kAstI32, kAstI32, kAstI32, kAstI32, // int, int, int -> int
+ // -- function #0 (sub)
+ kDeclFunctions, 3,
+ kDeclFunctionName,
+ 0, 0, // signature offset
+ kSubOffset, 0, 0, 0, // name offset
+ kBodySize1, 0, // body size
+ kExprI32Sub, // --
+ kExprGetLocal, 0, // --
+ kExprGetLocal, 1, // --
+ // -- function #1 (add)
+ kDeclFunctionName | kDeclFunctionImport,
+ 0, 0, // signature offset
+ kAddOffset, 0, 0, 0, // name offset
+ // -- function #2 (main)
+ kDeclFunctionName | kDeclFunctionExport,
+ 1, 0, // signature offset
+ kMainOffset, 0, 0, 0, // name offset
+ kBodySize2, 0, // body size
+ kExprCallIndirect, 0,
+ kExprGetLocal, 0,
+ kExprGetLocal, 1,
+ kExprGetLocal, 2,
+ // -- function table
+ kDeclFunctionTable,
+ 3,
+ 0, 0,
+ 1, 0,
+ 2, 0,
+ kDeclEnd,
+ 's', 'u', 'b', 0, // name
+ 'a', 'd', 'd', 0, // name
+ 'm', 'a', 'i', 'n', 0 // name
+ ), ffi);
+})();
+
+// Check the module exists.
+assertFalse(module === undefined);
+assertFalse(module === null);
+assertFalse(module === 0);
+assertEquals("object", typeof module);
+assertEquals("function", typeof module.main);
+
+assertEquals(5, module.main(0, 12, 7));
+assertEquals(19, module.main(1, 12, 7));
+
+assertTraps(kTrapFuncSigMismatch, "module.main(2, 12, 33)");
+assertTraps(kTrapFuncInvalid, "module.main(3, 12, 33)");
« no previous file with comments | « test/mjsunit/wasm/ffi-error.js ('k') | test/mjsunit/wasm/instantiate-module-basic.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698