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

Side by Side Diff: lib/src/codegen/js_codegen.dart

Issue 1142293002: Use dart.tearoff helper at tearoff sites (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Use dart.bind instead of dart.tearoff Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « lib/runtime/dart_runtime.js ('k') | test/codegen/expect/functions.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dev_compiler.src.codegen.js_codegen; 5 library dev_compiler.src.codegen.js_codegen;
6 6
7 import 'dart:collection' show HashSet, HashMap; 7 import 'dart:collection' show HashSet, HashMap;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; 10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator;
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 // For static methods, we add the raw type name, without generics or 1117 // For static methods, we add the raw type name, without generics or
1118 // library prefix. We don't need those because static calls can't use 1118 // library prefix. We don't need those because static calls can't use
1119 // the generic type. 1119 // the generic type.
1120 if (isStatic) { 1120 if (isStatic) {
1121 var dynType = _emitTypeName(fillDynamicTypeArgs(type, types)); 1121 var dynType = _emitTypeName(fillDynamicTypeArgs(type, types));
1122 return new JS.PropertyAccess(dynType, member); 1122 return new JS.PropertyAccess(dynType, member);
1123 } 1123 }
1124 1124
1125 // For instance members, we add implicit-this. 1125 // For instance members, we add implicit-this.
1126 // For method tear-offs, we ensure it's a bound method. 1126 // For method tear-offs, we ensure it's a bound method.
1127 var code = 'this.#'; 1127 var tearOff = element is MethodElement && !inInvocationContext(node);
1128 if (element is MethodElement && !inInvocationContext(node)) { 1128 var code = (tearOff) ? 'dart.bind(this, #)' : 'this.#';
1129 code += '.bind(this)';
1130 }
1131 return js.call(code, member); 1129 return js.call(code, member);
1132 } 1130 }
1133 1131
1134 // initializing formal parameter, e.g. `Point(this.x)` 1132 // initializing formal parameter, e.g. `Point(this.x)`
1135 if (element is ParameterElement && 1133 if (element is ParameterElement &&
1136 element.isInitializingFormal && 1134 element.isInitializingFormal &&
1137 element.isPrivate) { 1135 element.isPrivate) {
1138 /// Rename private names so they don't shadow the private field symbol. 1136 /// Rename private names so they don't shadow the private field symbol.
1139 /// The renamer would handle this, but it would prefer to rename the 1137 /// The renamer would handle this, but it would prefer to rename the
1140 /// temporary used for the private symbol. Instead rename the parameter. 1138 /// temporary used for the private symbol. Instead rename the parameter.
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 if (isStatic) { 1994 if (isStatic) {
1997 _loader.declareBeforeUse(member); 1995 _loader.declareBeforeUse(member);
1998 } 1996 }
1999 var name = _emitMemberName(memberId.name, 1997 var name = _emitMemberName(memberId.name,
2000 type: getStaticType(target), isStatic: isStatic); 1998 type: getStaticType(target), isStatic: isStatic);
2001 if (rules.isDynamicTarget(target)) { 1999 if (rules.isDynamicTarget(target)) {
2002 return js.call('dart.$DLOAD(#, #)', [_visit(target), name]); 2000 return js.call('dart.$DLOAD(#, #)', [_visit(target), name]);
2003 } 2001 }
2004 2002
2005 String code; 2003 String code;
2006 if (member != null && member is MethodElement) { 2004 if (member != null && member is MethodElement && !isStatic) {
2007 // Tear-off methods: explicitly bind it. 2005 // Tear-off methods: explicitly bind it.
2006 // TODO(leafp): Attach runtime types to these static tearoffs
2008 if (_requiresStaticDispatch(target, memberId.name)) { 2007 if (_requiresStaticDispatch(target, memberId.name)) {
2009 return js.call('dart.#.bind(#)', [name, _visit(target)]); 2008 return js.call('dart.#.bind(#)', [name, _visit(target)]);
2010 } 2009 }
2011 if (isStateless(target, target)) {
2012 return js.call('#.#.bind(#)', [_visit(target), name, _visit(target)]);
2013 }
2014 code = 'dart.bind(#, #)'; 2010 code = 'dart.bind(#, #)';
2015 } else if (_requiresStaticDispatch(target, memberId.name)) { 2011 } else if (_requiresStaticDispatch(target, memberId.name)) {
2016 return js.call('dart.#(#)', [name, _visit(target)]); 2012 return js.call('dart.#(#)', [name, _visit(target)]);
2017 } else { 2013 } else {
2018 code = '#.#'; 2014 code = '#.#';
2019 } 2015 }
2020 2016
2021 return js.call(code, [_visit(target), name]); 2017 return js.call(code, [_visit(target), name]);
2022 } 2018 }
2023 2019
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
2580 2576
2581 /// A special kind of element created by the compiler, signifying a temporary 2577 /// A special kind of element created by the compiler, signifying a temporary
2582 /// variable. These objects use instance equality, and should be shared 2578 /// variable. These objects use instance equality, and should be shared
2583 /// everywhere in the tree where they are treated as the same variable. 2579 /// everywhere in the tree where they are treated as the same variable.
2584 class TemporaryVariableElement extends LocalVariableElementImpl { 2580 class TemporaryVariableElement extends LocalVariableElementImpl {
2585 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); 2581 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name);
2586 2582
2587 int get hashCode => identityHashCode(this); 2583 int get hashCode => identityHashCode(this);
2588 bool operator ==(Object other) => identical(this, other); 2584 bool operator ==(Object other) => identical(this, other);
2589 } 2585 }
OLDNEW
« no previous file with comments | « lib/runtime/dart_runtime.js ('k') | test/codegen/expect/functions.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698