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

Side by Side Diff: src/mirror-delay.js

Issue 18445: Changes to the mirror handling... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/runtime.cc » ('j') | test/mjsunit/mirror-object.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 * @param {value or Object} value the value or object to retreive the mirror for 51 * @param {value or Object} value the value or object to retreive the mirror for
52 * @returns {Mirror} the mirror reflects the passed value or object 52 * @returns {Mirror} the mirror reflects the passed value or object
53 */ 53 */
54 function MakeMirror(value) { 54 function MakeMirror(value) {
55 var mirror; 55 var mirror;
56 for (id in mirror_cache_) { 56 for (id in mirror_cache_) {
57 mirror = mirror_cache_[id]; 57 mirror = mirror_cache_[id];
58 if (mirror.value() === value) { 58 if (mirror.value() === value) {
59 return mirror; 59 return mirror;
60 } 60 }
61 // Special check for NaN as NaN == NaN is false.
62 if (mirror.isNumber() && isNaN(mirror.value()) &&
63 typeof value == 'number' && isNaN(value)) {
64 return mirror;
65 }
61 } 66 }
62 67
63 if (IS_UNDEFINED(value)) { 68 if (IS_UNDEFINED(value)) {
64 mirror = new UndefinedMirror(); 69 mirror = new UndefinedMirror();
65 } else if (IS_NULL(value)) { 70 } else if (IS_NULL(value)) {
66 mirror = new NullMirror(); 71 mirror = new NullMirror();
67 } else if (IS_BOOLEAN(value)) { 72 } else if (IS_BOOLEAN(value)) {
68 mirror = new BooleanMirror(value); 73 mirror = new BooleanMirror(value);
69 } else if (IS_NUMBER(value)) { 74 } else if (IS_NUMBER(value)) {
70 mirror = new NumberMirror(value); 75 mirror = new NumberMirror(value);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 340
336 /** 341 /**
337 * Check whether the mirror reflects a script. 342 * Check whether the mirror reflects a script.
338 * @returns {boolean} True if the mirror reflects a script 343 * @returns {boolean} True if the mirror reflects a script
339 */ 344 */
340 Mirror.prototype.isScript = function() { 345 Mirror.prototype.isScript = function() {
341 return this instanceof ScriptMirror; 346 return this instanceof ScriptMirror;
342 } 347 }
343 348
344 349
350 /**
351 * Allocate a handle id for this object.
352 */
353 Mirror.prototype.allocateHandle_ = function() {
354 this.handle_ = next_handle_++;
355 }
356
357
345 Mirror.prototype.toText = function() { 358 Mirror.prototype.toText = function() {
346 // Simpel to text which is used when on specialization in subclass. 359 // Simpel to text which is used when on specialization in subclass.
347 return "#<" + builtins.GetInstanceName(this.constructor.name) + ">"; 360 return "#<" + builtins.GetInstanceName(this.constructor.name) + ">";
348 } 361 }
349 362
350 363
351 /** 364 /**
352 * Base class for all value mirror objects. 365 * Base class for all value mirror objects.
353 * @param {string} type The type of the mirror 366 * @param {string} type The type of the mirror
354 * @param {value} value The value reflected by this mirror 367 * @param {value} value The value reflected by this mirror
355 * @constructor 368 * @constructor
356 * @extends Mirror 369 * @extends Mirror
357 */ 370 */
358 function ValueMirror(type, value) { 371 function ValueMirror(type, value) {
359 Mirror.call(this, type); 372 Mirror.call(this, type);
360 this.handle_ = next_handle_++;
361 this.value_ = value; 373 this.value_ = value;
374 this.allocateHandle_();
362 } 375 }
363 inherits(ValueMirror, Mirror); 376 inherits(ValueMirror, Mirror);
364 377
365 378
366 Mirror.prototype.handle = function() { 379 Mirror.prototype.handle = function() {
367 return this.handle_; 380 return this.handle_;
368 }; 381 };
369 382
370 383
371 /** 384 /**
(...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 1522
1510 /** 1523 /**
1511 * Mirror object for script source. 1524 * Mirror object for script source.
1512 * @param {Script} script The script object 1525 * @param {Script} script The script object
1513 * @constructor 1526 * @constructor
1514 * @extends Mirror 1527 * @extends Mirror
1515 */ 1528 */
1516 function ScriptMirror(script) { 1529 function ScriptMirror(script) {
1517 Mirror.call(this, SCRIPT_TYPE); 1530 Mirror.call(this, SCRIPT_TYPE);
1518 this.script_ = script; 1531 this.script_ = script;
1532 this.allocateHandle_();
1519 } 1533 }
1520 inherits(ScriptMirror, Mirror); 1534 inherits(ScriptMirror, Mirror);
1521 1535
1522 1536
1523 ScriptMirror.prototype.name = function() { 1537 ScriptMirror.prototype.name = function() {
1524 return this.script_.name; 1538 return this.script_.name;
1525 }; 1539 };
1526 1540
1527 1541
1528 ScriptMirror.prototype.lineOffset = function() { 1542 ScriptMirror.prototype.lineOffset = function() {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 } 1663 }
1650 } 1664 }
1651 1665
1652 // Add the mirror to the list of mirrors to be serialized. 1666 // Add the mirror to the list of mirrors to be serialized.
1653 this.mirrors_.push(mirror); 1667 this.mirrors_.push(mirror);
1654 } 1668 }
1655 1669
1656 1670
1657 JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, 1671 JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference,
1658 details) { 1672 details) {
1659 // If serializing a reference to a value just return the reference and add the 1673 // If serializing a reference to a mirror just return the reference and add
1660 // mirror to the referenced mirrors. 1674 // the mirror to the referenced mirrors.
1661 if (reference && mirror.isValue()) { 1675 if (reference &&
1676 (mirror.isValue() || mirror.isScript())) {
1662 this.add_(mirror); 1677 this.add_(mirror);
1663 return '{"ref":' + mirror.handle() + '}'; 1678 return '{"ref":' + mirror.handle() + '}';
1664 } 1679 }
1665 1680
1666 // Collect the JSON property/value pairs in an array. 1681 // Collect the JSON property/value pairs in an array.
1667 var content = new Array(); 1682 var content = new Array();
1668 1683
1669 // Add the handle for value mirrors. 1684 // Add the handle for value mirrors.
1670 if (mirror.isValue()) { 1685 if (mirror.isValue()) {
1671 content.push(MakeJSONPair_('handle', NumberToJSON_(mirror.handle()))); 1686 content.push(MakeJSONPair_('handle', NumberToJSON_(mirror.handle())));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 1793
1779 // Add function specific properties. 1794 // Add function specific properties.
1780 if (mirror.isFunction()) { 1795 if (mirror.isFunction()) {
1781 // Add function specific properties. 1796 // Add function specific properties.
1782 content.push(MakeJSONPair_('name', StringToJSON_(mirror.name()))); 1797 content.push(MakeJSONPair_('name', StringToJSON_(mirror.name())));
1783 content.push(MakeJSONPair_('resolved', BooleanToJSON_(mirror.resolved()))); 1798 content.push(MakeJSONPair_('resolved', BooleanToJSON_(mirror.resolved())));
1784 if (mirror.resolved()) { 1799 if (mirror.resolved()) {
1785 content.push(MakeJSONPair_('source', StringToJSON_(mirror.source()))); 1800 content.push(MakeJSONPair_('source', StringToJSON_(mirror.source())));
1786 } 1801 }
1787 if (mirror.script()) { 1802 if (mirror.script()) {
1788 content.push(MakeJSONPair_('script', this.serializeValue(mirror.script())) ); 1803 content.push(MakeJSONPair_('script', this.serializeReference(mirror.script ())));
1789 } 1804 }
1790 } 1805 }
1791 1806
1792 // Add date specific properties. 1807 // Add date specific properties.
1793 if (mirror.isDate()) { 1808 if (mirror.isDate()) {
1794 // Add date specific properties. 1809 // Add date specific properties.
1795 content.push(MakeJSONPair_('value', DateToJSON_(mirror.value()))); 1810 content.push(MakeJSONPair_('value', DateToJSON_(mirror.value())));
1796 } 1811 }
1797 1812
1798 // Add actual properties - named properties followed by indexed properties. 1813 // Add actual properties - named properties followed by indexed properties.
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 /** 2040 /**
2026 * Convert a Date to ISO 8601 format. To avoid depending on the Date object 2041 * Convert a Date to ISO 8601 format. To avoid depending on the Date object
2027 * this method calls the functions in date.js directly and not through the 2042 * this method calls the functions in date.js directly and not through the
2028 * value. 2043 * value.
2029 * @param {Date} value The Date value to format as JSON 2044 * @param {Date} value The Date value to format as JSON
2030 * @return {string} JSON formatted Date value 2045 * @return {string} JSON formatted Date value
2031 */ 2046 */
2032 function DateToJSON_(value) { 2047 function DateToJSON_(value) {
2033 return '"' + DateToISO8601_(value) + '"'; 2048 return '"' + DateToISO8601_(value) + '"';
2034 } 2049 }
OLDNEW
« no previous file with comments | « no previous file | src/runtime.cc » ('j') | test/mjsunit/mirror-object.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698