Commit 2a5955a4 authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

Changes to the mirror handling

When getting properties for the global object proxy the properties from the global object are returned.

Script objects now have handles and are serialized by reference.

Added special handling for NaN.
Review URL: http://codereview.chromium.org/18445

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1116 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 05a04b10
...@@ -58,6 +58,11 @@ function MakeMirror(value) { ...@@ -58,6 +58,11 @@ function MakeMirror(value) {
if (mirror.value() === value) { if (mirror.value() === value) {
return mirror; return mirror;
} }
// Special check for NaN as NaN == NaN is false.
if (mirror.isNumber() && isNaN(mirror.value()) &&
typeof value == 'number' && isNaN(value)) {
return mirror;
}
} }
if (IS_UNDEFINED(value)) { if (IS_UNDEFINED(value)) {
...@@ -342,6 +347,14 @@ Mirror.prototype.isScript = function() { ...@@ -342,6 +347,14 @@ Mirror.prototype.isScript = function() {
} }
/**
* Allocate a handle id for this object.
*/
Mirror.prototype.allocateHandle_ = function() {
this.handle_ = next_handle_++;
}
Mirror.prototype.toText = function() { Mirror.prototype.toText = function() {
// Simpel to text which is used when on specialization in subclass. // Simpel to text which is used when on specialization in subclass.
return "#<" + builtins.GetInstanceName(this.constructor.name) + ">"; return "#<" + builtins.GetInstanceName(this.constructor.name) + ">";
...@@ -357,8 +370,8 @@ Mirror.prototype.toText = function() { ...@@ -357,8 +370,8 @@ Mirror.prototype.toText = function() {
*/ */
function ValueMirror(type, value) { function ValueMirror(type, value) {
Mirror.call(this, type); Mirror.call(this, type);
this.handle_ = next_handle_++;
this.value_ = value; this.value_ = value;
this.allocateHandle_();
} }
inherits(ValueMirror, Mirror); inherits(ValueMirror, Mirror);
...@@ -1516,6 +1529,7 @@ FrameMirror.prototype.toText = function(opt_locals) { ...@@ -1516,6 +1529,7 @@ FrameMirror.prototype.toText = function(opt_locals) {
function ScriptMirror(script) { function ScriptMirror(script) {
Mirror.call(this, SCRIPT_TYPE); Mirror.call(this, SCRIPT_TYPE);
this.script_ = script; this.script_ = script;
this.allocateHandle_();
} }
inherits(ScriptMirror, Mirror); inherits(ScriptMirror, Mirror);
...@@ -1656,9 +1670,10 @@ JSONProtocolSerializer.prototype.add_ = function(mirror) { ...@@ -1656,9 +1670,10 @@ JSONProtocolSerializer.prototype.add_ = function(mirror) {
JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference,
details) { details) {
// If serializing a reference to a value just return the reference and add the // If serializing a reference to a mirror just return the reference and add
// mirror to the referenced mirrors. // the mirror to the referenced mirrors.
if (reference && mirror.isValue()) { if (reference &&
(mirror.isValue() || mirror.isScript())) {
this.add_(mirror); this.add_(mirror);
return '{"ref":' + mirror.handle() + '}'; return '{"ref":' + mirror.handle() + '}';
} }
...@@ -1785,7 +1800,7 @@ JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content, ...@@ -1785,7 +1800,7 @@ JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content,
content.push(MakeJSONPair_('source', StringToJSON_(mirror.source()))); content.push(MakeJSONPair_('source', StringToJSON_(mirror.source())));
} }
if (mirror.script()) { if (mirror.script()) {
content.push(MakeJSONPair_('script', this.serializeValue(mirror.script()))); content.push(MakeJSONPair_('script', this.serializeReference(mirror.script())));
} }
} }
......
...@@ -4676,6 +4676,9 @@ static Object* Runtime_DebugLocalPropertyNames(Arguments args) { ...@@ -4676,6 +4676,9 @@ static Object* Runtime_DebugLocalPropertyNames(Arguments args) {
} }
CONVERT_ARG_CHECKED(JSObject, obj, 0); CONVERT_ARG_CHECKED(JSObject, obj, 0);
if (obj->IsJSGlobalProxy()) {
obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype()));
}
int n = obj->NumberOfLocalProperties(static_cast<PropertyAttributes>(NONE)); int n = obj->NumberOfLocalProperties(static_cast<PropertyAttributes>(NONE));
Handle<FixedArray> names = Factory::NewFixedArray(n); Handle<FixedArray> names = Factory::NewFixedArray(n);
obj->GetLocalPropertyNames(*names); obj->GetLocalPropertyNames(*names);
......
...@@ -53,7 +53,15 @@ function testNumberMirror(n) { ...@@ -53,7 +53,15 @@ function testNumberMirror(n) {
if (!isNaN(n)) { if (!isNaN(n)) {
assertEquals(n, fromJSON.value); assertEquals(n, fromJSON.value);
} else { } else {
assertTrue(isNaN(fromJSON.value)); // NaN values are encoded as strings.
assertTrue(typeof fromJSON.value == 'string');
if (n === Infinity) {
assertEquals('Infinity', fromJSON.value);
} else if (n === -Infinity) {
assertEquals('-Infinity', fromJSON.value);
} else {
assertEquals('NaN', fromJSON.value);
}
} }
} }
......
...@@ -135,7 +135,12 @@ function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) { ...@@ -135,7 +135,12 @@ function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) {
assertEquals(properties[i].value().type(), o.type, 'Unexpected serialized property type for ' + name); assertEquals(properties[i].value().type(), o.type, 'Unexpected serialized property type for ' + name);
if (properties[i].value().isPrimitive()) { if (properties[i].value().isPrimitive()) {
assertEquals(properties[i].value().value(), o.value, 'Unexpected serialized property value for ' + name); // Special check for NaN as NaN == NaN is false.
if (properties[i].value().isNumber() && isNaN(properties[i].value().value())) {
assertEquals('NaN', o.value, 'Unexpected serialized property value for ' + name);
} else {
assertEquals(properties[i].value().value(), o.value, 'Unexpected serialized property value for ' + name);
}
} else if (properties[i].value().isFunction()) { } else if (properties[i].value().isFunction()) {
assertEquals(properties[i].value().source(), o.source, 'Unexpected serialized property value for ' + name); assertEquals(properties[i].value().source(), o.source, 'Unexpected serialized property value for ' + name);
} }
...@@ -159,6 +164,7 @@ testObjectMirror({'a':1,'b':2}, 'Object', 'Object'); ...@@ -159,6 +164,7 @@ testObjectMirror({'a':1,'b':2}, 'Object', 'Object');
testObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y);}}, 'Object', 'Object'); testObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y);}}, 'Object', 'Object');
testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point'); testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point');
testObjectMirror(this, 'global', '', true); // Global object has special properties testObjectMirror(this, 'global', '', true); // Global object has special properties
testObjectMirror(this.__proto__, 'Object', '');
testObjectMirror([], 'Array', 'Array'); testObjectMirror([], 'Array', 'Array');
testObjectMirror([1,2], 'Array', 'Array'); testObjectMirror([1,2], 'Array', 'Array');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment