OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 return bound; | 86 return bound; |
87 } | 87 } |
88 | 88 |
89 /** | 89 /** |
90 * @constructor | 90 * @constructor |
91 */ | 91 */ |
92 var InjectedScript = function() | 92 var InjectedScript = function() |
93 { | 93 { |
94 /** @type {number} */ | 94 /** @type {number} */ |
95 this._lastBoundObjectId = 1; | 95 this._lastBoundObjectId = 1; |
96 /** @type {!Object.<number, Object>} */ | 96 /** @type {!Object.<number, *>} */ |
97 this._idToWrappedObject = {}; | 97 this._idToWrappedObject = {}; |
98 /** @type {!Object.<number, string>} */ | 98 /** @type {!Object.<number, string>} */ |
99 this._idToObjectGroupName = {}; | 99 this._idToObjectGroupName = {}; |
100 /** @type {!Object.<string, Array.<number>>} */ | 100 /** @type {!Object.<string, Array.<number>>} */ |
101 this._objectGroups = {}; | 101 this._objectGroups = {}; |
102 /** @type {!Object.<string, Object>} */ | 102 /** @type {!Object.<string, Object>} */ |
103 this._modules = {}; | 103 this._modules = {}; |
104 } | 104 } |
105 | 105 |
106 /** | 106 /** |
(...skipping 21 matching lines...) Expand all Loading... |
128 /** | 128 /** |
129 * @param {*} object | 129 * @param {*} object |
130 * @param {string} groupName | 130 * @param {string} groupName |
131 * @param {boolean} canAccessInspectedWindow | 131 * @param {boolean} canAccessInspectedWindow |
132 * @param {boolean} generatePreview | 132 * @param {boolean} generatePreview |
133 * @return {!RuntimeAgent.RemoteObject} | 133 * @return {!RuntimeAgent.RemoteObject} |
134 */ | 134 */ |
135 wrapObject: function(object, groupName, canAccessInspectedWindow, generatePr
eview) | 135 wrapObject: function(object, groupName, canAccessInspectedWindow, generatePr
eview) |
136 { | 136 { |
137 if (canAccessInspectedWindow) | 137 if (canAccessInspectedWindow) |
138 return this._wrapObject(object, groupName, false, generatePreview); | 138 return this._wrapObject(object, groupName, false, false, generatePre
view); |
139 return this._fallbackWrapper(object); | 139 return this._fallbackWrapper(object); |
140 }, | 140 }, |
141 | 141 |
142 /** | 142 /** |
143 * @param {*} object | 143 * @param {*} object |
144 * @return {!RuntimeAgent.RemoteObject} | 144 * @return {!RuntimeAgent.RemoteObject} |
145 */ | 145 */ |
146 _fallbackWrapper: function(object) | 146 _fallbackWrapper: function(object) |
147 { | 147 { |
148 var result = {}; | 148 var result = {}; |
(...skipping 16 matching lines...) Expand all Loading... |
165 if (!canAccessInspectedWindow) | 165 if (!canAccessInspectedWindow) |
166 return this._fallbackWrapper(table); | 166 return this._fallbackWrapper(table); |
167 var columnNames = null; | 167 var columnNames = null; |
168 if (typeof columns === "string") | 168 if (typeof columns === "string") |
169 columns = [columns]; | 169 columns = [columns]; |
170 if (InjectedScriptHost.type(columns) == "array") { | 170 if (InjectedScriptHost.type(columns) == "array") { |
171 columnNames = []; | 171 columnNames = []; |
172 for (var i = 0; i < columns.length; ++i) | 172 for (var i = 0; i < columns.length; ++i) |
173 columnNames.push(toString(columns[i])); | 173 columnNames.push(toString(columns[i])); |
174 } | 174 } |
175 return this._wrapObject(table, "console", false, true, columnNames, true
); | 175 return this._wrapObject(table, "console", false, false, true, columnName
s, true); |
176 }, | 176 }, |
177 | 177 |
178 /** | 178 /** |
179 * @param {*} object | 179 * @param {*} object |
180 */ | 180 */ |
181 inspectNode: function(object) | 181 inspectNode: function(object) |
182 { | 182 { |
183 this._inspect(object); | 183 this._inspect(object); |
184 }, | 184 }, |
185 | 185 |
(...skipping 23 matching lines...) Expand all Loading... |
209 } | 209 } |
210 InjectedScriptHost.inspect(objectId, hints); | 210 InjectedScriptHost.inspect(objectId, hints); |
211 return object; | 211 return object; |
212 }, | 212 }, |
213 | 213 |
214 /** | 214 /** |
215 * This method cannot throw. | 215 * This method cannot throw. |
216 * @param {*} object | 216 * @param {*} object |
217 * @param {string=} objectGroupName | 217 * @param {string=} objectGroupName |
218 * @param {boolean=} forceValueType | 218 * @param {boolean=} forceValueType |
| 219 * @param {boolean=} forceObjectId |
219 * @param {boolean=} generatePreview | 220 * @param {boolean=} generatePreview |
220 * @param {?Array.<string>=} columnNames | 221 * @param {?Array.<string>=} columnNames |
221 * @param {boolean=} isTable | 222 * @param {boolean=} isTable |
222 * @return {!RuntimeAgent.RemoteObject} | 223 * @return {!RuntimeAgent.RemoteObject} |
223 * @suppress {checkTypes} | 224 * @suppress {checkTypes} |
224 */ | 225 */ |
225 _wrapObject: function(object, objectGroupName, forceValueType, generatePrevi
ew, columnNames, isTable) | 226 _wrapObject: function(object, objectGroupName, forceValueType, forceObjectId
, generatePreview, columnNames, isTable) |
226 { | 227 { |
227 try { | 228 try { |
228 return new InjectedScript.RemoteObject(object, objectGroupName, forc
eValueType, generatePreview, columnNames, isTable); | 229 return new InjectedScript.RemoteObject(object, objectGroupName, forc
eValueType, forceObjectId, generatePreview, columnNames, isTable); |
229 } catch (e) { | 230 } catch (e) { |
230 try { | 231 try { |
231 var description = injectedScript._describe(e); | 232 var description = injectedScript._describe(e); |
232 } catch (ex) { | 233 } catch (ex) { |
233 var description = "<failed to convert exception to string>"; | 234 var description = "<failed to convert exception to string>"; |
234 } | 235 } |
235 return new InjectedScript.RemoteObject(description); | 236 return new InjectedScript.RemoteObject(description); |
236 } | 237 } |
237 }, | 238 }, |
238 | 239 |
239 /** | 240 /** |
240 * @param {Object} object | 241 * @param {*} object |
241 * @param {string=} objectGroupName | 242 * @param {string=} objectGroupName |
242 * @return {string} | 243 * @return {string} |
243 */ | 244 */ |
244 _bind: function(object, objectGroupName) | 245 _bind: function(object, objectGroupName) |
245 { | 246 { |
246 var id = this._lastBoundObjectId++; | 247 var id = this._lastBoundObjectId++; |
247 this._idToWrappedObject[id] = object; | 248 this._idToWrappedObject[id] = object; |
248 var objectId = "{\"injectedScriptId\":" + injectedScriptId + ",\"id\":"
+ id + "}"; | 249 var objectId = "{\"injectedScriptId\":" + injectedScriptId + ",\"id\":"
+ id + "}"; |
249 if (objectGroupName) { | 250 if (objectGroupName) { |
250 var group = this._objectGroups[objectGroupName]; | 251 var group = this._objectGroups[objectGroupName]; |
251 if (!group) { | 252 if (!group) { |
252 group = []; | 253 group = []; |
253 this._objectGroups[objectGroupName] = group; | 254 this._objectGroups[objectGroupName] = group; |
254 } | 255 } |
255 group.push(id); | 256 group.push(id); |
256 this._idToObjectGroupName[id] = objectGroupName; | 257 this._idToObjectGroupName[id] = objectGroupName; |
257 } | 258 } |
258 return objectId; | 259 return objectId; |
259 }, | 260 }, |
260 | 261 |
261 /** | 262 /** |
262 * @param {string} objectId | 263 * @param {string} objectId |
263 * @return {Object} | 264 * @return {{injectedScriptId: number, id: number}} |
264 */ | 265 */ |
265 _parseObjectId: function(objectId) | 266 _parseObjectId: function(objectId) |
266 { | 267 { |
267 return InjectedScriptHost.evaluate("(" + objectId + ")"); | 268 return InjectedScriptHost.evaluate("(" + objectId + ")"); |
268 }, | 269 }, |
269 | 270 |
270 /** | 271 /** |
271 * @param {string} objectGroupName | 272 * @param {string} objectGroupName |
272 */ | 273 */ |
273 releaseObjectGroup: function(objectGroupName) | 274 releaseObjectGroup: function(objectGroupName) |
(...skipping 24 matching lines...) Expand all Loading... |
298 | 299 |
299 /** | 300 /** |
300 * @param {string} objectId | 301 * @param {string} objectId |
301 * @param {boolean} ownProperties | 302 * @param {boolean} ownProperties |
302 * @param {boolean} accessorPropertiesOnly | 303 * @param {boolean} accessorPropertiesOnly |
303 * @return {Array.<RuntimeAgent.PropertyDescriptor>|boolean} | 304 * @return {Array.<RuntimeAgent.PropertyDescriptor>|boolean} |
304 */ | 305 */ |
305 getProperties: function(objectId, ownProperties, accessorPropertiesOnly) | 306 getProperties: function(objectId, ownProperties, accessorPropertiesOnly) |
306 { | 307 { |
307 var parsedObjectId = this._parseObjectId(objectId); | 308 var parsedObjectId = this._parseObjectId(objectId); |
308 var object = this._objectForId(parsedObjectId); | 309 var object = this._objectForId(parsedObjectId.id); |
309 var objectGroupName = this._idToObjectGroupName[parsedObjectId.id]; | 310 var objectGroupName = this._idToObjectGroupName[parsedObjectId.id]; |
310 | 311 |
311 if (!this._isDefined(object)) | 312 if (!this._isDefined(object)) |
312 return false; | 313 return false; |
313 var descriptors = this._propertyDescriptors(object, ownProperties, acces
sorPropertiesOnly); | 314 var descriptors = this._propertyDescriptors(/** @type {!Object} */ (obje
ct), ownProperties, accessorPropertiesOnly); |
314 | 315 |
315 // Go over properties, wrap object values. | 316 // Go over properties, wrap object values. |
316 for (var i = 0; i < descriptors.length; ++i) { | 317 for (var i = 0; i < descriptors.length; ++i) { |
317 var descriptor = descriptors[i]; | 318 var descriptor = descriptors[i]; |
318 if ("get" in descriptor) | 319 if ("get" in descriptor) |
319 descriptor.get = this._wrapObject(descriptor.get, objectGroupNam
e); | 320 descriptor.get = this._wrapObject(descriptor.get, objectGroupNam
e); |
320 if ("set" in descriptor) | 321 if ("set" in descriptor) |
321 descriptor.set = this._wrapObject(descriptor.set, objectGroupNam
e); | 322 descriptor.set = this._wrapObject(descriptor.set, objectGroupNam
e); |
322 if ("value" in descriptor) | 323 if ("value" in descriptor) |
323 descriptor.value = this._wrapObject(descriptor.value, objectGrou
pName); | 324 descriptor.value = this._wrapObject(descriptor.value, objectGrou
pName); |
324 if (!("configurable" in descriptor)) | 325 if (!("configurable" in descriptor)) |
325 descriptor.configurable = false; | 326 descriptor.configurable = false; |
326 if (!("enumerable" in descriptor)) | 327 if (!("enumerable" in descriptor)) |
327 descriptor.enumerable = false; | 328 descriptor.enumerable = false; |
328 } | 329 } |
329 return descriptors; | 330 return descriptors; |
330 }, | 331 }, |
331 | 332 |
332 /** | 333 /** |
333 * @param {string} objectId | 334 * @param {string} objectId |
334 * @return {Array.<Object>|boolean} | 335 * @return {Array.<Object>|boolean} |
335 */ | 336 */ |
336 getInternalProperties: function(objectId, ownProperties) | 337 getInternalProperties: function(objectId, ownProperties) |
337 { | 338 { |
338 var parsedObjectId = this._parseObjectId(objectId); | 339 var parsedObjectId = this._parseObjectId(objectId); |
339 var object = this._objectForId(parsedObjectId); | 340 var object = this._objectForId(parsedObjectId.id); |
340 var objectGroupName = this._idToObjectGroupName[parsedObjectId.id]; | 341 var objectGroupName = this._idToObjectGroupName[parsedObjectId.id]; |
341 if (!this._isDefined(object)) | 342 if (!this._isDefined(object)) |
342 return false; | 343 return false; |
343 var descriptors = []; | 344 var descriptors = []; |
344 var internalProperties = InjectedScriptHost.getInternalProperties(object
); | 345 var internalProperties = InjectedScriptHost.getInternalProperties(object
); |
345 if (internalProperties) { | 346 if (internalProperties) { |
346 for (var i = 0; i < internalProperties.length; i++) { | 347 for (var i = 0; i < internalProperties.length; i++) { |
347 var property = internalProperties[i]; | 348 var property = internalProperties[i]; |
348 var descriptor = { | 349 var descriptor = { |
349 name: property.name, | 350 name: property.name, |
350 value: this._wrapObject(property.value, objectGroupName) | 351 value: this._wrapObject(property.value, objectGroupName) |
351 }; | 352 }; |
352 descriptors.push(descriptor); | 353 descriptors.push(descriptor); |
353 } | 354 } |
354 } | 355 } |
355 return descriptors; | 356 return descriptors; |
356 }, | 357 }, |
357 | 358 |
358 /** | 359 /** |
359 * @param {string} functionId | 360 * @param {string} functionId |
360 * @return {!DebuggerAgent.FunctionDetails|string} | 361 * @return {!DebuggerAgent.FunctionDetails|string} |
361 */ | 362 */ |
362 getFunctionDetails: function(functionId) | 363 getFunctionDetails: function(functionId) |
363 { | 364 { |
364 var parsedFunctionId = this._parseObjectId(functionId); | 365 var parsedFunctionId = this._parseObjectId(functionId); |
365 var func = this._objectForId(parsedFunctionId); | 366 var func = this._objectForId(parsedFunctionId.id); |
366 if (typeof func !== "function") | 367 if (typeof func !== "function") |
367 return "Cannot resolve function by id."; | 368 return "Cannot resolve function by id."; |
368 var details = InjectedScriptHost.functionDetails(func); | 369 var details = InjectedScriptHost.functionDetails(func); |
369 if ("rawScopes" in details) { | 370 if ("rawScopes" in details) { |
370 var objectGroupName = this._idToObjectGroupName[parsedFunctionId.id]
; | 371 var objectGroupName = this._idToObjectGroupName[parsedFunctionId.id]
; |
371 var rawScopes = details.rawScopes; | 372 var rawScopes = details.rawScopes; |
372 var scopes = []; | 373 var scopes = []; |
373 delete details.rawScopes; | 374 delete details.rawScopes; |
374 for (var i = 0; i < rawScopes.length; i++) | 375 for (var i = 0; i < rawScopes.length; i++) |
375 scopes.push(InjectedScript.CallFrameProxy._createScopeJson(rawSc
opes[i].type, rawScopes[i].object, objectGroupName)); | 376 scopes.push(InjectedScript.CallFrameProxy._createScopeJson(rawSc
opes[i].type, rawScopes[i].object, objectGroupName)); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 } | 467 } |
467 | 468 |
468 return descriptors; | 469 return descriptors; |
469 }, | 470 }, |
470 | 471 |
471 /** | 472 /** |
472 * @param {string} expression | 473 * @param {string} expression |
473 * @param {string} objectGroup | 474 * @param {string} objectGroup |
474 * @param {boolean} injectCommandLineAPI | 475 * @param {boolean} injectCommandLineAPI |
475 * @param {boolean} returnByValue | 476 * @param {boolean} returnByValue |
| 477 * @param {boolean} forceObjectId |
476 * @param {boolean} generatePreview | 478 * @param {boolean} generatePreview |
477 * @return {*} | 479 * @return {*} |
478 */ | 480 */ |
479 evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByVa
lue, generatePreview) | 481 evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByVa
lue, forceObjectId, generatePreview) |
480 { | 482 { |
481 return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScript
Host, expression, objectGroup, false, injectCommandLineAPI, returnByValue, gener
atePreview); | 483 return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScript
Host, expression, objectGroup, false, injectCommandLineAPI, returnByValue, force
ObjectId, generatePreview); |
482 }, | 484 }, |
483 | 485 |
484 /** | 486 /** |
485 * @param {string} objectId | 487 * @param {string} objectId |
486 * @param {string} expression | 488 * @param {string} expression |
487 * @param {boolean} returnByValue | 489 * @param {boolean} returnByValue |
| 490 * @param {boolean} forceObjectId |
488 * @return {Object|string} | 491 * @return {Object|string} |
489 */ | 492 */ |
490 callFunctionOn: function(objectId, expression, args, returnByValue) | 493 callFunctionOn: function(objectId, expression, args, returnByValue, forceObj
ectId) |
491 { | 494 { |
492 var parsedObjectId = this._parseObjectId(objectId); | 495 var parsedObjectId = this._parseObjectId(objectId); |
493 var object = this._objectForId(parsedObjectId); | 496 var object = this._objectForId(parsedObjectId.id); |
494 if (!this._isDefined(object)) | 497 if (!this._isDefined(object)) |
495 return "Could not find object with given id"; | 498 return "Could not find object with given id"; |
496 | 499 |
497 if (args) { | 500 if (args) { |
498 var resolvedArgs = []; | 501 var resolvedArgs = []; |
499 args = InjectedScriptHost.evaluate(args); | 502 args = InjectedScriptHost.evaluate(args); |
500 for (var i = 0; i < args.length; ++i) { | 503 for (var i = 0; i < args.length; ++i) { |
501 var resolvedCallArgument; | 504 var resolvedCallArgument; |
502 try { | 505 try { |
503 resolvedCallArgument = this._resolveCallArgument(args[i]); | 506 resolvedCallArgument = this._resolveCallArgument(args[i]); |
504 } catch (e) { | 507 } catch (e) { |
505 return toString(e); | 508 return toString(e); |
506 } | 509 } |
507 resolvedArgs.push(resolvedCallArgument) | 510 resolvedArgs.push(resolvedCallArgument) |
508 } | 511 } |
509 } | 512 } |
510 | 513 |
511 try { | 514 try { |
512 var objectGroup = this._idToObjectGroupName[parsedObjectId.id]; | 515 var objectGroup = this._idToObjectGroupName[parsedObjectId.id]; |
513 var func = InjectedScriptHost.evaluate("(" + expression + ")"); | 516 var func = InjectedScriptHost.evaluate("(" + expression + ")"); |
514 if (typeof func !== "function") | 517 if (typeof func !== "function") |
515 return "Given expression does not evaluate to a function"; | 518 return "Given expression does not evaluate to a function"; |
516 | 519 |
517 return { wasThrown: false, | 520 return { wasThrown: false, |
518 result: this._wrapObject(func.apply(object, resolvedArgs),
objectGroup, returnByValue) }; | 521 result: this._wrapObject(func.apply(object, resolvedArgs),
objectGroup, returnByValue, forceObjectId) }; |
519 } catch (e) { | 522 } catch (e) { |
520 return this._createThrownValue(e, objectGroup); | 523 return this._createThrownValue(e, objectGroup); |
521 } | 524 } |
522 }, | 525 }, |
523 | 526 |
524 /** | 527 /** |
525 * Resolves a value from CallArgument description. | 528 * Resolves a value from CallArgument description. |
526 * @param {RuntimeAgent.CallArgument} callArgumentJson | 529 * @param {RuntimeAgent.CallArgument} callArgumentJson |
527 * @return {*} resolved value | 530 * @return {*} resolved value |
528 * @throws {string} error message | 531 * @throws {string} error message |
529 */ | 532 */ |
530 _resolveCallArgument: function(callArgumentJson) { | 533 _resolveCallArgument: function(callArgumentJson) { |
531 var objectId = callArgumentJson.objectId; | 534 var objectId = callArgumentJson.objectId; |
532 if (objectId) { | 535 if (objectId) { |
533 var parsedArgId = this._parseObjectId(objectId); | 536 var parsedArgId = this._parseObjectId(objectId); |
534 if (!parsedArgId || parsedArgId["injectedScriptId"] !== injectedScri
ptId) | 537 if (!parsedArgId || parsedArgId.injectedScriptId !== injectedScriptI
d) |
535 throw "Arguments should belong to the same JavaScript world as t
he target object."; | 538 throw "Arguments should belong to the same JavaScript world as t
he target object."; |
536 | 539 if (!this._hasObjectForId(parsedArgId.id)) |
537 var resolvedArg = this._objectForId(parsedArgId); | |
538 if (!this._isDefined(resolvedArg)) | |
539 throw "Could not find object with given id"; | 540 throw "Could not find object with given id"; |
540 | 541 return this._objectForId(parsedArgId.id); |
541 return resolvedArg; | 542 } else if ("value" in callArgumentJson) { |
542 } else if ("value" in callArgumentJson) | |
543 return callArgumentJson.value; | 543 return callArgumentJson.value; |
544 else | 544 } |
545 return undefined; | 545 return undefined; |
546 }, | 546 }, |
547 | 547 |
548 /** | 548 /** |
549 * @param {Function} evalFunction | 549 * @param {Function} evalFunction |
550 * @param {Object} object | 550 * @param {Object} object |
551 * @param {string} objectGroup | 551 * @param {string} objectGroup |
552 * @param {boolean} isEvalOnCallFrame | 552 * @param {boolean} isEvalOnCallFrame |
553 * @param {boolean} injectCommandLineAPI | 553 * @param {boolean} injectCommandLineAPI |
554 * @param {boolean} returnByValue | 554 * @param {boolean} returnByValue |
| 555 * @param {boolean} forceObjectId |
555 * @param {boolean} generatePreview | 556 * @param {boolean} generatePreview |
556 * @return {*} | 557 * @return {*} |
557 */ | 558 */ |
558 _evaluateAndWrap: function(evalFunction, object, expression, objectGroup, is
EvalOnCallFrame, injectCommandLineAPI, returnByValue, generatePreview) | 559 _evaluateAndWrap: function(evalFunction, object, expression, objectGroup, is
EvalOnCallFrame, injectCommandLineAPI, returnByValue, forceObjectId, generatePre
view) |
559 { | 560 { |
560 try { | 561 try { |
561 return { wasThrown: false, | 562 return { wasThrown: false, |
562 result: this._wrapObject(this._evaluateOn(evalFunction, obj
ect, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI), objectGr
oup, returnByValue, generatePreview) }; | 563 result: this._wrapObject(this._evaluateOn(evalFunction, obj
ect, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI), objectGr
oup, returnByValue, forceObjectId, generatePreview) }; |
563 } catch (e) { | 564 } catch (e) { |
564 return this._createThrownValue(e, objectGroup); | 565 return this._createThrownValue(e, objectGroup); |
565 } | 566 } |
566 }, | 567 }, |
567 | 568 |
568 /** | 569 /** |
569 * @param {*} value | 570 * @param {*} value |
570 * @param {string} objectGroup | 571 * @param {string} objectGroup |
571 * @return {Object} | 572 * @return {Object} |
572 */ | 573 */ |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 return result; | 629 return result; |
629 }, | 630 }, |
630 | 631 |
631 /** | 632 /** |
632 * @param {Object} topCallFrame | 633 * @param {Object} topCallFrame |
633 * @param {string} callFrameId | 634 * @param {string} callFrameId |
634 * @param {string} expression | 635 * @param {string} expression |
635 * @param {string} objectGroup | 636 * @param {string} objectGroup |
636 * @param {boolean} injectCommandLineAPI | 637 * @param {boolean} injectCommandLineAPI |
637 * @param {boolean} returnByValue | 638 * @param {boolean} returnByValue |
| 639 * @param {boolean} forceObjectId |
638 * @param {boolean} generatePreview | 640 * @param {boolean} generatePreview |
639 * @return {*} | 641 * @return {*} |
640 */ | 642 */ |
641 evaluateOnCallFrame: function(topCallFrame, callFrameId, expression, objectG
roup, injectCommandLineAPI, returnByValue, generatePreview) | 643 evaluateOnCallFrame: function(topCallFrame, callFrameId, expression, objectG
roup, injectCommandLineAPI, returnByValue, forceObjectId, generatePreview) |
642 { | 644 { |
643 var callFrame = this.callFrameForId(topCallFrame, callFrameId); | 645 var callFrame = this.callFrameForId(topCallFrame, callFrameId); |
644 if (!callFrame) | 646 if (!callFrame) |
645 return "Could not find call frame with given id"; | 647 return "Could not find call frame with given id"; |
646 return this._evaluateAndWrap(callFrame.evaluate, callFrame, expression,
objectGroup, true, injectCommandLineAPI, returnByValue, generatePreview); | 648 return this._evaluateAndWrap(callFrame.evaluate, callFrame, expression,
objectGroup, true, injectCommandLineAPI, returnByValue, forceObjectId, generateP
review); |
647 }, | 649 }, |
648 | 650 |
649 /** | 651 /** |
650 * @param {Object} topCallFrame | 652 * @param {Object} topCallFrame |
651 * @param {string} callFrameId | 653 * @param {string} callFrameId |
652 * @return {*} | 654 * @return {*} |
653 */ | 655 */ |
654 restartFrame: function(topCallFrame, callFrameId) | 656 restartFrame: function(topCallFrame, callFrameId) |
655 { | 657 { |
656 var callFrame = this.callFrameForId(topCallFrame, callFrameId); | 658 var callFrame = this.callFrameForId(topCallFrame, callFrameId); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 setVariableValue: function(topCallFrame, callFrameId, functionObjectId, scop
eNumber, variableName, newValueJsonString) | 693 setVariableValue: function(topCallFrame, callFrameId, functionObjectId, scop
eNumber, variableName, newValueJsonString) |
692 { | 694 { |
693 var setter; | 695 var setter; |
694 if (typeof callFrameId === "string") { | 696 if (typeof callFrameId === "string") { |
695 var callFrame = this.callFrameForId(topCallFrame, callFrameId); | 697 var callFrame = this.callFrameForId(topCallFrame, callFrameId); |
696 if (!callFrame) | 698 if (!callFrame) |
697 return "Could not find call frame with given id"; | 699 return "Could not find call frame with given id"; |
698 setter = callFrame.setVariableValue.bind(callFrame); | 700 setter = callFrame.setVariableValue.bind(callFrame); |
699 } else { | 701 } else { |
700 var parsedFunctionId = this._parseObjectId(/** @type {string} */ (fu
nctionObjectId)); | 702 var parsedFunctionId = this._parseObjectId(/** @type {string} */ (fu
nctionObjectId)); |
701 var func = this._objectForId(parsedFunctionId); | 703 var func = this._objectForId(parsedFunctionId.id); |
702 if (typeof func !== "function") | 704 if (typeof func !== "function") |
703 return "Cannot resolve function by id."; | 705 return "Cannot resolve function by id."; |
704 setter = InjectedScriptHost.setFunctionVariableValue.bind(InjectedSc
riptHost, func); | 706 setter = InjectedScriptHost.setFunctionVariableValue.bind(InjectedSc
riptHost, func); |
705 } | 707 } |
706 var newValueJson; | 708 var newValueJson; |
707 try { | 709 try { |
708 newValueJson = InjectedScriptHost.evaluate("(" + newValueJsonString
+ ")"); | 710 newValueJson = InjectedScriptHost.evaluate("(" + newValueJsonString
+ ")"); |
709 } catch (e) { | 711 } catch (e) { |
710 return "Failed to parse new value JSON " + newValueJsonString + " :
" + e; | 712 return "Failed to parse new value JSON " + newValueJsonString + " :
" + e; |
711 } | 713 } |
(...skipping 20 matching lines...) Expand all Loading... |
732 { | 734 { |
733 var parsedCallFrameId = InjectedScriptHost.evaluate("(" + callFrameId +
")"); | 735 var parsedCallFrameId = InjectedScriptHost.evaluate("(" + callFrameId +
")"); |
734 var ordinal = parsedCallFrameId["ordinal"]; | 736 var ordinal = parsedCallFrameId["ordinal"]; |
735 var callFrame = topCallFrame; | 737 var callFrame = topCallFrame; |
736 while (--ordinal >= 0 && callFrame) | 738 while (--ordinal >= 0 && callFrame) |
737 callFrame = callFrame.caller; | 739 callFrame = callFrame.caller; |
738 return callFrame; | 740 return callFrame; |
739 }, | 741 }, |
740 | 742 |
741 /** | 743 /** |
742 * @param {Object} objectId | 744 * @param {number} objectId |
743 * @return {Object} | 745 * @return {*} |
744 */ | 746 */ |
745 _objectForId: function(objectId) | 747 _objectForId: function(objectId) |
746 { | 748 { |
747 return this._idToWrappedObject[objectId.id]; | 749 return this._idToWrappedObject[objectId]; |
| 750 }, |
| 751 |
| 752 /** |
| 753 * @param {number} objectId |
| 754 * @return {boolean} |
| 755 */ |
| 756 _hasObjectForId: function(objectId) |
| 757 { |
| 758 return (objectId in this._idToWrappedObject); |
748 }, | 759 }, |
749 | 760 |
750 /** | 761 /** |
751 * @param {string} objectId | 762 * @param {string} objectId |
752 * @return {Object} | 763 * @return {*} |
753 */ | 764 */ |
754 findObjectById: function(objectId) | 765 findObjectById: function(objectId) |
755 { | 766 { |
756 var parsedObjectId = this._parseObjectId(objectId); | 767 var parsedObjectId = this._parseObjectId(objectId); |
757 return this._objectForId(parsedObjectId); | 768 return this._objectForId(parsedObjectId.id); |
758 }, | 769 }, |
759 | 770 |
760 /** | 771 /** |
761 * @param {string} objectId | 772 * @param {string} objectId |
762 * @return {Node} | 773 * @return {Node} |
763 */ | 774 */ |
764 nodeForObjectId: function(objectId) | 775 nodeForObjectId: function(objectId) |
765 { | 776 { |
766 var object = this.findObjectById(objectId); | 777 var object = this.findObjectById(objectId); |
767 if (!object || this._subtype(object) !== "node") | 778 if (!object || this._subtype(object) !== "node") |
(...skipping 27 matching lines...) Expand all Loading... |
795 this._modules[name] = module; | 806 this._modules[name] = module; |
796 return module; | 807 return module; |
797 }, | 808 }, |
798 | 809 |
799 /** | 810 /** |
800 * @param {*} object | 811 * @param {*} object |
801 * @return {boolean} | 812 * @return {boolean} |
802 */ | 813 */ |
803 _isDefined: function(object) | 814 _isDefined: function(object) |
804 { | 815 { |
805 return !!object || this._isHTMLAllCollection(object); | 816 return (!!object && !InjectedScript.primitiveTypes[typeof object]) || th
is._isHTMLAllCollection(object); |
806 }, | 817 }, |
807 | 818 |
808 /** | 819 /** |
809 * @param {*} object | 820 * @param {*} object |
810 * @return {boolean} | 821 * @return {boolean} |
811 */ | 822 */ |
812 _isHTMLAllCollection: function(object) | 823 _isHTMLAllCollection: function(object) |
813 { | 824 { |
814 // document.all is reported as undefined, but we still want to process i
t. | 825 // document.all is reported as undefined, but we still want to process i
t. |
815 return (typeof object === "undefined") && InjectedScriptHost.isHTMLAllCo
llection(object); | 826 return (typeof object === "undefined") && InjectedScriptHost.isHTMLAllCo
llection(object); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 * @type {!InjectedScript} | 917 * @type {!InjectedScript} |
907 * @const | 918 * @const |
908 */ | 919 */ |
909 var injectedScript = new InjectedScript(); | 920 var injectedScript = new InjectedScript(); |
910 | 921 |
911 /** | 922 /** |
912 * @constructor | 923 * @constructor |
913 * @param {*} object | 924 * @param {*} object |
914 * @param {string=} objectGroupName | 925 * @param {string=} objectGroupName |
915 * @param {boolean=} forceValueType | 926 * @param {boolean=} forceValueType |
| 927 * @param {boolean=} forceObjectId |
916 * @param {boolean=} generatePreview | 928 * @param {boolean=} generatePreview |
917 * @param {?Array.<string>=} columnNames | 929 * @param {?Array.<string>=} columnNames |
918 * @param {boolean=} isTable | 930 * @param {boolean=} isTable |
919 */ | 931 */ |
920 InjectedScript.RemoteObject = function(object, objectGroupName, forceValueType,
generatePreview, columnNames, isTable) | 932 InjectedScript.RemoteObject = function(object, objectGroupName, forceValueType,
forceObjectId, generatePreview, columnNames, isTable) |
921 { | 933 { |
922 this.type = typeof object; | 934 this.type = typeof object; |
923 if (injectedScript.isPrimitiveValue(object) || object === null || forceValue
Type) { | 935 if (injectedScript.isPrimitiveValue(object) || object === null || forceValue
Type) { |
924 // We don't send undefined values over JSON. | 936 // We don't send undefined values over JSON. |
925 if (this.type !== "undefined") | 937 if (this.type !== "undefined") |
926 this.value = object; | 938 this.value = object; |
927 | 939 |
928 // Null object is object with 'null' subtype. | 940 // Null object is object with 'null' subtype. |
929 if (object === null) | 941 if (object === null) |
930 this.subtype = "null"; | 942 this.subtype = "null"; |
931 | 943 |
932 // Provide user-friendly number values. | 944 // Provide user-friendly number values. |
933 if (this.type === "number") | 945 if (this.type === "number") |
934 this.description = toString(object); | 946 this.description = toString(object); |
| 947 |
| 948 if (forceObjectId) |
| 949 this.objectId = injectedScript._bind(object, objectGroupName); |
935 return; | 950 return; |
936 } | 951 } |
937 | 952 |
938 object = /** @type {Object} */ (object); | 953 object = /** @type {Object} */ (object); |
939 | 954 |
940 this.objectId = injectedScript._bind(object, objectGroupName); | 955 this.objectId = injectedScript._bind(object, objectGroupName); |
941 var subtype = injectedScript._subtype(object); | 956 var subtype = injectedScript._subtype(object); |
942 if (subtype) | 957 if (subtype) |
943 this.subtype = subtype; | 958 this.subtype = subtype; |
944 this.className = InjectedScriptHost.internalConstructorName(object); | 959 this.className = InjectedScriptHost.internalConstructorName(object); |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1470 */ | 1485 */ |
1471 _logEvent: function(event) | 1486 _logEvent: function(event) |
1472 { | 1487 { |
1473 inspectedWindow.console.log(event.type, event); | 1488 inspectedWindow.console.log(event.type, event); |
1474 } | 1489 } |
1475 } | 1490 } |
1476 | 1491 |
1477 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1492 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
1478 return injectedScript; | 1493 return injectedScript; |
1479 }) | 1494 }) |
OLD | NEW |