OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Javascript that is being injected into the inspectable page | 6 * @fileoverview Javascript that is being injected into the inspectable page |
7 * while debugging. | 7 * while debugging. |
8 */ | 8 */ |
9 goog.provide('devtools.Injected'); | 9 goog.provide('devtools.Injected'); |
10 | 10 |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 }; | 538 }; |
539 | 539 |
540 | 540 |
541 /** | 541 /** |
542 * Caches console object for subsequent calls to getConsoleObjectProperties. | 542 * Caches console object for subsequent calls to getConsoleObjectProperties. |
543 * @param {Object} obj Object to cache. | 543 * @param {Object} obj Object to cache. |
544 * @return {Object} console object wrapper. | 544 * @return {Object} console object wrapper. |
545 */ | 545 */ |
546 devtools.Injected.prototype.wrapConsoleObject = function(obj) { | 546 devtools.Injected.prototype.wrapConsoleObject = function(obj) { |
547 var type = typeof obj; | 547 var type = typeof obj; |
548 if (type == 'object' || type == 'function') { | 548 if ((type == 'object' && obj != null) || type == 'function') { |
549 var objId = '#consoleobj#' + this.lastCachedConsoleObjectId_++; | 549 var objId = '#consoleobj#' + this.lastCachedConsoleObjectId_++; |
550 this.cachedConsoleObjects_[objId] = obj; | 550 this.cachedConsoleObjects_[objId] = obj; |
551 var result = { ___devtools_id : objId }; | 551 var result = { ___devtools_id : objId }; |
552 // Loop below fills dummy object with properties for completion. | 552 // Loop below fills dummy object with properties for completion. |
553 for (var name in obj) { | 553 for (var name in obj) { |
554 result[name] = ''; | 554 result[name] = ''; |
555 } | 555 } |
556 return result; | 556 return result; |
557 } else { | |
558 return obj; | |
559 } | 557 } |
| 558 return obj; |
560 }; | 559 }; |
561 | 560 |
562 | 561 |
563 /** | 562 /** |
564 * Caches console object for subsequent calls to getConsoleObjectProperties. | 563 * Caches console object for subsequent calls to getConsoleObjectProperties. |
565 * @param {Object} obj Object to cache. | 564 * @param {Object} obj Object to cache. |
566 * @return {string} console object id. | 565 * @return {string} Console object wrapper serialized into a JSON string. |
567 */ | 566 */ |
568 devtools.Injected.prototype.evaluate = function(expression) { | 567 devtools.Injected.prototype.serializeConsoleObject = function(obj) { |
569 try { | 568 var result = this.wrapConsoleObject(obj); |
570 // Evaluate the expression in the global context of the inspected window. | 569 return JSON.stringify(result, |
571 return [ this.wrapConsoleObject(contentWindow.eval(expression)), false ]; | 570 function (key, value) { |
572 } catch (e) { | 571 if (value === undefined) { |
573 return [ e.toString(), true ]; | 572 return 'undefined'; |
574 } | 573 } |
| 574 return value; |
| 575 }); |
575 }; | 576 }; |
576 | 577 |
577 | 578 |
578 /** | 579 /** |
579 * Dispatches given method with given args on the host object. | 580 * Dispatches given method with given args on the host object. |
580 * @param {string} method Method name. | 581 * @param {string} method Method name. |
581 */ | 582 */ |
582 devtools.Injected.prototype.InspectorController = function(method, var_args) { | 583 devtools.Injected.prototype.InspectorController = function(method, var_args) { |
583 var args = Array.prototype.slice.call(arguments, 1); | 584 var args = Array.prototype.slice.call(arguments, 1); |
584 return InspectorController[method].apply(InspectorController, args); | 585 return InspectorController[method].apply(InspectorController, args); |
585 }; | 586 }; |
OLD | NEW |