Skip to content

Commit b62fdb5

Browse files
author
John Messerly
committed
fixes #217, Object members on extension types
[email protected] Review URL: https://codereview.chromium.org/1173023004.
1 parent e7a5cc3 commit b62fdb5

File tree

7 files changed

+47
-41
lines changed

7 files changed

+47
-41
lines changed

pkg/dev_compiler/lib/runtime/dart/_interceptors.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ dart.library('dart/_interceptors', null, /* Imports */[
340340
get [dartx.isNotEmpty]() {
341341
return !dart.notNull(this[dartx.isEmpty]);
342342
}
343-
[dartx.toString]() {
343+
toString() {
344344
return collection.ListBase.listToString(this);
345345
}
346346
[dartx.toList](opts) {
@@ -356,7 +356,7 @@ dart.library('dart/_interceptors', null, /* Imports */[
356356
get [dartx.iterator]() {
357357
return new (_internal.ListIterator$(E))(this);
358358
}
359-
get [dartx.hashCode]() {
359+
get hashCode() {
360360
return _js_helper.Primitives.objectHashCode(this);
361361
}
362362
get [dartx.length]() {
@@ -700,14 +700,14 @@ dart.library('dart/_interceptors', null, /* Imports */[
700700
}
701701
return dart.notNull(result) + "0"[dartx['*']](exponent);
702702
}
703-
[dartx.toString]() {
703+
toString() {
704704
if (dart.equals(this, 0) && 1 / this < 0) {
705705
return '-0.0';
706706
} else {
707707
return "" + this;
708708
}
709709
}
710-
get [dartx.hashCode]() {
710+
get hashCode() {
711711
return this & 0x1FFFFFFF;
712712
}
713713
[dartx['unary-']]() {
@@ -832,7 +832,7 @@ dart.library('dart/_interceptors', null, /* Imports */[
832832
throw new core.ArgumentError(other);
833833
return this >= other;
834834
}
835-
get [dartx.runtimeType]() {
835+
get runtimeType() {
836836
return core.num;
837837
}
838838
}
@@ -946,7 +946,7 @@ dart.library('dart/_interceptors', null, /* Imports */[
946946
i = JSInt._shru(JSInt._ors(i, JSInt._shrs(i, 16)), 0);
947947
return i;
948948
}
949-
get [dartx.runtimeType]() {
949+
get runtimeType() {
950950
return core.int;
951951
}
952952
[dartx['~']]() {
@@ -979,7 +979,7 @@ dart.library('dart/_interceptors', null, /* Imports */[
979979
JSDouble() {
980980
super.JSNumber();
981981
}
982-
get [dartx.runtimeType]() {
982+
get runtimeType() {
983983
return core.double;
984984
}
985985
}
@@ -1419,10 +1419,10 @@ dart.library('dart/_interceptors', null, /* Imports */[
14191419
throw new core.ArgumentError(other);
14201420
return dart.equals(this, other) ? 0 : this < other ? -1 : 1;
14211421
}
1422-
[dartx.toString]() {
1422+
toString() {
14231423
return this;
14241424
}
1425-
get [dartx.hashCode]() {
1425+
get hashCode() {
14261426
let hash = 0;
14271427
for (let i = 0; dart.notNull(i) < dart.notNull(this[dartx.length]); i = dart.notNull(i) + 1) {
14281428
hash = 536870911 & dart.notNull(hash) + this.charCodeAt(i);
@@ -1433,7 +1433,7 @@ dart.library('dart/_interceptors', null, /* Imports */[
14331433
hash = hash ^ hash >> 11;
14341434
return 536870911 & dart.notNull(hash) + ((16383 & dart.notNull(hash)) << 15);
14351435
}
1436-
get [dartx.runtimeType]() {
1436+
get runtimeType() {
14371437
return core.String;
14381438
}
14391439
get [dartx.length]() {
@@ -1517,13 +1517,13 @@ dart.library('dart/_interceptors', null, /* Imports */[
15171517
JSBool() {
15181518
super.Interceptor();
15191519
}
1520-
[dartx.toString]() {
1520+
toString() {
15211521
return String(this);
15221522
}
1523-
get [dartx.hashCode]() {
1523+
get hashCode() {
15241524
return this ? 2 * 3 * 23 * 3761 : 269 * 811;
15251525
}
1526-
get [dartx.runtimeType]() {
1526+
get runtimeType() {
15271527
return core.bool;
15281528
}
15291529
}

pkg/dev_compiler/lib/runtime/dart/_internal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2319,7 +2319,7 @@ dart.library('dart/_internal', null, /* Imports */[
23192319
}
23202320
get hashCode() {
23212321
let arbitraryPrime = 664597;
2322-
return 536870911 & dart.notNull(arbitraryPrime) * dart.notNull(dart[dartx.hashCode](this[_name]));
2322+
return 536870911 & dart.notNull(arbitraryPrime) * dart.notNull(dart.hashCode(this[_name]));
23232323
}
23242324
toString() {
23252325
return `Symbol("${this[_name]}")`;

pkg/dev_compiler/lib/runtime/dart/convert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ dart.library('dart/convert', null, /* Imports */[
13651365
dart.dsend(stringifier, 'writeObject', object);
13661366
}
13671367
writeNumber(number) {
1368-
this[_sink].write(dart[dartx.toString](number));
1368+
this[_sink].write(dart.toString(number));
13691369
}
13701370
writeString(string) {
13711371
this[_sink].write(string);
@@ -1431,7 +1431,7 @@ dart.library('dart/convert', null, /* Imports */[
14311431
this.index = 0;
14321432
}
14331433
writeNumber(number) {
1434-
this.writeAsciiString(dart[dartx.toString](number));
1434+
this.writeAsciiString(dart.toString(number));
14351435
}
14361436
writeAsciiString(string) {
14371437
for (let i = 0; dart.notNull(i) < dart.notNull(string[dartx.length]); i = dart.notNull(i) + 1) {

pkg/dev_compiler/lib/runtime/dart/core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ dart.library('dart/core', null, /* Imports */[
7676
let defaultValue = opts && 'defaultValue' in opts ? opts.defaultValue : false;
7777
throw new UnsupportedError('bool.fromEnvironment can only be used as a const constructor');
7878
}
79-
[dartx.toString]() {
79+
toString() {
8080
return this ? "true" : "false";
8181
}
8282
}
@@ -520,7 +520,7 @@ dart.library('dart/core', null, /* Imports */[
520520
return dart.equals(this[_duration], dart.dload(other, _duration));
521521
}
522522
get hashCode() {
523-
return dart[dartx.hashCode](this[_duration]);
523+
return dart.hashCode(this[_duration]);
524524
}
525525
compareTo(other) {
526526
return this[_duration][dartx.compareTo](other[_duration]);

pkg/dev_compiler/lib/src/codegen/js_codegen.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class JSCodegenVisitor extends GeneralizingAstVisitor {
9494
/// _interceptors.JSArray<E>, used for List literals.
9595
ClassElement _jsArray;
9696

97+
Map<String, DartType> _objectMembers;
98+
9799
JSCodegenVisitor(AbstractCompiler compiler, this.libraryInfo,
98100
this._extensionTypes, this._fieldsNeedingStorage)
99101
: compiler = compiler,
@@ -106,6 +108,8 @@ class JSCodegenVisitor extends GeneralizingAstVisitor {
106108
var src = context.sourceFactory.forUri('dart:_interceptors');
107109
var interceptors = context.computeLibraryElement(src);
108110
_jsArray = interceptors.getType('JSArray');
111+
112+
_objectMembers = getObjectMemberMap(types);
109113
}
110114

111115
LibraryElement get currentLibrary => libraryInfo.library;
@@ -578,7 +582,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor {
578582
}
579583
if (dartxNames.isNotEmpty) {
580584
body.add(js.statement('dart.defineExtensionNames(#)',
581-
[new JS.ArrayInitializer(dartxNames, multiline: true)]));
585+
[new JS.ArrayInitializer(dartxNames, multiline: true)]));
582586
}
583587
}
584588

@@ -2677,7 +2681,9 @@ class JSCodegenVisitor extends GeneralizingAstVisitor {
26772681
}
26782682

26792683
// Dart "extension" methods. Used for JS Array, Boolean, Number, String.
2680-
if (allowExtensions && _extensionTypes.contains(type.element)) {
2684+
if (allowExtensions &&
2685+
_extensionTypes.contains(type.element) &&
2686+
!_objectMembers.containsKey(name)) {
26812687
return js.call('dartx.#', _propertyName(name));
26822688
}
26832689

pkg/dev_compiler/test/codegen/expect/misc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ dart.library('misc', null, /* Imports */[
2121
});
2222
let Generic = Generic$();
2323
function main() {
24-
core.print(dart[dartx.toString](1));
25-
core.print(dart[dartx.toString](1.0));
26-
core.print(dart[dartx.toString](1.1));
24+
core.print(dart.toString(1));
25+
core.print(dart.toString(1.0));
26+
core.print(dart.toString(1.1));
2727
let x = 42;
2828
core.print(dart.equals(x, core.Object));
2929
core.print(dart.equals(x, Generic));

pkg/dev_compiler/tool/sdk_expected_errors.txt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,58 +34,58 @@ warning: line 91, column 14 of dart:_interceptors/js_number.dart: [DownCastImpli
3434
severe: line 110, column 17 of dart:_interceptors/js_number.dart: [StaticTypeError] Type check failed: this (JSNumber) is not of type double
3535
toDouble() => this;
3636
^^^^
37-
severe: line 347, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.abs (() → num) is not a subtype of int.abs (() → int).
37+
severe: line 349, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.abs (() → num) is not a subtype of int.abs (() → int).
3838
class JSInt extends JSNumber implements int, double {
3939
^^^^^^^^^^^^^^^^
40-
severe: line 347, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.unary- (() → num) is not a subtype of int.unary- (() → int).
40+
severe: line 349, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.unary- (() → num) is not a subtype of int.unary- (() → int).
4141
class JSInt extends JSNumber implements int, double {
4242
^^^^^^^^^^^^^^^^
43-
severe: line 347, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.<< ((num) → num) is not a subtype of int.<< ((int) → int).
43+
severe: line 349, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.<< ((num) → num) is not a subtype of int.<< ((int) → int).
4444
class JSInt extends JSNumber implements int, double {
4545
^^^^^^^^^^^^^^^^
46-
severe: line 347, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.>> ((num) → num) is not a subtype of int.>> ((int) → int).
46+
severe: line 349, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.>> ((num) → num) is not a subtype of int.>> ((int) → int).
4747
class JSInt extends JSNumber implements int, double {
4848
^^^^^^^^^^^^^^^^
49-
severe: line 347, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.& ((num) → num) is not a subtype of int.& ((int) → int).
49+
severe: line 349, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.& ((num) → num) is not a subtype of int.& ((int) → int).
5050
class JSInt extends JSNumber implements int, double {
5151
^^^^^^^^^^^^^^^^
52-
severe: line 347, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.| ((num) → num) is not a subtype of int.| ((int) → int).
52+
severe: line 349, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.| ((num) → num) is not a subtype of int.| ((int) → int).
5353
class JSInt extends JSNumber implements int, double {
5454
^^^^^^^^^^^^^^^^
55-
severe: line 347, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.^ ((num) → num) is not a subtype of int.^ ((int) → int).
55+
severe: line 349, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.^ ((num) → num) is not a subtype of int.^ ((int) → int).
5656
class JSInt extends JSNumber implements int, double {
5757
^^^^^^^^^^^^^^^^
58-
severe: line 347, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.sign (() → num) is not a subtype of int.sign (() → int).
58+
severe: line 349, column 13 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.sign (() → num) is not a subtype of int.sign (() → int).
5959
class JSInt extends JSNumber implements int, double {
6060
^^^^^^^^^^^^^^^^
61-
warning: line 355, column 12 of dart:_interceptors/js_number.dart: [DownCastImplicit] this & ((1 << width) - 1) (num) will need runtime check to cast to type int
61+
warning: line 357, column 12 of dart:_interceptors/js_number.dart: [DownCastImplicit] this & ((1 << width) - 1) (num) will need runtime check to cast to type int
6262
return this & ((1 << width) - 1);
6363
^^^^^^^^^^^^^^^^^^^^^^^^^
64-
warning: line 360, column 12 of dart:_interceptors/js_number.dart: [DownCastImplicit] (this & (signMask - 1)) - (this & signMask) (num) will need runtime check to cast to type int
64+
warning: line 362, column 12 of dart:_interceptors/js_number.dart: [DownCastImplicit] (this & (signMask - 1)) - (this & signMask) (num) will need runtime check to cast to type int
6565
return (this & (signMask - 1)) - (this & signMask);
6666
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67-
severe: line 418, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.remainder ((num) → num) is not a subtype of double.remainder ((num) → double).
67+
severe: line 420, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.remainder ((num) → num) is not a subtype of double.remainder ((num) → double).
6868
class JSDouble extends JSNumber implements double {
6969
^^^^^^^^^^^^^^^^
70-
severe: line 418, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.abs (() → num) is not a subtype of double.abs (() → double).
70+
severe: line 420, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.abs (() → num) is not a subtype of double.abs (() → double).
7171
class JSDouble extends JSNumber implements double {
7272
^^^^^^^^^^^^^^^^
73-
severe: line 418, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.unary- (() → num) is not a subtype of double.unary- (() → double).
73+
severe: line 420, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.unary- (() → num) is not a subtype of double.unary- (() → double).
7474
class JSDouble extends JSNumber implements double {
7575
^^^^^^^^^^^^^^^^
76-
severe: line 418, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.+ ((num) → num) is not a subtype of double.+ ((num) → double).
76+
severe: line 420, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.+ ((num) → num) is not a subtype of double.+ ((num) → double).
7777
class JSDouble extends JSNumber implements double {
7878
^^^^^^^^^^^^^^^^
79-
severe: line 418, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.- ((num) → num) is not a subtype of double.- ((num) → double).
79+
severe: line 420, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.- ((num) → num) is not a subtype of double.- ((num) → double).
8080
class JSDouble extends JSNumber implements double {
8181
^^^^^^^^^^^^^^^^
82-
severe: line 418, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.* ((num) → num) is not a subtype of double.* ((num) → double).
82+
severe: line 420, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.* ((num) → num) is not a subtype of double.* ((num) → double).
8383
class JSDouble extends JSNumber implements double {
8484
^^^^^^^^^^^^^^^^
85-
severe: line 418, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.% ((num) → num) is not a subtype of double.% ((num) → double).
85+
severe: line 420, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.% ((num) → num) is not a subtype of double.% ((num) → double).
8686
class JSDouble extends JSNumber implements double {
8787
^^^^^^^^^^^^^^^^
88-
severe: line 418, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.sign (() → num) is not a subtype of double.sign (() → double).
88+
severe: line 420, column 16 of dart:_interceptors/js_number.dart: [InvalidMethodOverride] Base class introduces an invalid override. The type of JSNumber.sign (() → num) is not a subtype of double.sign (() → double).
8989
class JSDouble extends JSNumber implements double {
9090
^^^^^^^^^^^^^^^^
9191
warning: line 86, column 14 of dart:_interceptors/js_string.dart: [DownCastComposite] JS('JSExtendableArray', r'#.split(#)', this, pattern) (dynamic) will need runtime check to cast to type List<String>

0 commit comments

Comments
 (0)