| 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 var thrower = { [Symbol.toPrimitive]: () => FAIL }; | 5 var thrower = { [Symbol.toPrimitive]: () => FAIL }; |
| 6 | 6 |
| 7 // Tests that a native conversion function is included in the | 7 // Tests that a native conversion function is included in the |
| 8 // stack trace. | 8 // stack trace. |
| 9 function testTraceNativeConversion(nativeFunc) { | 9 function testTraceNativeConversion(nativeFunc) { |
| 10 var nativeFuncName = nativeFunc.name; | 10 var nativeFuncName = nativeFunc.name; |
| 11 try { | 11 try { |
| 12 nativeFunc(thrower); | 12 nativeFunc(thrower); |
| 13 assertUnreachable(nativeFuncName); | 13 assertUnreachable(nativeFuncName); |
| 14 } catch (e) { | 14 } catch (e) { |
| 15 assertTrue(e.stack.indexOf(nativeFuncName) >= 0, nativeFuncName); | 15 assertTrue(e.stack.indexOf(nativeFuncName) >= 0, nativeFuncName); |
| 16 } | 16 } |
| 17 } | 17 } |
| 18 | 18 |
| 19 testTraceNativeConversion(Math.max); | 19 testTraceNativeConversion(Math.max); |
| 20 testTraceNativeConversion(Math.min); | 20 testTraceNativeConversion(Math.min); |
| 21 | 21 |
| 22 // C++ builtins. | |
| 23 testTraceNativeConversion(Math.acos); | |
| 24 testTraceNativeConversion(Math.asin); | |
| 25 testTraceNativeConversion(Math.fround); | |
| 26 testTraceNativeConversion(Math.imul); | |
| 27 | |
| 28 | |
| 29 function testBuiltinInStackTrace(script, expectedString) { | 22 function testBuiltinInStackTrace(script, expectedString) { |
| 30 try { | 23 try { |
| 31 eval(script); | 24 eval(script); |
| 32 assertUnreachable(expectedString); | 25 assertUnreachable(expectedString); |
| 33 } catch (e) { | 26 } catch (e) { |
| 34 assertTrue(e.stack.indexOf(expectedString) >= 0, expectedString); | 27 assertTrue(e.stack.indexOf(expectedString) >= 0, expectedString); |
| 35 } | 28 } |
| 36 } | 29 } |
| 37 | 30 |
| 38 // Use the full name ('String.getDate') in order to avoid false pass | |
| 39 // results when the method name is mentioned in the error message itself. | |
| 40 // This occurs, e.g., for Date.prototype.getYear, which uses a different code | |
| 41 // path and never hits the Generate_DatePrototype_GetField builtin. | |
| 42 testBuiltinInStackTrace("Date.prototype.getDate.call('')", "at String.getDate"); | 31 testBuiltinInStackTrace("Date.prototype.getDate.call('')", "at String.getDate"); |
| 43 testBuiltinInStackTrace("Date.prototype.getUTCDate.call('')", | 32 testBuiltinInStackTrace("Date.prototype.getUTCDate.call('')", |
| 44 "at String.getUTCDate"); | 33 "at String.getUTCDate"); |
| 45 testBuiltinInStackTrace("Date.prototype.getTime.call('')", "at String.getTime"); | 34 testBuiltinInStackTrace("Date.prototype.getTime.call('')", "at String.getTime"); |
| 46 | 35 |
| 47 // C++ builtins. | 36 // TODO(jgruber): These use a more generic expected string until detection of |
| 48 testBuiltinInStackTrace("Boolean.prototype.toString.call(thrower);", | 37 // assembly builtin constructors is fixed. |
| 49 "at Object.toString"); | 38 testBuiltinInStackTrace("Number(thrower);", "Number"); |
| 50 | 39 testBuiltinInStackTrace("new Number(thrower);", "Number"); |
| 51 // Constructor builtins. | 40 testBuiltinInStackTrace("String(thrower);", "String"); |
| 52 testBuiltinInStackTrace("new Date(thrower);", "at new Date"); | 41 testBuiltinInStackTrace("new String(thrower);", "String"); |
| 53 | 42 |
| 54 // Ensure we correctly pick up the receiver's string tag. | 43 // Ensure we correctly pick up the receiver's string tag. |
| 55 testBuiltinInStackTrace("Math.max(thrower);", "at Math.max"); | |
| 56 testBuiltinInStackTrace("Math.min(thrower);", "at Math.min"); | |
| 57 testBuiltinInStackTrace("Math.acos(thrower);", "at Math.acos"); | 44 testBuiltinInStackTrace("Math.acos(thrower);", "at Math.acos"); |
| 58 testBuiltinInStackTrace("Math.asin(thrower);", "at Math.asin"); | 45 testBuiltinInStackTrace("Math.asin(thrower);", "at Math.asin"); |
| 59 testBuiltinInStackTrace("Math.fround(thrower);", "at Math.fround"); | 46 testBuiltinInStackTrace("Math.fround(thrower);", "at Math.fround"); |
| 60 testBuiltinInStackTrace("Math.imul(thrower);", "at Math.imul"); | 47 testBuiltinInStackTrace("Math.imul(thrower);", "at Math.imul"); |
| 61 | 48 |
| 62 // As above, but function passed as an argument and then called. | 49 // As above, but function passed as an argument and then called. |
| 63 testBuiltinInStackTrace("((f, x) => f(x))(Math.max, thrower);", "at max"); | |
| 64 testBuiltinInStackTrace("((f, x) => f(x))(Math.min, thrower);", "at min"); | |
| 65 testBuiltinInStackTrace("((f, x) => f(x))(Math.acos, thrower);", "at acos"); | 50 testBuiltinInStackTrace("((f, x) => f(x))(Math.acos, thrower);", "at acos"); |
| 66 testBuiltinInStackTrace("((f, x) => f(x))(Math.asin, thrower);", "at asin"); | 51 testBuiltinInStackTrace("((f, x) => f(x))(Math.asin, thrower);", "at asin"); |
| 67 testBuiltinInStackTrace("((f, x) => f(x))(Math.fround, thrower);", "at fround"); | 52 testBuiltinInStackTrace("((f, x) => f(x))(Math.fround, thrower);", "at fround"); |
| 68 testBuiltinInStackTrace("((f, x) => f(x))(Math.imul, thrower);", "at imul"); | 53 testBuiltinInStackTrace("((f, x) => f(x))(Math.imul, thrower);", "at imul"); |
| OLD | NEW |