2015-05-05 13:55:28 +00:00
|
|
|
// 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.
|
|
|
|
|
2016-03-03 20:18:30 +00:00
|
|
|
var o = {
|
|
|
|
f: function() { throw new Error(); },
|
|
|
|
get j() { o.h(); },
|
|
|
|
set k(_) { o.j; },
|
|
|
|
};
|
2015-05-05 13:55:28 +00:00
|
|
|
o.g1 = function() { o.f() }
|
|
|
|
o.g2 = o.g1;
|
|
|
|
o.h = function() { o.g1() }
|
|
|
|
|
|
|
|
try {
|
2016-03-03 20:18:30 +00:00
|
|
|
o.k = 42;
|
2015-05-05 13:55:28 +00:00
|
|
|
} catch (e) {
|
2016-03-03 20:18:30 +00:00
|
|
|
Error.prepareStackTrace = function(e, frames) { return frames; };
|
2015-05-05 13:55:28 +00:00
|
|
|
var frames = e.stack;
|
2016-03-03 20:18:30 +00:00
|
|
|
Error.prepareStackTrace = undefined;
|
2015-05-05 13:55:28 +00:00
|
|
|
assertEquals("f", frames[0].getMethodName());
|
|
|
|
assertEquals(null, frames[1].getMethodName());
|
|
|
|
assertEquals("h", frames[2].getMethodName());
|
2016-03-03 20:18:30 +00:00
|
|
|
assertEquals("j", frames[3].getMethodName());
|
|
|
|
assertEquals("k", frames[4].getMethodName());
|
|
|
|
assertEquals(null, frames[5].getMethodName());
|
2015-05-05 13:55:28 +00:00
|
|
|
}
|
2017-08-25 15:02:17 +00:00
|
|
|
|
|
|
|
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");
|
|
|
|
}
|