From: yurys@chromium.org Date: Fri, 15 May 2009 07:35:11 +0000 (+0000) Subject: MirrorSerializer now converts mirrors to plain JS objects. This objects are serialize... X-Git-Tag: upstream/4.7.83~24103 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=acfc50ac126a41162e6ead602f14a96d6336fb17;p=platform%2Fupstream%2Fv8.git MirrorSerializer now converts mirrors to plain JS objects. This objects are serialized to json string using JSON.stringify. Review URL: http://codereview.chromium.org/113399 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1957 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/debug-delay.js b/src/debug-delay.js index 8530ca8..c7d1a87 100644 --- a/src/debug-delay.js +++ b/src/debug-delay.js @@ -833,7 +833,7 @@ BreakEvent.prototype.toJSONProtocol = function() { event: "break", body: { invocationText: this.exec_state_.frame(0).invocationText(), } - } + }; // Add script related information to the event if available. var script = this.func().script(); @@ -861,8 +861,7 @@ BreakEvent.prototype.toJSONProtocol = function() { o.body.breakpoints.push(number); } } - - return SimpleObjectToJSON_(o); + return JSON.stringify(ObjectToProtocolObject_(o)); }; @@ -923,7 +922,7 @@ ExceptionEvent.prototype.toJSONProtocol = function() { o.event = "exception"; o.body = { uncaught: this.uncaught_, exception: MakeMirror(this.exception_) - } + }; // Exceptions might happen whithout any JavaScript frames. if (this.exec_state_.frameCount() > 0) { @@ -1079,56 +1078,53 @@ ProtocolMessage.prototype.failed = function(message) { ProtocolMessage.prototype.toJSONProtocol = function() { // Encode the protocol header. - var json = '{'; - json += '"seq":' + this.seq; + var json = {}; + json.seq= this.seq; if (this.request_seq) { - json += ',"request_seq":' + this.request_seq; + json.request_seq = this.request_seq; } - json += ',"type":"' + this.type + '"'; + json.type = this.type; if (this.event) { - json += ',"event":' + StringToJSON_(this.event); + json.event = this.event; } if (this.command) { - json += ',"command":' + StringToJSON_(this.command); + json.command = this.command; } if (this.success) { - json += ',"success":' + this.success; + json.success = this.success; } else { - json += ',"success":false'; + json.success = false; } if (this.body) { - json += ',"body":'; // Encode the body part. + var bodyJson; var serializer = MakeMirrorSerializer(true, this.options_); if (this.body instanceof Mirror) { - json += serializer.serializeValue(this.body); + bodyJson = serializer.serializeValue(this.body); } else if (this.body instanceof Array) { - json += '['; + bodyJson = []; for (var i = 0; i < this.body.length; i++) { - if (i != 0) json += ','; if (this.body[i] instanceof Mirror) { - json += serializer.serializeValue(this.body[i]); + bodyJson.push(serializer.serializeValue(this.body[i])); } else { - json += SimpleObjectToJSON_(this.body[i], serializer); + bodyJson.push(ObjectToProtocolObject_(this.body[i], serializer)); } } - json += ']'; } else { - json += SimpleObjectToJSON_(this.body, serializer); + bodyJson = ObjectToProtocolObject_(this.body, serializer); } - json += ',"refs":'; - json += serializer.serializeReferencedObjects(); + json.body = bodyJson; + json.refs = serializer.serializeReferencedObjects(); } if (this.message) { - json += ',"message":' + StringToJSON_(this.message) ; + json.message = this.message; } if (this.running) { - json += ',"running":true'; + json.running = true; } else { - json += ',"running":false'; + json.running = false; } - json += '}'; - return json; + return JSON.stringify(json); } @@ -1799,97 +1795,82 @@ DebugCommandProcessor.prototype.formatCFrame = function(cframe_value) { /** - * Convert an Object to its JSON representation (see http://www.json.org/). - * This implementation simply runs through all string property names and adds - * each property to the JSON representation for some predefined types. For type - * "object" the function calls itself recursively unless the object has the - * function property "toJSONProtocol" in which case that is used. This is not - * a general implementation but sufficient for the debugger. Note that circular - * structures will cause infinite recursion. - * @param {Object} object The object to format as JSON + * Convert an Object to its debugger protocol representation. The representation + * may be serilized to a JSON object using JSON.stringify(). + * This implementation simply runs through all string property names, converts + * each property value to a protocol value and adds the property to the result + * object. For type "object" the function will be called recursively. Note that + * circular structures will cause infinite recursion. + * @param {Object} object The object to format as protocol object. * @param {MirrorSerializer} mirror_serializer The serializer to use if any * mirror objects are encountered. - * @return {string} JSON formatted object value + * @return {Object} Protocol object value. */ -function SimpleObjectToJSON_(object, mirror_serializer) { - var content = []; +function ObjectToProtocolObject_(object, mirror_serializer) { + var content = {}; for (var key in object) { // Only consider string keys. if (typeof key == 'string') { - var property_value = object[key]; - // Format the value based on its type. - var property_value_json; - switch (typeof property_value) { - case 'object': - if (property_value instanceof Mirror) { - property_value_json = mirror_serializer.serializeValue(property_value); - } else if (typeof property_value.toJSONProtocol == 'function') { - property_value_json = property_value.toJSONProtocol(true) - } else if (IS_ARRAY(property_value)){ - property_value_json = SimpleArrayToJSON_(property_value, mirror_serializer); - } else { - property_value_json = SimpleObjectToJSON_(property_value, mirror_serializer); - } - break; - - case 'boolean': - property_value_json = BooleanToJSON_(property_value); - break; - - case 'number': - property_value_json = NumberToJSON_(property_value); - break; - - case 'string': - property_value_json = StringToJSON_(property_value); - break; - - default: - property_value_json = null; - } - + var property_value_json = ValueToProtocolValue_(object[key], + mirror_serializer); // Add the property if relevant. - if (property_value_json) { - content.push(StringToJSON_(key) + ':' + property_value_json); + if (!IS_UNDEFINED(property_value_json)) { + content[key] = property_value_json; } } } - - // Make JSON object representation. - return '{' + content.join(',') + '}'; + + return content; } + /** - * Convert an array to its JSON representation. This is a VERY simple - * implementation just to support what is needed for the debugger. - * @param {Array} array The array to format as JSON + * Convert an array to its debugger protocol representation. It will convert + * each array element to a protocol value. + * @param {Array} array The array to format as protocol array. * @param {MirrorSerializer} mirror_serializer The serializer to use if any * mirror objects are encountered. - * @return {string} JSON formatted array value + * @return {Array} Protocol array value. */ -function SimpleArrayToJSON_(array, mirror_serializer) { - // Make JSON array representation. - var json = '['; +function ArrayToProtocolArray_(array, mirror_serializer) { + var json = []; for (var i = 0; i < array.length; i++) { - if (i != 0) { - json += ','; - } - var elem = array[i]; - if (elem instanceof Mirror) { - json += mirror_serializer.serializeValue(elem); - } else if (IS_OBJECT(elem)) { - json += SimpleObjectToJSON_(elem); - } else if (IS_BOOLEAN(elem)) { - json += BooleanToJSON_(elem); - } else if (IS_NUMBER(elem)) { - json += NumberToJSON_(elem); - } else if (IS_STRING(elem)) { - json += StringToJSON_(elem); - } else { - json += elem; - } + json.push(ValueToProtocolValue_(array[i], mirror_serializer)); + } + return json; +} + + +/** + * Convert a value to its debugger protocol representation. + * @param {*} value The value to format as protocol value. + * @param {MirrorSerializer} mirror_serializer The serializer to use if any + * mirror objects are encountered. + * @return {*} Protocol value. + */ +function ValueToProtocolValue_(value, mirror_serializer) { + // Format the value based on its type. + var json; + switch (typeof value) { + case 'object': + if (value instanceof Mirror) { + json = mirror_serializer.serializeValue(value); + } else if (IS_ARRAY(value)){ + json = ArrayToProtocolArray_(value, mirror_serializer); + } else { + json = ObjectToProtocolObject_(value, mirror_serializer); + } + break; + + case 'boolean': + case 'string': + case 'number': + json = value; + break + + default: + json = null; } - json += ']'; return json; } diff --git a/src/mirror-delay.js b/src/mirror-delay.js index 30f19f0..b6dc495 100644 --- a/src/mirror-delay.js +++ b/src/mirror-delay.js @@ -29,8 +29,7 @@ // Touch the RegExp and Date functions to make sure that date-delay.js and // regexp-delay.js has been loaded. This is required as the mirrors use -// functions within these files through the builtins object. See the -// function DateToISO8601_ as an example. +// functions within these files through the builtins object. RegExp; Date; @@ -935,7 +934,8 @@ inherits(DateMirror, ObjectMirror); DateMirror.prototype.toText = function() { - return DateToISO8601_(this.value_); + var s = JSON.stringify(this.value_); + return s.substring(1, s.length - 1); // cut quotes } @@ -1728,12 +1728,13 @@ JSONProtocolSerializer.prototype.serializeValue = function(mirror) { /** * Returns a serialization of all the objects referenced. * - * @param {Mirror} mirror The mirror to serialize - * @returns {String} JSON serialization + * @param {Mirror} mirror The mirror to serialize. + * @returns {Array.} Array of the referenced objects converted to + * protcol objects. */ JSONProtocolSerializer.prototype.serializeReferencedObjects = function() { - // Collect the JSON serialization of the referenced objects in an array. - var content = new Array(); + // Collect the protocol representation of the referenced objects in an array. + var content = []; // Get the number of referenced objects. var count = this.mirrors_.length; @@ -1742,8 +1743,7 @@ JSONProtocolSerializer.prototype.serializeReferencedObjects = function() { content.push(this.serialize_(this.mirrors_[i], false, false)); } - var json = ArrayToJSONArray_(content); - return json; + return content; } @@ -1772,19 +1772,19 @@ JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, if (reference && (mirror.isValue() || mirror.isScript() || mirror.isContext())) { this.add_(mirror); - return '{"ref":' + mirror.handle() + '}'; + return {'ref' : mirror.handle()}; } - // Collect the JSON property/value pairs in an array. - var content = new Array(); + // Collect the JSON property/value pairs. + var content = {}; // Add the mirror handle. if (mirror.isValue() || mirror.isScript() || mirror.isContext()) { - content.push(MakeJSONPair_('handle', NumberToJSON_(mirror.handle()))); + content.handle = mirror.handle(); } // Always add the type. - content.push(MakeJSONPair_('type', StringToJSON_(mirror.type()))); + content.type = mirror.type(); switch (mirror.type()) { case UNDEFINED_TYPE: @@ -1794,26 +1794,25 @@ JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, case BOOLEAN_TYPE: // Boolean values are simply represented by their value. - content.push(MakeJSONPair_('value', BooleanToJSON_(mirror.value()))); + content.value = mirror.value(); break; case NUMBER_TYPE: // Number values are simply represented by their value. - content.push(MakeJSONPair_('value', NumberToJSON_(mirror.value()))); + content.value = NumberToJSON_(mirror.value()); break; case STRING_TYPE: // String values might have their value cropped to keep down size. if (mirror.length() > kMaxProtocolStringLength) { var str = mirror.value().substring(0, kMaxProtocolStringLength); - content.push(MakeJSONPair_('value', StringToJSON_(str))); - content.push(MakeJSONPair_('fromIndex', NumberToJSON_(0))); - content.push(MakeJSONPair_('toIndex', - NumberToJSON_(kMaxProtocolStringLength))); + content.value = str; + content.fromIndex = 0; + content.toIndex = kMaxProtocolStringLength; } else { - content.push(MakeJSONPair_('value', StringToJSON_(mirror.value()))); + content.value = mirror.value(); } - content.push(MakeJSONPair_('length', NumberToJSON_(mirror.length()))); + content.length = mirror.length(); break; case OBJECT_TYPE: @@ -1836,46 +1835,38 @@ JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, case SCRIPT_TYPE: // Script is represented by id, name and source attributes. if (mirror.name()) { - content.push(MakeJSONPair_('name', StringToJSON_(mirror.name()))); + content.name = mirror.name(); } - content.push(MakeJSONPair_('id', NumberToJSON_(mirror.id()))); - content.push(MakeJSONPair_('lineOffset', - NumberToJSON_(mirror.lineOffset()))); - content.push(MakeJSONPair_('columnOffset', - NumberToJSON_(mirror.columnOffset()))); - content.push(MakeJSONPair_('lineCount', - NumberToJSON_(mirror.lineCount()))); + content.id = mirror.id(); + content.lineOffset = mirror.lineOffset(); + content.columnOffset = mirror.columnOffset(); + content.lineCount = mirror.lineCount(); if (mirror.data()) { - content.push(MakeJSONPair_('data', JSON.stringify(mirror.data()))); + content.data = mirror.data(); } if (this.includeSource_()) { - content.push(MakeJSONPair_('source', - StringToJSON_(mirror.source()))); + content.source = mirror.source(); } else { var sourceStart = mirror.source().substring(0, 80); - content.push(MakeJSONPair_('sourceStart', - StringToJSON_(sourceStart))); + content.sourceStart = sourceStart; } - content.push(MakeJSONPair_('sourceLength', - NumberToJSON_(mirror.source().length))); - content.push(MakeJSONPair_('scriptType', - NumberToJSON_(mirror.scriptType()))); + content.sourceLength = mirror.source().length; + content.scriptType = mirror.scriptType(); if (mirror.context()) { - content.push(MakeJSONPair_('context', - this.serializeReference(mirror.context()))); + content.context = this.serializeReference(mirror.context()); } break; case CONTEXT_TYPE: - content.push(MakeJSONPair_('data', JSON.stringify(mirror.data()))); + content.data = mirror.data(); break; } // Always add the text representation. - content.push(MakeJSONPair_('text', StringToJSON_(mirror.toText()))); + content.text = mirror.toText(); // Create and return the JSON string. - return ArrayToJSONObject_(content); + return content; } @@ -1893,44 +1884,40 @@ JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content, details) { // Add general object properties. - content.push(MakeJSONPair_('className', - StringToJSON_(mirror.className()))); - content.push(MakeJSONPair_('constructorFunction', - this.serializeReference(mirror.constructorFunction()))); - content.push(MakeJSONPair_('protoObject', - this.serializeReference(mirror.protoObject()))); - content.push(MakeJSONPair_('prototypeObject', - this.serializeReference(mirror.prototypeObject()))); + content.className = mirror.className(); + content.constructorFunction = + this.serializeReference(mirror.constructorFunction()); + content.protoObject = this.serializeReference(mirror.protoObject()); + content.prototypeObject = this.serializeReference(mirror.prototypeObject()); // Add flags to indicate whether there are interceptors. if (mirror.hasNamedInterceptor()) { - content.push(MakeJSONPair_('namedInterceptor', BooleanToJSON_(true))); + content.namedInterceptor = true; } if (mirror.hasIndexedInterceptor()) { - content.push(MakeJSONPair_('indexedInterceptor', BooleanToJSON_(true))); + content.indexedInterceptor = true; } // Add function specific properties. if (mirror.isFunction()) { // Add function specific properties. - content.push(MakeJSONPair_('name', StringToJSON_(mirror.name()))); + content.name = mirror.name(); if (!IS_UNDEFINED(mirror.inferredName())) { - content.push(MakeJSONPair_('inferredName', - StringToJSON_(mirror.inferredName()))); + content.inferredName = mirror.inferredName(); } - content.push(MakeJSONPair_('resolved', BooleanToJSON_(mirror.resolved()))); + content.resolved = mirror.resolved(); if (mirror.resolved()) { - content.push(MakeJSONPair_('source', StringToJSON_(mirror.source()))); + content.source = mirror.source(); } if (mirror.script()) { - content.push(MakeJSONPair_('script', this.serializeReference(mirror.script()))); + content.script = this.serializeReference(mirror.script()); } } // Add date specific properties. if (mirror.isDate()) { // Add date specific properties. - content.push(MakeJSONPair_('value', DateToJSON_(mirror.value()))); + content.value = mirror.value(); } // Add actual properties - named properties followed by indexed properties. @@ -1938,20 +1925,20 @@ JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content, var propertyIndexes = mirror.propertyNames(PropertyKind.Indexed); var p = new Array(propertyNames.length + propertyIndexes.length); for (var i = 0; i < propertyNames.length; i++) { - var property_mirror = mirror.property(propertyNames[i]); - p[i] = this.serializeProperty_(property_mirror); + var propertyMirror = mirror.property(propertyNames[i]); + p[i] = this.serializeProperty_(propertyMirror); if (details) { - this.add_(property_mirror.value()); + this.add_(propertyMirror.value()); } } for (var i = 0; i < propertyIndexes.length; i++) { - var property_mirror = mirror.property(propertyIndexes[i]); - p[propertyNames.length + i] = this.serializeProperty_(property_mirror); + var propertyMirror = mirror.property(propertyIndexes[i]); + p[propertyNames.length + i] = this.serializeProperty_(propertyMirror); if (details) { - this.add_(property_mirror.value()); + this.add_(propertyMirror.value()); } } - content.push(MakeJSONPair_('properties', ArrayToJSONArray_(p))); + content.properties = p; } @@ -1971,207 +1958,88 @@ JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content, * {"name":"hello","ref":1} * {"name":"length","attributes":7,"propertyType":3,"ref":2} * - * @param {PropertyMirror} property_mirror The property to serialize - * @returns {String} JSON serialization + * @param {PropertyMirror} propertyMirror The property to serialize. + * @returns {Object} Protocol object representing the property. */ -JSONProtocolSerializer.prototype.serializeProperty_ = function(property_mirror) { - var builder = new builtins.StringBuilder(); - builder.add('{"name":'); - builder.add(StringToJSON_(property_mirror.name())); - if (property_mirror.attributes() != PropertyAttribute.None) { - builder.add(',"attributes":'); - builder.add(NumberToJSON_(property_mirror.attributes())); +JSONProtocolSerializer.prototype.serializeProperty_ = function(propertyMirror) { + var result = {}; + + result.name = propertyMirror.name(); + if (propertyMirror.attributes() != PropertyAttribute.None) { + result.attributes = propertyMirror.attributes(); } - if (property_mirror.propertyType() != PropertyType.Normal) { - builder.add(',"propertyType":'); - builder.add(NumberToJSON_(property_mirror.propertyType())); + if (propertyMirror.propertyType() != PropertyType.Normal) { + result.propertyType = propertyMirror.propertyType(); } - builder.add(',"ref":'); - builder.add(NumberToJSON_(property_mirror.value().handle())); - builder.add('}'); - return builder.generate(); + result.ref = propertyMirror.value().handle(); + return result; } JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) { - content.push(MakeJSONPair_('index', NumberToJSON_(mirror.index()))); - content.push(MakeJSONPair_('receiver', - this.serializeReference(mirror.receiver()))); + content.index = mirror.index(); + content.receiver = this.serializeReference(mirror.receiver()); var func = mirror.func(); - content.push(MakeJSONPair_('func', this.serializeReference(func))); + content.func = this.serializeReference(func); if (func.script()) { - content.push(MakeJSONPair_('script', - this.serializeReference(func.script()))); + content.script = this.serializeReference(func.script()); } - content.push(MakeJSONPair_('constructCall', - BooleanToJSON_(mirror.isConstructCall()))); - content.push(MakeJSONPair_('debuggerFrame', - BooleanToJSON_(mirror.isDebuggerFrame()))); + content.constructCall = mirror.isConstructCall(); + content.debuggerFrame = mirror.isDebuggerFrame(); var x = new Array(mirror.argumentCount()); for (var i = 0; i < mirror.argumentCount(); i++) { - arg = new Array(); + var arg = {}; var argument_name = mirror.argumentName(i) if (argument_name) { - arg.push(MakeJSONPair_('name', StringToJSON_(argument_name))); + arg.name = argument_name; } - arg.push(MakeJSONPair_('value', - this.serializeReference(mirror.argumentValue(i)))); - x[i] = ArrayToJSONObject_(arg); + arg.value = this.serializeReference(mirror.argumentValue(i)); + x[i] = arg; } - content.push(MakeJSONPair_('arguments', ArrayToJSONArray_(x))); + content.arguments = x; var x = new Array(mirror.localCount()); for (var i = 0; i < mirror.localCount(); i++) { - var name = MakeJSONPair_('name', StringToJSON_(mirror.localName(i))); - var value = MakeJSONPair_('value', - this.serializeReference(mirror.localValue(i))); - x[i] = '{' + name + ',' + value + '}'; + var local = {}; + local.name = mirror.localName(i); + local.value = this.serializeReference(mirror.localValue(i)); + x[i] = local; } - content.push(MakeJSONPair_('locals', ArrayToJSONArray_(x))); - content.push(MakeJSONPair_('position', - NumberToJSON_(mirror.sourcePosition()))); + content.locals = x; + content.position = mirror.sourcePosition(); var line = mirror.sourceLine(); if (!IS_UNDEFINED(line)) { - content.push(MakeJSONPair_('line', NumberToJSON_(line))); + content.line = line; } var column = mirror.sourceColumn(); if (!IS_UNDEFINED(column)) { - content.push(MakeJSONPair_('column', NumberToJSON_(column))); + content.column = column; } var source_line_text = mirror.sourceLineText(); if (!IS_UNDEFINED(source_line_text)) { - content.push(MakeJSONPair_('sourceLineText', - StringToJSON_(source_line_text))); + content.sourceLineText = source_line_text; } } -function MakeJSONPair_(name, value) { - return '"' + name + '":' + value; -} - - -function ArrayToJSONObject_(content) { - return '{' + content.join(',') + '}'; -} - - -function ArrayToJSONArray_(content) { - return '[' + content.join(',') + ']'; -} - - -function BooleanToJSON_(value) { - return String(value); -} - - /** - * Convert a number to a JSON string value. For all finite numbers the number - * literal representation is used. For non finite numbers NaN, Infinite and + * Convert a number to a protocol value. For all finite numbers the number + * itself is returned. For non finite numbers NaN, Infinite and * -Infinite the string representation "NaN", "Infinite" or "-Infinite" - * (including the quotes) is returned. + * (not including the quotes) is returned. * - * @param {number} value The number value to convert to a JSON value - * @returns {String} JSON value + * @param {number} value The number value to convert to a protocol value. + * @returns {number|string} Protocol value. */ function NumberToJSON_(value) { if (isNaN(value)) { - return '"NaN"'; + return 'NaN'; } if (!isFinite(value)) { if (value > 0) { - return '"Infinity"'; + return 'Infinity'; } else { - return '"-Infinity"'; + return '-Infinity'; } } - return String(value); -} - - -// Mapping of some control characters to avoid the \uXXXX syntax for most -// commonly used control cahracters. -const ctrlCharMap_ = { - '\b': '\\b', - '\t': '\\t', - '\n': '\\n', - '\f': '\\f', - '\r': '\\r', - '"' : '\\"', - '\\': '\\\\' -}; - - -// Regular expression testing for ", \ and control characters (0x00 - 0x1F). -const ctrlCharTest_ = new RegExp('["\\\\\x00-\x1F]'); - - -// Regular expression matching ", \ and control characters (0x00 - 0x1F) -// globally. -const ctrlCharMatch_ = new RegExp('["\\\\\x00-\x1F]', 'g'); - - -/** - * Convert a String to its JSON representation (see http://www.json.org/). To - * avoid depending on the String object this method calls the functions in - * string.js directly and not through the value. - * @param {String} value The String value to format as JSON - * @return {string} JSON formatted String value - */ -function StringToJSON_(value) { - // Check for" , \ and control characters (0x00 - 0x1F). No need to call - // RegExpTest as ctrlchar is constructed using RegExp. - if (ctrlCharTest_.test(value)) { - // Replace ", \ and control characters (0x00 - 0x1F). - return '"' + - value.replace(ctrlCharMatch_, function (char) { - // Use charmap if possible. - var mapped = ctrlCharMap_[char]; - if (mapped) return mapped; - mapped = char.charCodeAt(); - // Convert control character to unicode escape sequence. - return '\\u00' + - %NumberToRadixString(Math.floor(mapped / 16), 16) + - %NumberToRadixString(mapped % 16, 16); - }) - + '"'; - } - - // Simple string with no special characters. - return '"' + value + '"'; -} - - -/** - * Convert a Date to ISO 8601 format. To avoid depending on the Date object - * this method calls the functions in date.js directly and not through the - * value. - * @param {Date} value The Date value to format as JSON - * @return {string} JSON formatted Date value - */ -function DateToISO8601_(value) { - function f(n) { - return n < 10 ? '0' + n : n; - } - function g(n) { - return n < 10 ? '00' + n : n < 100 ? '0' + n : n; - } - return builtins.GetUTCFullYearFrom(value) + '-' + - f(builtins.GetUTCMonthFrom(value) + 1) + '-' + - f(builtins.GetUTCDateFrom(value)) + 'T' + - f(builtins.GetUTCHoursFrom(value)) + ':' + - f(builtins.GetUTCMinutesFrom(value)) + ':' + - f(builtins.GetUTCSecondsFrom(value)) + '.' + - g(builtins.GetUTCMillisecondsFrom(value)) + 'Z'; -} - -/** - * Convert a Date to ISO 8601 format. To avoid depending on the Date object - * this method calls the functions in date.js directly and not through the - * value. - * @param {Date} value The Date value to format as JSON - * @return {string} JSON formatted Date value - */ -function DateToJSON_(value) { - return '"' + DateToISO8601_(value) + '"'; + return value; } diff --git a/test/mjsunit/mirror-array.js b/test/mjsunit/mirror-array.js index 1873d1e..eb8f72a 100644 --- a/test/mjsunit/mirror-array.js +++ b/test/mjsunit/mirror-array.js @@ -44,8 +44,9 @@ function testArrayMirror(a, names) { // Create mirror and JSON representation. var mirror = debug.MakeMirror(a); var serializer = debug.MakeMirrorSerializer(); - var json = serializer.serializeValue(mirror); - var refs = new MirrorRefCache(serializer.serializeReferencedObjects()); + var json = JSON.stringify(serializer.serializeValue(mirror)); + var refs = new MirrorRefCache( + JSON.stringify(serializer.serializeReferencedObjects())); // Check the mirror hierachy. assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierachy'); diff --git a/test/mjsunit/mirror-boolean.js b/test/mjsunit/mirror-boolean.js index 4f93089..311c781 100644 --- a/test/mjsunit/mirror-boolean.js +++ b/test/mjsunit/mirror-boolean.js @@ -32,7 +32,7 @@ function testBooleanMirror(b) { // Create mirror and JSON representation. var mirror = debug.MakeMirror(b); var serializer = debug.MakeMirrorSerializer(); - var json = serializer.serializeValue(mirror); + var json = JSON.stringify(serializer.serializeValue(mirror)); // Check the mirror hierachy. assertTrue(mirror instanceof debug.Mirror); diff --git a/test/mjsunit/mirror-date.js b/test/mjsunit/mirror-date.js index a6334d0..6b6a3ad 100644 --- a/test/mjsunit/mirror-date.js +++ b/test/mjsunit/mirror-date.js @@ -32,7 +32,7 @@ function testDateMirror(d, iso8601) { // Create mirror and JSON representation. var mirror = debug.MakeMirror(d); var serializer = debug.MakeMirrorSerializer(); - var json = serializer.serializeValue(mirror); + var json = JSON.stringify(serializer.serializeValue(mirror)); // Check the mirror hierachy. assertTrue(mirror instanceof debug.Mirror); @@ -55,9 +55,9 @@ function testDateMirror(d, iso8601) { assertEquals(iso8601, fromJSON.value); } - // Test Date values. -testDateMirror(new Date(Date.parse("Dec 25, 1995 1:30 UTC")), "1995-12-25T01:30:00.000Z"); +testDateMirror(new Date(Date.parse("Dec 25, 1995 1:30 UTC")), + "1995-12-25T01:30:00Z"); d = new Date(); d.setUTCFullYear(1967); d.setUTCMonth(0); // January. @@ -66,10 +66,10 @@ d.setUTCHours(9); d.setUTCMinutes(22); d.setUTCSeconds(59); d.setUTCMilliseconds(0); -testDateMirror(d, "1967-01-17T09:22:59.000Z"); +testDateMirror(d, "1967-01-17T09:22:59Z"); d.setUTCMilliseconds(1); -testDateMirror(d, "1967-01-17T09:22:59.001Z"); -d.setUTCMilliseconds(12); -testDateMirror(d, "1967-01-17T09:22:59.012Z"); -d.setUTCMilliseconds(123); -testDateMirror(d, "1967-01-17T09:22:59.123Z"); +testDateMirror(d, "1967-01-17T09:22:59Z"); +d.setUTCSeconds(12); +testDateMirror(d, "1967-01-17T09:22:12Z"); +d.setUTCSeconds(36); +testDateMirror(d, "1967-01-17T09:22:36Z"); diff --git a/test/mjsunit/mirror-error.js b/test/mjsunit/mirror-error.js index 37ec46c..4ed8c1b 100644 --- a/test/mjsunit/mirror-error.js +++ b/test/mjsunit/mirror-error.js @@ -44,8 +44,9 @@ function testErrorMirror(e) { // Create mirror and JSON representation. var mirror = debug.MakeMirror(e); var serializer = debug.MakeMirrorSerializer(); - var json = serializer.serializeValue(mirror); - var refs = new MirrorRefCache(serializer.serializeReferencedObjects()); + var json = JSON.stringify(serializer.serializeValue(mirror)); + var refs = new MirrorRefCache( + JSON.stringify(serializer.serializeReferencedObjects())); // Check the mirror hierachy. assertTrue(mirror instanceof debug.Mirror); diff --git a/test/mjsunit/mirror-function.js b/test/mjsunit/mirror-function.js index 59d9e78..58aee3d 100644 --- a/test/mjsunit/mirror-function.js +++ b/test/mjsunit/mirror-function.js @@ -44,8 +44,9 @@ function testFunctionMirror(f) { // Create mirror and JSON representation. var mirror = debug.MakeMirror(f); var serializer = debug.MakeMirrorSerializer(); - var json = serializer.serializeValue(mirror); - var refs = new MirrorRefCache(serializer.serializeReferencedObjects()); + var json = JSON.stringify(serializer.serializeValue(mirror)); + var refs = new MirrorRefCache( + JSON.stringify(serializer.serializeReferencedObjects())); // Check the mirror hierachy. assertTrue(mirror instanceof debug.Mirror); diff --git a/test/mjsunit/mirror-null.js b/test/mjsunit/mirror-null.js index db68966..1ee555b 100644 --- a/test/mjsunit/mirror-null.js +++ b/test/mjsunit/mirror-null.js @@ -31,7 +31,7 @@ // Create mirror and JSON representation. var mirror = debug.MakeMirror(null); var serializer = debug.MakeMirrorSerializer(); -var json = serializer.serializeValue(mirror); +var json = JSON.stringify(serializer.serializeValue(mirror)); // Check the mirror hierachy. assertTrue(mirror instanceof debug.Mirror); diff --git a/test/mjsunit/mirror-number.js b/test/mjsunit/mirror-number.js index 68eb0d7..2db5df4 100644 --- a/test/mjsunit/mirror-number.js +++ b/test/mjsunit/mirror-number.js @@ -32,7 +32,7 @@ function testNumberMirror(n) { // Create mirror and JSON representation. var mirror = debug.MakeMirror(n); var serializer = debug.MakeMirrorSerializer(); - var json = serializer.serializeValue(mirror); + var json = JSON.stringify(serializer.serializeValue(mirror)); // Check the mirror hierachy. assertTrue(mirror instanceof debug.Mirror); diff --git a/test/mjsunit/mirror-object.js b/test/mjsunit/mirror-object.js index e829a0e..ad7add8 100644 --- a/test/mjsunit/mirror-object.js +++ b/test/mjsunit/mirror-object.js @@ -44,8 +44,9 @@ function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) { // Create mirror and JSON representation. var mirror = debug.MakeMirror(obj); var serializer = debug.MakeMirrorSerializer(); - var json = serializer.serializeValue(mirror); - var refs = new MirrorRefCache(serializer.serializeReferencedObjects()); + var json = JSON.stringify(serializer.serializeValue(mirror)); + var refs = new MirrorRefCache( + JSON.stringify(serializer.serializeReferencedObjects())); // Check the mirror hierachy. assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierachy'); @@ -105,7 +106,7 @@ function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) { assertEquals(names.length, fromJSON.properties.length, 'Some properties missing in JSON'); for (var i = 0; i < fromJSON.properties.length; i++) { var name = fromJSON.properties[i].name; - if (!name) name = fromJSON.properties[i].index; + if (typeof name == 'undefined') name = fromJSON.properties[i].index; var found = false; for (var j = 0; j < names.length; j++) { if (names[j] == name) { @@ -157,7 +158,6 @@ function Point(x,y) { this.y_ = y; } - // Test a number of different objects. testObjectMirror({}, 'Object', 'Object'); testObjectMirror({'a':1,'b':2}, 'Object', 'Object'); diff --git a/test/mjsunit/mirror-regexp.js b/test/mjsunit/mirror-regexp.js index 0490b17..8c834bf 100644 --- a/test/mjsunit/mirror-regexp.js +++ b/test/mjsunit/mirror-regexp.js @@ -55,8 +55,9 @@ function testRegExpMirror(r) { // Create mirror and JSON representation. var mirror = debug.MakeMirror(r); var serializer = debug.MakeMirrorSerializer(); - var json = serializer.serializeValue(mirror); - var refs = new MirrorRefCache(serializer.serializeReferencedObjects()); + var json = JSON.stringify(serializer.serializeValue(mirror)); + var refs = new MirrorRefCache( + JSON.stringify(serializer.serializeReferencedObjects())); // Check the mirror hierachy. assertTrue(mirror instanceof debug.Mirror); diff --git a/test/mjsunit/mirror-script.js b/test/mjsunit/mirror-script.js index 61f0f3a..2ffa44f 100644 --- a/test/mjsunit/mirror-script.js +++ b/test/mjsunit/mirror-script.js @@ -32,7 +32,7 @@ function testScriptMirror(f, file_name, file_lines, script_type, script_source) // Create mirror and JSON representation. var mirror = debug.MakeMirror(f).script(); var serializer = debug.MakeMirrorSerializer(); - var json = serializer.serializeValue(mirror); + var json = JSON.stringify(serializer.serializeValue(mirror)); // Check the mirror hierachy. assertTrue(mirror instanceof debug.Mirror); diff --git a/test/mjsunit/mirror-string.js b/test/mjsunit/mirror-string.js index eeabc5f..c241849 100644 --- a/test/mjsunit/mirror-string.js +++ b/test/mjsunit/mirror-string.js @@ -34,7 +34,7 @@ function testStringMirror(s) { // Create mirror and JSON representation. var mirror = debug.MakeMirror(s); var serializer = debug.MakeMirrorSerializer(); - var json = serializer.serializeValue(mirror); + var json = JSON.stringify(serializer.serializeValue(mirror)); // Check the mirror hierachy. assertTrue(mirror instanceof debug.Mirror); diff --git a/test/mjsunit/mirror-undefined.js b/test/mjsunit/mirror-undefined.js index 2b5b84c..7f63239 100644 --- a/test/mjsunit/mirror-undefined.js +++ b/test/mjsunit/mirror-undefined.js @@ -31,7 +31,7 @@ // Create mirror and JSON representation. var mirror = debug.MakeMirror(void 0); var serializer = debug.MakeMirrorSerializer(); -var json = serializer.serializeValue(mirror); +var json = JSON.stringify(serializer.serializeValue(mirror)); // Check the mirror hierachy. assertTrue(mirror instanceof debug.Mirror); diff --git a/test/mjsunit/mirror-unresolved-function.js b/test/mjsunit/mirror-unresolved-function.js index 8d8ca37..c1fe4a3 100644 --- a/test/mjsunit/mirror-unresolved-function.js +++ b/test/mjsunit/mirror-unresolved-function.js @@ -42,8 +42,9 @@ MirrorRefCache.prototype.lookup = function(handle) { var mirror = new debug.UnresolvedFunctionMirror("f"); var serializer = debug.MakeMirrorSerializer(); -var json = serializer.serializeValue(mirror); -var refs = new MirrorRefCache(serializer.serializeReferencedObjects()); +var json = JSON.stringify(serializer.serializeValue(mirror)); +var refs = new MirrorRefCache( + JSON.stringify(serializer.serializeReferencedObjects())); // Check the mirror hierachy for unresolved functions. assertTrue(mirror instanceof debug.Mirror);