Skip to content

Commit 40b7dcf

Browse files
author
Chris K
committed
Support for function source in tooltips.
1 parent 234f1cd commit 40b7dcf

File tree

2 files changed

+103
-3
lines changed

2 files changed

+103
-3
lines changed

src/ecma-debugger/objectinspection.6.0/inspectiontooltip.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ cls.JSInspectionTooltip = function()
2323
_cur_ctx = ctx;
2424
_cur_ctx.target.addClass(CLASS_TOOLTIP_SELECTED);
2525
_tooltip.show(ctx.template);
26+
if (ctx.type.after_render)
27+
ctx.type.after_render();
2628
}
2729
else
2830
_hide_tooltip();

src/ecma-debugger/objectinspection.6.0/prettyprinter.js

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,60 @@ cls.PrettyPrinter.types[cls.PrettyPrinter.FUNCTION] =
109109
script: "object.toString()",
110110
template: function(message, ctx)
111111
{
112-
var VALUE = 2;
113-
var tmpl = templates.highlight_js_source(message[VALUE]);
114-
tmpl.push("class", "pretty-printed-code mono");
112+
var tmpl = [];
113+
if (ctx.function_definition)
114+
{
115+
var script = ctx.script;
116+
var start_line = ctx.function_definition.start_line;
117+
var end_line = ctx.function_definition.end_line;
118+
var line_numbers = ["ul"];
119+
var lines = ["div"];
120+
for (var i = start_line; i <= end_line; i++)
121+
{
122+
var data = script.get_line(i);
123+
var start_state = script.state_arr[i - 1];
124+
var line_tmpl = ["div"];
125+
window.templates.highlight_js_source(data, null, start_state, line_tmpl);
126+
lines.push(line_tmpl);
127+
var num_templ = ["li"];
128+
num_templ.push(["input", "value", String(i)]);
129+
num_templ.push(["span", "handler", "set-break-point"]);
130+
line_numbers.push(num_templ);
131+
}
132+
lines.push("class", "js-source-content js-source mono");
133+
line_numbers.push("class", "js-source-line-numbers");
134+
tmpl = ["div",
135+
lines,
136+
line_numbers,
137+
"class", "tooltip-function-source",
138+
"data-script-id", String(script.script_id)];
139+
}
140+
else
141+
{
142+
var VALUE = 2;
143+
tmpl = templates.highlight_js_source(message[VALUE]);
144+
tmpl.push("class", "pretty-printed-code mono");
145+
}
115146
return tmpl;
147+
},
148+
after_render: function()
149+
{
150+
var fn_tooltip = document.querySelector(".tooltip-function-source");
151+
if (fn_tooltip)
152+
{
153+
var line_numbers = fn_tooltip.querySelector(".js-source-line-numbers");
154+
var script_id = line_numbers && line_numbers.get_ancestor_attr("data-script-id");
155+
var script = window.runtimes.getScript(Number(script_id));
156+
cls.JsSourceView.update_breakpoints(script, line_numbers);
157+
}
158+
},
159+
init: function()
160+
{
161+
if (!this._is_initialized)
162+
{
163+
this._is_initialized = true;
164+
window.messages.addListener("breakpoint-updated", this.after_render);
165+
}
116166
}
117167
};
118168

@@ -148,6 +198,8 @@ cls.PrettyPrinter.types[cls.PrettyPrinter.REGEXP] =
148198

149199
cls.PrettyPrinter.prototype = new function()
150200
{
201+
var SUCCESS = 0;
202+
151203
this.register_types = function(list) {};
152204
this.unregister_types = function(list) {};
153205
/**
@@ -169,6 +221,8 @@ cls.PrettyPrinter.prototype = new function()
169221
!this._types.contains(cls.PrettyPrinter.types[type]))
170222
{
171223
this._types.push(cls.PrettyPrinter.types[type]);
224+
if (cls.PrettyPrinter.types[type].init)
225+
cls.PrettyPrinter.types[type].init();
172226
}
173227
}, this);
174228
};
@@ -230,12 +284,56 @@ cls.PrettyPrinter.prototype = new function()
230284
ctx.callback(ctx);
231285
};
232286

287+
this._print_function = function(ctx)
288+
{
289+
if (services["ecmascript-debugger"].requestGetFunctionPositions)
290+
{
291+
var tag = tagManager.set_callback(this, this._handle_function, [ctx]);
292+
var msg = [ctx.rt_id, [ctx.obj_id]];
293+
services["ecmascript-debugger"].requestGetFunctionPositions(tag, msg);
294+
}
295+
else
296+
this._print_object(ctx);
297+
};
298+
299+
this._handle_function = function(status, message, ctx)
300+
{
301+
var FUNCTION_POSITION_LIST = 0;
302+
var POSITION = 1;
303+
var SCRIPT_ID = 0;
304+
var LINE_NUMBER = 1;
305+
var pos = null;
306+
if (status === SUCCESS &&
307+
(pos = message[FUNCTION_POSITION_LIST]) &&
308+
(pos = pos[0]) &&
309+
(pos = pos[POSITION]))
310+
{
311+
var script = window.runtimes.getScript(pos[SCRIPT_ID]);
312+
if (script)
313+
{
314+
var funcion_definition = script.get_function(pos[LINE_NUMBER]);
315+
if (funcion_definition)
316+
{
317+
ctx.function_definition = funcion_definition;
318+
ctx.script = script;
319+
ctx.template = ctx.type.template(message, ctx);
320+
ctx.callback(ctx);
321+
return;
322+
}
323+
}
324+
}
325+
326+
this._print_object(ctx);
327+
};
328+
233329
this.print = function(ctx)
234330
{
235331
if (ctx.type = this._get_type(ctx.class_name))
236332
{
237333
if (ctx.type.traversal)
238334
this._print_element(ctx);
335+
else if (ctx.type.type == cls.PrettyPrinter.FUNCTION)
336+
this._print_function(ctx);
239337
else
240338
this._print_object(ctx);
241339
}

0 commit comments

Comments
 (0)