| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 dart2js.js_emitter.program_builder; | 5 library dart2js.js_emitter.program_builder; |
| 6 | 6 |
| 7 import '../../closure.dart' show ClosureFieldElement; | 7 import '../../closure.dart' show ClosureFieldElement; |
| 8 import '../../common.dart'; | 8 import '../../common.dart'; |
| 9 import '../../common/names.dart' show Names, Selectors; | 9 import '../../common/names.dart' show Names, Selectors; |
| 10 import '../../compiler.dart' show Compiler; | 10 import '../../compiler.dart' show Compiler; |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 // tearing off JavaScript methods as we cannot distinguish between calling | 338 // tearing off JavaScript methods as we cannot distinguish between calling |
| 339 // a regular getter that returns a JavaScript function and tearing off | 339 // a regular getter that returns a JavaScript function and tearing off |
| 340 // a method in the case where there exist multiple JavaScript classes | 340 // a method in the case where there exist multiple JavaScript classes |
| 341 // that conflict on whether the member is a getter or a method. | 341 // that conflict on whether the member is a getter or a method. |
| 342 var interceptorClass = _classes[helpers.jsJavaScriptObjectClass]; | 342 var interceptorClass = _classes[helpers.jsJavaScriptObjectClass]; |
| 343 var stubNames = new Set<String>(); | 343 var stubNames = new Set<String>(); |
| 344 librariesMap.forEach((LibraryElement library, List<Element> elements) { | 344 librariesMap.forEach((LibraryElement library, List<Element> elements) { |
| 345 for (Element e in elements) { | 345 for (Element e in elements) { |
| 346 if (e is ClassElement && backend.isJsInterop(e)) { | 346 if (e is ClassElement && backend.isJsInterop(e)) { |
| 347 e.declaration.forEachMember((_, Element member) { | 347 e.declaration.forEachMember((_, Element member) { |
| 348 var jsName = |
| 349 backend.nativeData.getUnescapedJSInteropName(member.name); |
| 348 if (!member.isInstanceMember) return; | 350 if (!member.isInstanceMember) return; |
| 349 if (member.isGetter || member.isField || member.isFunction) { | 351 if (member.isGetter || member.isField || member.isFunction) { |
| 350 var selectors = | 352 var selectors = |
| 351 _compiler.codegenWorld.getterInvocationsByName(member.name); | 353 _compiler.codegenWorld.getterInvocationsByName(member.name); |
| 352 if (selectors != null && !selectors.isEmpty) { | 354 if (selectors != null && !selectors.isEmpty) { |
| 353 for (var selector in selectors.keys) { | 355 for (var selector in selectors.keys) { |
| 354 var stubName = namer.invocationName(selector); | 356 var stubName = namer.invocationName(selector); |
| 355 if (stubNames.add(stubName.key)) { | 357 if (stubNames.add(stubName.key)) { |
| 356 interceptorClass.callStubs.add(_buildStubMethod(stubName, | 358 interceptorClass.callStubs.add(_buildStubMethod(stubName, |
| 357 js.js('function(obj) { return obj.# }', [member.name]), | 359 js.js('function(obj) { return obj.# }', [jsName]), |
| 358 element: member)); | 360 element: member)); |
| 359 } | 361 } |
| 360 } | 362 } |
| 361 } | 363 } |
| 362 } | 364 } |
| 363 | 365 |
| 364 if (member.isSetter || (member.isField && !member.isConst)) { | 366 if (member.isSetter || (member.isField && !member.isConst)) { |
| 365 var selectors = | 367 var selectors = |
| 366 _compiler.codegenWorld.setterInvocationsByName(member.name); | 368 _compiler.codegenWorld.setterInvocationsByName(member.name); |
| 367 if (selectors != null && !selectors.isEmpty) { | 369 if (selectors != null && !selectors.isEmpty) { |
| 368 var stubName = namer.setterForElement(member); | 370 var stubName = namer.setterForElement(member); |
| 369 if (stubNames.add(stubName.key)) { | 371 if (stubNames.add(stubName.key)) { |
| 370 interceptorClass.callStubs.add(_buildStubMethod( | 372 interceptorClass.callStubs.add(_buildStubMethod(stubName, |
| 371 stubName, | 373 js.js('function(obj, v) { return obj.# = v }', [jsName]), |
| 372 js.js('function(obj, v) { return obj.# = v }', | |
| 373 [member.name]), | |
| 374 element: member)); | 374 element: member)); |
| 375 } | 375 } |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 | 378 |
| 379 // Generating stubs for direct calls and stubs for call-through | 379 // Generating stubs for direct calls and stubs for call-through |
| 380 // of getters that happen to be functions. | 380 // of getters that happen to be functions. |
| 381 bool isFunctionLike = false; | 381 bool isFunctionLike = false; |
| 382 FunctionType functionType = null; | 382 FunctionType functionType = null; |
| 383 | 383 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 // calls and call-throughs of getters so that calling a | 440 // calls and call-throughs of getters so that calling a |
| 441 // getter that returns a function behaves the same as calling | 441 // getter that returns a function behaves the same as calling |
| 442 // a method. This is helpful as many typed JavaScript APIs | 442 // a method. This is helpful as many typed JavaScript APIs |
| 443 // specify member functions with getters that return | 443 // specify member functions with getters that return |
| 444 // functions. The behavior of this solution matches JavaScript | 444 // functions. The behavior of this solution matches JavaScript |
| 445 // behavior implicitly binding this only when JavaScript | 445 // behavior implicitly binding this only when JavaScript |
| 446 // would. | 446 // would. |
| 447 interceptorClass.callStubs.add(_buildStubMethod( | 447 interceptorClass.callStubs.add(_buildStubMethod( |
| 448 stubName, | 448 stubName, |
| 449 js.js('function(receiver, #) { return receiver.#(#) }', | 449 js.js('function(receiver, #) { return receiver.#(#) }', |
| 450 [parameters, member.name, parameters]), | 450 [parameters, jsName, parameters]), |
| 451 element: member)); | 451 element: member)); |
| 452 } | 452 } |
| 453 } | 453 } |
| 454 } | 454 } |
| 455 }); | 455 }); |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 }); | 458 }); |
| 459 } | 459 } |
| 460 | 460 |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 Constant constant = new Constant(name, holder, constantValue); | 975 Constant constant = new Constant(name, holder, constantValue); |
| 976 _constants[constantValue] = constant; | 976 _constants[constantValue] = constant; |
| 977 } | 977 } |
| 978 } | 978 } |
| 979 | 979 |
| 980 Holder _registerStaticStateHolder() { | 980 Holder _registerStaticStateHolder() { |
| 981 return _registry.registerHolder(namer.staticStateHolder, | 981 return _registry.registerHolder(namer.staticStateHolder, |
| 982 isStaticStateHolder: true); | 982 isStaticStateHolder: true); |
| 983 } | 983 } |
| 984 } | 984 } |
| OLD | NEW |