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

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

Issue 11445005: Fix issue 7086: support call-through getter for interceptor classes. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/language/interceptor5_test.dart » ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of js_backend; 5 part of js_backend;
6 6
7 /** 7 /**
8 * A function element that represents a closure call. The signature is copied 8 * A function element that represents a closure call. The signature is copied
9 * from the given element. 9 * from the given element.
10 */ 10 */
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 /** 1297 /**
1298 * Documentation wanted -- johnniwinther 1298 * Documentation wanted -- johnniwinther
1299 * 1299 *
1300 * Invariant: [member] must be a declaration element. 1300 * Invariant: [member] must be a declaration element.
1301 */ 1301 */
1302 void emitCallStubForGetter(Element member, 1302 void emitCallStubForGetter(Element member,
1303 Set<Selector> selectors, 1303 Set<Selector> selectors,
1304 DefineMemberFunction defineInstanceMember) { 1304 DefineMemberFunction defineInstanceMember) {
1305 assert(invariant(member, member.isDeclaration)); 1305 assert(invariant(member, member.isDeclaration));
1306 LibraryElement memberLibrary = member.getLibrary(); 1306 LibraryElement memberLibrary = member.getLibrary();
1307 JavaScriptBackend backend = compiler.backend;
1308 // If the class is an interceptor class, the stub gets the
1309 // receiver explicitely and we need to pass it to the getter call.
1310 bool isInterceptorClass =
1311 backend.isInterceptorClass(member.getEnclosingClass());
1312 String extraArgument = isInterceptorClass ? 'receiver' : '';
1307 String getter; 1313 String getter;
1308 if (member.isGetter()) { 1314 if (member.isGetter()) {
1309 getter = "this.${namer.getterName(member.getLibrary(), member.name)}()"; 1315 String getterName = namer.getterName(member.getLibrary(), member.name);
1316 getter = "this.$getterName($extraArgument)";
1310 } else { 1317 } else {
1311 String name = member.isNative() 1318 String name = member.isNative()
1312 ? member.nativeName() 1319 ? member.nativeName()
1313 : namer.instanceFieldName(memberLibrary, member.name); 1320 : namer.instanceFieldName(memberLibrary, member.name);
1314 getter = "this.$name"; 1321 getter = "this.$name";
1315 } 1322 }
1323
1316 for (Selector selector in selectors) { 1324 for (Selector selector in selectors) {
1317 if (selector.applies(member, compiler)) { 1325 if (selector.applies(member, compiler)) {
1318 String invocationName = 1326 String invocationName =
1319 namer.instanceMethodInvocationName(memberLibrary, member.name, 1327 namer.instanceMethodInvocationName(memberLibrary, member.name,
1320 selector); 1328 selector);
1321 SourceString callName = Namer.CLOSURE_INVOCATION_NAME; 1329 SourceString callName = Namer.CLOSURE_INVOCATION_NAME;
1322 String closureCallName = 1330 String closureCallName =
1323 namer.instanceMethodInvocationName(memberLibrary, callName, 1331 namer.instanceMethodInvocationName(memberLibrary, callName,
1324 selector); 1332 selector);
1325 List<String> arguments = <String>[]; 1333 List<String> arguments = <String>[];
1326 for (int i = 0; i < selector.argumentCount; i++) { 1334 for (int i = 0; i < selector.argumentCount; i++) {
1327 arguments.add("arg$i"); 1335 arguments.add("arg$i");
1328 } 1336 }
1329 String joined = Strings.join(arguments, ", "); 1337 String joined = Strings.join(arguments, ", ");
1330 CodeBuffer getterBuffer = new CodeBuffer(); 1338 CodeBuffer getterBuffer = new CodeBuffer();
1339 getterBuffer.add("function(");
1340 if (isInterceptorClass) {
1341 getterBuffer.add(extraArgument);
1342 if (!arguments.isEmpty) {
1343 getterBuffer.add(', ');
1344 }
1345 }
1331 getterBuffer.add( 1346 getterBuffer.add(
1332 "function($joined) { return $getter.$closureCallName($joined); }"); 1347 "$joined) { return $getter.$closureCallName($joined); }");
1333 defineInstanceMember(invocationName, getterBuffer); 1348 defineInstanceMember(invocationName, getterBuffer);
1334 } 1349 }
1335 } 1350 }
1336 } 1351 }
1337 1352
1338 void emitStaticNonFinalFieldInitializations(CodeBuffer buffer) { 1353 void emitStaticNonFinalFieldInitializations(CodeBuffer buffer) {
1339 ConstantHandler handler = compiler.constantHandler; 1354 ConstantHandler handler = compiler.constantHandler;
1340 List<VariableElement> staticNonFinalFields = 1355 List<VariableElement> staticNonFinalFields =
1341 handler.getStaticNonFinalFieldsForEmission(); 1356 handler.getStaticNonFinalFieldsForEmission();
1342 for (Element element in staticNonFinalFields) { 1357 for (Element element in staticNonFinalFields) {
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1832 const String HOOKS_API_USAGE = """ 1847 const String HOOKS_API_USAGE = """
1833 // Generated by dart2js, the Dart to JavaScript compiler. 1848 // Generated by dart2js, the Dart to JavaScript compiler.
1834 // The code supports the following hooks: 1849 // The code supports the following hooks:
1835 // dartPrint(message) - if this function is defined it is called 1850 // dartPrint(message) - if this function is defined it is called
1836 // instead of the Dart [print] method. 1851 // instead of the Dart [print] method.
1837 // dartMainRunner(main) - if this function is defined, the Dart [main] 1852 // dartMainRunner(main) - if this function is defined, the Dart [main]
1838 // method will not be invoked directly. 1853 // method will not be invoked directly.
1839 // Instead, a closure that will invoke [main] is 1854 // Instead, a closure that will invoke [main] is
1840 // passed to [dartMainRunner]. 1855 // passed to [dartMainRunner].
1841 """; 1856 """;
OLDNEW
« no previous file with comments | « no previous file | tests/language/interceptor5_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698