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 var stdlib = this; |
| 8 |
7 (function TestStdlibConstants() { | 9 (function TestStdlibConstants() { |
8 function Module(stdlib) { | 10 function Module(stdlib) { |
9 "use asm"; | 11 "use asm"; |
10 | 12 |
11 var StdlibInfinity = stdlib.Infinity; | 13 var StdlibInfinity = stdlib.Infinity; |
12 var StdlibNaN = stdlib.NaN; | 14 var StdlibNaN = stdlib.NaN; |
13 var StdlibMathE = stdlib.Math.E; | 15 var StdlibMathE = stdlib.Math.E; |
14 var StdlibMathLN10 = stdlib.Math.LN10; | 16 var StdlibMathLN10 = stdlib.Math.LN10; |
15 var StdlibMathLN2 = stdlib.Math.LN2; | 17 var StdlibMathLN2 = stdlib.Math.LN2; |
16 var StdlibMathLOG2E = stdlib.Math.LOG2E; | 18 var StdlibMathLOG2E = stdlib.Math.LOG2E; |
(...skipping 15 matching lines...) Expand all Loading... |
32 return 1; | 34 return 1; |
33 } | 35 } |
34 | 36 |
35 function nanCheck() { | 37 function nanCheck() { |
36 return +StdlibNaN; | 38 return +StdlibNaN; |
37 } | 39 } |
38 | 40 |
39 return {caller:caller, nanCheck:nanCheck}; | 41 return {caller:caller, nanCheck:nanCheck}; |
40 } | 42 } |
41 | 43 |
42 var m =Wasm.instantiateModuleFromAsm(Module.toString()); | 44 var m = Wasm.instantiateModuleFromAsm(Module.toString(), stdlib); |
43 assertEquals(1, m.caller()); | 45 assertEquals(1, m.caller()); |
44 assertTrue(isNaN(m.nanCheck())); | 46 assertTrue(isNaN(m.nanCheck())); |
45 })(); | 47 })(); |
46 | 48 |
47 | 49 |
| 50 (function TestBadNaNStdlib() { |
| 51 function Module(stdlib) { |
| 52 "use asm"; |
| 53 var StdlibNaN = stdlib.NaN; |
| 54 function foo() { return +StdlibNaN; } |
| 55 return {}; |
| 56 } |
| 57 assertThrows(function() { |
| 58 Wasm.instantiateModuleFromAsm(Module.toString(), { NaN: 0 }); |
| 59 }); |
| 60 })(); |
| 61 |
| 62 |
| 63 (function TestMissingNaNStdlib() { |
| 64 function Module(stdlib) { |
| 65 "use asm"; |
| 66 var StdlibNaN = stdlib.NaN; |
| 67 function foo() { return +StdlibNaN; } |
| 68 return {}; |
| 69 } |
| 70 assertThrows(function() { |
| 71 Wasm.instantiateModuleFromAsm(Module.toString(), {}); |
| 72 }); |
| 73 })(); |
| 74 |
| 75 |
48 (function TestStdlibFunctionsInside() { | 76 (function TestStdlibFunctionsInside() { |
49 function Module(stdlib) { | 77 function Module(stdlib) { |
50 "use asm"; | 78 "use asm"; |
51 | 79 |
52 var StdlibMathCeil = stdlib.Math.ceil; | 80 var StdlibMathCeil = stdlib.Math.ceil; |
53 var StdlibMathClz32 = stdlib.Math.clz32; | 81 var StdlibMathClz32 = stdlib.Math.clz32; |
54 var StdlibMathFloor = stdlib.Math.floor; | 82 var StdlibMathFloor = stdlib.Math.floor; |
55 var StdlibMathSqrt = stdlib.Math.sqrt; | 83 var StdlibMathSqrt = stdlib.Math.sqrt; |
56 var StdlibMathAbs = stdlib.Math.abs; | 84 var StdlibMathAbs = stdlib.Math.abs; |
57 var StdlibMathMin = stdlib.Math.min; | 85 var StdlibMathMin = stdlib.Math.min; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 if (!(deltaEqual(+StdlibMathAtan2(6.0, 7.0), 0.7086262721276703)|0)) | 141 if (!(deltaEqual(+StdlibMathAtan2(6.0, 7.0), 0.7086262721276703)|0)) |
114 return 0; | 142 return 0; |
115 if (+StdlibMathPow(6.0, 7.0) != 279936.0) return 0; | 143 if (+StdlibMathPow(6.0, 7.0) != 279936.0) return 0; |
116 | 144 |
117 return 1; | 145 return 1; |
118 } | 146 } |
119 | 147 |
120 return {caller:caller}; | 148 return {caller:caller}; |
121 } | 149 } |
122 | 150 |
123 var m = Wasm.instantiateModuleFromAsm(Module.toString()); | 151 var m = Wasm.instantiateModuleFromAsm(Module.toString(), stdlib); |
124 assertEquals(1, m.caller()); | 152 assertEquals(1, m.caller()); |
125 })(); | 153 })(); |
126 | 154 |
127 | 155 |
128 (function TestStdlibFunctionOutside() { | 156 (function TestStdlibFunctionOutside() { |
129 function looseEqual(x, y, delta) { | 157 function looseEqual(x, y, delta) { |
130 if (delta === undefined) { | 158 if (delta === undefined) { |
131 delta = 1.0e-10; | 159 delta = 1.0e-10; |
132 } | 160 } |
133 if (isNaN(x) && isNaN(y)) { | 161 if (isNaN(x) && isNaN(y)) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 fround2_f32: fround2_f32, | 285 fround2_f32: fround2_f32, |
258 fround2_f64: fround2_f64, | 286 fround2_f64: fround2_f64, |
259 min_i32: min_i32, | 287 min_i32: min_i32, |
260 min_f32: min_f32, | 288 min_f32: min_f32, |
261 min_f64: min_f64, | 289 min_f64: min_f64, |
262 max_i32: max_i32, | 290 max_i32: max_i32, |
263 max_f32: max_f32, | 291 max_f32: max_f32, |
264 max_f64: max_f64, | 292 max_f64: max_f64, |
265 }; | 293 }; |
266 } | 294 } |
267 var m = Wasm.instantiateModuleFromAsm(Module.toString()); | 295 var m = Wasm.instantiateModuleFromAsm(Module.toString(), stdlib); |
268 var values = { | 296 var values = { |
269 i32: [ | 297 i32: [ |
270 0, 1, -1, 123, 456, -123, -456, | 298 0, 1, -1, 123, 456, -123, -456, |
271 0x40000000, 0x7FFFFFFF, -0x80000000, | 299 0x40000000, 0x7FFFFFFF, -0x80000000, |
272 ], | 300 ], |
273 u32: [ | 301 u32: [ |
274 0, 1, 123, 456, | 302 0, 1, 123, 456, |
275 0x40000000, 0x7FFFFFFF, 0xFFFFFFFF, 0x80000000, | 303 0x40000000, 0x7FFFFFFF, 0xFFFFFFFF, 0x80000000, |
276 ], | 304 ], |
277 f32: [ | 305 f32: [ |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 if (!compare(expected, actual)) { | 380 if (!compare(expected, actual)) { |
353 print(expected + ' !== ' + actual + ' for ' + name + | 381 print(expected + ' !== ' + actual + ' for ' + name + |
354 ' with input ' + val0 + ' ' + val1); | 382 ' with input ' + val0 + ' ' + val1); |
355 assertTrue(false); | 383 assertTrue(false); |
356 } | 384 } |
357 } | 385 } |
358 } | 386 } |
359 } | 387 } |
360 } | 388 } |
361 })(); | 389 })(); |
OLD | NEW |