| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 | 8 |
| 9 function runSelect2(module, which, a, b) { | 9 function runSelect2(module, which, a, b) { |
| 10 assertEquals(which == 0 ? a : b, module.select(a, b)); | 10 assertEquals(which == 0 ? a : b, module.select(a, b)); |
| 11 } | 11 } |
| 12 | 12 |
| 13 function testSelect2(type) { | 13 function testSelect2(type) { |
| 14 var kBodySize = 2; | 14 var kBodySize = 3; |
| 15 var kNameOffset = kHeaderSize + 21 + kBodySize + 1; | 15 var kNameOffset = kHeaderSize + 21 + kBodySize + 1; |
| 16 | 16 |
| 17 for (var which = 0; which < 2; which++) { | 17 for (var which = 0; which < 2; which++) { |
| 18 print("type = " + type + ", which = " + which); | 18 print("type = " + type + ", which = " + which); |
| 19 | 19 |
| 20 var data = bytesWithHeader( | 20 var data = bytesWithHeader( |
| 21 // -- memory | 21 // -- memory |
| 22 kDeclMemory, | 22 kDeclMemory, |
| 23 12, 12, 1, // memory | 23 12, 12, 1, // memory |
| 24 // -- signatures | 24 // -- signatures |
| 25 kDeclSignatures, 1, | 25 kDeclSignatures, 1, |
| 26 2, type, type, type, // signature: (t,t)->t | 26 2, type, type, type, // signature: (t,t)->t |
| 27 // -- select | 27 // -- select |
| 28 kDeclFunctions, 1, | 28 kDeclFunctions, 1, |
| 29 kDeclFunctionName | kDeclFunctionExport, | 29 kDeclFunctionName | kDeclFunctionExport, |
| 30 0, 0, | 30 0, 0, |
| 31 kNameOffset, 0, 0, 0, // name offset | 31 kNameOffset, 0, 0, 0, // name offset |
| 32 kBodySize, 0, // body size | 32 kBodySize, 0, // body size |
| 33 kDeclNoLocals, |
| 33 kExprGetLocal, which, // -- | 34 kExprGetLocal, which, // -- |
| 34 kDeclEnd, | 35 kDeclEnd, |
| 35 's','e','l','e','c','t',0 // name | 36 's','e','l','e','c','t',0 // name |
| 36 ); | 37 ); |
| 37 | 38 |
| 38 var module = _WASMEXP_.instantiateModule(data); | 39 var module = _WASMEXP_.instantiateModule(data); |
| 39 | 40 |
| 40 assertEquals("function", typeof module.select); | 41 assertEquals("function", typeof module.select); |
| 41 runSelect2(module, which, 99, 97); | 42 runSelect2(module, which, 99, 97); |
| 42 runSelect2(module, which, -99, -97); | 43 runSelect2(module, which, -99, -97); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 ]; | 81 ]; |
| 81 | 82 |
| 82 for (var i = 0; i < 10; i++) { | 83 for (var i = 0; i < 10; i++) { |
| 83 if (which == i) assertEquals(a, result[i]); | 84 if (which == i) assertEquals(a, result[i]); |
| 84 else if (which == i+1) assertEquals(b, result[i]); | 85 else if (which == i+1) assertEquals(b, result[i]); |
| 85 else assertEquals(x, result[i]); | 86 else assertEquals(x, result[i]); |
| 86 } | 87 } |
| 87 } | 88 } |
| 88 | 89 |
| 89 function testSelect10(type) { | 90 function testSelect10(type) { |
| 90 var kBodySize = 2; | 91 var kBodySize = 3; |
| 91 var kNameOffset = kHeaderSize + 29 + kBodySize + 1; | 92 var kNameOffset = kHeaderSize + 29 + kBodySize + 1; |
| 92 | 93 |
| 93 for (var which = 0; which < 10; which++) { | 94 for (var which = 0; which < 10; which++) { |
| 94 print("type = " + type + ", which = " + which); | 95 print("type = " + type + ", which = " + which); |
| 95 | 96 |
| 96 var t = type; | 97 var t = type; |
| 97 var data = bytesWithHeader( | 98 var data = bytesWithHeader( |
| 98 kDeclMemory, | 99 kDeclMemory, |
| 99 12, 12, 1, // memory | 100 12, 12, 1, // memory |
| 100 // signatures | 101 // signatures |
| 101 kDeclSignatures, 1, | 102 kDeclSignatures, 1, |
| 102 10, t,t,t,t,t,t,t,t,t,t,t, // (tx10)->t | 103 10, t,t,t,t,t,t,t,t,t,t,t, // (tx10)->t |
| 103 // main function | 104 // main function |
| 104 kDeclFunctions, 1, | 105 kDeclFunctions, 1, |
| 105 kDeclFunctionName | kDeclFunctionExport, | 106 kDeclFunctionName | kDeclFunctionExport, |
| 106 0, 0, | 107 0, 0, |
| 107 kNameOffset, 0, 0, 0, // name offset | 108 kNameOffset, 0, 0, 0, // name offset |
| 108 kBodySize, 0, // body size | 109 kBodySize, 0, // body size |
| 110 kDeclNoLocals, |
| 109 kExprGetLocal, which, // -- | 111 kExprGetLocal, which, // -- |
| 110 kDeclEnd, | 112 kDeclEnd, |
| 111 's','e','l','e','c','t',0 // name | 113 's','e','l','e','c','t',0 // name |
| 112 ); | 114 ); |
| 113 | 115 |
| 114 var module = _WASMEXP_.instantiateModule(data); | 116 var module = _WASMEXP_.instantiateModule(data); |
| 115 | 117 |
| 116 assertEquals("function", typeof module.select); | 118 assertEquals("function", typeof module.select); |
| 117 runSelect10(module, which, 99, 97); | 119 runSelect10(module, which, 99, 97); |
| 118 runSelect10(module, which, -99, -97); | 120 runSelect10(module, which, -99, -97); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 130 runSelect10(module, which, -1.25, 5.25); | 132 runSelect10(module, which, -1.25, 5.25); |
| 131 runSelect10(module, which, Infinity, -Infinity); | 133 runSelect10(module, which, Infinity, -Infinity); |
| 132 } | 134 } |
| 133 } | 135 } |
| 134 } | 136 } |
| 135 | 137 |
| 136 | 138 |
| 137 testSelect10(kAstI32); | 139 testSelect10(kAstI32); |
| 138 testSelect10(kAstF32); | 140 testSelect10(kAstF32); |
| 139 testSelect10(kAstF64); | 141 testSelect10(kAstF64); |
| OLD | NEW |