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 '../js_emitter.dart' show | 7 import '../js_emitter.dart' show |
8 ClassStubGenerator, | 8 ClassStubGenerator, |
9 CodeEmitterTask, | 9 CodeEmitterTask, |
10 computeMixinClass, | 10 computeMixinClass, |
11 Emitter, | 11 Emitter, |
12 InterceptorStubGenerator, | 12 InterceptorStubGenerator, |
13 MainCallStubGenerator, | 13 MainCallStubGenerator, |
14 ParameterStubGenerator, | 14 ParameterStubGenerator, |
15 RuntimeTypeGenerator, | 15 RuntimeTypeGenerator, |
16 TypeTestProperties; | 16 TypeTestProperties; |
17 import '../model.dart'; | 17 import '../model.dart'; |
18 | 18 |
| 19 import '../../closure.dart' show |
| 20 ClosureFieldElement; |
19 import '../../common.dart'; | 21 import '../../common.dart'; |
20 import '../../common/names.dart' show | 22 import '../../common/names.dart' show |
21 Names; | 23 Names, |
| 24 Selectors; |
22 import '../../compiler.dart' show | 25 import '../../compiler.dart' show |
23 Compiler; | 26 Compiler; |
24 import '../../constants/values.dart' show | 27 import '../../constants/values.dart' show |
25 ConstantValue, | 28 ConstantValue, |
26 InterceptorConstantValue; | 29 InterceptorConstantValue; |
27 import '../../closure.dart' show | 30 import '../../core_types.dart' show |
28 ClosureFieldElement; | 31 CoreClasses; |
29 import '../../dart_types.dart' show | 32 import '../../dart_types.dart' show |
30 DartType; | 33 DartType; |
31 import '../../elements/elements.dart' show | 34 import '../../elements/elements.dart' show |
32 ClassElement, | 35 ClassElement, |
33 Element, | 36 Element, |
34 Elements, | 37 Elements, |
35 FieldElement, | 38 FieldElement, |
36 FunctionElement, | 39 FunctionElement, |
37 FunctionSignature, | 40 FunctionSignature, |
38 LibraryElement, | 41 LibraryElement, |
39 MethodElement, | 42 MethodElement, |
40 Name, | 43 Name, |
41 ParameterElement, | 44 ParameterElement, |
42 TypedefElement, | 45 TypedefElement, |
43 VariableElement; | 46 VariableElement; |
44 import '../../js/js.dart' as js; | 47 import '../../js/js.dart' as js; |
45 import '../../js_backend/js_backend.dart' show | 48 import '../../js_backend/js_backend.dart' show |
46 Namer, | 49 Namer, |
47 JavaScriptBackend, | 50 JavaScriptBackend, |
48 JavaScriptConstantCompiler, | 51 JavaScriptConstantCompiler, |
49 StringBackedName; | 52 StringBackedName; |
50 import '../../universe/call_structure.dart' show | |
51 CallStructure; | |
52 import '../../universe/selector.dart' show | 53 import '../../universe/selector.dart' show |
53 Selector; | 54 Selector; |
54 import '../../universe/universe.dart' show | 55 import '../../universe/universe.dart' show |
55 Universe, | 56 Universe, |
56 SelectorConstraints; | 57 SelectorConstraints; |
57 import '../../deferred_load.dart' show | 58 import '../../deferred_load.dart' show |
58 DeferredLoadTask, | 59 DeferredLoadTask, |
59 OutputUnit; | 60 OutputUnit; |
60 | 61 |
61 part 'collector.dart'; | 62 part 'collector.dart'; |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 List<Library> _buildLibraries(LibrariesMap librariesMap) { | 341 List<Library> _buildLibraries(LibrariesMap librariesMap) { |
341 List<Library> libraries = new List<Library>(librariesMap.length); | 342 List<Library> libraries = new List<Library>(librariesMap.length); |
342 int count = 0; | 343 int count = 0; |
343 librariesMap.forEach((LibraryElement library, List<Element> elements) { | 344 librariesMap.forEach((LibraryElement library, List<Element> elements) { |
344 libraries[count++] = _buildLibrary(library, elements); | 345 libraries[count++] = _buildLibrary(library, elements); |
345 }); | 346 }); |
346 return libraries; | 347 return libraries; |
347 } | 348 } |
348 | 349 |
349 void _addJsInteropStubs(LibrariesMap librariesMap) { | 350 void _addJsInteropStubs(LibrariesMap librariesMap) { |
350 if (_classes.containsKey(_compiler.objectClass)) { | 351 if (_classes.containsKey(_compiler.coreClasses.objectClass)) { |
351 var toStringInvocation = namer.invocationName(new Selector.call( | 352 var toStringInvocation = namer.invocationName(Selectors.toString_); |
352 new Name("toString", _compiler.objectClass.library), | |
353 CallStructure.NO_ARGS)); | |
354 // TODO(jacobr): register toString as used so that it is always accessible | 353 // TODO(jacobr): register toString as used so that it is always accessible |
355 // from JavaScript. | 354 // from JavaScript. |
356 _classes[_compiler.objectClass].callStubs.add(_buildStubMethod( | 355 _classes[_compiler.coreClasses.objectClass].callStubs.add( |
357 new StringBackedName("toString"), | 356 _buildStubMethod( |
358 js.js('function() { return this.#(this) }', toStringInvocation))); | 357 new StringBackedName("toString"), |
| 358 js.js('function() { return this.#(this) }', toStringInvocation))); |
359 } | 359 } |
360 | 360 |
361 // We add all members from classes marked with isJsInterop to the base | 361 // We add all members from classes marked with isJsInterop to the base |
362 // Interceptor class with implementations that directly call the | 362 // Interceptor class with implementations that directly call the |
363 // corresponding JavaScript member. We do not attempt to bind this when | 363 // corresponding JavaScript member. We do not attempt to bind this when |
364 // tearing off JavaScript methods as we cannot distinguish between calling | 364 // tearing off JavaScript methods as we cannot distinguish between calling |
365 // a regular getter that returns a JavaScript function and tearing off | 365 // a regular getter that returns a JavaScript function and tearing off |
366 // a method in the case where there exist multiple JavaScript classes | 366 // a method in the case where there exist multiple JavaScript classes |
367 // that conflict on whether the member is a getter or a method. | 367 // that conflict on whether the member is a getter or a method. |
368 var interceptorClass = _classes[backend.jsJavaScriptObjectClass]; | 368 var interceptorClass = _classes[backend.jsJavaScriptObjectClass]; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 }); | 521 }); |
522 } | 522 } |
523 } | 523 } |
524 } | 524 } |
525 | 525 |
526 List<StubMethod> typeVariableReaderStubs = | 526 List<StubMethod> typeVariableReaderStubs = |
527 runtimeTypeGenerator.generateTypeVariableReaderStubs(element); | 527 runtimeTypeGenerator.generateTypeVariableReaderStubs(element); |
528 | 528 |
529 List<StubMethod> noSuchMethodStubs = <StubMethod>[]; | 529 List<StubMethod> noSuchMethodStubs = <StubMethod>[]; |
530 | 530 |
531 if (backend.enabledNoSuchMethod && element == _compiler.objectClass) { | 531 if (backend.enabledNoSuchMethod && element.isObject) { |
532 Map<js.Name, Selector> selectors = | 532 Map<js.Name, Selector> selectors = |
533 classStubGenerator.computeSelectorsForNsmHandlers(); | 533 classStubGenerator.computeSelectorsForNsmHandlers(); |
534 selectors.forEach((js.Name name, Selector selector) { | 534 selectors.forEach((js.Name name, Selector selector) { |
535 // If the program contains `const Symbol` names we have to retain them. | 535 // If the program contains `const Symbol` names we have to retain them. |
536 String selectorName = selector.name; | 536 String selectorName = selector.name; |
537 if (selector.isSetter) selectorName = "$selectorName="; | 537 if (selector.isSetter) selectorName = "$selectorName="; |
538 if (backend.symbolsUsed.contains(selectorName)) { | 538 if (backend.symbolsUsed.contains(selectorName)) { |
539 _symbolsMap[name] = selectorName; | 539 _symbolsMap[name] = selectorName; |
540 } | 540 } |
541 noSuchMethodStubs | 541 noSuchMethodStubs |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 Constant constant = new Constant(name, holder, constantValue); | 961 Constant constant = new Constant(name, holder, constantValue); |
962 _constants[constantValue] = constant; | 962 _constants[constantValue] = constant; |
963 } | 963 } |
964 } | 964 } |
965 | 965 |
966 Holder _registerStaticStateHolder() { | 966 Holder _registerStaticStateHolder() { |
967 return _registry.registerHolder( | 967 return _registry.registerHolder( |
968 namer.staticStateHolder, isStaticStateHolder: true); | 968 namer.staticStateHolder, isStaticStateHolder: true); |
969 } | 969 } |
970 } | 970 } |
OLD | NEW |