Index: extensions/renderer/resources/utils.js |
diff --git a/extensions/renderer/resources/utils.js b/extensions/renderer/resources/utils.js |
index 853c652361d42c660af1a91039da124a3fa65a8f..a5437411c2279422f84f1d0cb62de4918b70dbc6 100644 |
--- a/extensions/renderer/resources/utils.js |
+++ b/extensions/renderer/resources/utils.js |
@@ -124,7 +124,40 @@ function expose(name, cls, exposed) { |
return publicClass; |
} |
+/** |
+ * Copies |value| recursively. |value| must not contain cyclic references. |
+ * Copies only nested structures of non-object types (like number or string), |
+ * Array, Uint8Array and the directly owned properties of objects (it ignores |
+ * prototypes). |
not at google - send to devlin
2014/06/19 00:12:42
there's actually a really sneaky way you can imple
pneubeck (no reviews)
2014/06/19 16:09:41
Done.
|
+ */ |
+function deepCopy(value) { |
+ if (value === null) |
+ return null; |
+ if (typeof(value) !== 'object') |
+ return value; |
+ |
+ var copy = null; |
+ if (Array.isArray(value) ) { |
+ copy = new Array(); |
+ for (var i = 0; i < value.length; i++) |
+ copy[i] = deepCopy(value[i]); |
+ } else if (value.__proto__.constructor.name === 'Uint8Array') { |
not at google - send to devlin
2014/06/19 00:12:42
I don't think you need the __proto__ ? just value.
|
+ copy = new Uint8Array(value.length); |
+ for (var i = 0; i < value.length; i++) |
+ copy[i] = value[i]; |
+ } else { |
+ copy = new Object(); |
+ for (var key in value) { |
+ if (!value.hasOwnProperty(key)) |
+ continue; |
+ copy[key] = deepCopy(value[key]); |
not at google - send to devlin
2014/06/19 00:12:42
nit: I would invert the hasOwnProperty check to sa
|
+ } |
+ } |
+ return copy; |
+} |
+ |
exports.forEach = forEach; |
exports.loadTypeSchema = loadTypeSchema; |
exports.lookup = lookup; |
exports.expose = expose; |
+exports.deepCopy = deepCopy; |