OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
6 * Enum for WebDriver status codes. | 6 * Enum for WebDriver status codes. |
7 * @enum {number} | 7 * @enum {number} |
8 */ | 8 */ |
9 var StatusCode = { | 9 var StatusCode = { |
10 STALE_ELEMENT_REFERENCE: 10, | 10 STALE_ELEMENT_REFERENCE: 10, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 142 } |
143 | 143 |
144 /** | 144 /** |
145 * Wraps the given value to be transmitted remotely by converting | 145 * Wraps the given value to be transmitted remotely by converting |
146 * appropriate objects to cached object IDs. | 146 * appropriate objects to cached object IDs. |
147 * | 147 * |
148 * @param {*} value The value to wrap. | 148 * @param {*} value The value to wrap. |
149 * @return {*} The wrapped value. | 149 * @return {*} The wrapped value. |
150 */ | 150 */ |
151 function wrap(value) { | 151 function wrap(value) { |
152 if (typeof(value) == 'object' && value != null) { | 152 if (value instanceof Object && value != null) { |
153 var nodeType = value['nodeType']; | 153 var nodeType = value['nodeType']; |
154 if (nodeType == NodeType.ELEMENT || nodeType == NodeType.DOCUMENT | 154 if (nodeType == NodeType.ELEMENT || nodeType == NodeType.DOCUMENT |
155 || (SHADOW_DOM_ENABLED && value instanceof ShadowRoot)) { | 155 || (SHADOW_DOM_ENABLED && value instanceof ShadowRoot)) { |
156 var wrapped = {}; | 156 var wrapped = {}; |
157 var root = getNodeRootThroughAnyShadows(value); | 157 var root = getNodeRootThroughAnyShadows(value); |
158 wrapped[ELEMENT_KEY] = getPageCache(root).storeItem(value); | 158 wrapped[ELEMENT_KEY] = getPageCache(root).storeItem(value); |
159 return wrapped; | 159 return wrapped; |
160 } | 160 } |
161 | 161 |
162 var obj = (typeof(value.length) == 'number') ? [] : {}; | 162 var obj = (typeof(value.length) == 'number') ? [] : {}; |
163 for (var prop in value) | 163 for (var prop in value) |
164 obj[prop] = wrap(value[prop]); | 164 obj[prop] = wrap(value[prop]); |
165 return obj; | 165 return obj; |
166 } | 166 } |
167 return value; | 167 return value; |
168 } | 168 } |
169 | 169 |
170 /** | 170 /** |
171 * Unwraps the given value by converting from object IDs to the cached | 171 * Unwraps the given value by converting from object IDs to the cached |
172 * objects. | 172 * objects. |
173 * | 173 * |
174 * @param {*} value The value to unwrap. | 174 * @param {*} value The value to unwrap. |
175 * @param {Cache} cache The cache to retrieve wrapped elements from. | 175 * @param {Cache} cache The cache to retrieve wrapped elements from. |
176 * @return {*} The unwrapped value. | 176 * @return {*} The unwrapped value. |
177 */ | 177 */ |
178 function unwrap(value, cache) { | 178 function unwrap(value, cache) { |
179 if (typeof(value) == 'object' && value != null) { | 179 if (value instanceof Object && value != null) { |
180 if (ELEMENT_KEY in value) | 180 if (ELEMENT_KEY in value) |
181 return cache.retrieveItem(value[ELEMENT_KEY]); | 181 return cache.retrieveItem(value[ELEMENT_KEY]); |
182 | 182 |
183 var obj = (typeof(value.length) == 'number') ? [] : {}; | 183 var obj = (typeof(value.length) == 'number') ? [] : {}; |
184 for (var prop in value) | 184 for (var prop in value) |
185 obj[prop] = unwrap(value[prop], cache); | 185 obj[prop] = unwrap(value[prop], cache); |
186 return obj; | 186 return obj; |
187 } | 187 } |
188 return value; | 188 return value; |
189 } | 189 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 var returnValue = wrap(func.apply(null, unwrap(args, cache))); | 229 var returnValue = wrap(func.apply(null, unwrap(args, cache))); |
230 } catch (error) { | 230 } catch (error) { |
231 status = error.code || StatusCode.UNKNOWN_ERROR; | 231 status = error.code || StatusCode.UNKNOWN_ERROR; |
232 var returnValue = error.message; | 232 var returnValue = error.message; |
233 } | 233 } |
234 return { | 234 return { |
235 status: status, | 235 status: status, |
236 value: returnValue | 236 value: returnValue |
237 } | 237 } |
238 } | 238 } |
OLD | NEW |