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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
6 | 6 |
7 | 7 |
8 class OldEmitter implements Emitter { | 8 class OldEmitter implements Emitter { |
9 final Compiler compiler; | 9 final Compiler compiler; |
10 final CodeEmitterTask task; | 10 final CodeEmitterTask task; |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 // The full code that is written to each hunk part-file. | 37 // The full code that is written to each hunk part-file. |
38 Map<OutputUnit, CodeOutput> outputBuffers = new Map<OutputUnit, CodeOutput>(); | 38 Map<OutputUnit, CodeOutput> outputBuffers = new Map<OutputUnit, CodeOutput>(); |
39 | 39 |
40 String classesCollector; | 40 String classesCollector; |
41 Set<ClassElement> get neededClasses => task.neededClasses; | 41 Set<ClassElement> get neededClasses => task.neededClasses; |
42 Map<OutputUnit, List<ClassElement>> get outputClassLists | 42 Map<OutputUnit, List<ClassElement>> get outputClassLists |
43 => task.outputClassLists; | 43 => task.outputClassLists; |
44 Map<OutputUnit, List<ConstantValue>> get outputConstantLists | 44 Map<OutputUnit, List<ConstantValue>> get outputConstantLists |
45 => task.outputConstantLists; | 45 => task.outputConstantLists; |
46 final Map<String, String> mangledFieldNames = <String, String>{}; | 46 final Map<jsAst.Name, String> mangledFieldNames = |
47 final Map<String, String> mangledGlobalFieldNames = <String, String>{}; | 47 new HashMap<jsAst.Name, String>(); |
48 final Set<String> recordedMangledNames = new Set<String>(); | 48 final Map<jsAst.Name, String> mangledGlobalFieldNames = |
| 49 new HashMap<jsAst.Name, String>(); |
| 50 final Set<jsAst.Name> recordedMangledNames = new Set<jsAst.Name>(); |
49 | 51 |
50 List<TypedefElement> get typedefsNeededForReflection => | 52 List<TypedefElement> get typedefsNeededForReflection => |
51 task.typedefsNeededForReflection; | 53 task.typedefsNeededForReflection; |
52 | 54 |
53 JavaScriptBackend get backend => compiler.backend; | 55 JavaScriptBackend get backend => compiler.backend; |
54 TypeVariableHandler get typeVariableHandler => backend.typeVariableHandler; | 56 TypeVariableHandler get typeVariableHandler => backend.typeVariableHandler; |
55 | 57 |
56 String get _ => space; | 58 String get _ => space; |
57 String get space => compiler.enableMinification ? "" : " "; | 59 String get space => compiler.enableMinification ? "" : " "; |
58 String get n => compiler.enableMinification ? "" : "\n"; | 60 String get n => compiler.enableMinification ? "" : "\n"; |
(...skipping 27 matching lines...) Expand all Loading... |
86 | 88 |
87 final bool generateSourceMap; | 89 final bool generateSourceMap; |
88 | 90 |
89 OldEmitter(Compiler compiler, Namer namer, this.generateSourceMap, this.task) | 91 OldEmitter(Compiler compiler, Namer namer, this.generateSourceMap, this.task) |
90 : this.compiler = compiler, | 92 : this.compiler = compiler, |
91 this.namer = namer, | 93 this.namer = namer, |
92 cachedEmittedConstants = compiler.cacheStrategy.newSet(), | 94 cachedEmittedConstants = compiler.cacheStrategy.newSet(), |
93 cachedClassBuilders = compiler.cacheStrategy.newMap(), | 95 cachedClassBuilders = compiler.cacheStrategy.newMap(), |
94 cachedElements = compiler.cacheStrategy.newSet() { | 96 cachedElements = compiler.cacheStrategy.newSet() { |
95 constantEmitter = new ConstantEmitter( | 97 constantEmitter = new ConstantEmitter( |
96 compiler, namer, this.constantReference, makeConstantListTemplate); | 98 compiler, namer, this.constantReference, constantListGenerator); |
97 containerBuilder.emitter = this; | 99 containerBuilder.emitter = this; |
98 classEmitter.emitter = this; | 100 classEmitter.emitter = this; |
99 nsmEmitter.emitter = this; | 101 nsmEmitter.emitter = this; |
100 interceptorEmitter.emitter = this; | 102 interceptorEmitter.emitter = this; |
101 } | 103 } |
102 | 104 |
103 List<jsAst.Node> cspPrecompiledFunctionFor(OutputUnit outputUnit) { | 105 List<jsAst.Node> cspPrecompiledFunctionFor(OutputUnit outputUnit) { |
104 return _cspPrecompiledFunctions.putIfAbsent( | 106 return _cspPrecompiledFunctions.putIfAbsent( |
105 outputUnit, | 107 outputUnit, |
106 () => new List<jsAst.Node>()); | 108 () => new List<jsAst.Node>()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 if (a.isInterceptor != b.isInterceptor) { | 147 if (a.isInterceptor != b.isInterceptor) { |
146 return a.isInterceptor ? -1 : 1; | 148 return a.isInterceptor ? -1 : 1; |
147 } | 149 } |
148 | 150 |
149 // Sorting by the long name clusters constants with the same constructor | 151 // Sorting by the long name clusters constants with the same constructor |
150 // which compresses a tiny bit better. | 152 // which compresses a tiny bit better. |
151 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b)); | 153 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b)); |
152 if (r != 0) return r; | 154 if (r != 0) return r; |
153 // Resolve collisions in the long name by using the constant name (i.e. JS | 155 // Resolve collisions in the long name by using the constant name (i.e. JS |
154 // name) which is unique. | 156 // name) which is unique. |
155 return namer.constantName(a).compareTo(namer.constantName(b)); | 157 // TODO(herhut): Find a better way to resolve collisions. |
| 158 return namer.constantName(a).hashCode.compareTo( |
| 159 namer.constantName(b).hashCode); |
156 } | 160 } |
157 | 161 |
158 @override | 162 @override |
159 jsAst.Expression constantReference(ConstantValue value) { | 163 jsAst.Expression constantReference(ConstantValue value) { |
160 if (value.isFunction) { | 164 if (value.isFunction) { |
161 FunctionConstantValue functionConstant = value; | 165 FunctionConstantValue functionConstant = value; |
162 return isolateStaticClosureAccess(functionConstant.element); | 166 return isolateStaticClosureAccess(functionConstant.element); |
163 } | 167 } |
164 | 168 |
165 // We are only interested in the "isInlined" part, but it does not hurt to | 169 // We are only interested in the "isInlined" part, but it does not hurt to |
(...skipping 14 matching lines...) Expand all Loading... |
180 String get finishIsolateConstructorName | 184 String get finishIsolateConstructorName |
181 => '${namer.isolateName}.\$finishIsolateConstructor'; | 185 => '${namer.isolateName}.\$finishIsolateConstructor'; |
182 String get isolatePropertiesName | 186 String get isolatePropertiesName |
183 => '${namer.isolateName}.${namer.isolatePropertiesName}'; | 187 => '${namer.isolateName}.${namer.isolatePropertiesName}'; |
184 String get lazyInitializerProperty | 188 String get lazyInitializerProperty |
185 => r'$lazy'; | 189 => r'$lazy'; |
186 String get lazyInitializerName | 190 String get lazyInitializerName |
187 => '${namer.isolateName}.${lazyInitializerProperty}'; | 191 => '${namer.isolateName}.${lazyInitializerProperty}'; |
188 String get initName => 'init'; | 192 String get initName => 'init'; |
189 | 193 |
190 String get makeConstListProperty => namer.internalGlobal('makeConstantList'); | 194 jsAst.Name get makeConstListProperty |
| 195 => namer.internalGlobal('makeConstantList'); |
191 | 196 |
192 /// The name of the property that contains all field names. | 197 /// The name of the property that contains all field names. |
193 /// | 198 /// |
194 /// This property is added to constructors when isolate support is enabled. | 199 /// This property is added to constructors when isolate support is enabled. |
195 static const String FIELD_NAMES_PROPERTY_NAME = r"$__fields__"; | 200 static const String FIELD_NAMES_PROPERTY_NAME = r"$__fields__"; |
196 | 201 |
197 /// For deferred loading we communicate the initializers via this global var. | 202 /// For deferred loading we communicate the initializers via this global var. |
198 final String deferredInitializers = r"$dart_deferred_initializers$"; | 203 final String deferredInitializers = r"$dart_deferred_initializers$"; |
199 | 204 |
200 /// Contains the global state that is needed to initialize and load a | 205 /// Contains the global state that is needed to initialize and load a |
201 /// deferred library. | 206 /// deferred library. |
202 String get globalsHolder => namer.internalGlobal("globalsHolder"); | 207 jsAst.Name get globalsHolder => namer.internalGlobal("globalsHolder"); |
203 | 208 |
204 @override | 209 @override |
205 jsAst.Expression generateEmbeddedGlobalAccess(String global) { | 210 jsAst.Expression generateEmbeddedGlobalAccess(String global) { |
206 return js(generateEmbeddedGlobalAccessString(global)); | 211 return js(generateEmbeddedGlobalAccessString(global)); |
207 } | 212 } |
208 | 213 |
209 String generateEmbeddedGlobalAccessString(String global) { | 214 String generateEmbeddedGlobalAccessString(String global) { |
210 // TODO(floitsch): don't use 'init' as global embedder storage. | 215 // TODO(floitsch): don't use 'init' as global embedder storage. |
211 return '$initName.$global'; | 216 return '$initName.$global'; |
212 } | 217 } |
213 | 218 |
214 jsAst.PropertyAccess globalPropertyAccess(Element element) { | 219 jsAst.PropertyAccess globalPropertyAccess(Element element) { |
215 String name = namer.globalPropertyName(element); | 220 jsAst.Name name = namer.globalPropertyName(element); |
216 jsAst.PropertyAccess pa = new jsAst.PropertyAccess.field( | 221 jsAst.PropertyAccess pa = new jsAst.PropertyAccess( |
217 new jsAst.VariableUse(namer.globalObjectFor(element)), | 222 new jsAst.VariableUse(namer.globalObjectFor(element)), |
218 name); | 223 name); |
219 return pa; | 224 return pa; |
220 } | 225 } |
221 | 226 |
222 @override | 227 @override |
223 jsAst.Expression isolateLazyInitializerAccess(FieldElement element) { | 228 jsAst.Expression isolateLazyInitializerAccess(FieldElement element) { |
224 return jsAst.js('#.#', [namer.globalObjectFor(element), | 229 return jsAst.js('#.#', [namer.globalObjectFor(element), |
225 namer.lazyInitializerName(element)]); | 230 namer.lazyInitializerName(element)]); |
226 } | 231 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 return backend.rti.representationGenerator | 291 return backend.rti.representationGenerator |
287 .templateForCreateFunctionType; | 292 .templateForCreateFunctionType; |
288 | 293 |
289 case JsBuiltin.isSubtype: | 294 case JsBuiltin.isSubtype: |
290 // TODO(floitsch): move this closer to where is-check properties are | 295 // TODO(floitsch): move this closer to where is-check properties are |
291 // built. | 296 // built. |
292 String isPrefix = namer.operatorIsPrefix; | 297 String isPrefix = namer.operatorIsPrefix; |
293 return jsAst.js.expressionTemplateFor( | 298 return jsAst.js.expressionTemplateFor( |
294 "('$isPrefix' + #) in #.prototype"); | 299 "('$isPrefix' + #) in #.prototype"); |
295 | 300 |
296 case JsBuiltin.isFunctionTypeRti: | 301 case JsBuiltin.isGivenTypeRti: |
297 String functionClassName = | 302 return jsAst.js.expressionTemplateFor('#.$typeNameProperty === #'); |
298 backend.namer.runtimeTypeName(compiler.functionClass); | |
299 return jsAst.js.expressionTemplateFor( | |
300 '#.$typeNameProperty === "$functionClassName"'); | |
301 | |
302 case JsBuiltin.isDartObjectTypeRti: | |
303 String objectClassName = | |
304 backend.namer.runtimeTypeName(compiler.objectClass); | |
305 return jsAst.js.expressionTemplateFor( | |
306 '#.$typeNameProperty === "$objectClassName"'); | |
307 | |
308 case JsBuiltin.isNullTypeRti: | |
309 String nullClassName = | |
310 backend.namer.runtimeTypeName(compiler.nullClass); | |
311 return jsAst.js.expressionTemplateFor( | |
312 '#.$typeNameProperty === "$nullClassName"'); | |
313 | 303 |
314 case JsBuiltin.getMetadata: | 304 case JsBuiltin.getMetadata: |
315 String metadataAccess = | 305 String metadataAccess = |
316 generateEmbeddedGlobalAccessString(embeddedNames.METADATA); | 306 generateEmbeddedGlobalAccessString(embeddedNames.METADATA); |
317 return jsAst.js.expressionTemplateFor("$metadataAccess[#]"); | 307 return jsAst.js.expressionTemplateFor("$metadataAccess[#]"); |
318 | 308 |
319 case JsBuiltin.getType: | 309 case JsBuiltin.getType: |
320 String typesAccess = | 310 String typesAccess = |
321 generateEmbeddedGlobalAccessString(embeddedNames.TYPES); | 311 generateEmbeddedGlobalAccessString(embeddedNames.TYPES); |
322 return jsAst.js.expressionTemplateFor("$typesAccess[#]"); | 312 return jsAst.js.expressionTemplateFor("$typesAccess[#]"); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 /// The reflection name of a getter 'foo' is 'foo'. | 354 /// The reflection name of a getter 'foo' is 'foo'. |
365 /// The reflection name of a setter 'foo' is 'foo='. | 355 /// The reflection name of a setter 'foo' is 'foo='. |
366 /// The reflection name of a method 'foo' is 'foo:N:M:O', where N is the | 356 /// The reflection name of a method 'foo' is 'foo:N:M:O', where N is the |
367 /// number of required arguments, M is the number of optional arguments, and | 357 /// number of required arguments, M is the number of optional arguments, and |
368 /// O is the named arguments. | 358 /// O is the named arguments. |
369 /// The reflection name of a constructor is similar to a regular method but | 359 /// The reflection name of a constructor is similar to a regular method but |
370 /// starts with 'new '. | 360 /// starts with 'new '. |
371 /// The reflection name of class 'C' is 'C'. | 361 /// The reflection name of class 'C' is 'C'. |
372 /// An anonymous mixin application has no reflection name. | 362 /// An anonymous mixin application has no reflection name. |
373 /// This is used by js_mirrors.dart. | 363 /// This is used by js_mirrors.dart. |
374 String getReflectionName(elementOrSelector, String mangledName) { | 364 String getReflectionName(elementOrSelector, jsAst.Name mangledName) { |
375 String name = elementOrSelector.name; | 365 String name = elementOrSelector.name; |
376 if (backend.shouldRetainName(name) || | 366 if (backend.shouldRetainName(name) || |
377 elementOrSelector is Element && | 367 elementOrSelector is Element && |
378 // Make sure to retain names of unnamed constructors, and | 368 // Make sure to retain names of unnamed constructors, and |
379 // for common native types. | 369 // for common native types. |
380 ((name == '' && | 370 ((name == '' && |
381 backend.isAccessibleByReflection(elementOrSelector)) || | 371 backend.isAccessibleByReflection(elementOrSelector)) || |
382 _isNativeTypeNeedingReflectionName(elementOrSelector))) { | 372 _isNativeTypeNeedingReflectionName(elementOrSelector))) { |
383 | 373 |
384 // TODO(ahe): Enable the next line when I can tell the difference between | 374 // TODO(ahe): Enable the next line when I can tell the difference between |
385 // an instance method and a global. They may have the same mangled name. | 375 // an instance method and a global. They may have the same mangled name. |
386 // if (recordedMangledNames.contains(mangledName)) return null; | 376 // if (recordedMangledNames.contains(mangledName)) return null; |
387 recordedMangledNames.add(mangledName); | 377 recordedMangledNames.add(mangledName); |
388 return getReflectionNameInternal(elementOrSelector, mangledName); | 378 return getReflectionNameInternal(elementOrSelector, mangledName); |
389 } | 379 } |
390 return null; | 380 return null; |
391 } | 381 } |
392 | 382 |
393 String getReflectionNameInternal(elementOrSelector, String mangledName) { | 383 String getReflectionNameInternal(elementOrSelector, |
| 384 jsAst.Name mangledName) { |
394 String name = namer.privateName(elementOrSelector.memberName); | 385 String name = namer.privateName(elementOrSelector.memberName); |
395 if (elementOrSelector.isGetter) return name; | 386 if (elementOrSelector.isGetter) return name; |
396 if (elementOrSelector.isSetter) { | 387 if (elementOrSelector.isSetter) { |
397 if (!mangledName.startsWith(namer.setterPrefix)) return '$name='; | 388 if (mangledName is! SetterName) return '$name='; |
398 String base = mangledName.substring(namer.setterPrefix.length); | 389 SetterName setterName = mangledName; |
399 String getter = '${namer.getterPrefix}$base'; | 390 jsAst.Name base = setterName.base; |
| 391 jsAst.Name getter = namer.deriveGetterName(base); |
400 mangledFieldNames.putIfAbsent(getter, () => name); | 392 mangledFieldNames.putIfAbsent(getter, () => name); |
401 assert(mangledFieldNames[getter] == name); | 393 assert(mangledFieldNames[getter] == name); |
402 recordedMangledNames.add(getter); | 394 recordedMangledNames.add(getter); |
403 // TODO(karlklose,ahe): we do not actually need to store information | 395 // TODO(karlklose,ahe): we do not actually need to store information |
404 // about the name of this setter in the output, but it is needed for | 396 // about the name of this setter in the output, but it is needed for |
405 // marking the function as invokable by reflection. | 397 // marking the function as invokable by reflection. |
406 return '$name='; | 398 return '$name='; |
407 } | 399 } |
408 if (elementOrSelector is Element && elementOrSelector.isClosure) { | 400 if (elementOrSelector is Element && elementOrSelector.isClosure) { |
409 // Closures are synthesized and their name might conflict with existing | 401 // Closures are synthesized and their name might conflict with existing |
410 // globals. Assign an illegal name, and make sure they don't clash | 402 // globals. Assign an illegal name, and make sure they don't clash |
411 // with each other. | 403 // with each other. |
412 return " $mangledName"; | 404 return " $name"; |
413 } | 405 } |
414 if (elementOrSelector is Selector | 406 if (elementOrSelector is Selector |
415 || elementOrSelector.isFunction | 407 || elementOrSelector.isFunction |
416 || elementOrSelector.isConstructor) { | 408 || elementOrSelector.isConstructor) { |
417 int positionalParameterCount; | 409 int positionalParameterCount; |
418 String namedArguments = ''; | 410 String namedArguments = ''; |
419 bool isConstructor = false; | 411 bool isConstructor = false; |
420 if (elementOrSelector is Selector) { | 412 if (elementOrSelector is Selector) { |
421 CallStructure callStructure = elementOrSelector.callStructure; | 413 CallStructure callStructure = elementOrSelector.callStructure; |
422 positionalParameterCount = callStructure.positionalArgumentCount; | 414 positionalParameterCount = callStructure.positionalArgumentCount; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 } | 486 } |
495 } | 487 } |
496 | 488 |
497 void assembleClass(Class cls, ClassBuilder enclosingBuilder, | 489 void assembleClass(Class cls, ClassBuilder enclosingBuilder, |
498 Fragment fragment) { | 490 Fragment fragment) { |
499 ClassElement classElement = cls.element; | 491 ClassElement classElement = cls.element; |
500 compiler.withCurrentElement(classElement, () { | 492 compiler.withCurrentElement(classElement, () { |
501 if (compiler.hasIncrementalSupport) { | 493 if (compiler.hasIncrementalSupport) { |
502 ClassBuilder cachedBuilder = | 494 ClassBuilder cachedBuilder = |
503 cachedClassBuilders.putIfAbsent(classElement, () { | 495 cachedClassBuilders.putIfAbsent(classElement, () { |
504 ClassBuilder builder = new ClassBuilder(classElement, namer); | 496 ClassBuilder builder = |
| 497 new ClassBuilder.forClass(classElement, namer); |
505 classEmitter.emitClass(cls, builder, fragment); | 498 classEmitter.emitClass(cls, builder, fragment); |
506 return builder; | 499 return builder; |
507 }); | 500 }); |
508 invariant(classElement, cachedBuilder.fields.isEmpty); | 501 invariant(classElement, cachedBuilder.fields.isEmpty); |
509 invariant(classElement, cachedBuilder.superName == null); | 502 invariant(classElement, cachedBuilder.superName == null); |
510 invariant(classElement, cachedBuilder.functionType == null); | 503 invariant(classElement, cachedBuilder.functionType == null); |
511 invariant(classElement, cachedBuilder.fieldMetadata == null); | 504 invariant(classElement, cachedBuilder.fieldMetadata == null); |
512 enclosingBuilder.properties.addAll(cachedBuilder.properties); | 505 enclosingBuilder.properties.addAll(cachedBuilder.properties); |
513 } else { | 506 } else { |
514 classEmitter.emitClass(cls, enclosingBuilder, fragment); | 507 classEmitter.emitClass(cls, enclosingBuilder, fragment); |
515 } | 508 } |
516 }); | 509 }); |
517 } | 510 } |
518 | 511 |
519 void assembleStaticFunctions(Iterable<Method> staticFunctions, | 512 void assembleStaticFunctions(Iterable<Method> staticFunctions, |
520 Fragment fragment) { | 513 Fragment fragment) { |
521 if (staticFunctions == null) return; | 514 if (staticFunctions == null) return; |
522 | 515 |
523 for (Method method in staticFunctions) { | 516 for (Method method in staticFunctions) { |
524 Element element = method.element; | 517 Element element = method.element; |
525 // We need to filter out null-elements for the interceptors. | 518 // We need to filter out null-elements for the interceptors. |
526 // TODO(floitsch): use the precomputed interceptors here. | 519 // TODO(floitsch): use the precomputed interceptors here. |
527 if (element == null) continue; | 520 if (element == null) continue; |
528 ClassBuilder builder = new ClassBuilder(element, namer); | 521 ClassBuilder builder = new ClassBuilder.forStatics(element, namer); |
529 containerBuilder.addMemberMethod(method, builder); | 522 containerBuilder.addMemberMethod(method, builder); |
530 getElementDescriptor(element, fragment).properties | 523 getElementDescriptor(element, fragment).properties |
531 .addAll(builder.properties); | 524 .addAll(builder.properties); |
532 } | 525 } |
533 } | 526 } |
534 | 527 |
535 jsAst.Statement buildStaticNonFinalFieldInitializations( | 528 jsAst.Statement buildStaticNonFinalFieldInitializations( |
536 OutputUnit outputUnit) { | 529 OutputUnit outputUnit) { |
537 jsAst.Statement buildInitialization(Element element, | 530 jsAst.Statement buildInitialization(Element element, |
538 jsAst.Expression initialValue) { | 531 jsAst.Expression initialValue) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 | 611 |
619 List<jsAst.Expression> buildLaziesInfo(List<VariableElement> lazies) { | 612 List<jsAst.Expression> buildLaziesInfo(List<VariableElement> lazies) { |
620 List<jsAst.Expression> laziesInfo = <jsAst.Expression>[]; | 613 List<jsAst.Expression> laziesInfo = <jsAst.Expression>[]; |
621 for (VariableElement element in Elements.sortedByPosition(lazies)) { | 614 for (VariableElement element in Elements.sortedByPosition(lazies)) { |
622 jsAst.Expression code = backend.generatedCode[element]; | 615 jsAst.Expression code = backend.generatedCode[element]; |
623 // The code is null if we ended up not needing the lazily | 616 // The code is null if we ended up not needing the lazily |
624 // initialized field after all because of constant folding | 617 // initialized field after all because of constant folding |
625 // before code generation. | 618 // before code generation. |
626 if (code == null) continue; | 619 if (code == null) continue; |
627 if (compiler.enableMinification) { | 620 if (compiler.enableMinification) { |
628 laziesInfo.addAll([js.string(namer.globalPropertyName(element)), | 621 laziesInfo.addAll([js.quoteName(namer.globalPropertyName(element)), |
629 js.string(namer.lazyInitializerName(element)), | 622 js.quoteName(namer.lazyInitializerName(element)), |
630 code]); | 623 code]); |
631 } else { | 624 } else { |
632 laziesInfo.addAll([js.string(namer.globalPropertyName(element)), | 625 laziesInfo.addAll([js.quoteName(namer.globalPropertyName(element)), |
633 js.string(namer.lazyInitializerName(element)), | 626 js.quoteName(namer.lazyInitializerName(element)), |
634 code, | 627 code, |
635 js.string(element.name)]); | 628 js.string(element.name)]); |
636 } | 629 } |
637 } | 630 } |
638 return laziesInfo; | 631 return laziesInfo; |
639 } | 632 } |
640 | 633 |
641 jsAst.Expression buildLazilyInitializedStaticField( | 634 jsAst.Expression buildLazilyInitializedStaticField( |
642 VariableElement element, {String isolateProperties}) { | 635 VariableElement element, {String isolateProperties}) { |
643 jsAst.Expression code = backend.generatedCode[element]; | 636 jsAst.Expression code = backend.generatedCode[element]; |
644 // The code is null if we ended up not needing the lazily | 637 // The code is null if we ended up not needing the lazily |
645 // initialized field after all because of constant folding | 638 // initialized field after all because of constant folding |
646 // before code generation. | 639 // before code generation. |
647 if (code == null) return null; | 640 if (code == null) return null; |
648 // The code only computes the initial value. We build the lazy-check | 641 // The code only computes the initial value. We build the lazy-check |
649 // here: | 642 // here: |
650 // lazyInitializer(fieldName, getterName, initial, name, prototype); | 643 // lazyInitializer(fieldName, getterName, initial, name, prototype); |
651 // The name is used for error reporting. The 'initial' must be a | 644 // The name is used for error reporting. The 'initial' must be a |
652 // closure that constructs the initial value. | 645 // closure that constructs the initial value. |
653 if (isolateProperties != null) { | 646 if (isolateProperties != null) { |
654 // This is currently only used in incremental compilation to patch | 647 // This is currently only used in incremental compilation to patch |
655 // in new lazy values. | 648 // in new lazy values. |
656 return js('#(#,#,#,#,#)', | 649 return js('#(#,#,#,#,#)', |
657 [js(lazyInitializerName), | 650 [js(lazyInitializerName), |
658 js.string(namer.globalPropertyName(element)), | 651 js.quoteName(namer.globalPropertyName(element)), |
659 js.string(namer.lazyInitializerName(element)), | 652 js.quoteName(namer.lazyInitializerName(element)), |
660 code, | 653 code, |
661 js.string(element.name), | 654 js.string(element.name), |
662 isolateProperties]); | 655 isolateProperties]); |
663 } | 656 } |
664 | 657 |
665 if (compiler.enableMinification) { | 658 if (compiler.enableMinification) { |
666 return js('#(#,#,#)', | 659 return js('#(#,#,#)', |
667 [js(lazyInitializerName), | 660 [js(lazyInitializerName), |
668 js.string(namer.globalPropertyName(element)), | 661 js.quoteName(namer.globalPropertyName(element)), |
669 js.string(namer.lazyInitializerName(element)), | 662 js.quoteName(namer.lazyInitializerName(element)), |
670 code]); | 663 code]); |
671 } else { | 664 } else { |
672 return js('#(#,#,#,#)', | 665 return js('#(#,#,#,#)', |
673 [js(lazyInitializerName), | 666 [js(lazyInitializerName), |
674 js.string(namer.globalPropertyName(element)), | 667 js.quoteName(namer.globalPropertyName(element)), |
675 js.string(namer.lazyInitializerName(element)), | 668 js.quoteName(namer.lazyInitializerName(element)), |
676 code, | 669 code, |
677 js.string(element.name)]); | 670 js.string(element.name)]); |
678 } | 671 } |
679 } | 672 } |
680 | 673 |
681 jsAst.Statement buildMetadata(Program program, OutputUnit outputUnit) { | 674 jsAst.Statement buildMetadata(Program program, OutputUnit outputUnit) { |
682 List<jsAst.Statement> parts = <jsAst.Statement>[]; | 675 List<jsAst.Statement> parts = <jsAst.Statement>[]; |
683 | 676 |
684 jsAst.Expression types = program.metadataTypesForOutputUnit(outputUnit); | 677 jsAst.Expression types = program.metadataTypesForOutputUnit(outputUnit); |
685 | 678 |
(...skipping 27 matching lines...) Expand all Loading... |
713 if (cachedEmittedConstants.contains(constantValue)) continue; | 706 if (cachedEmittedConstants.contains(constantValue)) continue; |
714 cachedEmittedConstants.add(constantValue); | 707 cachedEmittedConstants.add(constantValue); |
715 } | 708 } |
716 parts.add(buildConstantInitializer(constantValue)); | 709 parts.add(buildConstantInitializer(constantValue)); |
717 } | 710 } |
718 | 711 |
719 return new jsAst.Block(parts); | 712 return new jsAst.Block(parts); |
720 } | 713 } |
721 | 714 |
722 jsAst.Statement buildConstantInitializer(ConstantValue constant) { | 715 jsAst.Statement buildConstantInitializer(ConstantValue constant) { |
723 String name = namer.constantName(constant); | 716 jsAst.Name name = namer.constantName(constant); |
724 return js.statement('#.# = #', | 717 return js.statement('#.# = #', |
725 [namer.globalObjectForConstant(constant), name, | 718 [namer.globalObjectForConstant(constant), name, |
726 constantInitializerExpression(constant)]); | 719 constantInitializerExpression(constant)]); |
727 } | 720 } |
728 | 721 |
729 jsAst.Template get makeConstantListTemplate { | 722 jsAst.Expression constantListGenerator(jsAst.Expression array) { |
730 // TODO(floitsch): there is no harm in caching the template. | 723 // TODO(floitsch): there is no harm in caching the template. |
731 return jsAst.js.uncachedExpressionTemplate( | 724 return js('${namer.isolateName}.#(#)', [makeConstListProperty, array]); |
732 '${namer.isolateName}.$makeConstListProperty(#)'); | |
733 } | 725 } |
734 | 726 |
735 jsAst.Statement buildMakeConstantList() { | 727 jsAst.Statement buildMakeConstantList() { |
736 if (task.outputContainsConstantList) { | 728 if (task.outputContainsConstantList) { |
737 return js.statement(r''' | 729 return js.statement(r''' |
738 // Functions are stored in the hidden class and not as properties in | 730 // Functions are stored in the hidden class and not as properties in |
739 // the object. We never actually look at the value, but only want | 731 // the object. We never actually look at the value, but only want |
740 // to know if the property exists. | 732 // to know if the property exists. |
741 #.# = function (list) { | 733 #.# = function (list) { |
742 list.immutable$list = Array; | 734 list.immutable$list = Array; |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 ..add(js('#', namer.globalObjectFor(library))) | 1009 ..add(js('#', namer.globalObjectFor(library))) |
1018 ..add(initializer); | 1010 ..add(initializer); |
1019 if (library == compiler.mainApp) { | 1011 if (library == compiler.mainApp) { |
1020 parts.add(js.number(1)); | 1012 parts.add(js.number(1)); |
1021 } | 1013 } |
1022 | 1014 |
1023 return new jsAst.ArrayInitializer(parts); | 1015 return new jsAst.ArrayInitializer(parts); |
1024 } | 1016 } |
1025 | 1017 |
1026 void assemblePrecompiledConstructor(OutputUnit outputUnit, | 1018 void assemblePrecompiledConstructor(OutputUnit outputUnit, |
1027 String constructorName, | 1019 jsAst.Name constructorName, |
1028 jsAst.Expression constructorAst, | 1020 jsAst.Expression constructorAst, |
1029 List<String> fields) { | 1021 List<String> fields) { |
1030 cspPrecompiledFunctionFor(outputUnit).add( | 1022 cspPrecompiledFunctionFor(outputUnit).add( |
1031 new jsAst.FunctionDeclaration( | 1023 new jsAst.FunctionDeclaration(constructorName, constructorAst)); |
1032 new jsAst.VariableDeclaration(constructorName), constructorAst)); | |
1033 | 1024 |
1034 String fieldNamesProperty = FIELD_NAMES_PROPERTY_NAME; | 1025 String fieldNamesProperty = FIELD_NAMES_PROPERTY_NAME; |
1035 bool hasIsolateSupport = compiler.hasIsolateSupport; | 1026 bool hasIsolateSupport = compiler.hasIsolateSupport; |
1036 jsAst.Node fieldNamesArray = | 1027 jsAst.Node fieldNamesArray = |
1037 hasIsolateSupport ? js.stringArray(fields) : new jsAst.LiteralNull(); | 1028 hasIsolateSupport ? js.stringArray(fields) : new jsAst.LiteralNull(); |
1038 | 1029 |
1039 cspPrecompiledFunctionFor(outputUnit).add(js.statement(r''' | 1030 cspPrecompiledFunctionFor(outputUnit).add(js.statement(r''' |
1040 { | 1031 { |
1041 #constructorName.#typeNameProperty = #constructorNameString; | 1032 #constructorName.#typeNameProperty = #constructorNameString; |
1042 // IE does not have a name property. | 1033 // IE does not have a name property. |
1043 if (!("name" in #constructorName)) | 1034 if (!("name" in #constructorName)) |
1044 #constructorName.name = #constructorNameString; | 1035 #constructorName.name = #constructorNameString; |
1045 $desc = $collectedClasses$.#constructorName[1]; | 1036 $desc = $collectedClasses$.#constructorName[1]; |
1046 #constructorName.prototype = $desc; | 1037 #constructorName.prototype = $desc; |
1047 ''' /* next string is not a raw string */ ''' | 1038 ''' /* next string is not a raw string */ ''' |
1048 if (#hasIsolateSupport) { | 1039 if (#hasIsolateSupport) { |
1049 #constructorName.$fieldNamesProperty = #fieldNamesArray; | 1040 #constructorName.$fieldNamesProperty = #fieldNamesArray; |
1050 } | 1041 } |
1051 }''', | 1042 }''', |
1052 {"constructorName": constructorName, | 1043 {"constructorName": constructorName, |
1053 "typeNameProperty": typeNameProperty, | 1044 "typeNameProperty": typeNameProperty, |
1054 "constructorNameString": js.string(constructorName), | 1045 "constructorNameString": js.quoteName(constructorName), |
1055 "hasIsolateSupport": hasIsolateSupport, | 1046 "hasIsolateSupport": hasIsolateSupport, |
1056 "fieldNamesArray": fieldNamesArray})); | 1047 "fieldNamesArray": fieldNamesArray})); |
1057 | 1048 |
1058 cspPrecompiledConstructorNamesFor(outputUnit).add(js('#', constructorName)); | 1049 cspPrecompiledConstructorNamesFor(outputUnit).add(js('#', constructorName)); |
1059 } | 1050 } |
1060 | 1051 |
1061 void assembleTypedefs(Program program) { | 1052 void assembleTypedefs(Program program) { |
1062 Fragment mainFragment = program.mainFragment; | 1053 Fragment mainFragment = program.mainFragment; |
1063 OutputUnit mainOutputUnit = mainFragment.outputUnit; | 1054 OutputUnit mainOutputUnit = mainFragment.outputUnit; |
1064 | 1055 |
1065 // Emit all required typedef declarations into the main output unit. | 1056 // Emit all required typedef declarations into the main output unit. |
1066 // TODO(karlklose): unify required classes and typedefs to declarations | 1057 // TODO(karlklose): unify required classes and typedefs to declarations |
1067 // and have builders for each kind. | 1058 // and have builders for each kind. |
1068 for (TypedefElement typedef in typedefsNeededForReflection) { | 1059 for (TypedefElement typedef in typedefsNeededForReflection) { |
1069 LibraryElement library = typedef.library; | 1060 LibraryElement library = typedef.library; |
1070 // TODO(karlklose): add a TypedefBuilder and move this code there. | 1061 // TODO(karlklose): add a TypedefBuilder and move this code there. |
1071 DartType type = typedef.alias; | 1062 DartType type = typedef.alias; |
1072 // TODO(zarah): reify type variables once reflection on type arguments of | 1063 // TODO(zarah): reify type variables once reflection on type arguments of |
1073 // typedefs is supported. | 1064 // typedefs is supported. |
1074 jsAst.Expression typeIndex = | 1065 jsAst.Expression typeIndex = |
1075 task.metadataCollector.reifyType(type, ignoreTypeVariables: true); | 1066 task.metadataCollector.reifyType(type, ignoreTypeVariables: true); |
1076 ClassBuilder builder = new ClassBuilder(typedef, namer); | 1067 ClassBuilder builder = new ClassBuilder.forStatics(typedef, namer); |
1077 builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, typeIndex); | 1068 builder.addPropertyByName(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, |
1078 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, | 1069 typeIndex); |
1079 js.boolean(true)); | 1070 builder.addPropertyByName(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, |
| 1071 js.boolean(true)); |
1080 | 1072 |
1081 // We can be pretty sure that the objectClass is initialized, since | 1073 // We can be pretty sure that the objectClass is initialized, since |
1082 // typedefs are only emitted with reflection, which requires lots of | 1074 // typedefs are only emitted with reflection, which requires lots of |
1083 // classes. | 1075 // classes. |
1084 assert(compiler.objectClass != null); | 1076 assert(compiler.objectClass != null); |
1085 builder.superName = namer.className(compiler.objectClass); | 1077 builder.superName = namer.className(compiler.objectClass); |
1086 jsAst.Node declaration = builder.toObjectInitializer(); | 1078 jsAst.Node declaration = builder.toObjectInitializer(); |
1087 String mangledName = namer.globalPropertyName(typedef); | 1079 jsAst.Name mangledName = namer.globalPropertyName(typedef); |
1088 String reflectionName = getReflectionName(typedef, mangledName); | 1080 String reflectionName = getReflectionName(typedef, mangledName); |
1089 getElementDescriptor(library, mainFragment) | 1081 getElementDescriptor(library, mainFragment) |
1090 ..addProperty(mangledName, declaration) | 1082 ..addProperty(mangledName, declaration) |
1091 ..addProperty("+$reflectionName", js.string('')); | 1083 ..addPropertyByName("+$reflectionName", js.string('')); |
1092 // Also emit a trivial constructor for CSP mode. | 1084 // Also emit a trivial constructor for CSP mode. |
1093 String constructorName = mangledName; | 1085 jsAst.Name constructorName = mangledName; |
1094 jsAst.Expression constructorAst = js('function() {}'); | 1086 jsAst.Expression constructorAst = js('function() {}'); |
1095 List<String> fieldNames = []; | 1087 List<String> fieldNames = []; |
1096 assemblePrecompiledConstructor(mainOutputUnit, | 1088 assemblePrecompiledConstructor(mainOutputUnit, |
1097 constructorName, | 1089 constructorName, |
1098 constructorAst, | 1090 constructorAst, |
1099 fieldNames); | 1091 fieldNames); |
1100 } | 1092 } |
1101 } | 1093 } |
1102 | 1094 |
1103 jsAst.Statement buildGlobalObjectSetup(bool isProgramSplit) { | 1095 jsAst.Statement buildGlobalObjectSetup(bool isProgramSplit) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 } | 1175 } |
1184 } | 1176 } |
1185 | 1177 |
1186 return new jsAst.Block(parts); | 1178 return new jsAst.Block(parts); |
1187 } | 1179 } |
1188 | 1180 |
1189 jsAst.Statement buildMangledNames() { | 1181 jsAst.Statement buildMangledNames() { |
1190 List<jsAst.Statement> parts = <jsAst.Statement>[]; | 1182 List<jsAst.Statement> parts = <jsAst.Statement>[]; |
1191 | 1183 |
1192 if (!mangledFieldNames.isEmpty) { | 1184 if (!mangledFieldNames.isEmpty) { |
1193 var keys = mangledFieldNames.keys.toList(); | 1185 List<jsAst.Name> keys = mangledFieldNames.keys.toList()..sort(); |
1194 keys.sort(); | |
1195 var properties = []; | 1186 var properties = []; |
1196 for (String key in keys) { | 1187 for (jsAst.Name key in keys) { |
1197 var value = js.string('${mangledFieldNames[key]}'); | 1188 var value = js.string(mangledFieldNames[key]); |
1198 properties.add(new jsAst.Property(js.string(key), value)); | 1189 properties.add(new jsAst.Property(key, value)); |
1199 } | 1190 } |
1200 | 1191 |
1201 jsAst.Expression mangledNamesAccess = | 1192 jsAst.Expression mangledNamesAccess = |
1202 generateEmbeddedGlobalAccess(embeddedNames.MANGLED_NAMES); | 1193 generateEmbeddedGlobalAccess(embeddedNames.MANGLED_NAMES); |
1203 var map = new jsAst.ObjectInitializer(properties); | 1194 var map = new jsAst.ObjectInitializer(properties); |
1204 parts.add(js.statement('# = #', [mangledNamesAccess, map])); | 1195 parts.add(js.statement('# = #', [mangledNamesAccess, map])); |
1205 } | 1196 } |
1206 | 1197 |
1207 if (!mangledGlobalFieldNames.isEmpty) { | 1198 if (!mangledGlobalFieldNames.isEmpty) { |
1208 var keys = mangledGlobalFieldNames.keys.toList(); | 1199 List<jsAst.Name> keys = mangledGlobalFieldNames.keys.toList() |
1209 keys.sort(); | 1200 ..sort(); |
1210 var properties = []; | 1201 List<jsAst.Property> properties = <jsAst.Property>[]; |
1211 for (String key in keys) { | 1202 for (jsAst.Name key in keys) { |
1212 var value = js.string('${mangledGlobalFieldNames[key]}'); | 1203 jsAst.Literal value = js.string(mangledGlobalFieldNames[key]); |
1213 properties.add(new jsAst.Property(js.string(key), value)); | 1204 properties.add(new jsAst.Property(js.quoteName(key), value)); |
1214 } | 1205 } |
1215 jsAst.Expression mangledGlobalNamesAccess = | 1206 jsAst.Expression mangledGlobalNamesAccess = |
1216 generateEmbeddedGlobalAccess(embeddedNames.MANGLED_GLOBAL_NAMES); | 1207 generateEmbeddedGlobalAccess(embeddedNames.MANGLED_GLOBAL_NAMES); |
1217 var map = new jsAst.ObjectInitializer(properties); | 1208 jsAst.ObjectInitializer map = new jsAst.ObjectInitializer(properties); |
1218 parts.add(js.statement('# = #', [mangledGlobalNamesAccess, map])); | 1209 parts.add(js.statement('# = #', [mangledGlobalNamesAccess, map])); |
1219 } | 1210 } |
1220 | 1211 |
1221 return new jsAst.Block(parts); | 1212 return new jsAst.Block(parts); |
1222 } | 1213 } |
1223 | 1214 |
1224 void checkEverythingEmitted(Iterable<Element> elements) { | 1215 void checkEverythingEmitted(Iterable<Element> elements) { |
1225 List<Element> pendingStatics; | 1216 List<Element> pendingStatics; |
1226 if (!compiler.hasIncrementalSupport) { | 1217 if (!compiler.hasIncrementalSupport) { |
1227 pendingStatics = | 1218 pendingStatics = |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 return ''' | 1701 return ''' |
1711 | 1702 |
1712 //# sourceMappingURL=$sourceMapFileName | 1703 //# sourceMappingURL=$sourceMapFileName |
1713 '''; | 1704 '''; |
1714 } | 1705 } |
1715 return ''; | 1706 return ''; |
1716 } | 1707 } |
1717 | 1708 |
1718 ClassBuilder getElementDescriptor(Element element, Fragment fragment) { | 1709 ClassBuilder getElementDescriptor(Element element, Fragment fragment) { |
1719 Element owner = element.library; | 1710 Element owner = element.library; |
| 1711 bool isClass = false; |
1720 if (!element.isLibrary && !element.isTopLevel && !element.isNative) { | 1712 if (!element.isLibrary && !element.isTopLevel && !element.isNative) { |
1721 // For static (not top level) elements, record their code in a buffer | 1713 // For static (not top level) elements, record their code in a buffer |
1722 // specific to the class. For now, not supported for native classes and | 1714 // specific to the class. For now, not supported for native classes and |
1723 // native elements. | 1715 // native elements. |
1724 ClassElement cls = | 1716 ClassElement cls = |
1725 element.enclosingClassOrCompilationUnit.declaration; | 1717 element.enclosingClassOrCompilationUnit.declaration; |
1726 if (compiler.codegenWorld.directlyInstantiatedClasses.contains(cls) && | 1718 if (compiler.codegenWorld.directlyInstantiatedClasses.contains(cls) && |
1727 !cls.isNative && | 1719 !cls.isNative && |
1728 compiler.deferredLoadTask.outputUnitForElement(element) == | 1720 compiler.deferredLoadTask.outputUnitForElement(element) == |
1729 compiler.deferredLoadTask.outputUnitForElement(cls)) { | 1721 compiler.deferredLoadTask.outputUnitForElement(cls)) { |
1730 owner = cls; | 1722 owner = cls; |
1731 } | 1723 } |
1732 } | 1724 } |
1733 if (owner == null) { | 1725 if (owner == null) { |
1734 compiler.internalError(element, 'Owner is null.'); | 1726 compiler.internalError(element, 'Owner is null.'); |
1735 } | 1727 } |
1736 return elementDescriptors | 1728 return elementDescriptors |
1737 .putIfAbsent(fragment, () => new Map<Element, ClassBuilder>()) | 1729 .putIfAbsent(fragment, () => new Map<Element, ClassBuilder>()) |
1738 .putIfAbsent(owner, () => new ClassBuilder(owner, namer)); | 1730 .putIfAbsent(owner, () { |
| 1731 return new ClassBuilder(owner, namer, owner.isClass); |
| 1732 }); |
1739 } | 1733 } |
1740 | 1734 |
1741 /// Emits support-code for deferred loading into [output]. | 1735 /// Emits support-code for deferred loading into [output]. |
1742 jsAst.Statement buildDeferredBoilerPlate( | 1736 jsAst.Statement buildDeferredBoilerPlate( |
1743 Map<OutputUnit, _DeferredOutputUnitHash> deferredLoadHashes) { | 1737 Map<OutputUnit, _DeferredOutputUnitHash> deferredLoadHashes) { |
1744 List<jsAst.Statement> parts = <jsAst.Statement>[]; | 1738 List<jsAst.Statement> parts = <jsAst.Statement>[]; |
1745 | 1739 |
1746 parts.add(js.statement(''' | 1740 parts.add(js.statement(''' |
1747 { | 1741 { |
1748 // Function for checking if a hunk is loaded given its hash. | 1742 // Function for checking if a hunk is loaded given its hash. |
1749 #isHunkLoaded = function(hunkHash) { | 1743 #isHunkLoaded = function(hunkHash) { |
1750 return !!$deferredInitializers[hunkHash]; | 1744 return !!$deferredInitializers[hunkHash]; |
1751 }; | 1745 }; |
1752 #deferredInitialized = new Object(null); | 1746 #deferredInitialized = new Object(null); |
1753 // Function for checking if a hunk is initialized given its hash. | 1747 // Function for checking if a hunk is initialized given its hash. |
1754 #isHunkInitialized = function(hunkHash) { | 1748 #isHunkInitialized = function(hunkHash) { |
1755 return #deferredInitialized[hunkHash]; | 1749 return #deferredInitialized[hunkHash]; |
1756 }; | 1750 }; |
1757 // Function for initializing a loaded hunk, given its hash. | 1751 // Function for initializing a loaded hunk, given its hash. |
1758 #initializeLoadedHunk = function(hunkHash) { | 1752 #initializeLoadedHunk = function(hunkHash) { |
1759 $deferredInitializers[hunkHash]( | 1753 $deferredInitializers[hunkHash]( |
1760 $globalsHolder, ${namer.currentIsolate}); | 1754 #globalsHolder, ${namer.currentIsolate}); |
1761 #deferredInitialized[hunkHash] = true; | 1755 #deferredInitialized[hunkHash] = true; |
1762 }; | 1756 }; |
1763 } | 1757 } |
1764 ''', {"isHunkLoaded": generateEmbeddedGlobalAccess( | 1758 ''', {"globalsHolder": globalsHolder, |
| 1759 "isHunkLoaded": generateEmbeddedGlobalAccess( |
1765 embeddedNames.IS_HUNK_LOADED), | 1760 embeddedNames.IS_HUNK_LOADED), |
1766 "isHunkInitialized": generateEmbeddedGlobalAccess( | 1761 "isHunkInitialized": generateEmbeddedGlobalAccess( |
1767 embeddedNames.IS_HUNK_INITIALIZED), | 1762 embeddedNames.IS_HUNK_INITIALIZED), |
1768 "initializeLoadedHunk": generateEmbeddedGlobalAccess( | 1763 "initializeLoadedHunk": generateEmbeddedGlobalAccess( |
1769 embeddedNames.INITIALIZE_LOADED_HUNK), | 1764 embeddedNames.INITIALIZE_LOADED_HUNK), |
1770 "deferredInitialized": generateEmbeddedGlobalAccess( | 1765 "deferredInitialized": generateEmbeddedGlobalAccess( |
1771 embeddedNames.DEFERRED_INITIALIZED)})); | 1766 embeddedNames.DEFERRED_INITIALIZED)})); |
1772 | 1767 |
1773 // Write a javascript mapping from Deferred import load ids (derrived | 1768 // Write a javascript mapping from Deferred import load ids (derrived |
1774 // from the import prefix.) to a list of lists of uris of hunks to load, | 1769 // from the import prefix.) to a list of lists of uris of hunks to load, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1827 for (Fragment fragment in program.deferredFragments) { | 1822 for (Fragment fragment in program.deferredFragments) { |
1828 OutputUnit outputUnit = fragment.outputUnit; | 1823 OutputUnit outputUnit = fragment.outputUnit; |
1829 jsAst.Expression libraryDescriptor = deferredAsts[outputUnit]; | 1824 jsAst.Expression libraryDescriptor = deferredAsts[outputUnit]; |
1830 List<jsAst.Statement> body = <jsAst.Statement>[]; | 1825 List<jsAst.Statement> body = <jsAst.Statement>[]; |
1831 | 1826 |
1832 // No renaming in the top-level function to save the locals for the | 1827 // No renaming in the top-level function to save the locals for the |
1833 // nested context where they will be used more. | 1828 // nested context where they will be used more. |
1834 body.add(js.comment("/* ::norenaming:: ")); | 1829 body.add(js.comment("/* ::norenaming:: ")); |
1835 | 1830 |
1836 for (String globalObject in Namer.reservedGlobalObjectNames) { | 1831 for (String globalObject in Namer.reservedGlobalObjectNames) { |
1837 body.add(js.statement('var #object = ${globalsHolder}.#object;', | 1832 body.add(js.statement('var #object = #globalsHolder.#object;', |
1838 {'object': globalObject})); | 1833 {'globalsHolder': globalsHolder, |
| 1834 'object': globalObject})); |
1839 } | 1835 } |
1840 body..add(js.statement('var init = ${globalsHolder}.init;')) | 1836 body..add(js.statement('var init = #globalsHolder.init;', |
| 1837 {'globalsHolder': globalsHolder})) |
1841 ..add(js.statement('var $setupProgramName = ' | 1838 ..add(js.statement('var $setupProgramName = ' |
1842 '$globalsHolder.$setupProgramName;')) | 1839 '#globalsHolder.$setupProgramName;', |
| 1840 {'globalsHolder': globalsHolder})) |
1843 ..add(js.statement('var ${namer.isolateName} = ' | 1841 ..add(js.statement('var ${namer.isolateName} = ' |
1844 '${globalsHolder}.${namer.isolateName};')); | 1842 '#globalsHolder.${namer.isolateName};', |
| 1843 {'globalsHolder': globalsHolder})); |
1845 String typesAccess = | 1844 String typesAccess = |
1846 generateEmbeddedGlobalAccessString(embeddedNames.TYPES); | 1845 generateEmbeddedGlobalAccessString(embeddedNames.TYPES); |
1847 if (libraryDescriptor != null) { | 1846 if (libraryDescriptor != null) { |
1848 // The argument to reflectionDataParser is assigned to a temporary | 1847 // The argument to reflectionDataParser is assigned to a temporary |
1849 // 'dart' so that 'dart.' will appear as the prefix to dart methods | 1848 // 'dart' so that 'dart.' will appear as the prefix to dart methods |
1850 // in stack traces and profile entries. | 1849 // in stack traces and profile entries. |
1851 body.add(js.statement('var dart = #', libraryDescriptor)); | 1850 body.add(js.statement('var dart = #', libraryDescriptor)); |
1852 | 1851 |
1853 if (compiler.useContentSecurityPolicy) { | 1852 if (compiler.useContentSecurityPolicy) { |
1854 body.add(buildCspPrecompiledFunctionFor(outputUnit)); | 1853 body.add(buildCspPrecompiledFunctionFor(outputUnit)); |
(...skipping 12 matching lines...) Expand all Loading... |
1867 | 1866 |
1868 body.add(buildCompileTimeConstants(fragment.constants, | 1867 body.add(buildCompileTimeConstants(fragment.constants, |
1869 isMainFragment: false)); | 1868 isMainFragment: false)); |
1870 body.add(buildStaticNonFinalFieldInitializations(outputUnit)); | 1869 body.add(buildStaticNonFinalFieldInitializations(outputUnit)); |
1871 | 1870 |
1872 List<jsAst.Statement> statements = <jsAst.Statement>[]; | 1871 List<jsAst.Statement> statements = <jsAst.Statement>[]; |
1873 | 1872 |
1874 statements | 1873 statements |
1875 ..add(buildGeneratedBy()) | 1874 ..add(buildGeneratedBy()) |
1876 ..add(js.statement('${deferredInitializers}.current = ' | 1875 ..add(js.statement('${deferredInitializers}.current = ' |
1877 """function (${globalsHolder}) { | 1876 """function (#) { |
1878 # | 1877 # |
1879 } | 1878 } |
1880 """, [body])); | 1879 """, [globalsHolder, body])); |
1881 | 1880 |
1882 result[outputUnit] = new jsAst.Program(statements); | 1881 result[outputUnit] = new jsAst.Program(statements); |
1883 } | 1882 } |
1884 | 1883 |
1885 return result; | 1884 return result; |
1886 } | 1885 } |
1887 | 1886 |
1888 /// Returns a map from OutputUnit to a hash of its content. The hash uniquely | 1887 /// Returns a map from OutputUnit to a hash of its content. The hash uniquely |
1889 /// identifies the code of the output-unit. It does not include | 1888 /// identifies the code of the output-unit. It does not include |
1890 /// boilerplate JS code, like the sourcemap directives or the hash | 1889 /// boilerplate JS code, like the sourcemap directives or the hash |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2002 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2001 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
2003 if (element.isInstanceMember) { | 2002 if (element.isInstanceMember) { |
2004 cachedClassBuilders.remove(element.enclosingClass); | 2003 cachedClassBuilders.remove(element.enclosingClass); |
2005 | 2004 |
2006 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2005 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
2007 | 2006 |
2008 } | 2007 } |
2009 } | 2008 } |
2010 } | 2009 } |
2011 } | 2010 } |
OLD | NEW |