Skip to content

Commit

Permalink
fixes #216, JSNumber members
Browse files Browse the repository at this point in the history
  • Loading branch information
John Messerly committed Jun 10, 2015
1 parent 86a8ac2 commit e7a5cc3
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 4 deletions.
47 changes: 47 additions & 0 deletions pkg/dev_compiler/lib/runtime/dart/_interceptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,50 @@ dart.library('dart/_interceptors', null, /* Imports */[
let _shrReceiverPositive = Symbol('_shrReceiverPositive');
let _shrOtherPositive = Symbol('_shrOtherPositive');
let _shrBothPositive = Symbol('_shrBothPositive');
dart.defineExtensionNames([
'compareTo',
'isNegative',
'isNaN',
'isInfinite',
'isFinite',
'remainder',
'abs',
'sign',
'toInt',
'truncate',
'ceil',
'floor',
'round',
'ceilToDouble',
'floorToDouble',
'roundToDouble',
'truncateToDouble',
'clamp',
'toDouble',
'toStringAsFixed',
'toStringAsExponential',
'toStringAsPrecision',
'toRadixString',
'toString',
'hashCode',
'unary-',
'+',
'-',
'/',
'*',
'%',
'~/',
'<<',
'>>',
'&',
'|',
'^',
'<',
'>',
'<=',
'>=',
'runtimeType'
]);
class JSNumber extends Interceptor {
JSNumber() {
super.Interceptor();
Expand Down Expand Up @@ -928,6 +972,9 @@ dart.library('dart/_interceptors', null, /* Imports */[
});
JSInt[dart.metadata] = () => [dart.const(new _js_helper.JsPeerInterface({name: 'Number'}))];
dart.registerExtension(dart.global.Number, JSInt);
dart.defineExtensionNames([
'runtimeType'
]);
class JSDouble extends JSNumber {
JSDouble() {
super.JSNumber();
Expand Down
6 changes: 6 additions & 0 deletions pkg/dev_compiler/lib/runtime/dart/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ dart.library('dart/core', null, /* Imports */[
constructors: () => ({_Proxy: [_Proxy, []]})
});
let proxy = dart.const(new _Proxy());
dart.defineExtensionNames([
'toString'
]);
class bool extends Object {
static fromEnvironment(name, opts) {
let defaultValue = opts && 'defaultValue' in opts ? opts.defaultValue : false;
Expand Down Expand Up @@ -1254,6 +1257,9 @@ dart.library('dart/core', null, /* Imports */[
}
}
let Iterable$ = dart.generic(function(E) {
dart.defineExtensionNames([
'join'
]);
class Iterable extends Object {
Iterable() {
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/dev_compiler/lib/runtime/dart_runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,12 @@ var dart, dartx;
// Mark the JS type's instances so we can easily check for extensions.
assert(jsProto[_extensionType] === void 0);
jsProto[_extensionType] = extProto;
copyPropertiesHelper(jsProto, extProto, getOwnPropertySymbols(extProto));

let dartObjProto = core.Object.prototype;
while (extProto !== dartObjProto && extProto !== jsProto) {
copyPropertiesHelper(jsProto, extProto, getOwnPropertySymbols(extProto));
extProto = extProto.__proto__;
}
}
dart.registerExtension = registerExtension;

Expand Down
8 changes: 5 additions & 3 deletions pkg/dev_compiler/lib/src/codegen/js_codegen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -569,15 +569,17 @@ class JSCodegenVisitor extends GeneralizingAstVisitor {
var name = classElem.name;
var body = <JS.Statement>[];

if (jsPeerName != null) {
if (_extensionTypes.contains(classElem)) {
var dartxNames = [];
for (var m in methods) {
if (!m.isAbstract && !m.isStatic && m.element.isPublic) {
dartxNames.add(_elementMemberName(m.element, allowExtensions: false));
}
}
body.add(js.statement('dart.defineExtensionNames(#)',
[new JS.ArrayInitializer(dartxNames, multiline: true)]));
if (dartxNames.isNotEmpty) {
body.add(js.statement('dart.defineExtensionNames(#)',
[new JS.ArrayInitializer(dartxNames, multiline: true)]));
}
}

body.add(new JS.ClassDeclaration(cls));
Expand Down
2 changes: 2 additions & 0 deletions pkg/dev_compiler/tool/input_sdk/private/js_number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ class JSNumber extends Interceptor implements num {
*/
// TODO(jmesserly): for dev_compiler all numbers will get `int` members at
// runtime for dynamic dispatch. We can fix by checking it at dispatch time.
// TODO(jmesserly): merge with JSNumber? That would simplify generated code,
// and dart_runtime's extension mechanism.
@JsPeerInterface(name: 'Number')
class JSInt extends JSNumber implements int, double {
const JSInt();
Expand Down

0 comments on commit e7a5cc3

Please sign in to comment.