| 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: --validate-asm --allow-natives-syntax |
| 6 | 6 |
| 7 var stdlib = this; | 7 var stdlib = this; |
| 8 | 8 |
| 9 function assertValidAsm(func) { |
| 10 assertTrue(%IsAsmWasmCode(func) || |
| 11 %GetOptimizationStatus(func) === 3); |
| 12 } |
| 13 |
| 9 (function TestStdlibConstants() { | 14 (function TestStdlibConstants() { |
| 10 function Module(stdlib) { | 15 function Module(stdlib) { |
| 11 "use asm"; | 16 "use asm"; |
| 12 | 17 |
| 13 var StdlibInfinity = stdlib.Infinity; | 18 var StdlibInfinity = stdlib.Infinity; |
| 14 var StdlibNaN = stdlib.NaN; | 19 var StdlibNaN = stdlib.NaN; |
| 15 var StdlibMathE = stdlib.Math.E; | 20 var StdlibMathE = stdlib.Math.E; |
| 16 var StdlibMathLN10 = stdlib.Math.LN10; | 21 var StdlibMathLN10 = stdlib.Math.LN10; |
| 17 var StdlibMathLN2 = stdlib.Math.LN2; | 22 var StdlibMathLN2 = stdlib.Math.LN2; |
| 18 var StdlibMathLOG2E = stdlib.Math.LOG2E; | 23 var StdlibMathLOG2E = stdlib.Math.LOG2E; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 34 return 1; | 39 return 1; |
| 35 } | 40 } |
| 36 | 41 |
| 37 function nanCheck() { | 42 function nanCheck() { |
| 38 return +StdlibNaN; | 43 return +StdlibNaN; |
| 39 } | 44 } |
| 40 | 45 |
| 41 return {caller:caller, nanCheck:nanCheck}; | 46 return {caller:caller, nanCheck:nanCheck}; |
| 42 } | 47 } |
| 43 | 48 |
| 44 var m = Wasm.instantiateModuleFromAsm(Module.toString(), stdlib); | 49 var m = Module(stdlib); |
| 50 assertValidAsm(Module); |
| 45 assertEquals(1, m.caller()); | 51 assertEquals(1, m.caller()); |
| 46 assertTrue(isNaN(m.nanCheck())); | 52 assertTrue(isNaN(m.nanCheck())); |
| 47 })(); | 53 })(); |
| 48 | 54 |
| 49 | 55 |
| 50 (function TestBadNaNStdlib() { | 56 (function TestBadNaNStdlib() { |
| 51 function Module(stdlib) { | 57 function Module(stdlib) { |
| 52 "use asm"; | 58 "use asm"; |
| 53 var StdlibNaN = stdlib.NaN; | 59 var StdlibNaN = stdlib.NaN; |
| 54 function foo() { return +StdlibNaN; } | 60 function foo() { return +StdlibNaN; } |
| 55 return {}; | 61 return {}; |
| 56 } | 62 } |
| 57 assertThrows(function() { | 63 Module({ NaN: 0 }); |
| 58 Wasm.instantiateModuleFromAsm(Module.toString(), { NaN: 0 }); | 64 assertFalse(%IsAsmWasmCode(Module)); |
| 59 }); | |
| 60 })(); | 65 })(); |
| 61 | 66 |
| 62 | 67 |
| 63 (function TestMissingNaNStdlib() { | 68 (function TestMissingNaNStdlib() { |
| 64 function Module(stdlib) { | 69 function Module(stdlib) { |
| 65 "use asm"; | 70 "use asm"; |
| 66 var StdlibNaN = stdlib.NaN; | 71 var StdlibNaN = stdlib.NaN; |
| 67 function foo() { return +StdlibNaN; } | 72 function foo() { return +StdlibNaN; } |
| 68 return {}; | 73 return {}; |
| 69 } | 74 } |
| 70 assertThrows(function() { | 75 Module({}); |
| 71 Wasm.instantiateModuleFromAsm(Module.toString(), {}); | 76 assertFalse(%IsAsmWasmCode(Module)); |
| 72 }); | |
| 73 })(); | 77 })(); |
| 74 | 78 |
| 75 | 79 |
| 76 (function TestStdlibFunctionsInside() { | 80 (function TestStdlibFunctionsInside() { |
| 77 function Module(stdlib) { | 81 function Module(stdlib) { |
| 78 "use asm"; | 82 "use asm"; |
| 79 | 83 |
| 80 var StdlibMathCeil = stdlib.Math.ceil; | 84 var StdlibMathCeil = stdlib.Math.ceil; |
| 81 var StdlibMathClz32 = stdlib.Math.clz32; | 85 var StdlibMathClz32 = stdlib.Math.clz32; |
| 82 var StdlibMathFloor = stdlib.Math.floor; | 86 var StdlibMathFloor = stdlib.Math.floor; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 if (!(deltaEqual(+StdlibMathAtan2(6.0, 7.0), 0.7086262721276703)|0)) | 145 if (!(deltaEqual(+StdlibMathAtan2(6.0, 7.0), 0.7086262721276703)|0)) |
| 142 return 0; | 146 return 0; |
| 143 if (+StdlibMathPow(6.0, 7.0) != 279936.0) return 0; | 147 if (+StdlibMathPow(6.0, 7.0) != 279936.0) return 0; |
| 144 | 148 |
| 145 return 1; | 149 return 1; |
| 146 } | 150 } |
| 147 | 151 |
| 148 return {caller:caller}; | 152 return {caller:caller}; |
| 149 } | 153 } |
| 150 | 154 |
| 151 var m = Wasm.instantiateModuleFromAsm(Module.toString(), stdlib); | 155 var m = Module(stdlib); |
| 156 assertValidAsm(Module); |
| 152 assertEquals(1, m.caller()); | 157 assertEquals(1, m.caller()); |
| 153 })(); | 158 })(); |
| 154 | 159 |
| 155 | 160 |
| 156 (function TestStdlibFunctionOutside() { | 161 (function TestStdlibFunctionOutside() { |
| 157 function looseEqual(x, y, delta) { | 162 function looseEqual(x, y, delta) { |
| 158 if (delta === undefined) { | 163 if (delta === undefined) { |
| 159 delta = 1.0e-10; | 164 delta = 1.0e-10; |
| 160 } | 165 } |
| 161 if (isNaN(x) && isNaN(y)) { | 166 if (isNaN(x) && isNaN(y)) { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 fround2_f32: fround2_f32, | 290 fround2_f32: fround2_f32, |
| 286 fround2_f64: fround2_f64, | 291 fround2_f64: fround2_f64, |
| 287 min_i32: min_i32, | 292 min_i32: min_i32, |
| 288 min_f32: min_f32, | 293 min_f32: min_f32, |
| 289 min_f64: min_f64, | 294 min_f64: min_f64, |
| 290 max_i32: max_i32, | 295 max_i32: max_i32, |
| 291 max_f32: max_f32, | 296 max_f32: max_f32, |
| 292 max_f64: max_f64, | 297 max_f64: max_f64, |
| 293 }; | 298 }; |
| 294 } | 299 } |
| 295 var m = Wasm.instantiateModuleFromAsm(Module.toString(), stdlib); | 300 var m = Module(stdlib); |
| 301 assertValidAsm(Module); |
| 296 var values = { | 302 var values = { |
| 297 i32: [ | 303 i32: [ |
| 298 0, 1, -1, 123, 456, -123, -456, | 304 0, 1, -1, 123, 456, -123, -456, |
| 299 0x40000000, 0x7FFFFFFF, -0x80000000, | 305 0x40000000, 0x7FFFFFFF, -0x80000000, |
| 300 ], | 306 ], |
| 301 u32: [ | 307 u32: [ |
| 302 0, 1, 123, 456, | 308 0, 1, 123, 456, |
| 303 0x40000000, 0x7FFFFFFF, 0xFFFFFFFF, 0x80000000, | 309 0x40000000, 0x7FFFFFFF, 0xFFFFFFFF, 0x80000000, |
| 304 ], | 310 ], |
| 305 f32: [ | 311 f32: [ |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 if (!compare(expected, actual)) { | 386 if (!compare(expected, actual)) { |
| 381 print(expected + ' !== ' + actual + ' for ' + name + | 387 print(expected + ' !== ' + actual + ' for ' + name + |
| 382 ' with input ' + val0 + ' ' + val1); | 388 ' with input ' + val0 + ' ' + val1); |
| 383 assertTrue(false); | 389 assertTrue(false); |
| 384 } | 390 } |
| 385 } | 391 } |
| 386 } | 392 } |
| 387 } | 393 } |
| 388 } | 394 } |
| 389 })(); | 395 })(); |
| OLD | NEW |