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

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/code_generator.dart

Issue 2484913004: Fix crashing bug for closures of the form () { return; } (Closed)
Patch Set: Only re-export the main methods. The ddc codegen doesn't depend on any other methods being exported… Created 4 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 2
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 import 'dart:collection' show HashMap, HashSet; 6 import 'dart:collection' show HashMap, HashSet;
7 import 'dart:math' show min, max; 7 import 'dart:math' show min, max;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 510
511 if (export is TypeDefiningElement || 511 if (export is TypeDefiningElement ||
512 export is FunctionElement || 512 export is FunctionElement ||
513 _eagerTopLevelFields.contains(export)) { 513 _eagerTopLevelFields.contains(export)) {
514 // classes, typedefs, functions, and eager init fields can be assigned 514 // classes, typedefs, functions, and eager init fields can be assigned
515 // directly. 515 // directly.
516 // TODO(jmesserly): we don't know about eager init fields from other 516 // TODO(jmesserly): we don't know about eager init fields from other
517 // modules we import, so we will never go down this code path for them. 517 // modules we import, so we will never go down this code path for them.
518 _moduleItems 518 _moduleItems
519 .add(js.statement('#.# = #;', [libraryName, name.selector, name])); 519 .add(js.statement('#.# = #;', [libraryName, name.selector, name]));
520 } else {
521 // top-level fields, getters, setters need to copy the property
522 // descriptor.
523 _moduleItems.add(_callHelperStatement(
524 'export(#, #, #);', [libraryName, name.receiver, name.selector]));
525 } 520 }
526 } 521 }
527 522
528 for (var export in exportedNames.definedNames.values) { 523 // We only need to export main as it is the only method party of the
529 if (export is PropertyAccessorElement) { 524 // publically exposed JS API for a library.
530 export = (export as PropertyAccessorElement).variable; 525 var export = exportedNames.get('main');
531 }
532 526
533 // Don't allow redefining names from this library. 527 if (export == null) return;
534 if (currentNames.containsKey(export.name)) continue; 528 if (export is PropertyAccessorElement) {
529 export = (export as PropertyAccessorElement).variable;
530 }
535 531
536 if (export.isSynthetic && export is PropertyInducingElement) { 532 // Don't allow redefining names from this library.
537 _emitDeclaration(export.getter); 533 if (currentNames.containsKey(export.name)) return;
538 _emitDeclaration(export.setter); 534
539 } else { 535 if (export.isSynthetic && export is PropertyInducingElement) {
540 _emitDeclaration(export); 536 _emitDeclaration(export.getter);
541 } 537 _emitDeclaration(export.setter);
542 if (export is ClassElement && export.typeParameters.isNotEmpty) { 538 } else {
543 // Export the generic name as well. 539 _emitDeclaration(export);
544 // TODO(jmesserly): revisit generic classes
545 emitExport(export, suffix: r'$');
546 }
547 emitExport(export);
548 } 540 }
541 emitExport(export);
549 } 542 }
550 543
551 @override 544 @override
552 visitAsExpression(AsExpression node) { 545 visitAsExpression(AsExpression node) {
553 Expression fromExpr = node.expression; 546 Expression fromExpr = node.expression;
554 var from = getStaticType(fromExpr); 547 var from = getStaticType(fromExpr);
555 var to = node.type.type; 548 var to = node.type.type;
556 549
557 JS.Expression jsFrom = _visit(fromExpr); 550 JS.Expression jsFrom = _visit(fromExpr);
558 if (_inWhitelistCode(node)) return jsFrom; 551 if (_inWhitelistCode(node)) return jsFrom;
(...skipping 5037 matching lines...) Expand 10 before | Expand all | Expand 10 after
5596 var targetIdentifier = target as SimpleIdentifier; 5589 var targetIdentifier = target as SimpleIdentifier;
5597 5590
5598 if (targetIdentifier.staticElement is! PrefixElement) return false; 5591 if (targetIdentifier.staticElement is! PrefixElement) return false;
5599 var prefix = targetIdentifier.staticElement as PrefixElement; 5592 var prefix = targetIdentifier.staticElement as PrefixElement;
5600 5593
5601 // The library the prefix is referring to must come from a deferred import. 5594 // The library the prefix is referring to must come from a deferred import.
5602 var containingLibrary = (target.root as CompilationUnit).element.library; 5595 var containingLibrary = (target.root as CompilationUnit).element.library;
5603 var imports = containingLibrary.getImportsWithPrefix(prefix); 5596 var imports = containingLibrary.getImportsWithPrefix(prefix);
5604 return imports.length == 1 && imports[0].isDeferred; 5597 return imports.length == 1 && imports[0].isDeferred;
5605 } 5598 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698