Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Unified Diff: dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 23996002: Use interceptors to handle runtime types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comment Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
diff --git a/dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart b/dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
index 3118874217d4d8cebfdf1478105c9cb3c626cab5..284715d245a936361b175bcf1b5ccdccabbd03e4 100644
--- a/dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
+++ b/dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
@@ -3159,18 +3159,35 @@ class CodeEmitterTask extends CompilerTask {
block.statements.add(buildInterceptorCheck(backend.jsArrayClass));
}
+ // Recognize JavaScript functions that correspond to Dart constructors
+ // (generated by defineClass that adds the property 'builtin$cls').
+ // TODO(ahe): Either integrate this with native dispatchProperty, or use a
+ // mixin approach in defineClass.
+ block.statements.add(
+ js.if_(r'typeof receiver == "function" && "builtin$cls" in receiver',
+ buildReturnInterceptor(backend.jsRuntimeType)));
+
+ // Recognize JavaScript object literals that are used to encode function
+ // types. These objects are generated by
+ // [TypeRepresentationGenerator.visitFunctionType] and always have the
ngeoffray 2013/09/10 10:42:26 missing something after 'and'.
+ // "func" property (namer.functionTypeTag()).
+ // TODO(ahe): This should be a real Dart object and we should be able to
+ // remove this test (so I'm keeping the redundant "object" test).
+ block.statements.add(
+ js.if_(r'typeof receiver == "object"'
+ // JavaScript object literals have Object as constructor.
+ ' && receiver.constructor === Object'
+ ' && "${namer.functionTypeTag()}" in receiver',
+ buildReturnInterceptor(backend.jsFunctionType)));
+
if (hasNative) {
block.statements.add(
- js.if_(
- js('(typeof receiver) != "object"'),
- js.return_(js('receiver'))));
+ js.if_('typeof receiver != "object"', js.return_('receiver')));
- // if (receiver instanceof $.Object) return receiver;
- // return $.getNativeInterceptor(receiver);
block.statements.add(
js.if_(js('receiver instanceof #',
js(namer.isolateAccess(compiler.objectClass))),
- js.return_(js('receiver'))));
+ js.return_('receiver')));
block.statements.add(
js.return_(
js(namer.isolateAccess(backend.getNativeInterceptorMethod))(
« no previous file with comments | « dart/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart ('k') | dart/sdk/lib/_internal/lib/interceptors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698