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) {
if (mirror.value() === value) {
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)) {
......@@ -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() {
// Simpel to text which is used when on specialization in subclass.
return "#<" + builtins.GetInstanceName(this.constructor.name) + ">";
......@@ -357,8 +370,8 @@ Mirror.prototype.toText = function() {
*/
function ValueMirror(type, value) {
Mirror.call(this, type);
this.handle_ = next_handle_++;
this.value_ = value;
this.allocateHandle_();
}
inherits(ValueMirror, Mirror);
......@@ -1516,6 +1529,7 @@ FrameMirror.prototype.toText = function(opt_locals) {
function ScriptMirror(script) {
Mirror.call(this, SCRIPT_TYPE);
this.script_ = script;
this.allocateHandle_();
}
inherits(ScriptMirror, Mirror);
......@@ -1656,9 +1670,10 @@ JSONProtocolSerializer.prototype.add_ = function(mirror) {
JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference,
details) {
// If serializing a reference to a value just return the reference and add the
// mirror to the referenced mirrors.
if (reference && mirror.isValue()) {
// 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())) {
this.add_(mirror);
return '{"ref":' + mirror.handle() + '}';
}
......@@ -1785,7 +1800,7 @@ JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content,
content.push(MakeJSONPair_('source', StringToJSON_(mirror.source())));
}
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) {
}
CONVERT_ARG_CHECKED(JSObject, obj, 0);
if (obj->IsJSGlobalProxy()) {
obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype()));
}
int n = obj->NumberOfLocalProperties(static_cast<PropertyAttributes>(NONE));
Handle<FixedArray> names = Factory::NewFixedArray(n);
obj->GetLocalPropertyNames(*names);
......
......@@ -53,7 +53,15 @@ function testNumberMirror(n) {
if (!isNaN(n)) {
assertEquals(n, fromJSON.value);
} 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) {
assertEquals(properties[i].value().type(), o.type, 'Unexpected serialized property type for ' + name);
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()) {
assertEquals(properties[i].value().source(), o.source, 'Unexpected serialized property value for ' + name);
}
......@@ -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(new Point(-1.2,2.003), 'Object', 'Point');
testObjectMirror(this, 'global', '', true); // Global object has special properties
testObjectMirror(this.__proto__, 'Object', '');
testObjectMirror([], '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