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

Unified Diff: test/mjsunit/wasm/import-memory.js

Issue 2392943006: [wasm] Implement importing of WebAssembly.Memory. (Closed)
Patch Set: Address review comments Created 4 years, 2 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-module-builder.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/wasm/import-memory.js
diff --git a/test/mjsunit/wasm/import-memory.js b/test/mjsunit/wasm/import-memory.js
new file mode 100644
index 0000000000000000000000000000000000000000..30c1acc25a914e1074922bf760b11c300c197326
--- /dev/null
+++ b/test/mjsunit/wasm/import-memory.js
@@ -0,0 +1,82 @@
+// 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");
+load("test/mjsunit/wasm/wasm-module-builder.js");
+
+(function TestOne() {
+ print("TestOne");
+ let memory = new WebAssembly.Memory({initial: 1});
+ assertEquals(kPageSize, memory.buffer.byteLength);
+ let i32 = new Int32Array(memory.buffer);
+ let builder = new WasmModuleBuilder();
+ builder.addImportedMemory("mine");
+ builder.addFunction("main", kSig_i_v)
+ .addBody([
+ kExprI32Const, 0,
+ kExprI32LoadMem, 0, 0])
+ .exportAs("main");
+
+ let main = builder.instantiate({mine: memory}).exports.main;
+ assertEquals(0, main());
+
+ i32[0] = 993377;
+
+ assertEquals(993377, main());
+})();
+
+(function TestIdentity() {
+ print("TestIdentity");
+ let memory = new WebAssembly.Memory({initial: 1});
+ let i32 = new Int32Array(memory.buffer);
+ let builder = new WasmModuleBuilder();
+ builder.addImportedMemory("garg");
+ builder.exportMemoryAs("daggle");
+
+ let instance = builder.instantiate({garg: memory});
+ assertSame(memory, instance.exports.daggle);
+})();
+
+
+(function TestImportExport() {
+ print("TestImportExport");
+ var i1;
+ {
+ let builder = new WasmModuleBuilder();
+ builder.addMemory(1, 1, false);
+ builder.exportMemoryAs("exported_mem");
+ builder.addFunction("foo", kSig_i_i)
+ .addBody([
+ kExprGetLocal, 0,
+ kExprI32LoadMem, 0, 0])
+ .exportAs("foo");
+ i1 = builder.instantiate();
+ }
+
+ var i2;
+ {
+ let builder = new WasmModuleBuilder();
+ builder.addMemory(1, 1, false);
+ builder.addImportedMemory("imported_mem");
+ builder.addFunction("bar", kSig_i_i)
+ .addBody([
+ kExprGetLocal, 0,
+ kExprI32LoadMem, 0, 0])
+ .exportAs("bar");
+ i2 = builder.instantiate({imported_mem: i1.exports.exported_mem});
+ }
+
+ let i32 = new Int32Array(i1.exports.exported_mem.buffer);
+
+ for (var i = 0; i < 1e11; i = i * 3 + 5) {
+ for (var j = 0; j < 10; j++) {
+ var val = i + 99077 + j;
+ i32[j] = val;
+ assertEquals(val | 0, i1.exports.foo(j * 4));
+ assertEquals(val | 0, i2.exports.bar(j * 4));
+ }
+ }
+})();
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | test/mjsunit/wasm/wasm-module-builder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698