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

Side by Side Diff: pkg/dev_compiler/tool/input_sdk/private/js_array.dart

Issue 2979353002: implement `Invocation.typeArguments` in DDC (Closed)
Patch Set: fix Created 3 years, 5 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
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 part of dart._interceptors; 5 part of dart._interceptors;
6 6
7 /** 7 /**
8 * The interceptor class for [List]. The compiler recognizes this 8 * The interceptor class for [List]. The compiler recognizes this
9 * class as an interceptor, and changes references to [:this:] to 9 * class as an interceptor, and changes references to [:this:] to
10 * actually use the receiver of the method, which is generated as an extra 10 * actually use the receiver of the method, which is generated as an extra
11 * argument added to each member. 11 * argument added to each member.
12 */ 12 */
13 @JsPeerInterface(name: 'Array') 13 @JsPeerInterface(name: 'Array')
14 class JSArray<E> implements List<E>, JSIndexable<E> { 14 class JSArray<E> implements List<E>, JSIndexable<E> {
15 const JSArray(); 15 const JSArray();
16 16
17 /** 17 /**
18 * Constructor for adding type parameters to an existing JavaScript Array.
19 */
20 factory JSArray.typed(allocation) =>
21 // TODO(jmesserly): skip this when E is dynamic and Object.
22 JS('-dynamic', 'dart.list(#, #)', allocation, E);
23
24 /**
25 * Constructor for adding type parameters to an existing JavaScript 18 * Constructor for adding type parameters to an existing JavaScript
26 * Array. Used for creating literal lists. 19 * Array. Used for creating literal lists.
27 */ 20 */
28 factory JSArray.of(allocation) { 21 factory JSArray.of(allocation) {
29 // TODO(sra): Move this to core.List for better readability. 22 // TODO(sra): Move this to core.List for better readability.
30 // Capture the parameterized ES6 'JSArray' class. 23 // Capture the parameterized ES6 'JSArray' class.
31 return JS('-dynamic', 'dart.setType(#, JSArray)', allocation); 24 return dart.setType(allocation, JS('', 'JSArray'));
Leaf 2017/07/26 00:46:31 This change caused a dart._check to be added here,
Jennifer Messerly 2017/07/26 01:23:00 oh shoot, I thought I'd fixed that before landing
Jennifer Messerly 2017/07/26 01:33:47 fixed in https://codereview.chromium.org/298506300
32 } 25 }
33 26
34 // TODO(jmesserly): consider a fixed array subclass instead. 27 // TODO(jmesserly): consider a fixed array subclass instead.
35 factory JSArray.markFixed(allocation) => 28 factory JSArray.markFixed(allocation) =>
36 new JSArray<E>.typed(markFixedList(allocation)); 29 new JSArray<E>.of(markFixedList(allocation));
37 30
38 factory JSArray.markGrowable(allocation) = JSArray<E>.typed; 31 factory JSArray.markGrowable(allocation) = JSArray<E>.of;
39 32
40 static List markFixedList(List list) { 33 static List markFixedList(List list) {
41 // Functions are stored in the hidden class and not as properties in 34 // Functions are stored in the hidden class and not as properties in
42 // the object. We never actually look at the value, but only want 35 // the object. We never actually look at the value, but only want
43 // to know if the property exists. 36 // to know if the property exists.
44 JS('void', r'#.fixed$length = Array', list); 37 JS('void', r'#.fixed$length = Array', list);
45 return JS('JSFixedArray', '#', list); 38 return JS('JSFixedArray', '#', list);
46 } 39 }
47 40
48 static List markUnmodifiableList(List list) { 41 static List markUnmodifiableList(List list) {
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 313 }
321 if (end == null) { 314 if (end == null) {
322 end = length; 315 end = length;
323 } else { 316 } else {
324 if (end is! int) throw argumentErrorValue(end); 317 if (end is! int) throw argumentErrorValue(end);
325 if (end < start || end > length) { 318 if (end < start || end > length) {
326 throw new RangeError.range(end, start, length, "end"); 319 throw new RangeError.range(end, start, length, "end");
327 } 320 }
328 } 321 }
329 if (start == end) return <E>[]; 322 if (start == end) return <E>[];
330 return new JSArray<E>.typed(JS('', r'#.slice(#, #)', this, start, end)); 323 return new JSArray<E>.of(JS('', r'#.slice(#, #)', this, start, end));
331 } 324 }
332 325
333 Iterable<E> getRange(int start, int end) { 326 Iterable<E> getRange(int start, int end) {
334 RangeError.checkValidRange(start, end, this.length); 327 RangeError.checkValidRange(start, end, this.length);
335 return new SubListIterable<E>(this, start, end); 328 return new SubListIterable<E>(this, start, end);
336 } 329 }
337 330
338 E get first { 331 E get first {
339 if (length > 0) return this[0]; 332 if (length > 0) return this[0];
340 throw IterableElementError.noElement(); 333 throw IterableElementError.noElement();
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 518
526 bool get isEmpty => length == 0; 519 bool get isEmpty => length == 0;
527 520
528 bool get isNotEmpty => !isEmpty; 521 bool get isNotEmpty => !isEmpty;
529 522
530 String toString() => ListBase.listToString(this); 523 String toString() => ListBase.listToString(this);
531 524
532 List<E> toList({bool growable: true}) { 525 List<E> toList({bool growable: true}) {
533 var list = JS('', '#.slice()', this); 526 var list = JS('', '#.slice()', this);
534 if (!growable) markFixedList(list); 527 if (!growable) markFixedList(list);
535 return new JSArray<E>.typed(list); 528 return new JSArray<E>.of(list);
536 } 529 }
537 530
538 Set<E> toSet() => new Set<E>.from(this); 531 Set<E> toSet() => new Set<E>.from(this);
539 532
540 Iterator<E> get iterator => new ArrayIterator<E>(this); 533 Iterator<E> get iterator => new ArrayIterator<E>(this);
541 534
542 int get hashCode => Primitives.objectHashCode(this); 535 int get hashCode => Primitives.objectHashCode(this);
543 536
544 bool operator ==(other) => identical(this, other); 537 bool operator ==(other) => identical(this, other);
545 538
(...skipping 30 matching lines...) Expand all
576 JS('int', '#', index) < 0) { 569 JS('int', '#', index) < 0) {
577 throw diagnoseIndexError(this, index); 570 throw diagnoseIndexError(this, index);
578 } 571 }
579 JS('void', r'#[#] = #', this, index, value); 572 JS('void', r'#[#] = #', this, index, value);
580 } 573 }
581 574
582 Map<int, E> asMap() { 575 Map<int, E> asMap() {
583 return new ListMapView<E>(this); 576 return new ListMapView<E>(this);
584 } 577 }
585 578
586 Type get runtimeType => wrapType(JS('', '#(#)', getGenericClass(List), E)); 579 Type get runtimeType =>
580 dart.wrapType(JS('', '#(#)', dart.getGenericClass(List), E));
587 } 581 }
588 582
589 /** 583 /**
590 * Dummy subclasses that allow the backend to track more precise 584 * Dummy subclasses that allow the backend to track more precise
591 * information about arrays through their type. The CPA type inference 585 * information about arrays through their type. The CPA type inference
592 * relies on the fact that these classes do not override [] nor []=. 586 * relies on the fact that these classes do not override [] nor []=.
593 * 587 *
594 * These classes are really a fiction, and can have no methods, since 588 * These classes are really a fiction, and can have no methods, since
595 * getInterceptor always returns JSArray. We should consider pushing the 589 * getInterceptor always returns JSArray. We should consider pushing the
596 * 'isGrowable' and 'isMutable' checks into the getInterceptor implementation so 590 * 'isGrowable' and 'isMutable' checks into the getInterceptor implementation so
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 626
633 if (_index >= length) { 627 if (_index >= length) {
634 _current = null; 628 _current = null;
635 return false; 629 return false;
636 } 630 }
637 _current = _iterable[_index]; 631 _current = _iterable[_index];
638 _index++; 632 _index++;
639 return true; 633 return true;
640 } 634 }
641 } 635 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/tool/input_sdk/private/interceptors.dart ('k') | pkg/dev_compiler/tool/input_sdk/private/regexp_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698