Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 String get N => compiler.enableMinification ? "\n" : ";\n"; | 62 String get N => compiler.enableMinification ? "\n" : ";\n"; |
| 63 | 63 |
| 64 CodeBuffer getBuffer(OutputUnit outputUnit) { | 64 CodeBuffer getBuffer(OutputUnit outputUnit) { |
| 65 return outputBuffers.putIfAbsent(outputUnit, () => new CodeBuffer()); | 65 return outputBuffers.putIfAbsent(outputUnit, () => new CodeBuffer()); |
| 66 } | 66 } |
| 67 | 67 |
| 68 CodeBuffer get mainBuffer { | 68 CodeBuffer get mainBuffer { |
| 69 return getBuffer(compiler.deferredLoadTask.mainOutputUnit); | 69 return getBuffer(compiler.deferredLoadTask.mainOutputUnit); |
| 70 } | 70 } |
| 71 | 71 |
| 72 String useCspOrNonCspVersion(String cspVersion, String nonCspVersion) { | |
| 73 return compiler.useContentSecurityPolicy ? cspVersion : nonCspVersion; | |
| 74 } | |
| 75 | |
| 72 /** | 76 /** |
| 73 * List of expressions and statements that will be included in the | 77 * List of expressions and statements that will be included in the |
| 74 * precompiled function. | 78 * precompiled function. |
| 75 * | 79 * |
| 76 * To save space, dart2js normally generates constructors and accessors | 80 * To save space, dart2js normally generates constructors and accessors |
| 77 * dynamically. This doesn't work in CSP mode, so dart2js emits them directly | 81 * dynamically. This doesn't work in CSP mode, so dart2js emits them directly |
| 78 * when in CSP mode. | 82 * when in CSP mode. |
| 79 */ | 83 */ |
| 80 Map<OutputUnit, List<jsAst.Node>> _cspPrecompiledFunctions = | 84 Map<OutputUnit, List<jsAst.Node>> _cspPrecompiledFunctions = |
| 81 new Map<OutputUnit, List<jsAst.Node>>(); | 85 new Map<OutputUnit, List<jsAst.Node>>(); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 var pendingClasses = Object.create(null); | 487 var pendingClasses = Object.create(null); |
| 484 var allClasses = #allClasses; | 488 var allClasses = #allClasses; |
| 485 var constructors; | 489 var constructors; |
| 486 | 490 |
| 487 if (#debugFastObjects) | 491 if (#debugFastObjects) |
| 488 print("Number of classes: " + | 492 print("Number of classes: " + |
| 489 Object.getOwnPropertyNames(\$\$).length); | 493 Object.getOwnPropertyNames(\$\$).length); |
| 490 | 494 |
| 491 var hasOwnProperty = Object.prototype.hasOwnProperty; | 495 var hasOwnProperty = Object.prototype.hasOwnProperty; |
| 492 | 496 |
| 493 if (typeof dart_precompiled == "function") { | 497 ${useCspOrNonCspVersion(''' |
|
floitsch
2014/12/17 15:03:38
There is an easier nicer solution:
`if (#) { ...
zarah
2014/12/18 08:22:16
Done.
| |
| 494 constructors = dart_precompiled(collectedClasses); | 498 constructors = dart_precompiled(collectedClasses); |
| 495 } else { | 499 ''',''' |
| 496 var combinedConstructorFunction = | 500 var combinedConstructorFunction = |
| 497 "function \$reflectable(fn){fn.$reflectableField=1;return fn};\\n"+ | 501 "function \$reflectable(fn){fn.$reflectableField=1;return fn};\\n"+ |
| 498 "var \$desc;\\n"; | 502 "var \$desc;\\n"; |
| 499 var constructorsList = []; | 503 var constructorsList = []; |
| 500 } | 504 ''')} |
| 501 | 505 |
| 502 for (var cls in collectedClasses) { | 506 for (var cls in collectedClasses) { |
| 503 var desc = collectedClasses[cls]; | 507 var desc = collectedClasses[cls]; |
| 504 if (desc instanceof Array) desc = desc[1]; | 508 if (desc instanceof Array) desc = desc[1]; |
| 505 | 509 |
| 506 /* The 'fields' are either a constructor function or a | 510 /* The 'fields' are either a constructor function or a |
| 507 * string encoding fields, constructor and superclass. Gets the | 511 * string encoding fields, constructor and superclass. Gets the |
| 508 * superclass and fields in the format | 512 * superclass and fields in the format |
| 509 * 'Super;field1,field2' | 513 * 'Super;field1,field2' |
| 510 * from the CLASS_DESCRIPTOR_PROPERTY property on the descriptor. | 514 * from the CLASS_DESCRIPTOR_PROPERTY property on the descriptor. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 522 split = supr.split(":"); | 526 split = supr.split(":"); |
| 523 if (split.length == 2) { | 527 if (split.length == 2) { |
| 524 supr = split[0]; | 528 supr = split[0]; |
| 525 var functionSignature = split[1]; | 529 var functionSignature = split[1]; |
| 526 if (functionSignature) | 530 if (functionSignature) |
| 527 desc.$signaturePropertyName = (function(s) { | 531 desc.$signaturePropertyName = (function(s) { |
| 528 return function(){ return #metadata[s]; }; | 532 return function(){ return #metadata[s]; }; |
| 529 })(functionSignature); | 533 })(functionSignature); |
| 530 } | 534 } |
| 531 | 535 |
| 532 if (typeof dart_precompiled != "function") { | 536 ${useCspOrNonCspVersion(''' |
| 533 combinedConstructorFunction += defineClass(cls, fields); | 537 ''', ''' |
| 534 constructorsList.push(cls); | 538 combinedConstructorFunction += defineClass(cls, fields); |
| 535 } | 539 constructorsList.push(cls); |
| 540 ''')} | |
| 536 if (supr) pendingClasses[cls] = supr; | 541 if (supr) pendingClasses[cls] = supr; |
| 537 } | 542 } |
| 538 | 543 |
| 539 if (typeof dart_precompiled != "function") { | 544 ${useCspOrNonCspVersion(''' |
| 540 combinedConstructorFunction += | 545 ''',''' |
| 541 "return [\\n " + constructorsList.join(",\\n ") + "\\n]"; | 546 combinedConstructorFunction += |
| 542 var constructors = | 547 "return [\\n " + constructorsList.join(",\\n ") + "\\n]"; |
| 543 new Function("\$collectedClasses", combinedConstructorFunction) | 548 var constructors = |
| 544 (collectedClasses); | 549 new Function("\$collectedClasses", combinedConstructorFunction) |
| 545 combinedConstructorFunction = null; | 550 (collectedClasses); |
| 546 } | 551 combinedConstructorFunction = null; |
| 552 ''')} | |
| 547 | 553 |
| 548 for (var i = 0; i < constructors.length; i++) { | 554 for (var i = 0; i < constructors.length; i++) { |
| 549 var constructor = constructors[i]; | 555 var constructor = constructors[i]; |
| 550 var cls = constructor.name; | 556 var cls = constructor.name; |
| 551 var desc = collectedClasses[cls]; | 557 var desc = collectedClasses[cls]; |
| 552 var globalObject = isolateProperties; | 558 var globalObject = isolateProperties; |
| 553 if (desc instanceof Array) { | 559 if (desc instanceof Array) { |
| 554 globalObject = desc[0] || isolateProperties; | 560 globalObject = desc[0] || isolateProperties; |
| 555 desc = desc[1]; | 561 desc = desc[1]; |
| 556 } | 562 } |
| (...skipping 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2263 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2269 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 2264 if (element.isInstanceMember) { | 2270 if (element.isInstanceMember) { |
| 2265 cachedClassBuilders.remove(element.enclosingClass); | 2271 cachedClassBuilders.remove(element.enclosingClass); |
| 2266 | 2272 |
| 2267 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2273 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2268 | 2274 |
| 2269 } | 2275 } |
| 2270 } | 2276 } |
| 2271 } | 2277 } |
| 2272 } | 2278 } |
| OLD | NEW |