@@ -20,7 +20,6 @@ public class QuickJSEngine : IJavaScriptEngine
2020 public object NativeEngine => Runtime ;
2121 public EngineCapabilities Capabilities { get ; } = EngineCapabilities . None ;
2222
23- private ReactContext Context ;
2423 private Action < IJavaScriptEngine > OnInitialize ;
2524
2625 public ScriptRuntime Runtime { get ; private set ; }
@@ -35,13 +34,8 @@ public class QuickJSEngine : IJavaScriptEngine
3534 public QuickJSEngine ( ReactContext context , bool debug , bool awaitDebugger , Action < IJavaScriptEngine > onInitialize )
3635 {
3736 OnInitialize = onInitialize ;
38- Context = context ;
3937
40- #if JSB_UNITYLESS
41- var logger = new DefaultScriptLogger ( ) ;
42- #else
4338 var logger = new QuickJSLogger ( ) ;
44- #endif
4539
4640 Runtime = ScriptEngine . CreateRuntime ( context . IsEditorContext ) ;
4741 Runtime . AddModuleResolvers ( ) ;
@@ -50,37 +44,29 @@ public QuickJSEngine(ReactContext context, bool debug, bool awaitDebugger, Actio
5044 {
5145 withDebugServer = debug ,
5246 waitingForDebugger = awaitDebugger ,
53- fileSystem = GetFileSystem ( context , logger ) ,
47+ fileSystem = new DefaultFileSystem ( logger ) ,
5448 asyncManager = new DefaultAsyncManager ( ) ,
5549 logger = logger ,
56- binder = DefaultBinder . GetBinder ( true ) ,
50+ binder = InvokeReflectBinding ,
5751 debugServerPort = 9222 ,
5852 byteBufferAllocator = new QuickJS . IO . ByteBufferPooledAllocator ( ) ,
5953 pathResolver = new PathResolver ( ) ,
6054 } ) ;
6155 }
6256
63- private IFileSystem GetFileSystem ( ReactContext ctx , IScriptLogger logger )
57+ public static void InvokeReflectBinding ( ScriptRuntime runtime )
6458 {
65- #if JSB_UNITYLESS
66- return new DefaultFileSystem ( logger ) ;
67- #else
68- if ( ctx . Source . IsDevServer ) return new DefaultFileSystem ( logger ) ;
69-
70- switch ( ctx . Source . Type )
59+ var bm = new BindingManager ( new Prefs { } , new BindingManager . Args
7160 {
72- case ScriptSourceType . TextAsset :
73- case ScriptSourceType . File :
74- return new DefaultFileSystem ( logger ) ;
75- case ScriptSourceType . Url :
76- case ScriptSourceType . Resource :
77- case ScriptSourceType . Raw :
78- default :
79- return new ResourcesFileSystem ( logger ) ;
80- }
81- #endif
61+ bindingCallback = new ReflectBindingCallback ( runtime ) ,
62+ bindingLogger = new DefaultBindingLogger ( LogLevel . Error ) ,
63+ } ) ;
64+ bm . Collect ( ) ;
65+ bm . Generate ( TypeBindingFlags . None ) ;
66+ bm . Report ( ) ;
8267 }
8368
69+
8470 private void Runtime_OnInitialized ( ScriptRuntime obj )
8571 {
8672 MainContext = Runtime . GetMainContext ( ) ;
@@ -179,7 +165,6 @@ public void Dispose()
179165 MainContext = null ;
180166 TypeRegister = null ;
181167 ObjectCache = null ;
182- Context = null ;
183168
184169 Runtime . Shutdown ( ) ;
185170 Runtime = null ;
@@ -218,7 +203,6 @@ public IJavaScriptEngine Create(ReactContext context, bool debug, bool awaitDebu
218203 }
219204 }
220205
221- #if ! JSB_UNITYLESS
222206 internal class QuickJSLogger : IScriptLogger
223207 {
224208 public void WriteException ( Exception exception )
@@ -260,6 +244,5 @@ public void Write(LogLevel ll, string fmt, params object[] args)
260244 }
261245 }
262246 }
263- #endif
264247}
265248#endif
0 commit comments