OLD | NEW |
---|---|
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 function a$b$c$d() { return FAIL; } | 87 function a$b$c$d() { return FAIL; } |
88 function Wookie() { } | 88 function Wookie() { } |
89 Wookie.prototype.d = a$b$c$d; | 89 Wookie.prototype.d = a$b$c$d; |
90 (new Wookie).d(); | 90 (new Wookie).d(); |
91 } | 91 } |
92 | 92 |
93 function testAnonymousMethod() { | 93 function testAnonymousMethod() { |
94 (function () { FAIL }).call([1, 2, 3]); | 94 (function () { FAIL }).call([1, 2, 3]); |
95 } | 95 } |
96 | 96 |
97 function testFunctionName() { | |
98 function gen(name, counter) { | |
99 var f = function foo() { | |
100 if (counter === 0) { | |
101 FAIL; | |
102 } | |
103 gen(name, counter - 1)(); | |
104 } | |
105 if (counter === 4) { | |
106 Object.defineProperty(f, 'name', {get: function(){ throw 239; }}); | |
107 } else if (counter == 3) { | |
108 Object.defineProperty(f, 'name', {value: 'boo' + '_' + counter}); | |
109 } else { | |
110 Object.defineProperty(f, 'name', {writable: true}); | |
111 if (counter === 2) | |
112 f.name = 42; | |
113 else | |
114 f.name = name + '_' + counter; | |
115 } | |
116 return f; | |
117 } | |
118 gen('foo', 4)(); | |
119 } | |
120 | |
97 function CustomError(message, stripPoint) { | 121 function CustomError(message, stripPoint) { |
98 this.message = message; | 122 this.message = message; |
99 Error.captureStackTrace(this, stripPoint); | 123 Error.captureStackTrace(this, stripPoint); |
100 } | 124 } |
101 | 125 |
102 CustomError.prototype.toString = function () { | 126 CustomError.prototype.toString = function () { |
103 return "CustomError: " + this.message; | 127 return "CustomError: " + this.message; |
104 }; | 128 }; |
105 | 129 |
106 function testDefaultCustomError() { | 130 function testDefaultCustomError() { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 testTrace("testNestedEval", testNestedEval, ["eval at Inner (eval at Outer"]); | 278 testTrace("testNestedEval", testNestedEval, ["eval at Inner (eval at Outer"]); |
255 testTrace("testEvalWithSourceURL", testEvalWithSourceURL, | 279 testTrace("testEvalWithSourceURL", testEvalWithSourceURL, |
256 [ "at Doo (res://name:1:18)" ]); | 280 [ "at Doo (res://name:1:18)" ]); |
257 testTrace("testNestedEvalWithSourceURL", testNestedEvalWithSourceURL, | 281 testTrace("testNestedEvalWithSourceURL", testNestedEvalWithSourceURL, |
258 [" at Inner (res://inner-eval:1:20)", | 282 [" at Inner (res://inner-eval:1:20)", |
259 " at Outer (res://outer-eval:1:37)"]); | 283 " at Outer (res://outer-eval:1:37)"]); |
260 testTrace("testValue", testValue, ["at Number.causeError"]); | 284 testTrace("testValue", testValue, ["at Number.causeError"]); |
261 testTrace("testConstructor", testConstructor, ["new Plonk"]); | 285 testTrace("testConstructor", testConstructor, ["new Plonk"]); |
262 testTrace("testRenamedMethod", testRenamedMethod, ["Wookie.a$b$c$d [as d]"]); | 286 testTrace("testRenamedMethod", testRenamedMethod, ["Wookie.a$b$c$d [as d]"]); |
263 testTrace("testAnonymousMethod", testAnonymousMethod, ["Array.<anonymous>"]); | 287 testTrace("testAnonymousMethod", testAnonymousMethod, ["Array.<anonymous>"]); |
288 testTrace("testFunctionName", testFunctionName, | |
289 [" at foo_0 ", " at foo_1", " at foo ", " at boo_3 ", " at foo "]); | |
Yang
2015/03/10 10:48:55
Do we test the inferred name code path? I thought
kozy
2015/03/10 15:26:08
Test added.
| |
264 testTrace("testDefaultCustomError", testDefaultCustomError, | 290 testTrace("testDefaultCustomError", testDefaultCustomError, |
265 ["hep-hey", "new CustomError"], | 291 ["hep-hey", "new CustomError"], |
266 ["collectStackTrace"]); | 292 ["collectStackTrace"]); |
267 testTrace("testStrippedCustomError", testStrippedCustomError, ["hep-hey"], | 293 testTrace("testStrippedCustomError", testStrippedCustomError, ["hep-hey"], |
268 ["new CustomError", "collectStackTrace"]); | 294 ["new CustomError", "collectStackTrace"]); |
269 testTrace("testClassNames", testClassNames, | 295 testTrace("testClassNames", testClassNames, |
270 ["new MyObj", "MyObjCreator.Create"], ["as Create"]); | 296 ["new MyObj", "MyObjCreator.Create"], ["as Create"]); |
271 testCallerCensorship(); | 297 testCallerCensorship(); |
272 testUnintendedCallerCensorship(); | 298 testUnintendedCallerCensorship(); |
273 testErrorsDuringFormatting(); | 299 testErrorsDuringFormatting(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 | 370 |
345 my_error = {}; | 371 my_error = {}; |
346 Object.preventExtensions(my_error); | 372 Object.preventExtensions(my_error); |
347 assertThrows(function() { Error.captureStackTrace(my_error); }); | 373 assertThrows(function() { Error.captureStackTrace(my_error); }); |
348 | 374 |
349 var fake_error = {}; | 375 var fake_error = {}; |
350 my_error = new Error(); | 376 my_error = new Error(); |
351 var stolen_getter = Object.getOwnPropertyDescriptor(my_error, 'stack').get; | 377 var stolen_getter = Object.getOwnPropertyDescriptor(my_error, 'stack').get; |
352 Object.defineProperty(fake_error, 'stack', { get: stolen_getter }); | 378 Object.defineProperty(fake_error, 'stack', { get: stolen_getter }); |
353 assertEquals(undefined, fake_error.stack); | 379 assertEquals(undefined, fake_error.stack); |
OLD | NEW |