Skip to content

Commit

Permalink
fixes #217, Object members on extension types
Browse files Browse the repository at this point in the history
R=vsm@google.com

Review URL: https://codereview.chromium.org/1173023004.
  • Loading branch information
John Messerly committed Jun 10, 2015
1 parent e7a5cc3 commit b62fdb5
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 41 deletions.
26 changes: 13 additions & 13 deletions pkg/dev_compiler/lib/runtime/dart/_interceptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ dart.library('dart/_interceptors', null, /* Imports */[
get [dartx.isNotEmpty]() {
return !dart.notNull(this[dartx.isEmpty]);
}
[dartx.toString]() {
toString() {
return collection.ListBase.listToString(this);
}
[dartx.toList](opts) {
Expand All @@ -356,7 +356,7 @@ dart.library('dart/_interceptors', null, /* Imports */[
get [dartx.iterator]() {
return new (_internal.ListIterator$(E))(this);
}
get [dartx.hashCode]() {
get hashCode() {
return _js_helper.Primitives.objectHashCode(this);
}
get [dartx.length]() {
Expand Down Expand Up @@ -700,14 +700,14 @@ dart.library('dart/_interceptors', null, /* Imports */[
}
return dart.notNull(result) + "0"[dartx['*']](exponent);
}
[dartx.toString]() {
toString() {
if (dart.equals(this, 0) && 1 / this < 0) {
return '-0.0';
} else {
return "" + this;
}
}
get [dartx.hashCode]() {
get hashCode() {
return this & 0x1FFFFFFF;
}
[dartx['unary-']]() {
Expand Down Expand Up @@ -832,7 +832,7 @@ dart.library('dart/_interceptors', null, /* Imports */[
throw new core.ArgumentError(other);
return this >= other;
}
get [dartx.runtimeType]() {
get runtimeType() {
return core.num;
}
}
Expand Down Expand Up @@ -946,7 +946,7 @@ dart.library('dart/_interceptors', null, /* Imports */[
i = JSInt._shru(JSInt._ors(i, JSInt._shrs(i, 16)), 0);
return i;
}
get [dartx.runtimeType]() {
get runtimeType() {
return core.int;
}
[dartx['~']]() {
Expand Down Expand Up @@ -979,7 +979,7 @@ dart.library('dart/_interceptors', null, /* Imports */[
JSDouble() {
super.JSNumber();
}
get [dartx.runtimeType]() {
get runtimeType() {
return core.double;
}
}
Expand Down Expand Up @@ -1419,10 +1419,10 @@ dart.library('dart/_interceptors', null, /* Imports */[
throw new core.ArgumentError(other);
return dart.equals(this, other) ? 0 : this < other ? -1 : 1;
}
[dartx.toString]() {
toString() {
return this;
}
get [dartx.hashCode]() {
get hashCode() {
let hash = 0;
for (let i = 0; dart.notNull(i) < dart.notNull(this[dartx.length]); i = dart.notNull(i) + 1) {
hash = 536870911 & dart.notNull(hash) + this.charCodeAt(i);
Expand All @@ -1433,7 +1433,7 @@ dart.library('dart/_interceptors', null, /* Imports */[
hash = hash ^ hash >> 11;
return 536870911 & dart.notNull(hash) + ((16383 & dart.notNull(hash)) << 15);
}
get [dartx.runtimeType]() {
get runtimeType() {
return core.String;
}
get [dartx.length]() {
Expand Down Expand Up @@ -1517,13 +1517,13 @@ dart.library('dart/_interceptors', null, /* Imports */[
JSBool() {
super.Interceptor();
}
[dartx.toString]() {
toString() {
return String(this);
}
get [dartx.hashCode]() {
get hashCode() {
return this ? 2 * 3 * 23 * 3761 : 269 * 811;
}
get [dartx.runtimeType]() {
get runtimeType() {
return core.bool;
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dev_compiler/lib/runtime/dart/_internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2319,7 +2319,7 @@ dart.library('dart/_internal', null, /* Imports */[
}
get hashCode() {
let arbitraryPrime = 664597;
return 536870911 & dart.notNull(arbitraryPrime) * dart.notNull(dart[dartx.hashCode](this[_name]));
return 536870911 & dart.notNull(arbitraryPrime) * dart.notNull(dart.hashCode(this[_name]));
}
toString() {
return `Symbol("${this[_name]}")`;
Expand Down
4 changes: 2 additions & 2 deletions pkg/dev_compiler/lib/runtime/dart/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ dart.library('dart/convert', null, /* Imports */[
dart.dsend(stringifier, 'writeObject', object);
}
writeNumber(number) {
this[_sink].write(dart[dartx.toString](number));
this[_sink].write(dart.toString(number));
}
writeString(string) {
this[_sink].write(string);
Expand Down Expand Up @@ -1431,7 +1431,7 @@ dart.library('dart/convert', null, /* Imports */[
this.index = 0;
}
writeNumber(number) {
this.writeAsciiString(dart[dartx.toString](number));
this.writeAsciiString(dart.toString(number));
}
writeAsciiString(string) {
for (let i = 0; dart.notNull(i) < dart.notNull(string[dartx.length]); i = dart.notNull(i) + 1) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/dev_compiler/lib/runtime/dart/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ dart.library('dart/core', null, /* Imports */[
let defaultValue = opts && 'defaultValue' in opts ? opts.defaultValue : false;
throw new UnsupportedError('bool.fromEnvironment can only be used as a const constructor');
}
[dartx.toString]() {
toString() {
return this ? "true" : "false";
}
}
Expand Down Expand Up @@ -520,7 +520,7 @@ dart.library('dart/core', null, /* Imports */[
return dart.equals(this[_duration], dart.dload(other, _duration));
}
get hashCode() {
return dart[dartx.hashCode](this[_duration]);
return dart.hashCode(this[_duration]);
}
compareTo(other) {
return this[_duration][dartx.compareTo](other[_duration]);
Expand Down
10 changes: 8 additions & 2 deletions pkg/dev_compiler/lib/src/codegen/js_codegen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class JSCodegenVisitor extends GeneralizingAstVisitor {
/// _interceptors.JSArray<E>, used for List literals.
ClassElement _jsArray;

Map<String, DartType> _objectMembers;

JSCodegenVisitor(AbstractCompiler compiler, this.libraryInfo,
this._extensionTypes, this._fieldsNeedingStorage)
: compiler = compiler,
Expand All @@ -106,6 +108,8 @@ class JSCodegenVisitor extends GeneralizingAstVisitor {
var src = context.sourceFactory.forUri('dart:_interceptors');
var interceptors = context.computeLibraryElement(src);
_jsArray = interceptors.getType('JSArray');

_objectMembers = getObjectMemberMap(types);
}

LibraryElement get currentLibrary => libraryInfo.library;
Expand Down Expand Up @@ -578,7 +582,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor {
}
if (dartxNames.isNotEmpty) {
body.add(js.statement('dart.defineExtensionNames(#)',
[new JS.ArrayInitializer(dartxNames, multiline: true)]));
[new JS.ArrayInitializer(dartxNames, multiline: true)]));
}
}

Expand Down Expand Up @@ -2677,7 +2681,9 @@ class JSCodegenVisitor extends GeneralizingAstVisitor {
}

// Dart "extension" methods. Used for JS Array, Boolean, Number, String.
if (allowExtensions && _extensionTypes.contains(type.element)) {
if (allowExtensions &&
_extensionTypes.contains(type.element) &&
!_objectMembers.containsKey(name)) {
return js.call('dartx.#', _propertyName(name));
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/dev_compiler/test/codegen/expect/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ dart.library('misc', null, /* Imports */[
});
let Generic = Generic$();
function main() {
core.print(dart[dartx.toString](1));
core.print(dart[dartx.toString](1.0));
core.print(dart[dartx.toString](1.1));
core.print(dart.toString(1));
core.print(dart.toString(1.0));
core.print(dart.toString(1.1));
let x = 42;
core.print(dart.equals(x, core.Object));
core.print(dart.equals(x, Generic));
Expand Down
36 changes: 18 additions & 18 deletions pkg/dev_compiler/tool/sdk_expected_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,58 +34,58 @@ warning: line 91, column 14 of dart:_interceptors/js_number.dart: [DownCastImpli
severe: line 110, column 17 of dart:_interceptors/js_number.dart: [StaticTypeError] Type check failed: this (JSNumber) is not of type double
toDouble() => this;
^^^^
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).
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).
class JSInt extends JSNumber implements int, double {
^^^^^^^^^^^^^^^^
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).
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).
class JSInt extends JSNumber implements int, double {
^^^^^^^^^^^^^^^^
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).
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).
class JSInt extends JSNumber implements int, double {
^^^^^^^^^^^^^^^^
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).
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).
class JSInt extends JSNumber implements int, double {
^^^^^^^^^^^^^^^^
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).
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).
class JSInt extends JSNumber implements int, double {
^^^^^^^^^^^^^^^^
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).
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).
class JSInt extends JSNumber implements int, double {
^^^^^^^^^^^^^^^^
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).
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).
class JSInt extends JSNumber implements int, double {
^^^^^^^^^^^^^^^^
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).
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).
class JSInt extends JSNumber implements int, double {
^^^^^^^^^^^^^^^^
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
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
return this & ((1 << width) - 1);
^^^^^^^^^^^^^^^^^^^^^^^^^
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
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
return (this & (signMask - 1)) - (this & signMask);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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).
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).
class JSDouble extends JSNumber implements double {
^^^^^^^^^^^^^^^^
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).
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).
class JSDouble extends JSNumber implements double {
^^^^^^^^^^^^^^^^
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).
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).
class JSDouble extends JSNumber implements double {
^^^^^^^^^^^^^^^^
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).
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).
class JSDouble extends JSNumber implements double {
^^^^^^^^^^^^^^^^
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).
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).
class JSDouble extends JSNumber implements double {
^^^^^^^^^^^^^^^^
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).
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).
class JSDouble extends JSNumber implements double {
^^^^^^^^^^^^^^^^
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).
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).
class JSDouble extends JSNumber implements double {
^^^^^^^^^^^^^^^^
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).
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).
class JSDouble extends JSNumber implements double {
^^^^^^^^^^^^^^^^
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>
Expand Down

0 comments on commit b62fdb5

Please sign in to comment.