Skip to content

Commit

Permalink
Attach type info to extension method and object method tear-offs
Browse files Browse the repository at this point in the history
Fixes #189.

BUG=
R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1293293002 .
  • Loading branch information
leafpetersen committed Aug 19, 2015
1 parent 3806525 commit 8d36859
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 222 deletions.
3 changes: 3 additions & 0 deletions pkg/dev_compiler/lib/runtime/_classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ dart_library.library('dart_runtime/_classes', null, /* Imports */[
copyTheseProperties(jsProto, extProto, getOwnPropertySymbols(extProto));
extProto = extProto.__proto__;
}
let originalSigFn = getOwnPropertyDescriptor(dartExtType, _methodSig).get;
assert(originalSigFn);
defineMemoizedGetter(jsType, _methodSig, originalSigFn);
}
exports.registerExtension = registerExtension;

Expand Down
5 changes: 3 additions & 2 deletions pkg/dev_compiler/lib/src/codegen/js_codegen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2456,9 +2456,10 @@ class JSCodegenVisitor extends GeneralizingAstVisitor {
String code;
if (member != null && member is MethodElement && !isStatic) {
// Tear-off methods: explicitly bind it.
// TODO(leafp): Attach runtime types to these static tearoffs
if (_requiresStaticDispatch(target, memberId.name)) {
return js.call('dart.#.bind(#)', [name, _visit(target)]);
var type = member.type;
var clos = js.call('dart.#.bind(#)', [name, _visit(target)]);
return js.call('dart.fn(#, #)', [clos, _emitFunctionTypeParts(type)]);
}
code = 'dart.bind(#, #)';
} else if (_requiresStaticDispatch(target, memberId.name)) {
Expand Down
10 changes: 10 additions & 0 deletions pkg/dev_compiler/test/browser/runtime_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,16 @@ suite('instanceOf', () => {
checkType(c.ListBase.listToString,
dart.functionType(core.String, [core.String]), false, true);

// Tear-off of extension methods on primitives
checkType(dart.bind(3.0, dartx.floor),
dart.functionType(core.int, []));
checkType(dart.bind(3.0, dartx.floor),
dart.functionType(core.String, []), false, true);
checkType(dart.bind("", dartx.endsWith),
dart.functionType(core.bool, [core.String]));
checkType(dart.bind("", dartx.endsWith),
dart.functionType(core.bool, [core.int]), false, true);

// Tear off a mixin method
class Base {
m(x) {return x;}
Expand Down
Loading

0 comments on commit 8d36859

Please sign in to comment.