Skip to content

Commit 63bec8c

Browse files
committed
Update DebuggerScript from Blink/8d2d750
1 parent 6f328b2 commit 63bec8c

File tree

1 file changed

+73
-53
lines changed

1 file changed

+73
-53
lines changed

InjectedScript/DebuggerScript.js

Lines changed: 73 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,6 @@ DebuggerScript.getAfterCompileScript = function(eventData)
5454
return DebuggerScript._formatScript(eventData.script_.script_);
5555
}
5656

57-
DebuggerScript.getWorkerScripts = function()
58-
{
59-
var result = [];
60-
var scripts = Debug.scripts();
61-
for (var i = 0; i < scripts.length; ++i) {
62-
var script = scripts[i];
63-
// Workers don't share same V8 heap now so there is no need to complicate stuff with
64-
// the context id like we do to discriminate between scripts from different pages.
65-
// However we need to filter out v8 native scripts.
66-
if (script.context_data && script.context_data === "worker")
67-
result.push(DebuggerScript._formatScript(script));
68-
}
69-
return result;
70-
}
71-
7257
DebuggerScript.getFunctionScopes = function(fun)
7358
{
7459
var mirror = MakeMirror(fun);
@@ -89,6 +74,31 @@ DebuggerScript.getFunctionScopes = function(fun)
8974
return result;
9075
}
9176

77+
DebuggerScript.getGeneratorObjectDetails = function(object)
78+
{
79+
var mirror = MakeMirror(object, true /* transient */);
80+
if (!mirror.isGenerator())
81+
return null;
82+
var funcMirror = mirror.func();
83+
if (!funcMirror.resolved())
84+
return null;
85+
var result = {
86+
"function": funcMirror.value(),
87+
"functionName": DebuggerScript._displayFunctionName(funcMirror) || "",
88+
"status": mirror.status()
89+
};
90+
var script = funcMirror.script();
91+
var location = mirror.sourceLocation() || funcMirror.sourceLocation();
92+
if (script && location) {
93+
result["location"] = {
94+
"scriptId": String(script.id()),
95+
"lineNumber": location.line,
96+
"columnNumber": location.column
97+
};
98+
}
99+
return result;
100+
}
101+
92102
DebuggerScript.getCollectionEntries = function(object)
93103
{
94104
var mirror = MakeMirror(object, true /* transient */);
@@ -103,20 +113,6 @@ DebuggerScript.getCollectionEntries = function(object)
103113
}
104114
}
105115

106-
DebuggerScript.getInternalProperties = function(value)
107-
{
108-
var properties = ObjectMirror.GetInternalProperties(value);
109-
var result = [];
110-
for (var i = 0; i < properties.length; i++) {
111-
var mirror = properties[i];
112-
result.push({
113-
name: mirror.name(),
114-
value: mirror.value().value()
115-
});
116-
}
117-
return result;
118-
}
119-
120116
DebuggerScript.setFunctionVariableValue = function(functionValue, scopeIndex, variableName, newValue)
121117
{
122118
var mirror = MakeMirror(functionValue);
@@ -134,24 +130,24 @@ DebuggerScript._setScopeVariableValue = function(scopeHolder, scopeIndex, variab
134130
return undefined;
135131
}
136132

137-
DebuggerScript.getScripts = function(contextData)
133+
DebuggerScript.getScripts = function(contextGroupId)
138134
{
139135
var result = [];
140-
141-
if (!contextData)
142-
return result;
143-
var comma = contextData.indexOf(",");
144-
if (comma === -1)
145-
return result;
146-
// Context data is a string in the following format:
147-
// ("page"|"injected")","<page id>
148-
var idSuffix = contextData.substring(comma); // including the comma
149-
150136
var scripts = Debug.scripts();
137+
var contextDataPrefix = null;
138+
if (contextGroupId)
139+
contextDataPrefix = contextGroupId + ",";
151140
for (var i = 0; i < scripts.length; ++i) {
152141
var script = scripts[i];
153-
if (script.context_data && script.context_data.lastIndexOf(idSuffix) != -1)
154-
result.push(DebuggerScript._formatScript(script));
142+
if (contextDataPrefix) {
143+
if (!script.context_data)
144+
continue;
145+
// Context data is a string in the following format:
146+
// <id>","("page"|"injected"|"worker")
147+
if (script.context_data.indexOf(contextDataPrefix) !== 0)
148+
continue;
149+
}
150+
result.push(DebuggerScript._formatScript(script));
155151
}
156152
return result;
157153
}
@@ -183,7 +179,8 @@ DebuggerScript._formatScript = function(script)
183179
startColumn: script.column_offset,
184180
endLine: endLine,
185181
endColumn: endColumn,
186-
isContentScript: !!script.context_data && script.context_data.indexOf("injected") == 0
182+
isContentScript: !!script.context_data && script.context_data.endsWith(",injected"),
183+
isInternalScript: script.is_debugger_script
187184
};
188185
}
189186

@@ -276,6 +273,11 @@ DebuggerScript.stepOutOfFunction = function(execState, callFrame)
276273
execState.prepareStep(Debug.StepAction.StepOut, 1);
277274
}
278275

276+
DebuggerScript.clearStepping = function()
277+
{
278+
Debug.clearStepping();
279+
}
280+
279281
// Returns array in form:
280282
// [ 0, <v8_result_report> ] in case of success
281283
// or [ 1, <general_error_message>, <compiler_message>, <line_number>, <column_number> ] in case of compile error, numbers are 1-based.
@@ -296,7 +298,7 @@ DebuggerScript.liveEditScriptSource = function(scriptId, newSource, preview)
296298
var changeLog = [];
297299
try {
298300
var result = Debug.LiveEdit.SetScriptSource(scriptToEdit, newSource, preview, changeLog);
299-
return [0, result];
301+
return [0, result.stack_modified];
300302
} catch (e) {
301303
if (e instanceof Debug.LiveEdit.Failure && "details" in e) {
302304
var details = e.details;
@@ -357,6 +359,17 @@ DebuggerScript.isEvalCompilation = function(eventData)
357359
return (script.compilationType() === Debug.ScriptCompilationType.Eval);
358360
}
359361

362+
DebuggerScript._displayFunctionName = function(funcMirror)
363+
{
364+
if (!funcMirror.resolved())
365+
return undefined
366+
var displayName;
367+
var valueMirror = funcMirror.property("displayName").value();
368+
if (valueMirror && valueMirror.isString())
369+
displayName = valueMirror.value();
370+
return displayName || funcMirror.name() || funcMirror.inferredName();
371+
}
372+
360373
// NOTE: This function is performance critical, as it can be run on every
361374
// statement that generates an async event (like addEventListener) to support
362375
// asynchronous call stacks. Thus, when possible, initialize the data lazily.
@@ -458,14 +471,19 @@ DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror, callerFrame, sc
458471

459472
function functionName()
460473
{
461-
var func = ensureFuncMirror();
462-
if (!func.resolved())
463-
return undefined;
464-
var displayName;
465-
var valueMirror = func.property("displayName").value();
466-
if (valueMirror && valueMirror.isString())
467-
displayName = valueMirror.value();
468-
return displayName || func.name() || func.inferredName();
474+
return DebuggerScript._displayFunctionName(ensureFuncMirror());
475+
}
476+
477+
function functionLine()
478+
{
479+
var location = ensureFuncMirror().sourceLocation();
480+
return location ? location.line : 0;
481+
}
482+
483+
function functionColumn()
484+
{
485+
var location = ensureFuncMirror().sourceLocation();
486+
return location ? location.column : 0;
469487
}
470488

471489
function evaluate(expression, scopeExtension)
@@ -475,7 +493,7 @@ DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror, callerFrame, sc
475493

476494
function restart()
477495
{
478-
return Debug.LiveEdit.RestartFrame(frameMirror);
496+
return frameMirror.restart();
479497
}
480498

481499
function setVariableValue(scopeNumber, variableName, newValue)
@@ -511,6 +529,8 @@ DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror, callerFrame, sc
511529
"column": column,
512530
"scriptName": scriptName,
513531
"functionName": functionName,
532+
"functionLine": functionLine,
533+
"functionColumn": functionColumn,
514534
"thisObject": thisObject,
515535
"scopeChain": lazyScopeChain,
516536
"scopeType": lazyScopeTypes,

0 commit comments

Comments
 (0)