Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1035)

Side by Side Diff: test/mjsunit/stack-traces.js

Issue 1507273002: Make Error.prototype.toString spec compliant; and fix various side-effect-free error printing metho… (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 assertTrue(threw, "UnintendedCallerCensorship didn't throw"); 206 assertTrue(threw, "UnintendedCallerCensorship didn't throw");
207 } 207 }
208 208
209 // If an error occurs while the stack trace is being formatted it should 209 // If an error occurs while the stack trace is being formatted it should
210 // be handled gracefully. 210 // be handled gracefully.
211 function testErrorsDuringFormatting() { 211 function testErrorsDuringFormatting() {
212 function Nasty() { } 212 function Nasty() { }
213 Nasty.prototype.foo = function () { throw new RangeError(); }; 213 Nasty.prototype.foo = function () { throw new RangeError(); };
214 var n = new Nasty(); 214 var n = new Nasty();
215 n.__defineGetter__('constructor', function () { CONS_FAIL; }); 215 n.__defineGetter__('constructor', function () { CONS_FAIL; });
216 var threw = false; 216 assertThrows(()=>n.foo(), RangeError);
217 try {
218 n.foo();
219 } catch (e) {
220 threw = true;
221 assertTrue(e.stack.indexOf('<error: ReferenceError') != -1,
222 "ErrorsDuringFormatting didn't contain error: ReferenceError");
223 }
224 assertTrue(threw, "ErrorsDuringFormatting didn't throw");
225 threw = false;
226 // Now we can't even format the message saying that we couldn't format 217 // Now we can't even format the message saying that we couldn't format
227 // the stack frame. Put that in your pipe and smoke it! 218 // the stack frame. Put that in your pipe and smoke it!
228 ReferenceError.prototype.toString = function () { NESTED_FAIL; }; 219 ReferenceError.prototype.toString = function () { NESTED_FAIL; };
229 try { 220 assertThrows(()=>n.foo(), RangeError);
230 n.foo();
231 } catch (e) {
232 threw = true;
233 assertTrue(e.stack.indexOf('<error>') != -1,
234 "ErrorsDuringFormatting didn't contain <error>");
235 }
236 assertTrue(threw, "ErrorsDuringFormatting didnt' throw (2)");
237 } 221 }
238 222
239 223
240 // Poisonous object that throws a reference error if attempted converted to 224 // Poisonous object that throws a reference error if attempted converted to
241 // a primitive values. 225 // a primitive values.
242 var thrower = { valueOf: function() { FAIL; }, 226 var thrower = { valueOf: function() { FAIL; },
243 toString: function() { FAIL; } }; 227 toString: function() { FAIL; } };
244 228
245 // Tests that a native constructor function is included in the 229 // Tests that a native constructor function is included in the
246 // stack trace. 230 // stack trace.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 362
379 my_error = {}; 363 my_error = {};
380 Object.preventExtensions(my_error); 364 Object.preventExtensions(my_error);
381 assertThrows(function() { Error.captureStackTrace(my_error); }); 365 assertThrows(function() { Error.captureStackTrace(my_error); });
382 366
383 var fake_error = {}; 367 var fake_error = {};
384 my_error = new Error(); 368 my_error = new Error();
385 var stolen_getter = Object.getOwnPropertyDescriptor(my_error, 'stack').get; 369 var stolen_getter = Object.getOwnPropertyDescriptor(my_error, 'stack').get;
386 Object.defineProperty(fake_error, 'stack', { get: stolen_getter }); 370 Object.defineProperty(fake_error, 'stack', { get: stolen_getter });
387 assertEquals(undefined, fake_error.stack); 371 assertEquals(undefined, fake_error.stack);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698