Handle symbols in FrameMirror#invocationText().
Fix a TypeError when putting together the invocationText for a symbol method's stack frame. See https://github.com/nodejs/node/issues/7536. Review-Url: https://codereview.chromium.org/2122793003 Cr-Commit-Position: refs/heads/master@{#37597}
This commit is contained in:
parent
62c950bc26
commit
1f53e42bd6
@ -1499,6 +1499,12 @@ PropertyMirror.prototype.name = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
PropertyMirror.prototype.toText = function() {
|
||||||
|
if (IS_SYMBOL(this.name_)) return %SymbolDescriptiveString(this.name_);
|
||||||
|
return this.name_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
PropertyMirror.prototype.isIndexed = function() {
|
PropertyMirror.prototype.isIndexed = function() {
|
||||||
for (var i = 0; i < this.name_.length; i++) {
|
for (var i = 0; i < this.name_.length; i++) {
|
||||||
if (this.name_[i] < '0' || '9' < this.name_[i]) {
|
if (this.name_[i] < '0' || '9' < this.name_[i]) {
|
||||||
@ -2034,10 +2040,10 @@ FrameMirror.prototype.invocationText = function() {
|
|||||||
if (display_receiver) {
|
if (display_receiver) {
|
||||||
result += '.';
|
result += '.';
|
||||||
}
|
}
|
||||||
result += property.name();
|
result += property.toText();
|
||||||
} else {
|
} else {
|
||||||
result += '[';
|
result += '[';
|
||||||
result += property.name();
|
result += property.toText();
|
||||||
result += ']';
|
result += ']';
|
||||||
}
|
}
|
||||||
// Also known as - if the name in the function doesn't match the name
|
// Also known as - if the name in the function doesn't match the name
|
||||||
|
@ -35,7 +35,8 @@ function Point(x, y) {
|
|||||||
|
|
||||||
Point.prototype.distanceTo = function(p) {
|
Point.prototype.distanceTo = function(p) {
|
||||||
debugger;
|
debugger;
|
||||||
return Math.sqrt(Math.pow(Math.abs(this.x - p.x), 2) + Math.pow(Math.abs(this.y - p.y), 2))
|
return Math.sqrt(Math.pow(Math.abs(this.x - p.x), 2) +
|
||||||
|
Math.pow(Math.abs(this.y - p.y), 2))
|
||||||
}
|
}
|
||||||
|
|
||||||
p1 = new Point(1,1);
|
p1 = new Point(1,1);
|
||||||
@ -58,7 +59,7 @@ a=[1,2,distance];
|
|||||||
// Get the Debug object exposed from the debug context global object.
|
// Get the Debug object exposed from the debug context global object.
|
||||||
Debug = debug.Debug
|
Debug = debug.Debug
|
||||||
|
|
||||||
testConstructor = false; // Flag to control which part of the test is run.
|
what = 'constructor'; // Flag to control which part of the test is run.
|
||||||
listenerCalled = false;
|
listenerCalled = false;
|
||||||
exception = false;
|
exception = false;
|
||||||
|
|
||||||
@ -72,28 +73,45 @@ function safeEval(code) {
|
|||||||
|
|
||||||
function listener(event, exec_state, event_data, data) {
|
function listener(event, exec_state, event_data, data) {
|
||||||
try {
|
try {
|
||||||
if (event == Debug.DebugEvent.Break)
|
if (event == Debug.DebugEvent.Break) {
|
||||||
{
|
if (what == 'constructor') {
|
||||||
if (!testConstructor) {
|
|
||||||
// The expected backtrace is
|
// The expected backtrace is
|
||||||
// 0: Call distance on Point where distance is a property on the prototype
|
// 0: Call distance on Point where distance is a prototype property
|
||||||
// 1: Call distance on Point where distance is a direct property
|
// 1: Call distance on Point where distance is a direct property
|
||||||
// 2: Call on function an array element 2
|
// 2: Call on function an array element 2
|
||||||
// 3: [anonymous]
|
// 3: [anonymous]
|
||||||
assertEquals("#<Point>.distanceTo(p=#<Point>)", exec_state.frame(0).invocationText());
|
assertEquals("#<Point>.distanceTo(p=#<Point>)",
|
||||||
assertEquals("#<Point>.distanceTo(p=#<Point>)", exec_state.frame(1).invocationText());
|
exec_state.frame(0).invocationText());
|
||||||
assertEquals("#<Array>[2](aka distance)(p=#<Point>, q=#<Point>)", exec_state.frame(2).invocationText());
|
assertEquals("#<Point>.distanceTo(p=#<Point>)",
|
||||||
|
exec_state.frame(1).invocationText());
|
||||||
|
assertEquals("#<Array>[2](aka distance)(p=#<Point>, q=#<Point>)",
|
||||||
|
exec_state.frame(2).invocationText());
|
||||||
assertEquals("[anonymous]()", exec_state.frame(3).invocationText());
|
assertEquals("[anonymous]()", exec_state.frame(3).invocationText());
|
||||||
listenerCalled = true;
|
listenerCalled = true;
|
||||||
} else {
|
} else if (what == 'breakpoint') {
|
||||||
// The expected backtrace is
|
// The expected backtrace is
|
||||||
// 0: Call Point constructor
|
// 0: Call Point constructor
|
||||||
// 1: Call on global function createPoint
|
// 1: Call on global function createPoint
|
||||||
// 2: [anonymous]
|
// 2: [anonymous]
|
||||||
assertEquals("new Point(x=0, y=0)", exec_state.frame(0).invocationText());
|
assertEquals("new Point(x=0, y=0)",
|
||||||
assertEquals("createPoint(x=0, y=0)", exec_state.frame(1).invocationText());
|
exec_state.frame(0).invocationText());
|
||||||
|
assertEquals("createPoint(x=0, y=0)",
|
||||||
|
exec_state.frame(1).invocationText());
|
||||||
assertEquals("[anonymous]()", exec_state.frame(2).invocationText());
|
assertEquals("[anonymous]()", exec_state.frame(2).invocationText());
|
||||||
listenerCalled = true;
|
listenerCalled = true;
|
||||||
|
} else if (what == 'symbol') {
|
||||||
|
// The expected backtrace is
|
||||||
|
// 0: Call Point constructor
|
||||||
|
// 1: Call on symbol method
|
||||||
|
// 2: [anonymous]
|
||||||
|
assertEquals("new Point(x=0, y=0)",
|
||||||
|
exec_state.frame(0).invocationText());
|
||||||
|
assertEquals("#<Object>[Symbol(Das Symbol)](x=0, y=0)",
|
||||||
|
exec_state.frame(1).invocationText());
|
||||||
|
assertEquals("[anonymous]()", exec_state.frame(2).invocationText());
|
||||||
|
listenerCalled = true;
|
||||||
|
} else {
|
||||||
|
assertUnreachable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -112,11 +130,21 @@ assertTrue(listenerCalled);
|
|||||||
assertFalse(exception, "exception in listener")
|
assertFalse(exception, "exception in listener")
|
||||||
|
|
||||||
// Set a break point and call to invoke the debug event listener.
|
// Set a break point and call to invoke the debug event listener.
|
||||||
|
what = 'breakpoint';
|
||||||
listenerCalled = false;
|
listenerCalled = false;
|
||||||
testConstructor = true;
|
|
||||||
Debug.setBreakPoint(Point, 0, 0);
|
Debug.setBreakPoint(Point, 0, 0);
|
||||||
createPoint(0, 0);
|
createPoint(0, 0);
|
||||||
|
|
||||||
// Make sure that the debug event listener vas invoked (again).
|
// Make sure that the debug event listener vas invoked (again).
|
||||||
assertTrue(listenerCalled);
|
assertTrue(listenerCalled);
|
||||||
assertFalse(exception, "exception in listener")
|
assertFalse(exception, "exception in listener")
|
||||||
|
|
||||||
|
what = 'symbol';
|
||||||
|
listenerCalled = false;
|
||||||
|
var S = Symbol('Das Symbol');
|
||||||
|
var o = { [S](x, y) { return new Point(x, y); } };
|
||||||
|
Debug.setBreakPoint(Point, 0, 0);
|
||||||
|
o[S](0, 0);
|
||||||
|
|
||||||
|
assertTrue(listenerCalled);
|
||||||
|
assertFalse(exception, "exception in listener")
|
||||||
|
Loading…
Reference in New Issue
Block a user