Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3160)

Unified Diff: src/mirror-delay.js

Issue 111001: Added context information to scripts (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/factory.cc ('k') | src/objects.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/mirror-delay.js
===================================================================
--- src/mirror-delay.js (revision 1869)
+++ src/mirror-delay.js (working copy)
@@ -155,6 +155,7 @@
const PROPERTY_TYPE = 'property';
const FRAME_TYPE = 'frame';
const SCRIPT_TYPE = 'script';
+const CONTEXT_TYPE = 'context';
// Maximum length when sending strings through the JSON protocol.
const kMaxProtocolStringLength = 80;
@@ -364,6 +365,15 @@
/**
+ * Check whether the mirror reflects a context.
+ * @returns {boolean} True if the mirror reflects a context
+ */
+Mirror.prototype.isContext = function() {
+ return this instanceof ContextMirror;
+}
+
+
+/**
* Allocate a handle id for this object.
*/
Mirror.prototype.allocateHandle_ = function() {
@@ -1547,6 +1557,7 @@
function ScriptMirror(script) {
Mirror.call(this, SCRIPT_TYPE);
this.script_ = script;
+ this.context_ = new ContextMirror(script.context_data);
this.allocateHandle_();
}
inherits(ScriptMirror, Mirror);
@@ -1608,6 +1619,11 @@
}
+ScriptMirror.prototype.context = function() {
+ return this.context_;
+};
+
+
ScriptMirror.prototype.toText = function() {
var result = '';
result += this.name();
@@ -1625,13 +1641,35 @@
/**
+ * Mirror object for context.
+ * @param {Object} data The context data
+ * @constructor
+ * @extends Mirror
+ */
+function ContextMirror(data) {
+ Mirror.call(this, CONTEXT_TYPE);
+ this.data_ = data;
+ this.allocateHandle_();
+}
+inherits(ContextMirror, Mirror);
+
+
+ContextMirror.prototype.data = function() {
+ return this.data_;
+};
+
+
+/**
* Returns a mirror serializer
*
* @param {boolean} details Set to true to include details
+ * @param {Object} options Options comtrolling the serialization
+ * The following options can be set:
+ * includeSource: include ths full source of scripts
* @returns {MirrorSerializer} mirror serializer
*/
-function MakeMirrorSerializer(details) {
- return new JSONProtocolSerializer(details);
+function MakeMirrorSerializer(details, options) {
+ return new JSONProtocolSerializer(details, options);
}
@@ -1641,8 +1679,9 @@
* serialized
* @constructor
*/
-function JSONProtocolSerializer(details) {
+function JSONProtocolSerializer(details, options) {
this.details_ = details;
+ this.options_ = options;
this.mirrors_ = [ ];
}
@@ -1694,6 +1733,11 @@
}
+JSONProtocolSerializer.prototype.includeSource_ = function() {
+ return this.options_ && this.options_.includeSource;
+}
+
+
JSONProtocolSerializer.prototype.add_ = function(mirror) {
// If this mirror is already in the list just return.
for (var i = 0; i < this.mirrors_.length; i++) {
@@ -1712,7 +1756,7 @@
// If serializing a reference to a mirror just return the reference and add
// the mirror to the referenced mirrors.
if (reference &&
- (mirror.isValue() || mirror.isScript())) {
+ (mirror.isValue() || mirror.isScript() || mirror.isContext())) {
this.add_(mirror);
return '{"ref":' + mirror.handle() + '}';
}
@@ -1721,7 +1765,7 @@
var content = new Array();
// Add the mirror handle.
- if (mirror.isValue() || mirror.isScript()) {
+ if (mirror.isValue() || mirror.isScript() || mirror.isContext()) {
content.push(MakeJSONPair_('handle', NumberToJSON_(mirror.handle())));
}
@@ -1787,9 +1831,30 @@
NumberToJSON_(mirror.columnOffset())));
content.push(MakeJSONPair_('lineCount',
NumberToJSON_(mirror.lineCount())));
+ if (mirror.data()) {
+ content.push(MakeJSONPair_('data', JSON.stringify(mirror.data())));
+ }
+ if (this.includeSource_()) {
+ content.push(MakeJSONPair_('source',
+ StringToJSON_(mirror.source())));
+ } else {
+ var sourceStart = mirror.source().substring(0, 80);
+ content.push(MakeJSONPair_('sourceStart',
+ StringToJSON_(sourceStart)));
+ }
+ content.push(MakeJSONPair_('sourceLength',
yurys 2009/05/06 07:22:34 it seems that you can switch to JSON.stringify for
Søren Thygesen Gjesse 2009/05/06 07:48:54 Sure, that would clean up the code quite a bit.
+ NumberToJSON_(mirror.source().length)));
content.push(MakeJSONPair_('scriptType',
NumberToJSON_(mirror.scriptType())));
+ if (mirror.context()) {
+ content.push(MakeJSONPair_('context',
+ this.serializeReference(mirror.context())));
+ }
break;
+
+ case CONTEXT_TYPE:
+ content.push(MakeJSONPair_('data', JSON.stringify(mirror.data())));
+ break;
}
// Always add the text representation.
« no previous file with comments | « src/factory.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698