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 var debug = true; | 10 var debug = true; |
11 | 11 |
12 (function BasicTest() { | 12 (function BasicTest() { |
13 var module = new WasmModuleBuilder(); | 13 var module = new WasmModuleBuilder(); |
14 module.addMemory(1, 2, false); | 14 module.addMemory(1, 2, false); |
15 module.addFunction("foo", kSig_i_v) | 15 module.addFunction("foo", kSig_i) |
16 .addBody([kExprI8Const, 11]) | 16 .addBody([kExprI8Const, 11]) |
17 .exportAs("blarg"); | 17 .exportAs("blarg"); |
18 | 18 |
19 var buffer = module.toBuffer(debug); | 19 var buffer = module.toBuffer(debug); |
20 var instance = Wasm.instantiateModule(buffer); | 20 var instance = Wasm.instantiateModule(buffer); |
21 assertEquals(11, instance.exports.blarg()); | 21 assertEquals(11, instance.exports.blarg()); |
22 })(); | 22 })(); |
23 | 23 |
24 (function ImportTest() { | 24 (function ImportTest() { |
25 var module = new WasmModuleBuilder(); | 25 var module = new WasmModuleBuilder(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 var buffer = module.toBuffer(debug); | 110 var buffer = module.toBuffer(debug); |
111 var instance = Wasm.instantiateModule(buffer); | 111 var instance = Wasm.instantiateModule(buffer); |
112 assertEquals(151587081, instance.exports.load(0)); | 112 assertEquals(151587081, instance.exports.load(0)); |
113 })(); | 113 })(); |
114 | 114 |
115 | 115 |
116 (function BasicTestWithUint8Array() { | 116 (function BasicTestWithUint8Array() { |
117 var module = new WasmModuleBuilder(); | 117 var module = new WasmModuleBuilder(); |
118 module.addMemory(1, 2, false); | 118 module.addMemory(1, 2, false); |
119 module.addFunction("foo", kSig_i_v) | 119 module.addFunction("foo", kSig_i) |
120 .addBody([kExprI8Const, 17]) | 120 .addBody([kExprI8Const, 17]) |
121 .exportAs("blarg"); | 121 .exportAs("blarg"); |
122 | 122 |
123 var buffer = module.toBuffer(debug); | 123 var buffer = module.toBuffer(debug); |
124 var array = new Uint8Array(buffer); | 124 var array = new Uint8Array(buffer); |
125 var instance = Wasm.instantiateModule(array); | 125 var instance = Wasm.instantiateModule(array); |
126 assertEquals(17, instance.exports.blarg()); | 126 assertEquals(17, instance.exports.blarg()); |
127 | 127 |
128 var kPad = 5; | 128 var kPad = 5; |
129 var buffer2 = new ArrayBuffer(kPad + buffer.byteLength + kPad); | 129 var buffer2 = new ArrayBuffer(kPad + buffer.byteLength + kPad); |
(...skipping 14 matching lines...) Expand all Loading... |
144 var index = module.addImportWithModule("mod", "print", makeSig_v_x(kAstI32))
; | 144 var index = module.addImportWithModule("mod", "print", makeSig_v_x(kAstI32))
; |
145 module.addFunction("foo", kSig_v_v) | 145 module.addFunction("foo", kSig_v_v) |
146 .addBody([kExprI8Const, 19, kExprCallFunction, index]) | 146 .addBody([kExprI8Const, 19, kExprCallFunction, index]) |
147 .exportAs("main"); | 147 .exportAs("main"); |
148 | 148 |
149 var buffer = module.toBuffer(debug); | 149 var buffer = module.toBuffer(debug); |
150 var instance = Wasm.instantiateModule(buffer, {mod: {print: print}}); | 150 var instance = Wasm.instantiateModule(buffer, {mod: {print: print}}); |
151 print("should print 19! "); | 151 print("should print 19! "); |
152 instance.exports.main(); | 152 instance.exports.main(); |
153 })(); | 153 })(); |
OLD | NEW |