Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var createClassWrapper = requireNative('utils').createClassWrapper; | 5 var createClassWrapper = requireNative('utils').createClassWrapper; |
| 6 var schemaRegistry = requireNative('schema_registry'); | 6 var schemaRegistry = requireNative('schema_registry'); |
| 7 var CHECK = requireNative('logging').CHECK; | 7 var CHECK = requireNative('logging').CHECK; |
| 8 var WARNING = requireNative('logging').WARNING; | 8 var WARNING = requireNative('logging').WARNING; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 get: function() { | 117 get: function() { |
| 118 return privates(this).impl[readonly]; | 118 return privates(this).impl[readonly]; |
| 119 }, | 119 }, |
| 120 }); | 120 }); |
| 121 }); | 121 }); |
| 122 } | 122 } |
| 123 | 123 |
| 124 return publicClass; | 124 return publicClass; |
| 125 } | 125 } |
| 126 | 126 |
| 127 /** | |
| 128 * Copies |value| recursively. |value| must not contain cyclic references. | |
| 129 * Copies only nested structures of non-object types (like number or string), | |
| 130 * Array, Uint8Array and the directly owned properties of objects (it ignores | |
| 131 * 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.
| |
| 132 */ | |
| 133 function deepCopy(value) { | |
| 134 if (value === null) | |
| 135 return null; | |
| 136 if (typeof(value) !== 'object') | |
| 137 return value; | |
| 138 | |
| 139 var copy = null; | |
| 140 if (Array.isArray(value) ) { | |
| 141 copy = new Array(); | |
| 142 for (var i = 0; i < value.length; i++) | |
| 143 copy[i] = deepCopy(value[i]); | |
| 144 } 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.
| |
| 145 copy = new Uint8Array(value.length); | |
| 146 for (var i = 0; i < value.length; i++) | |
| 147 copy[i] = value[i]; | |
| 148 } else { | |
| 149 copy = new Object(); | |
| 150 for (var key in value) { | |
| 151 if (!value.hasOwnProperty(key)) | |
| 152 continue; | |
| 153 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
| |
| 154 } | |
| 155 } | |
| 156 return copy; | |
| 157 } | |
| 158 | |
| 127 exports.forEach = forEach; | 159 exports.forEach = forEach; |
| 128 exports.loadTypeSchema = loadTypeSchema; | 160 exports.loadTypeSchema = loadTypeSchema; |
| 129 exports.lookup = lookup; | 161 exports.lookup = lookup; |
| 130 exports.expose = expose; | 162 exports.expose = expose; |
| 163 exports.deepCopy = deepCopy; | |
| OLD | NEW |