Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: sdk/lib/html/html_common/conversions.dart

Issue 17301008: Remove =List in JS, use JSExtendableArray instead. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 5
6 // Conversions for IDBKey. 6 // Conversions for IDBKey.
7 // 7 //
8 // Per http://www.w3.org/TR/IndexedDB/#key-construct 8 // Per http://www.w3.org/TR/IndexedDB/#key-construct
9 // 9 //
10 // "A value is said to be a valid key if it is one of the following types: Array 10 // "A value is said to be a valid key if it is one of the following types: Array
(...skipping 16 matching lines...) Expand all
27 // window as a parameter. 27 // window as a parameter.
28 28
29 part of html_common; 29 part of html_common;
30 30
31 31
32 /// Converts a JavaScript object with properties into a Dart Map. 32 /// Converts a JavaScript object with properties into a Dart Map.
33 /// Not suitable for nested objects. 33 /// Not suitable for nested objects.
34 Map convertNativeToDart_Dictionary(object) { 34 Map convertNativeToDart_Dictionary(object) {
35 if (object == null) return null; 35 if (object == null) return null;
36 var dict = {}; 36 var dict = {};
37 for (final key in JS('=List', 'Object.getOwnPropertyNames(#)', object)) { 37 for (final key in JS('JSExtendableArray', 'Object.getOwnPropertyNames(#)', obj ect)) {
kasperl 2013/06/21 06:03:55 Long line.
ngeoffray 2013/06/24 09:47:23 Done.
38 dict[key] = JS('var', '#[#]', object, key); 38 dict[key] = JS('var', '#[#]', object, key);
39 } 39 }
40 return dict; 40 return dict;
41 } 41 }
42 42
43 /// Converts a flat Dart map into a JavaScript object with properties. 43 /// Converts a flat Dart map into a JavaScript object with properties.
44 convertDartToNative_Dictionary(Map dict) { 44 convertDartToNative_Dictionary(Map dict) {
45 if (dict == null) return null; 45 if (dict == null) return null;
46 var object = JS('var', '{}'); 46 var object = JS('var', '{}');
47 dict.forEach((String key, value) { 47 dict.forEach((String key, value) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 if (e is List) { 158 if (e is List) {
159 // Since a JavaScript Array is an instance of Dart List it is possible to 159 // Since a JavaScript Array is an instance of Dart List it is possible to
160 // avoid making a copy of the list if there is no need to copy anything 160 // avoid making a copy of the list if there is no need to copy anything
161 // reachable from the array. We defer creating a new array until a cycle 161 // reachable from the array. We defer creating a new array until a cycle
162 // is detected or a subgraph was copied. 162 // is detected or a subgraph was copied.
163 int length = e.length; 163 int length = e.length;
164 var slot = findSlot(e); 164 var slot = findSlot(e);
165 var copy = readSlot(slot); 165 var copy = readSlot(slot);
166 if (copy != null) { 166 if (copy != null) {
167 if (true == copy) { // Cycle, so commit to making a copy. 167 if (true == copy) { // Cycle, so commit to making a copy.
168 copy = JS('=List', 'new Array(#)', length); 168 copy = JS('JSExtendableArray', 'new Array(#)', length);
169 writeSlot(slot, copy); 169 writeSlot(slot, copy);
170 } 170 }
171 return copy; 171 return copy;
172 } 172 }
173 173
174 int i = 0; 174 int i = 0;
175 175
176 // Always clone the list, as it may have non-native properties or methods 176 // Always clone the list, as it may have non-native properties or methods
177 // from interceptors and such. 177 // from interceptors and such.
178 copy = JS('=List', 'new Array(#)', length); 178 copy = JS('JSExtendableArray', 'new Array(#)', length);
179 writeSlot(slot, copy); 179 writeSlot(slot, copy);
180 180
181 for ( ; i < length; i++) { 181 for ( ; i < length; i++) {
182 copy[i] = walk(e[i]); 182 copy[i] = walk(e[i]);
183 } 183 }
184 return copy; 184 return copy;
185 } 185 }
186 186
187 throw new UnimplementedError('structured clone of other type'); 187 throw new UnimplementedError('structured clone of other type');
188 } 188 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 247
248 if (isJavaScriptSimpleObject(e)) { 248 if (isJavaScriptSimpleObject(e)) {
249 // TODO(sra): If mustCopy is false, swizzle the prototype for one of a Map 249 // TODO(sra): If mustCopy is false, swizzle the prototype for one of a Map
250 // implementation that uses the properies as storage. 250 // implementation that uses the properies as storage.
251 var slot = findSlot(e); 251 var slot = findSlot(e);
252 var copy = readSlot(slot); 252 var copy = readSlot(slot);
253 if (copy != null) return copy; 253 if (copy != null) return copy;
254 copy = {}; 254 copy = {};
255 255
256 writeSlot(slot, copy); 256 writeSlot(slot, copy);
257 for (final key in JS('=List', 'Object.keys(#)', e)) { 257 for (final key in JS('JSExtendableArray', 'Object.keys(#)', e)) {
258 copy[key] = walk(JS('var', '#[#]', e, key)); 258 copy[key] = walk(JS('var', '#[#]', e, key));
259 } 259 }
260 return copy; 260 return copy;
261 } 261 }
262 262
263 if (isJavaScriptArray(e)) { 263 if (isJavaScriptArray(e)) {
264 var slot = findSlot(e); 264 var slot = findSlot(e);
265 var copy = readSlot(slot); 265 var copy = readSlot(slot);
266 if (copy != null) return copy; 266 if (copy != null) return copy;
267 267
268 int length = e.length; 268 int length = e.length;
269 // Since a JavaScript Array is an instance of Dart List, we can modify it 269 // Since a JavaScript Array is an instance of Dart List, we can modify it
270 // in-place unless we must copy. 270 // in-place unless we must copy.
271 copy = mustCopy ? JS('=List', 'new Array(#)', length) : e; 271 copy = mustCopy ? JS('JSExtendableArray', 'new Array(#)', length) : e;
272 writeSlot(slot, copy); 272 writeSlot(slot, copy);
273 273
274 for (int i = 0; i < length; i++) { 274 for (int i = 0; i < length; i++) {
275 copy[i] = walk(e[i]); 275 copy[i] = walk(e[i]);
276 } 276 }
277 return copy; 277 return copy;
278 } 278 }
279 279
280 // Assume anything else is already a valid Dart object, either by having 280 // Assume anything else is already a valid Dart object, either by having
281 // already been processed, or e.g. a clonable native class. 281 // already been processed, or e.g. a clonable native class.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 bool isJavaScriptArray(value) => JS('bool', '# instanceof Array', value); 335 bool isJavaScriptArray(value) => JS('bool', '# instanceof Array', value);
336 bool isJavaScriptSimpleObject(value) => 336 bool isJavaScriptSimpleObject(value) =>
337 JS('bool', 'Object.getPrototypeOf(#) === Object.prototype', value); 337 JS('bool', 'Object.getPrototypeOf(#) === Object.prototype', value);
338 bool isImmutableJavaScriptArray(value) => 338 bool isImmutableJavaScriptArray(value) =>
339 JS('bool', r'!!(#.immutable$list)', value); 339 JS('bool', r'!!(#.immutable$list)', value);
340 340
341 341
342 342
343 const String _serializedScriptValue = 343 const String _serializedScriptValue =
344 'num|String|bool|' 344 'num|String|bool|'
345 '=List|=Object|' 345 'JSExtendableArray|=Object|'
346 'Blob|File|ByteBuffer|TypedData' 346 'Blob|File|ByteBuffer|TypedData'
347 // TODO(sra): Add Date, RegExp. 347 // TODO(sra): Add Date, RegExp.
348 ; 348 ;
349 const annotation_Creates_SerializedScriptValue = 349 const annotation_Creates_SerializedScriptValue =
350 const Creates(_serializedScriptValue); 350 const Creates(_serializedScriptValue);
351 const annotation_Returns_SerializedScriptValue = 351 const annotation_Returns_SerializedScriptValue =
352 const Returns(_serializedScriptValue); 352 const Returns(_serializedScriptValue);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698