Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 3fe7460

Browse files
author
Olivier Chafik
committed
Fix dart.registerExtension
1 parent 7c26d43 commit 3fe7460

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

lib/runtime/dart/_interceptors.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ dart_library.library('dart/_interceptors', null, /* Imports */[
393393
}
394394
}
395395
dart.setBaseClass(JSArray, dart.global.Array);
396-
dart.registerExtension(dart.global.Array, JSArray);
397396
JSArray[dart.implements] = () => [core.List$(E), JSIndexable];
398397
dart.setSignature(JSArray, {
399398
constructors: () => ({
@@ -456,6 +455,7 @@ dart_library.library('dart/_interceptors', null, /* Imports */[
456455
return JSArray;
457456
});
458457
let JSArray = JSArray$();
458+
dart.registerExtension(dart.global.Array, JSArray);
459459
let JSMutableArray$ = dart.generic(function(E) {
460460
class JSMutableArray extends JSArray$(E) {
461461
JSMutableArray() {
@@ -956,7 +956,6 @@ dart_library.library('dart/_interceptors', null, /* Imports */[
956956
return dart.as(~this >>> 0, core.int);
957957
}
958958
}
959-
dart.registerExtension(dart.global.Number, JSInt);
960959
JSInt[dart.implements] = () => [core.int, core.double];
961960
dart.setSignature(JSInt, {
962961
constructors: () => ({JSInt: [JSInt, []]}),
@@ -975,6 +974,7 @@ dart_library.library('dart/_interceptors', null, /* Imports */[
975974
names: ['_bitCount', '_shru', '_shrs', '_ors', '_spread']
976975
});
977976
JSInt[dart.metadata] = () => [dart.const(new _js_helper.JsPeerInterface({name: 'Number'}))];
977+
dart.registerExtension(dart.global.Number, JSInt);
978978
dart.defineExtensionNames([
979979
'runtimeType'
980980
]);
@@ -1450,7 +1450,6 @@ dart_library.library('dart/_interceptors', null, /* Imports */[
14501450
return this[index];
14511451
}
14521452
}
1453-
dart.registerExtension(dart.global.String, JSString);
14541453
JSString[dart.implements] = () => [core.String, JSIndexable];
14551454
dart.setSignature(JSString, {
14561455
constructors: () => ({JSString: [JSString, []]}),
@@ -1490,6 +1489,7 @@ dart_library.library('dart/_interceptors', null, /* Imports */[
14901489
names: ['_isWhitespace', '_skipLeadingWhitespace', '_skipTrailingWhitespace']
14911490
});
14921491
JSString[dart.metadata] = () => [dart.const(new _js_helper.JsPeerInterface({name: 'String'}))];
1492+
dart.registerExtension(dart.global.String, JSString);
14931493
let _string = Symbol('_string');
14941494
class _CodeUnits extends _internal.UnmodifiableListBase$(core.int) {
14951495
_CodeUnits(string) {
@@ -1530,12 +1530,12 @@ dart_library.library('dart/_interceptors', null, /* Imports */[
15301530
return core.bool;
15311531
}
15321532
}
1533-
dart.registerExtension(dart.global.Boolean, JSBool);
15341533
JSBool[dart.implements] = () => [core.bool];
15351534
dart.setSignature(JSBool, {
15361535
constructors: () => ({JSBool: [JSBool, []]})
15371536
});
15381537
JSBool[dart.metadata] = () => [dart.const(new _js_helper.JsPeerInterface({name: 'Boolean'}))];
1538+
dart.registerExtension(dart.global.Boolean, JSBool);
15391539
class JSIndexable extends core.Object {}
15401540
class JSMutableIndexable extends JSIndexable {}
15411541
class JSObject extends core.Object {}

lib/src/codegen/js_codegen.dart

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,16 @@ class _ClassBuilder {
6565
final List<JS.Statement> prelude = [];
6666
/// Members of the class declaration.
6767
final List<JS.Method> body = [];
68-
/// Builders for statements that should appear after the class declaration.
69-
/// These builders will get a qualified reference to the class as argument so
70-
/// they can refer to it if they so wish.
68+
/// Builders for statements that should appear just after the class
69+
/// declaration. These builders will get a local or qualified reference to the
70+
/// class as argument so they can refer to it if they so wish.
71+
///
72+
/// Note that these statements may be wrapped in generic or lazy classes
73+
/// definitions, so they might not be top-level.
7174
final List<_ClassRefStatementBuilder> statements = [];
75+
/// Statements for extension classes are treated separately, as they need to
76+
/// be at the top-level.
77+
final List<JS.Statement> topLevelStatements = [];
7278

7379
_ClassBuilder(this.info);
7480
}
@@ -653,7 +659,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
653659
new JS.Identifier(name),
654660
heritage,
655661
builder.body.where((m) => m != null).toList(growable: false));
656-
return _finishType(element.type, ({bool isExportable}) {
662+
var result = _finishType(element.type, ({bool isExportable}) {
657663
var classRef = isExportable
658664
? _maybeQualifiedLocalType(name)
659665
: new JS.Identifier(name);
@@ -665,6 +671,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
665671
return statementBuilder(classRef);
666672
})));
667673
});
674+
return _statement([result]..addAll(builder.topLevelStatements));
668675
}
669676

670677
/// Given a class definition statement factory, completes its declaration.
@@ -805,11 +812,11 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
805812
// Probably fine for objects coming from JS, but not if we actually
806813
// want to support construction of instances with generic types other
807814
// than dynamic. See issue #154 for Array and List<E> related bug.
808-
builder.statements.add((classRef) =>
815+
builder.topLevelStatements.add(
809816
js.statement(
810817
'dart.registerExtension(dart.global.#, #);', [
811818
_propertyName(jsPeerName),
812-
classRef
819+
classElem.name
813820
]));
814821
}
815822
void _addClassInterfaces(_ClassBuilder builder) {

0 commit comments

Comments
 (0)