| 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 = false; | 10 var debug = false; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 0, kExprGetLocal, 1, kExprGetLocal, 2, kExprCallIndirect, kAri
ty2, 0]) | 92 0, kExprGetLocal, 1, kExprGetLocal, 2, kExprCallIndirect, kAri
ty2, 0]) |
| 93 .exportAs("main"); | 93 .exportAs("main"); |
| 94 module.appendToFunctionTable([0]); | 94 module.appendToFunctionTable([0]); |
| 95 | 95 |
| 96 var instance = module.instantiate(); | 96 var instance = module.instantiate(); |
| 97 assertEquals(44, instance.exports.main(0, 11, 33)); | 97 assertEquals(44, instance.exports.main(0, 11, 33)); |
| 98 assertEquals(7777, instance.exports.main(0, 2222, 5555)); | 98 assertEquals(7777, instance.exports.main(0, 2222, 5555)); |
| 99 assertThrows(function() { instance.exports.main(1, 1, 1); }); | 99 assertThrows(function() { instance.exports.main(1, 1, 1); }); |
| 100 })(); | 100 })(); |
| 101 | 101 |
| 102 (function SimdSplatExtractTest() { |
| 103 print("simd test"); |
| 104 var module = new WasmModuleBuilder(); |
| 105 module.addFunction("splatextract", kSig_i_ii) |
| 106 .addBody([kExprGetLocal, 0, kExprInt32x4Splat, |
| 107 kExprGetLocal, 1, kExprInt32x4ExtractLane]) |
| 108 .exportAs("main"); |
| 109 var instance = module.instantiate(); |
| 110 assertEquals(123, instance.exports.main(123, 2)); |
| 111 })(); |
| 112 |
| 102 (function DataSegmentTest() { | 113 (function DataSegmentTest() { |
| 103 var module = new WasmModuleBuilder(); | 114 var module = new WasmModuleBuilder(); |
| 104 module.addMemory(1, 1, false); | 115 module.addMemory(1, 1, false); |
| 105 module.addFunction("load", kSig_i_i) | 116 module.addFunction("load", kSig_i_i) |
| 106 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) | 117 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) |
| 107 .exportAs("load"); | 118 .exportAs("load"); |
| 108 module.addDataSegment(0, [9, 9, 9, 9], true); | 119 module.addDataSegment(0, [9, 9, 9, 9], true); |
| 109 | 120 |
| 110 var buffer = module.toBuffer(debug); | 121 var buffer = module.toBuffer(debug); |
| 111 var instance = Wasm.instantiateModule(buffer); | 122 var instance = Wasm.instantiateModule(buffer); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 var index = module.addImportWithModule("mod", "print", makeSig_v_x(kAstI32))
; | 155 var index = module.addImportWithModule("mod", "print", makeSig_v_x(kAstI32))
; |
| 145 module.addFunction("foo", kSig_v_v) | 156 module.addFunction("foo", kSig_v_v) |
| 146 .addBody([kExprI8Const, 19, kExprCallImport, kArity1, index]) | 157 .addBody([kExprI8Const, 19, kExprCallImport, kArity1, index]) |
| 147 .exportAs("main"); | 158 .exportAs("main"); |
| 148 | 159 |
| 149 var buffer = module.toBuffer(debug); | 160 var buffer = module.toBuffer(debug); |
| 150 var instance = Wasm.instantiateModule(buffer, {mod: {print: print}}); | 161 var instance = Wasm.instantiateModule(buffer, {mod: {print: print}}); |
| 151 print("should print 19! "); | 162 print("should print 19! "); |
| 152 instance.exports.main(); | 163 instance.exports.main(); |
| 153 })(); | 164 })(); |
| OLD | NEW |