OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
6 | 6 |
7 load("test/mjsunit/wasm/wasm-constants.js"); | 7 load("test/mjsunit/wasm/wasm-constants.js"); |
8 load("test/mjsunit/wasm/wasm-module-builder.js"); | 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
9 | 9 |
10 function instantiate(sig, body) { | 10 function instantiate(sig, body) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 })(); | 72 })(); |
73 | 73 |
74 | 74 |
75 (function testRun() { | 75 (function testRun() { |
76 print("testRun"); | 76 print("testRun"); |
77 var builder = new WasmModuleBuilder(); | 77 var builder = new WasmModuleBuilder(); |
78 | 78 |
79 builder.addMemory(12, 12, true); | 79 builder.addMemory(12, 12, true); |
80 | 80 |
81 var func = builder.addFunction("", [kAstStmt]) | 81 var func = builder.addFunction("", [kAstStmt]) |
82 .addBody([kExprI32StoreMem, 0, 0, kExprI8Const, 0, kExprI8Const, 77]); | 82 .addBody([kExprI8Const, 0, kExprI8Const, 77, kExprI32StoreMem, 0, 0]); |
83 | 83 |
84 builder.addStart(func.index); | 84 builder.addStart(func.index); |
85 | 85 |
86 var module = builder.instantiate(); | 86 var module = builder.instantiate(); |
87 var memory = module.exports.memory; | 87 var memory = module.exports.memory; |
88 var view = new Int8Array(memory); | 88 var view = new Int8Array(memory); |
89 assertEquals(77, view[0]); | 89 assertEquals(77, view[0]); |
90 })(); | 90 })(); |
91 | 91 |
92 (function testStartFFI() { | 92 (function testStartFFI() { |
93 print("testStartFFI"); | 93 print("testStartFFI"); |
94 var ranned = false; | 94 var ranned = false; |
95 var ffi = { foo : function() { | 95 var ffi = { foo : function() { |
96 print("we ranned at stert!"); | 96 print("we ranned at stert!"); |
97 ranned = true; | 97 ranned = true; |
98 }}; | 98 }}; |
99 | 99 |
100 var builder = new WasmModuleBuilder(); | 100 var builder = new WasmModuleBuilder(); |
101 var sig_index = builder.addSignature([kAstStmt]); | 101 var sig_index = builder.addSignature([kAstStmt]); |
102 | 102 |
103 builder.addImport("foo", sig_index); | 103 builder.addImport("foo", sig_index); |
104 var func = builder.addFunction("", sig_index) | 104 var func = builder.addFunction("", sig_index) |
105 .addBody([kExprCallImport, 0]); | 105 .addBody([kExprCallImport, kArity0, 0]); |
106 | 106 |
107 builder.addStart(func.index); | 107 builder.addStart(func.index); |
108 | 108 |
109 var module = builder.instantiate(ffi); | 109 var module = builder.instantiate(ffi); |
110 assertTrue(ranned); | 110 assertTrue(ranned); |
111 })(); | 111 })(); |
OLD | NEW |