mirror of
				https://github.com/tc39/test262.git
				synced 2025-10-29 18:53:58 +01:00 
			
		
		
		
	sourceRevisionAtLastExport: 33f2fb0e53d135f0ee17cfccd9d993eb2a6f47de targetRevisionAtLastExport: 31340cbd9add103f586d501b0c3354b7b182abc0
		
			
				
	
	
		
			52 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| // Copyright 2015 the V8 project authors. All rights reserved.
 | |
| // Use of this source code is governed by a BSD-style license that can be
 | |
| // found in the LICENSE file.
 | |
| 
 | |
| var o = {
 | |
|   f: function() { throw new Error(); },
 | |
|   get j() { o.h(); },
 | |
|   set k(_) { o.j; },
 | |
| };
 | |
| o.g1 = function() { o.f() }
 | |
| o.g2 = o.g1;
 | |
| o.h = function() { o.g1() }
 | |
| 
 | |
| try {
 | |
|   o.k = 42;
 | |
| } catch (e) {
 | |
|   Error.prepareStackTrace = function(e, frames) { return frames; };
 | |
|   var frames = e.stack;
 | |
|   Error.prepareStackTrace = undefined;
 | |
|   assertEquals("f", frames[0].getMethodName());
 | |
|   assertEquals(null, frames[1].getMethodName());
 | |
|   assertEquals("h", frames[2].getMethodName());
 | |
|   assertEquals("j", frames[3].getMethodName());
 | |
|   assertEquals("k", frames[4].getMethodName());
 | |
|   assertEquals(null, frames[5].getMethodName());
 | |
| }
 | |
| 
 | |
| function testMethodName(f, frameNumber, expectedName) {
 | |
|   try {
 | |
|     Error.prepareStackTrace = function(e, frames) { return frames; }
 | |
|     f();
 | |
|     assertUnreachable();
 | |
|   } catch (e) {
 | |
|     const frame = e.stack[frameNumber];
 | |
|     assertEquals(expectedName, frame.getMethodName());
 | |
|   } finally {
 | |
|     Error.prepareStackTrace = undefined;
 | |
|   }
 | |
| }
 | |
| 
 | |
| const thrower = { valueOf: () => { throw new Error(); }};
 | |
| 
 | |
| {
 | |
|   const str = "";
 | |
|   testMethodName(() => { str.indexOf(str, thrower); }, 1, "indexOf");
 | |
| }
 | |
| 
 | |
| {
 | |
|   const nr = 42;
 | |
|   testMethodName(() => { nr.toString(thrower); }, 1, "toString");
 | |
| }
 |