@@ -17,18 +17,13 @@ import 'options.dart' show BytecodeOptions;
1717import '../metadata/direct_call.dart' show DirectCallMetadata;
1818
1919class LocalVariables {
20- final Map <TreeNode , Scope > _scopes = < TreeNode , Scope > {};
21- final Map <VariableDeclaration , VarDesc > _vars =
22- < VariableDeclaration , VarDesc > {};
23- final Map <TreeNode , List <int >> _temps = < TreeNode , List <int >> {};
24- final Map <TreeNode , VariableDeclaration > _capturedSavedContextVars =
25- < TreeNode , VariableDeclaration > {};
26- final Map <TreeNode , VariableDeclaration > _capturedExceptionVars =
27- < TreeNode , VariableDeclaration > {};
28- final Map <TreeNode , VariableDeclaration > _capturedStackTraceVars =
29- < TreeNode , VariableDeclaration > {};
30- final Map <ForInStatement , VariableDeclaration > _capturedIteratorVars =
31- < ForInStatement , VariableDeclaration > {};
20+ final _scopes = new Map <TreeNode , Scope >();
21+ final _vars = new Map <VariableDeclaration , VarDesc >();
22+ Map <TreeNode , List <int >> _temps;
23+ Map <TreeNode , VariableDeclaration > _capturedSavedContextVars;
24+ Map <TreeNode , VariableDeclaration > _capturedExceptionVars;
25+ Map <TreeNode , VariableDeclaration > _capturedStackTraceVars;
26+ Map <ForInStatement , VariableDeclaration > _capturedIteratorVars;
3227 final BytecodeOptions options;
3328 final TypeEnvironment typeEnvironment;
3429 final Map <TreeNode , DirectCallMetadata > directCallMetadata;
@@ -155,13 +150,15 @@ class LocalVariables {
155150 }
156151
157152 VariableDeclaration capturedSavedContextVar (TreeNode node) =>
158- _capturedSavedContextVars[node];
153+ _capturedSavedContextVars != null
154+ ? _capturedSavedContextVars[node]
155+ : null ;
159156 VariableDeclaration capturedExceptionVar (TreeNode node) =>
160- _capturedExceptionVars[node];
157+ _capturedExceptionVars != null ? _capturedExceptionVars [node] : null ;
161158 VariableDeclaration capturedStackTraceVar (TreeNode node) =>
162- _capturedStackTraceVars[node];
159+ _capturedStackTraceVars != null ? _capturedStackTraceVars [node] : null ;
163160 VariableDeclaration capturedIteratorVar (ForInStatement node) =>
164- _capturedIteratorVars[node];
161+ _capturedIteratorVars != null ? _capturedIteratorVars [node] : null ;
165162
166163 int get asyncExceptionParamIndexInFrame {
167164 assert (_currentFrame.isSyncYielding);
@@ -521,12 +518,18 @@ class _ScopeBuilder extends RecursiveVisitor<Null> {
521518 void _captureSyntheticVariables () {
522519 int depth = 0 ;
523520 for (TreeNode tryBlock in _enclosingTryBlocks) {
521+ locals._capturedSavedContextVars ?? =
522+ new Map <TreeNode , VariableDeclaration >();
524523 _captureSyntheticVariable (ContinuationVariables .savedTryContextVar (depth),
525524 tryBlock, locals._capturedSavedContextVars);
526525 ++ depth;
527526 }
528527 depth = 0 ;
529528 for (TreeNode tryBlock in _enclosingTryCatches) {
529+ locals._capturedExceptionVars ?? =
530+ new Map <TreeNode , VariableDeclaration >();
531+ locals._capturedStackTraceVars ?? =
532+ new Map <TreeNode , VariableDeclaration >();
530533 _captureSyntheticVariable (ContinuationVariables .exceptionVar (depth),
531534 tryBlock, locals._capturedExceptionVars);
532535 _captureSyntheticVariable (ContinuationVariables .stackTraceVar (depth),
@@ -685,6 +688,8 @@ class _ScopeBuilder extends RecursiveVisitor<Null> {
685688 // Declare a variable to hold 'iterator' so it could be captured.
686689 iteratorVar = new VariableDeclaration (':iterator' );
687690 _declareVariable (iteratorVar);
691+ locals._capturedIteratorVars ?? =
692+ new Map <ForInStatement , VariableDeclaration >();
688693 locals._capturedIteratorVars[node] = iteratorVar;
689694 }
690695
@@ -886,6 +891,7 @@ class _Allocator extends RecursiveVisitor<Null> {
886891 }
887892
888893 void _allocateTemp (TreeNode node, {int count: 1 }) {
894+ locals._temps ?? = new Map <TreeNode , List <int >>();
889895 assert (locals._temps[node] == null );
890896 if (_currentScope.tempsUsed + count > _currentFrame.temporaries.length) {
891897 // Allocate new local slots for temporary variables.
@@ -1143,7 +1149,9 @@ class _Allocator extends RecursiveVisitor<Null> {
11431149 @override
11441150 visitForInStatement (ForInStatement node) {
11451151 _allocateTemp (node);
1146- _ensureVariableAllocated (locals._capturedIteratorVars[node]);
1152+ if (locals._capturedIteratorVars != null ) {
1153+ _ensureVariableAllocated (locals._capturedIteratorVars[node]);
1154+ }
11471155
11481156 node.iterable.accept (this );
11491157
0 commit comments