@@ -8,6 +8,7 @@ This Source Code Form is subject to the terms of the
88using System ;
99using System . Collections . Generic ;
1010using System . Diagnostics ;
11+ using System . Linq ;
1112using ScriptEngine . Machine . Contexts ;
1213
1314namespace ScriptEngine . Machine
@@ -58,25 +59,28 @@ public static IEnumerable<VariableInfo> GetProperties(this IRuntimeContextInstan
5859 private static IEnumerable < VariableInfo > GetPropertiesWithPrivate ( IRuntimeContextInstance context )
5960 {
6061 if ( ! ( context is UserScriptContextInstance userScript ) )
61- return Array . Empty < VariableInfo > ( ) ;
62+ return GetPropertiesWithoutPrivate ( context ) ;
6263
63- List < VariableInfo > infos = new List < VariableInfo > ( ) ;
64- foreach ( var variable in userScript . Module . Variables )
64+ var infos = new List < VariableInfo > ( ) ;
65+ for ( int i = 1 ; i < userScript . GetOwnPropCount ( ) ; i ++ ) // skip ThisObject == _ownProperties[0]
6566 {
6667 infos . Add ( new VariableInfo ( ) {
67- Identifier = variable . Identifier ,
68- Type = variable . Type ,
69- Index = variable . Index ,
70- Annotations = HackGetAnnotations ( context , variable . Index ) ,
71- IsExport = variable . IsExport
68+ Identifier = userScript . GetPropName ( i ) ,
69+ Type = SymbolType . ContextProperty ,
70+ Index = i ,
71+ Annotations = Array . Empty < AnnotationDefinition > ( ) ,
72+ IsExport = false
7273 } ) ;
7374 }
7475
75- return infos ;
76+ return infos . Concat ( userScript . Module . Variables ) ;
7677 }
7778
7879 private static IEnumerable < VariableInfo > GetPropertiesWithoutPrivate ( IRuntimeContextInstance context )
7980 {
81+ if ( context is UserScriptContextInstance userScript )
82+ return userScript . Module . Variables . Where ( x => x . IsExport ) . ToList ( ) ;
83+
8084 VariableInfo [ ] infos = new VariableInfo [ context . GetPropCount ( ) ] ;
8185 for ( int i = 0 ; i < infos . Length ; i ++ )
8286 {
@@ -85,26 +89,14 @@ private static IEnumerable<VariableInfo> GetPropertiesWithoutPrivate(IRuntimeCon
8589 Identifier = context . GetPropName ( i ) ,
8690 Type = SymbolType . ContextProperty ,
8791 Index = i ,
88- Annotations = HackGetAnnotations ( context , i ) ,
92+ Annotations = Array . Empty < AnnotationDefinition > ( ) ,
8993 IsExport = true
9094 } ;
9195 }
9296
9397 return infos ;
9498 }
9599
96- private static AnnotationDefinition [ ] HackGetAnnotations ( IRuntimeContextInstance context , int i )
97- {
98- if ( ! ( context is UserScriptContextInstance userScript ) )
99- return Array . Empty < AnnotationDefinition > ( ) ;
100-
101- if ( i == 0 )
102- return Array . Empty < AnnotationDefinition > ( ) ;
103-
104- var variable = userScript . Module . Variables [ i - 1 ] ;
105- return variable . Annotations ;
106- }
107-
108100 public static IValue GetPropValue ( this IRuntimeContextInstance context , string propName )
109101 {
110102 int propNum = context . FindProperty ( propName ) ;
0 commit comments