@@ -186,7 +186,7 @@ public Engine(Action<Engine, Options> options)
186
186
Object . _prototype = Function . PrototypeObject ;
187
187
188
188
// create the global environment http://www.ecma-international.org/ecma-262/5.1/#sec-10.2.3
189
- GlobalEnvironment = LexicalEnvironment . NewGlobalEnvironment ( this , Global ) ;
189
+ GlobalEnvironment = JintEnvironment . NewGlobalEnvironment ( this , Global , Global ) ;
190
190
191
191
// create the global execution context http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.1.1
192
192
EnterExecutionContext ( GlobalEnvironment , GlobalEnvironment ) ;
@@ -213,7 +213,7 @@ public Engine(Action<Engine, Options> options)
213
213
Options . Apply ( this ) ;
214
214
}
215
215
216
- internal LexicalEnvironment GlobalEnvironment { get ; }
216
+ internal GlobalEnvironmentRecord GlobalEnvironment { get ; }
217
217
public GlobalObject Global { get ; }
218
218
public ObjectConstructor Object { get ; }
219
219
public FunctionConstructor Function { get ; }
@@ -274,8 +274,8 @@ internal Options Options
274
274
public DebugHandler DebugHandler => _debugHandler ??= new DebugHandler ( this ) ;
275
275
276
276
public ExecutionContext EnterExecutionContext (
277
- LexicalEnvironment lexicalEnvironment ,
278
- LexicalEnvironment variableEnvironment )
277
+ EnvironmentRecord lexicalEnvironment ,
278
+ EnvironmentRecord variableEnvironment )
279
279
{
280
280
var context = new ExecutionContext (
281
281
lexicalEnvironment ,
@@ -285,6 +285,12 @@ public ExecutionContext EnterExecutionContext(
285
285
return context ;
286
286
}
287
287
288
+ internal ExecutionContext EnterExecutionContext ( ExecutionContext context )
289
+ {
290
+ _executionContexts . Push ( context ) ;
291
+ return context ;
292
+ }
293
+
288
294
public Engine SetValue ( JsValue name , Delegate value )
289
295
{
290
296
Global . FastAddProperty ( name , new DelegateWrapper ( this , value ) , true , false , true ) ;
@@ -791,26 +797,26 @@ public JsValue GetValue(JsValue scope, JsValue property)
791
797
/// <summary>
792
798
/// https://tc39.es/ecma262/#sec-resolvebinding
793
799
/// </summary>
794
- internal Reference ResolveBinding ( string name , LexicalEnvironment env = null )
800
+ internal Reference ResolveBinding ( string name , EnvironmentRecord env = null )
795
801
{
796
802
env ??= ExecutionContext . LexicalEnvironment ;
797
803
return GetIdentifierReference ( env , name , StrictModeScope . IsStrictModeCode ) ;
798
804
}
799
805
800
- private Reference GetIdentifierReference ( LexicalEnvironment env , string name , bool strict )
806
+ private Reference GetIdentifierReference ( EnvironmentRecord env , string name , bool strict )
801
807
{
802
808
if ( env is null )
803
809
{
804
810
return new Reference ( JsValue . Undefined , name , strict ) ;
805
811
}
806
812
807
- var envRec = env . _record ;
813
+ var envRec = env ;
808
814
if ( envRec . HasBinding ( name ) )
809
815
{
810
816
return new Reference ( envRec , name , strict ) ;
811
817
}
812
818
813
- return GetIdentifierReference ( env . _outer , name , strict ) ;
819
+ return GetIdentifierReference ( env . _outerEnv , name , strict ) ;
814
820
}
815
821
816
822
/// <summary>
@@ -837,10 +843,8 @@ internal JsValue ResolveThisBinding()
837
843
/// </summary>
838
844
private void GlobalDeclarationInstantiation (
839
845
Script script ,
840
- LexicalEnvironment env )
846
+ GlobalEnvironmentRecord env )
841
847
{
842
- var envRec = ( GlobalEnvironmentRecord ) env . _record ;
843
-
844
848
var hoistingScope = HoistingScope . GetProgramLevelDeclarations ( script ) ;
845
849
var functionDeclarations = hoistingScope . _functionDeclarations ;
846
850
var varDeclarations = hoistingScope . _variablesDeclarations ;
@@ -858,7 +862,7 @@ private void GlobalDeclarationInstantiation(
858
862
var fn = d . Id . Name ;
859
863
if ( ! declaredFunctionNames . Contains ( fn ) )
860
864
{
861
- var fnDefinable = envRec . CanDeclareGlobalFunction ( fn ) ;
865
+ var fnDefinable = env . CanDeclareGlobalFunction ( fn ) ;
862
866
if ( ! fnDefinable )
863
867
{
864
868
ExceptionHelper . ThrowTypeError ( this ) ;
@@ -882,14 +886,14 @@ private void GlobalDeclarationInstantiation(
882
886
{
883
887
var vn = boundNames [ j ] ;
884
888
885
- if ( envRec . HasLexicalDeclaration ( vn ) )
889
+ if ( env . HasLexicalDeclaration ( vn ) )
886
890
{
887
891
ExceptionHelper . ThrowSyntaxError ( this , $ "Identifier '{ vn } ' has already been declared") ;
888
892
}
889
893
890
894
if ( ! declaredFunctionNames . Contains ( vn ) )
891
895
{
892
- var vnDefinable = envRec . CanDeclareGlobalVar ( vn ) ;
896
+ var vnDefinable = env . CanDeclareGlobalVar ( vn ) ;
893
897
if ( ! vnDefinable )
894
898
{
895
899
ExceptionHelper . ThrowTypeError ( this ) ;
@@ -911,20 +915,20 @@ private void GlobalDeclarationInstantiation(
911
915
for ( var j = 0 ; j < boundNames . Count ; j ++ )
912
916
{
913
917
var dn = boundNames [ j ] ;
914
- if ( envRec . HasVarDeclaration ( dn )
915
- || envRec . HasLexicalDeclaration ( dn )
916
- || envRec . HasRestrictedGlobalProperty ( dn ) )
918
+ if ( env . HasVarDeclaration ( dn )
919
+ || env . HasLexicalDeclaration ( dn )
920
+ || env . HasRestrictedGlobalProperty ( dn ) )
917
921
{
918
922
ExceptionHelper . ThrowSyntaxError ( this , $ "Identifier '{ dn } ' has already been declared") ;
919
923
}
920
924
921
925
if ( d . Kind == VariableDeclarationKind . Const )
922
926
{
923
- envRec . CreateImmutableBinding ( dn , strict : true ) ;
927
+ env . CreateImmutableBinding ( dn , strict : true ) ;
924
928
}
925
929
else
926
930
{
927
- envRec . CreateMutableBinding ( dn , canBeDeleted : false ) ;
931
+ env . CreateMutableBinding ( dn , canBeDeleted : false ) ;
928
932
}
929
933
}
930
934
}
@@ -934,19 +938,19 @@ private void GlobalDeclarationInstantiation(
934
938
{
935
939
var fn = f . Id ! . Name ;
936
940
937
- if ( envRec . HasLexicalDeclaration ( fn ) )
941
+ if ( env . HasLexicalDeclaration ( fn ) )
938
942
{
939
943
ExceptionHelper . ThrowSyntaxError ( this , $ "Identifier '{ fn } ' has already been declared") ;
940
944
}
941
945
942
946
var fo = Function . InstantiateFunctionObject ( f , env ) ;
943
- envRec . CreateGlobalFunctionBinding ( fn , fo , canBeDeleted : false ) ;
947
+ env . CreateGlobalFunctionBinding ( fn , fo , canBeDeleted : false ) ;
944
948
}
945
949
946
950
for ( var i = 0 ; i < declaredVarNames . Count ; i ++ )
947
951
{
948
952
var vn = declaredVarNames [ i ] ;
949
- envRec . CreateGlobalVarBinding ( vn , canBeDeleted : false ) ;
953
+ env . CreateGlobalVarBinding ( vn , canBeDeleted : false ) ;
950
954
}
951
955
}
952
956
@@ -956,11 +960,11 @@ private void GlobalDeclarationInstantiation(
956
960
internal ArgumentsInstance FunctionDeclarationInstantiation (
957
961
FunctionInstance functionInstance ,
958
962
JsValue [ ] argumentsList ,
959
- LexicalEnvironment env )
963
+ EnvironmentRecord env )
960
964
{
961
965
var func = functionInstance . _functionDefinition ;
962
966
963
- var envRec = ( FunctionEnvironmentRecord ) env . _record ;
967
+ var envRec = ( FunctionEnvironmentRecord ) env ;
964
968
var strict = StrictModeScope . IsStrictModeCode ;
965
969
966
970
var configuration = func . Initialize ( this , functionInstance ) ;
@@ -1010,7 +1014,7 @@ internal ArgumentsInstance FunctionDeclarationInstantiation(
1010
1014
// Else,
1011
1015
// Perform ? IteratorBindingInitialization for formals with iteratorRecord and env as arguments.
1012
1016
1013
- LexicalEnvironment varEnv ;
1017
+ EnvironmentRecord varEnv ;
1014
1018
DeclarativeEnvironmentRecord varEnvRec ;
1015
1019
if ( ! hasParameterExpressions )
1016
1020
{
@@ -1028,8 +1032,8 @@ internal ArgumentsInstance FunctionDeclarationInstantiation(
1028
1032
{
1029
1033
// NOTE: A separate Environment Record is needed to ensure that closures created by expressions
1030
1034
// in the formal parameter list do not have visibility of declarations in the function body.
1031
- varEnv = LexicalEnvironment . NewDeclarativeEnvironment ( this , env ) ;
1032
- varEnvRec = ( DeclarativeEnvironmentRecord ) varEnv . _record ;
1035
+ varEnv = JintEnvironment . NewDeclarativeEnvironment ( this , env ) ;
1036
+ varEnvRec = ( DeclarativeEnvironmentRecord ) varEnv ;
1033
1037
1034
1038
UpdateVariableEnvironment ( varEnv ) ;
1035
1039
@@ -1044,10 +1048,10 @@ internal ArgumentsInstance FunctionDeclarationInstantiation(
1044
1048
// NOTE: Annex B.3.3.1 adds additional steps at this point.
1045
1049
// A https://tc39.es/ecma262/#sec-web-compat-functiondeclarationinstantiation
1046
1050
1047
- LexicalEnvironment lexEnv ;
1051
+ EnvironmentRecord lexEnv ;
1048
1052
if ( ! strict )
1049
1053
{
1050
- lexEnv = LexicalEnvironment . NewDeclarativeEnvironment ( this , varEnv ) ;
1054
+ lexEnv = JintEnvironment . NewDeclarativeEnvironment ( this , varEnv ) ;
1051
1055
// NOTE: Non-strict functions use a separate lexical Environment Record for top-level lexical declarations
1052
1056
// so that a direct eval can determine whether any var scoped declarations introduced by the eval code conflict
1053
1057
// with pre-existing top-level lexically scoped declarations. This is not needed for strict functions
@@ -1058,7 +1062,7 @@ internal ArgumentsInstance FunctionDeclarationInstantiation(
1058
1062
lexEnv = varEnv ;
1059
1063
}
1060
1064
1061
- var lexEnvRec = lexEnv . _record ;
1065
+ var lexEnvRec = lexEnv ;
1062
1066
1063
1067
UpdateLexicalEnvironment ( lexEnv ) ;
1064
1068
@@ -1077,7 +1081,7 @@ internal ArgumentsInstance FunctionDeclarationInstantiation(
1077
1081
1078
1082
private void InitializeFunctions (
1079
1083
LinkedList < FunctionDeclaration > functionsToInitialize ,
1080
- LexicalEnvironment lexEnv ,
1084
+ EnvironmentRecord lexEnv ,
1081
1085
DeclarativeEnvironmentRecord varEnvRec )
1082
1086
{
1083
1087
foreach ( var f in functionsToInitialize )
@@ -1129,14 +1133,14 @@ private ArgumentsInstance CreateUnmappedArgumentsObject(JsValue[] argumentsList)
1129
1133
/// </summary>
1130
1134
internal void EvalDeclarationInstantiation (
1131
1135
Script script ,
1132
- LexicalEnvironment varEnv ,
1133
- LexicalEnvironment lexEnv ,
1136
+ EnvironmentRecord varEnv ,
1137
+ EnvironmentRecord lexEnv ,
1134
1138
bool strict )
1135
1139
{
1136
1140
var hoistingScope = HoistingScope . GetProgramLevelDeclarations ( script ) ;
1137
1141
1138
- var lexEnvRec = ( DeclarativeEnvironmentRecord ) lexEnv . _record ;
1139
- var varEnvRec = varEnv . _record ;
1142
+ var lexEnvRec = ( DeclarativeEnvironmentRecord ) lexEnv ;
1143
+ var varEnvRec = varEnv ;
1140
1144
1141
1145
if ( ! strict && hoistingScope . _variablesDeclarations != null )
1142
1146
{
@@ -1156,9 +1160,9 @@ internal void EvalDeclarationInstantiation(
1156
1160
}
1157
1161
1158
1162
var thisLex = lexEnv ;
1159
- while ( thisLex != varEnv )
1163
+ while ( ! ReferenceEquals ( thisLex , varEnv ) )
1160
1164
{
1161
- var thisEnvRec = thisLex . _record ;
1165
+ var thisEnvRec = thisLex ;
1162
1166
if ( ! ( thisEnvRec is ObjectEnvironmentRecord ) )
1163
1167
{
1164
1168
ref readonly var nodes = ref hoistingScope . _variablesDeclarations ;
@@ -1173,7 +1177,7 @@ internal void EvalDeclarationInstantiation(
1173
1177
}
1174
1178
}
1175
1179
1176
- thisLex = thisLex . _outer ;
1180
+ thisLex = thisLex . _outerEnv ;
1177
1181
}
1178
1182
}
1179
1183
@@ -1295,13 +1299,13 @@ internal void EvalDeclarationInstantiation(
1295
1299
}
1296
1300
1297
1301
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
1298
- internal void UpdateLexicalEnvironment ( LexicalEnvironment newEnv )
1302
+ internal void UpdateLexicalEnvironment ( EnvironmentRecord newEnv )
1299
1303
{
1300
1304
_executionContexts . ReplaceTopLexicalEnvironment ( newEnv ) ;
1301
1305
}
1302
1306
1303
1307
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
1304
- internal void UpdateVariableEnvironment ( LexicalEnvironment newEnv )
1308
+ internal void UpdateVariableEnvironment ( EnvironmentRecord newEnv )
1305
1309
{
1306
1310
_executionContexts . ReplaceTopVariableEnvironment ( newEnv ) ;
1307
1311
}
0 commit comments