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

Unified Diff: test/mjsunit/wasm/export-table.js

Issue 1744713003: [wasm] Add an export table. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months 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 | « src/wasm/wasm-module.cc ('k') | test/mjsunit/wasm/wasm-constants.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/wasm/export-table.js
diff --git a/test/mjsunit/wasm/export-table.js b/test/mjsunit/wasm/export-table.js
new file mode 100644
index 0000000000000000000000000000000000000000..a3650d169f83e910731db5d7c351ecd98639752c
--- /dev/null
+++ b/test/mjsunit/wasm/export-table.js
@@ -0,0 +1,89 @@
+// Copyright 2016 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.
+
+// Flags: --expose-wasm
+
+load("test/mjsunit/wasm/wasm-constants.js");
+
+(function testExportedMain() {
+ var kBodySize = 3;
+ var kReturnValue = 99;
+ var kNameMainOffset = 4 + 7 + kBodySize + 8 + 1;
+
+ var data = bytes(
+ // signatures
+ kDeclSignatures, 1,
+ 0, kAstI32, // void -> i32
+ // -- main function
+ kDeclFunctions,
+ 1,
+ 0, // decl flags
+ 0, 0, // signature index
+ kBodySize, 0,
+ // main body
+ kExprReturn,
+ kExprI8Const,
+ kReturnValue,
+ // exports
+ kDeclExportTable,
+ 1,
+ 0, 0, // func index index
+ kNameMainOffset, 0, 0, 0, // function name offset
+ // names
+ kDeclEnd,
+ 'm', 'a', 'i', 'n', 0 // --
+ );
+
+ var ffi = new Object();
+ var module = _WASMEXP_.instantiateModule(data, ffi);
+
+ assertEquals("object", typeof module.exports);
+ assertEquals("function", typeof module.exports.main);
+
+ assertEquals(kReturnValue, module.exports.main());
+})();
+
+(function testExportedTwice() {
+ var kBodySize = 3;
+ var kReturnValue = 99;
+ var kNameMainOffset = 4 + 7 + kBodySize + 14 + 1;
+ var kNameFooOffset = kNameMainOffset + 5;
+
+ var data = bytes(
+ // signatures
+ kDeclSignatures, 1,
+ 0, kAstI32, // void -> i32
+ // -- main function
+ kDeclFunctions,
+ 1,
+ 0, // decl flags
+ 0, 0, // signature index
+ kBodySize, 0,
+ // main body
+ kExprReturn,
+ kExprI8Const,
+ kReturnValue,
+ // exports
+ kDeclExportTable,
+ 2,
+ 0, 0, // func index index
+ kNameMainOffset, 0, 0, 0, // function name offset
+ 0, 0, // func index index
+ kNameFooOffset, 0, 0, 0, // function name offset
+ // names
+ kDeclEnd,
+ 'b', 'l', 'a', 'h', 0, // --
+ 'f', 'o', 'o', 0 // --
+ );
+
+ var ffi = new Object();
+ var module = _WASMEXP_.instantiateModule(data, ffi);
+
+ assertEquals("object", typeof module.exports);
+ assertEquals("function", typeof module.exports.blah);
+ assertEquals("function", typeof module.exports.foo);
+
+ assertEquals(kReturnValue, module.exports.blah());
+ assertEquals(kReturnValue, module.exports.foo());
+})();
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | test/mjsunit/wasm/wasm-constants.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698