Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: safari/ext/content.js

Issue 5670052883857408: Fixed properties defined on prototype in Safari background page proxy (Closed)
Patch Set: Addressed comments Created Feb. 26, 2014, 11:24 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: safari/ext/content.js
===================================================================
--- a/safari/ext/content.js
+++ b/safari/ext/content.js
@@ -138,53 +138,57 @@
},
serialize: function(obj, memo)
{
- var objectId = this.objects.indexOf(obj);
- if (objectId != -1)
- return {type: "hosted", objectId: objectId};
+ if ((typeof obj == "object" || typeof obj == "function") && obj != null)
+ {
+ if ("__proxyObjectId" in obj)
+ return {type: "hosted", objectId: obj.__proxyObjectId};
- if (typeof obj == "function")
- {
- var callbackId = this.callbacks.indexOf(obj);
- if (callbackId == -1)
- callbackId = this.callbacks.push(obj) - 1;
+ if (typeof obj == "function")
+ {
+ var callbackId;
+ if ("__proxyCallbackId" in obj)
+ callbackId = obj.__proxyCallbackId;
+ else
+ {
+ callbackId = this.callbacks.push(obj) - 1;
+ Object.defineProperty(obj, "__proxyCallbackId", {value: callbackId});
+ }
- return {type: "callback", callbackId: callbackId, frameId: documentInfo.frameId};
- }
-
- if (typeof obj == "object" &&
- obj != null &&
- obj.constructor != Date &&
- obj.constructor != RegExp)
- {
- if (!memo)
- memo = {specs: [], objects: []};
-
- var idx = memo.objects.indexOf(obj);
- if (idx != -1)
- return memo.specs[idx];
-
- var spec = {};
- memo.specs.push(spec);
- memo.objects.push(obj);
-
- if (obj.constructor == Array)
- {
- spec.type = "array";
- spec.items = [];
-
- for (var i = 0; i < obj.length; i++)
- spec.items.push(this.serialize(obj[i], memo));
- }
- else
- {
- spec.type = "object";
- spec.properties = {};
-
- for (var k in obj)
- spec.properties[k] = this.serialize(obj[k], memo);
+ return {type: "callback", callbackId: callbackId, frameId: documentInfo.frameId};
}
- return spec;
+ if (obj.constructor != Date && obj.constructor != RegExp)
+ {
+ if (!memo)
+ memo = {specs: [], objects: []};
+
+ var idx = memo.objects.indexOf(obj);
+ if (idx != -1)
+ return memo.specs[idx];
+
+ var spec = {};
+ memo.specs.push(spec);
+ memo.objects.push(obj);
+
+ if (obj.constructor == Array)
+ {
+ spec.type = "array";
+ spec.items = [];
+
+ for (var i = 0; i < obj.length; i++)
+ spec.items.push(this.serialize(obj[i], memo));
+ }
+ else
+ {
+ spec.type = "object";
+ spec.properties = {};
+
+ for (var k in obj)
+ spec.properties[k] = this.serialize(obj[k], memo);
+ }
+
+ return spec;
+ }
}
return {type: "value", value: obj};
@@ -225,10 +229,6 @@
return this.deserializeSequence(spec.items, array, memo);
}
},
- getObjectId: function(obj)
- {
- return this.objects.indexOf(obj);
- },
getProperty: function(objectId, property)
{
return this.deserializeResult(
@@ -246,7 +246,7 @@
return {
get: function()
{
- return proxy.getProperty(proxy.getObjectId(this), property);
+ return proxy.getProperty(this.__proxyObjectId, property);
},
set: function(value)
{
@@ -254,7 +254,7 @@
proxy.send(
{
type: "setProperty",
- objectId: proxy.getObjectId(this),
+ objectId: this.__proxyObjectId,
property: property,
value: proxy.serialize(value)
})
@@ -274,7 +274,7 @@
{
type: "callFunction",
functionId: objectId,
- contextId: proxy.getObjectId(this),
+ contextId: this.__proxyObjectId,
args: Array.prototype.map.call(
arguments,
proxy.serialize.bind(proxy)
@@ -308,6 +308,7 @@
obj = {};
this.objects[objectId] = obj;
+ Object.defineProperty(obj, "__proxyObjectId", {value: objectId});
}
var ignored = [];
@@ -334,13 +335,21 @@
}
for (var property in objectInfo.properties)
+ {
if (ignored.indexOf(property) == -1)
- Object.defineProperty(obj, property, this.createProperty(
- property, objectInfo.properties[property].enumerable
- ));
+ {
+ var desc = Object.getOwnPropertyDescriptor(obj, property);
- if (objectInfo.isFunction)
- obj.prototype = this.getProperty(objectId, "prototype");
+ if (!desc || desc.configurable)
+ {
+ Object.defineProperty(obj, property, this.createProperty(
+ property, objectInfo.properties[property].enumerable
+ ));
+ }
+ else if (desc.writable)
+ obj[property] = this.getProperty(objectId, property);
+ }
+ }
return obj;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld