Ejemplo n.º 1
0
        private MethodInfo GetStaticBind(IScriptLogger logger)
        {
            var bindAll = typeof(Values).GetMethod("BindAll", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);

            if (bindAll == null)
            {
                throw new Exception("generate binding code before run");
            }

            var codeGenVersionField = typeof(Values).GetField("CodeGenVersion");

            if (codeGenVersionField == null || !codeGenVersionField.IsStatic || !codeGenVersionField.IsLiteral || codeGenVersionField.FieldType != typeof(uint))
            {
                throw new Exception("binding code version mismatch");
            }

            var codeGenVersion = (uint)codeGenVersionField.GetValue(null);

            if (codeGenVersion != ScriptEngine.VERSION)
            {
                if (logger != null)
                {
                    logger.Write(LogLevel.Warn, "CodeGenVersion: {0} != {1}", codeGenVersion, ScriptEngine.VERSION);
                }
            }

            return(bindAll);
        }
Ejemplo n.º 2
0
        private void testCode(Assembly assembly, IScriptLogger logger)
        {
            var scriptLoggerType = GetFirstLoggerHost(assembly.GetTypes());

            if (scriptLoggerType != null)
            {
                var scriptLogger = Activator.CreateInstance(scriptLoggerType) as IScriptLoggerHost;
                scriptLogger.Execute(logger);
            }
        }
Ejemplo n.º 3
0
        public void Initialize(IFileSystem fileSystem, IFileResolver resolver, IScriptRuntimeListener listener, IScriptLogger logger, IO.IByteBufferAllocator byteBufferAllocator)
        {
            if (logger == null)
            {
                throw new NullReferenceException(nameof(logger));
            }

            if (fileSystem == null)
            {
                throw new NullReferenceException(nameof(fileSystem));
            }

            MethodInfo bindAll = null;

            if (!isWorker)
            {
                if (listener == null)
                {
                    throw new NullReferenceException(nameof(listener));
                }

                bindAll = typeof(Values).GetMethod("BindAll", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                if (bindAll == null)
                {
                    throw new Exception("Generate binding code before run");
                }
            }
            _listener            = listener;
            _fileResolver        = resolver;
            _byteBufferAllocator = byteBufferAllocator;
            _autorelease         = new Utils.AutoReleasePool();
            _fileSystem          = fileSystem;
            _logger       = logger;
            _timerManager = new TimerManager(_logger);
            _typeDB       = new TypeDB(this, _mainContext);

            var register = new TypeRegister(this, _mainContext);

            register.RegisterType(typeof(ScriptBridge));
            // await Task.Run(() => runner.OnBind(this, register));
            if (bindAll != null)
            {
                bindAll.Invoke(null, new object[] { register });
            }
            listener.OnBind(this, register);
            if (!_isWorker)
            {
                JSWorker.Bind(register);
            }
            TimerManager.Bind(register);
            ScriptContext.Bind(register);
            register.Finish();
            listener.OnComplete(this);
        }
Ejemplo n.º 4
0
        public static IHttpWebScrapper Create(
            ISongRequestScriptSettings settings,
            IScriptLogger logger)
        {
            logger.Info($"Creating web scrapper for driver '{settings.SelectedBrowserDriver.Value}'.");
            logger.Info($"WebDriver path: [{settings.BrowserDriverPath.Value}].");
            logger.Info($"WebDriver executable name: [{settings.BrowserDriverExecutableName.GetFullFilename()}].");

            var webDriver = CreateWebDriver(settings, logger);

            return(new HttpWebScrapper(settings, logger, webDriver));
        }
Ejemplo n.º 5
0
 private DriverProvider(
     IScriptLogger logger,
     CustomDriverManager customDriverManager,
     IDriverConfig driverConfig,
     DriverVersion driverVersion,
     Architecture architecture)
 {
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
     _customDriverManager = customDriverManager ?? throw new ArgumentNullException(nameof(customDriverManager));
     _driverConfig        = driverConfig ?? throw new ArgumentNullException(nameof(driverConfig));
     _driverVersion       = driverVersion ?? throw new ArgumentNullException(nameof(driverVersion));
     _architecture        = architecture;
 }
Ejemplo n.º 6
0
        public void print_exception(IScriptLogger logger, LogLevel logLevel, string title)
        {
            var ex = JSApi.JS_GetException(this);

            if (logger != null)
            {
                var err_fileName   = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_fileName);
                var err_lineNumber = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_lineNumber);
                var err_message    = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_message);
                var err_stack      = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_stack);

                var fileName   = err_fileName.IsNullish() ? "native" : GetString(err_fileName);
                var lineNumber = err_lineNumber.IsNullish() ? null : GetString(err_lineNumber);
                var message    = GetString(err_message);
                var stack      = GetString(err_stack);

                if (string.IsNullOrEmpty(lineNumber))
                {
                    if (string.IsNullOrEmpty(stack))
                    {
                        logger.Write(logLevel, "[{0}] {1} {2}",
                                     fileName, title, message);
                    }
                    else
                    {
                        logger.Write(logLevel, "[{0}] {1} {2}\nJavascript stack:\n{3}",
                                     fileName, title, message, stack);
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(stack))
                    {
                        logger.Write(logLevel, "[{0}:{1}] {2} {3}",
                                     fileName, lineNumber, title, message);
                    }
                    else
                    {
                        logger.Write(logLevel, "[{0}:{1}] {2} {3}\nJavascript stack:\n{4}",
                                     fileName, lineNumber, title, message, stack);
                    }
                }

                JSApi.JS_FreeValue(this, err_fileName);
                JSApi.JS_FreeValue(this, err_lineNumber);
                JSApi.JS_FreeValue(this, err_message);
                JSApi.JS_FreeValue(this, err_stack);
            }

            JSApi.JS_FreeValue(this, ex);
        }
        internal HttpWebScrapper(
            ISongRequestScriptSettings settings,
            IScriptLogger logger,
            IWebDriver webDriver)
        {
            _settings  = settings ?? throw new ArgumentNullException(nameof(settings));
            _logger    = logger ?? throw new ArgumentNullException(nameof(logger));
            _webDriver = webDriver ?? throw new ArgumentNullException(nameof(webDriver));

            _newSongTextFieldLazy  = new Lazy <IWebElement>(() => FindNewSongTextField());
            _addSongButtonLazy     = new Lazy <IWebElement>(() => FindAddSongButton());
            _skipSongButtonLazy    = new Lazy <IWebElement>(() => FindSkipSongButton());
            _removeQueueButtonLazy = new Lazy <IWebElement>(() => FindRemoveQueueSongButton());
        }
Ejemplo n.º 8
0
        public static DriverProvider Create(
            IScriptLogger logger,
            FilePath driverPath,
            FileName driverExecutableName,
            IDriverConfig driverConfig,
            DriverVersion driverVersion,
            Architecture architecture = Architecture.Auto)
        {
            var driverManager = CustomDriverManager.Create(driverPath, driverExecutableName);

            return(new DriverProvider(
                       logger: logger,
                       customDriverManager: driverManager,
                       driverConfig: driverConfig,
                       driverVersion: driverVersion,
                       architecture: architecture
                       ));
        }
Ejemplo n.º 9
0
        public static DriverProvider Create(
            ISongRequestScriptSettings settings,
            IScriptLogger logger,
            Architecture architecture = Architecture.Auto)
        {
            return(settings.SelectedBrowserDriver.Value switch
            {
                WebDriverType.RawEdgeDriver => CreateForEdge(settings, logger, architecture),

                WebDriverType.RawChromeDriver => CreateForChrome(settings, logger, architecture),

                WebDriverType.RawFirefoxDriver => CreateForFirefox(settings, logger, architecture),

                WebDriverType.RawOperaDriver => CreateForOpera(settings, logger, architecture),

                _ => throw new ArgumentOutOfRangeException(
                    nameof(settings.SelectedBrowserDriver),
                    settings.SelectedBrowserDriver,
                    $"Unexpected webdriver type value: '{settings.SelectedBrowserDriver.Value}'."
                    )
            });
Ejemplo n.º 10
0
        private MethodInfo GetReflectBind(IScriptLogger logger)
        {
            var UnityHelper = Values.FindType("QuickJS.Unity.UnityHelper");

            if (UnityHelper != null)
            {
                var IsReflectBindingSupported = UnityHelper.GetMethod("IsReflectBindingSupported");
                if (IsReflectBindingSupported != null && (bool)IsReflectBindingSupported.Invoke(null, null))
                {
                    var bindAll = UnityHelper.GetMethod("InvokeReflectBinding");
                    if (bindAll == null)
                    {
                        throw new Exception("failed to get method: UnityHelper.InvokeReflectBinding");
                    }

                    return(bindAll);
                }
            }

            return(null);
        }
Ejemplo n.º 11
0
 public Scheduler(IScriptLogger logger, int jiffies = 8, int slots = 160, int depth = 4, int prealloc = 50, int capacity = 500)
 {
     _threadId = Thread.CurrentThread.ManagedThreadId;
     _logger   = logger;
     _jiffies  = jiffies;
     _wheels   = new Wheel[depth];
     for (int i = 0; i < depth; i++)
     {
         int interval = 1;
         for (var j = 0; j < i; j++)
         {
             interval *= slots;
         }
         _wheels[i] = new Wheel(i, jiffies, jiffies * interval, slots);
     }
     _poolCapacity = capacity;
     while (prealloc-- > 0)
     {
         _pool.Add(new TimeHandle());
     }
 }
Ejemplo n.º 12
0
        private static IWebDriver CreateWebDriver(
            ISongRequestScriptSettings settings,
            IScriptLogger logger)
        {
            EnsureBrowserDriverIsInstalled(settings, logger);

            return(settings.SelectedBrowserDriver.Value switch
            {
                WebDriverType.RawEdgeDriver => CreateEdgeDriver(settings),

                WebDriverType.RawChromeDriver => CreateChromeDriver(settings),

                WebDriverType.RawFirefoxDriver => CreateFirefoxDriver(settings),

                WebDriverType.RawOperaDriver => CreateOperaDriver(settings),

                _ => throw new ArgumentOutOfRangeException(
                    nameof(settings.SelectedBrowserDriver),
                    settings.SelectedBrowserDriver,
                    $"Unexpected webdriver type value: '{settings.SelectedBrowserDriver.Value}'."
                    )
            });
Ejemplo n.º 13
0
        public void Initialize(IFileSystem fileSystem, IScriptRuntimeListener runner, IScriptLogger logger, IO.ByteBufferAllocator byteBufferAllocator, int step = 30)
        {
            if (logger == null)
            {
                throw new NullReferenceException(nameof(logger));
            }
            if (runner == null)
            {
                throw new NullReferenceException(nameof(runner));
            }
            if (fileSystem == null)
            {
                throw new NullReferenceException(nameof(fileSystem));
            }
            var bindAll = typeof(Values).GetMethod("BindAll");

            if (bindAll == null)
            {
                throw new Exception("Generate binding code before run");
            }
            _byteBufferAllocator = byteBufferAllocator;
            _fileSystem          = fileSystem;
            _logger = logger;

            _typeDB = new TypeDB(this, _mainContext);
            var register = new TypeRegister(this, _mainContext);

            register.RegisterType(typeof(ScriptBridge));
            // await Task.Run(() => runner.OnBind(this, register));
            bindAll.Invoke(null, new object[] { register });
            runner.OnBind(this, register);
            TimerManager.Bind(register);
            ScriptContext.Bind(register);
            register.Finish();
            runner.OnComplete(this);
        }
Ejemplo n.º 14
0
 public HttpFileSystem(IScriptLogger logger, string baseUrl)
 {
     _url    = baseUrl;
     _logger = logger;
 }
Ejemplo n.º 15
0
 public ResourcesFileSystem(IScriptLogger logger)
 {
     _logger = logger;
 }
Ejemplo n.º 16
0
        public void Initialize(IFileSystem fileSystem, IPathResolver resolver, IScriptRuntimeListener listener, IScriptLogger logger, IO.IByteBufferAllocator byteBufferAllocator)
        {
            if (logger == null)
            {
                throw new NullReferenceException(nameof(logger));
            }

            if (fileSystem == null)
            {
                throw new NullReferenceException(nameof(fileSystem));
            }

            MethodInfo bindAll = null;

            if (!isWorker)
            {
                if (listener == null)
                {
                    throw new NullReferenceException(nameof(listener));
                }

                bindAll = typeof(Values).GetMethod("BindAll", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                if (bindAll == null)
                {
                    throw new Exception("generate binding code before run");
                }

                var codeGenVersionField = typeof(Values).GetField("CodeGenVersion");
                if (codeGenVersionField == null || !codeGenVersionField.IsStatic || !codeGenVersionField.IsLiteral || codeGenVersionField.FieldType != typeof(uint))
                {
                    throw new Exception("binding code version mismatch");
                }

                var codeGenVersion = (uint)codeGenVersionField.GetValue(null);
                if (codeGenVersion != ScriptEngine.VERSION)
                {
                    if (logger != null)
                    {
                        logger.Write(LogLevel.Warn, "CodeGenVersion: {0} != {1}", codeGenVersion, ScriptEngine.VERSION);
                    }
                }
            }

            _isValid   = true;
            _isRunning = true;
            // _rwlock = new ReaderWriterLockSlim();
            _rt = JSApi.JS_NewRuntime();
            JSApi.JS_SetHostPromiseRejectionTracker(_rt, JSApi.PromiseRejectionTracker, IntPtr.Zero);
            JSApi.JS_SetRuntimeOpaque(_rt, (IntPtr)_runtimeId);
            JSApi.JS_SetModuleLoaderFunc(_rt, module_normalize, module_loader, IntPtr.Zero);
            CreateContext();
            JSApi.JS_NewClass(_rt, JSApi.JSB_GetBridgeClassID(), "CSharpClass", JSApi.class_finalizer);

            _listener            = listener;
            _pathResolver        = resolver;
            _byteBufferAllocator = byteBufferAllocator;
            _autorelease         = new Utils.AutoReleasePool();
            _fileSystem          = fileSystem;
            _logger       = logger;
            _objectCache  = new ObjectCache(_logger);
            _timerManager = new TimerManager(_logger);
            _typeDB       = new TypeDB(this, _mainContext);
            listener.OnCreate(this);

            var register = new TypeRegister(this, _mainContext);

            register.RegisterType(typeof(Unity.JSBehaviour));
#if UNITY_EDITOR
            register.RegisterType(typeof(Unity.JSEditorWindow));
#endif
            // await Task.Run(() => runner.OnBind(this, register));
            if (bindAll != null)
            {
                bindAll.Invoke(null, new object[] { register });
            }
            listener.OnBind(this, register);
            if (!_isWorker)
            {
                JSWorker.Bind(register);
            }
            TimerManager.Bind(register);
            ScriptContext.Bind(register);
            register.Finish();
            listener.OnComplete(this);
        }
Ejemplo n.º 17
0
        // this method will be marked as private in the future
        public void Initialize(IFileSystem fileSystem, IPathResolver resolver, IScriptRuntimeListener listener, IAsyncManager asyncManager, IScriptLogger logger, IO.IByteBufferAllocator byteBufferAllocator, bool useReflectBind = true)
        {
            if (fileSystem == null)
            {
                throw new NullReferenceException(nameof(fileSystem));
            }

            MethodInfo bindAll = null;

            if (!isWorker)
            {
                if (listener == null)
                {
                    throw new NullReferenceException(nameof(listener));
                }

#if UNITY_EDITOR
                bindAll        = (useReflectBind ? GetReflectBind(logger) : null) ?? GetStaticBind(logger);
                _isReflectBind = bindAll.Name == "InvokeReflectBinding";
                logger?.Write(LogLevel.Info, _isReflectBind ? "Running in ReflectBind mode" : "Running in StaticBind mode");
#else
                bindAll = GetStaticBind(logger);
#endif
            }

            asyncManager.Initialize(_mainThreadId);

            _isValid   = true;
            _isRunning = true;
            _logger    = logger;
            // _rwlock = new ReaderWriterLockSlim();
            _rt = JSApi.JS_NewRuntime();
            JSApi.JS_SetHostPromiseRejectionTracker(_rt, JSApi.PromiseRejectionTracker, IntPtr.Zero);
#if UNITY_EDITOR
            JSApi.JS_SetInterruptHandler(_rt, _InterruptHandler, IntPtr.Zero);
#else
            if (isWorker)
            {
                JSApi.JS_SetInterruptHandler(_rt, _InterruptHandler, IntPtr.Zero);
            }
#endif
            JSApi.JS_SetRuntimeOpaque(_rt, (IntPtr)_runtimeId);
            JSApi.JS_SetModuleLoaderFunc(_rt, module_normalize, module_loader, IntPtr.Zero);
            CreateContext();
            JSApi.JS_NewClass(_rt, JSApi.JSB_GetBridgeClassID(), "CSharpClass", JSApi.class_finalizer);

            _listener            = listener;
            _pathResolver        = resolver;
            _asyncManager        = asyncManager;
            _byteBufferAllocator = byteBufferAllocator;
            _autorelease         = new Utils.AutoReleasePool();
            _fileSystem          = fileSystem;
            _objectCache         = new ObjectCache(_logger);
            _timerManager        = new TimerManager(_logger);
            _typeDB = new TypeDB(this, _mainContext);
            _typeDB.AddType(typeof(Unity.JSBehaviour), JSApi.JS_UNDEFINED);
#if UNITY_EDITOR
            _typeDB.AddType(typeof(Unity.JSEditorWindow), JSApi.JS_UNDEFINED);
            _typeDB.AddType(typeof(Unity.JSBehaviourInspector), JSApi.JS_UNDEFINED);
#endif
            listener.OnCreate(this);

            // await Task.Run(() => runner.OnBind(this, register));
            if (bindAll != null)
            {
                bindAll.Invoke(null, new object[] { this });
            }

            var register = new TypeRegister(_mainContext);
            listener.OnBind(this, register);
            if (!_isWorker)
            {
                JSWorker.Bind(register);
            }
            TimerManager.Bind(register);
            register.Finish();

            AddStaticModule("jsb", ScriptContext.Bind);
            FindModuleResolver <StaticModuleResolver>().Warmup(_mainContext);

            listener.OnComplete(this);
        }
Ejemplo n.º 18
0
 public ObjectCache(IScriptLogger logger)
 {
     _logger = logger;
 }
Ejemplo n.º 19
0
        public void Initialize(IFileSystem fileSystem, IPathResolver resolver, IScriptRuntimeListener listener, IAsyncManager asyncManager, IScriptLogger logger, IO.IByteBufferAllocator byteBufferAllocator)
        {
            if (fileSystem == null)
            {
                throw new NullReferenceException(nameof(fileSystem));
            }

            MethodInfo bindAll = null;

            if (!isWorker)
            {
                if (listener == null)
                {
                    throw new NullReferenceException(nameof(listener));
                }

                bindAll = typeof(Values).GetMethod("BindAll", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                if (bindAll == null)
                {
#if UNITY_EDITOR
                    var throwError = true;
                    foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        var UnityHelper = assembly.GetType("QuickJS.Unity.UnityHelper");
                        if (UnityHelper != null)
                        {
                            var IsReflectBindingSupported = UnityHelper.GetMethod("IsReflectBindingSupported");
                            if (IsReflectBindingSupported != null)
                            {
                                if ((bool)IsReflectBindingSupported.Invoke(null, null))
                                {
                                    var InvokeReflectBinding = UnityHelper.GetMethod("InvokeReflectBinding");
                                    if (InvokeReflectBinding != null)
                                    {
                                        bindAll    = InvokeReflectBinding;
                                        throwError = false;
                                    }
                                }
                            }
                            break;
                        }
                    }

                    if (throwError)
                    {
                        throw new Exception("generate binding code before run");
                    }
#else
                    throw new Exception("generate binding code before run");
#endif
                }
                else
                {
                    var codeGenVersionField = typeof(Values).GetField("CodeGenVersion");
                    if (codeGenVersionField == null || !codeGenVersionField.IsStatic || !codeGenVersionField.IsLiteral || codeGenVersionField.FieldType != typeof(uint))
                    {
                        throw new Exception("binding code version mismatch");
                    }

                    var codeGenVersion = (uint)codeGenVersionField.GetValue(null);
                    if (codeGenVersion != ScriptEngine.VERSION)
                    {
                        if (logger != null)
                        {
                            logger.Write(LogLevel.Warn, "CodeGenVersion: {0} != {1}", codeGenVersion, ScriptEngine.VERSION);
                        }
                    }
                }
            }

            asyncManager.Initialize(_mainThreadId);

            _isValid   = true;
            _isRunning = true;
            // _rwlock = new ReaderWriterLockSlim();
            _rt = JSApi.JS_NewRuntime();
            JSApi.JS_SetHostPromiseRejectionTracker(_rt, JSApi.PromiseRejectionTracker, IntPtr.Zero);
#if UNITY_EDITOR
            JSApi.JS_SetInterruptHandler(_rt, _InterruptHandler, IntPtr.Zero);
#else
            if (isWorker)
            {
                JSApi.JS_SetInterruptHandler(_rt, _InterruptHandler, IntPtr.Zero);
            }
#endif
            JSApi.JS_SetRuntimeOpaque(_rt, (IntPtr)_runtimeId);
            JSApi.JS_SetModuleLoaderFunc(_rt, module_normalize, module_loader, IntPtr.Zero);
            CreateContext();
            JSApi.JS_NewClass(_rt, JSApi.JSB_GetBridgeClassID(), "CSharpClass", JSApi.class_finalizer);

            _listener            = listener;
            _pathResolver        = resolver;
            _asyncManager        = asyncManager;
            _byteBufferAllocator = byteBufferAllocator;
            _autorelease         = new Utils.AutoReleasePool();
            _fileSystem          = fileSystem;
            _logger       = logger;
            _objectCache  = new ObjectCache(_logger);
            _timerManager = new TimerManager(_logger);
            _typeDB       = new TypeDB(this, _mainContext);
            _typeDB.AddType(typeof(Unity.JSBehaviour), JSApi.JS_UNDEFINED);
#if UNITY_EDITOR
            _typeDB.AddType(typeof(Unity.JSEditorWindow), JSApi.JS_UNDEFINED);
            _typeDB.AddType(typeof(Unity.JSBehaviourInspector), JSApi.JS_UNDEFINED);
#endif
            listener.OnCreate(this);

            // await Task.Run(() => runner.OnBind(this, register));
            if (bindAll != null)
            {
                bindAll.Invoke(null, new object[] { this });
            }

            var register = new TypeRegister(_mainContext);
            listener.OnBind(this, register);
            if (!_isWorker)
            {
                JSWorker.Bind(register);
            }
            TimerManager.Bind(register);
            register.Finish();

            AddStaticModule("jsb", ScriptContext.Bind);
            FindModuleResolver <StaticModuleResolver>().Warmup(_mainContext);

            listener.OnComplete(this);
        }
Ejemplo n.º 20
0
 public TimerManager(IScriptLogger logger, int jiffies = 8, int slots = 160, int depth = 4, int prealloc = 50, int capacity = 500)
     : base(logger, jiffies, slots, depth, prealloc, capacity)
 {
 }
Ejemplo n.º 21
0
        // this method will be marked as private in the future
        public void Initialize(IFileSystem fileSystem, IPathResolver resolver, IAsyncManager asyncManager, IScriptLogger logger, IO.IByteBufferAllocator byteBufferAllocator, IBinder binder)
        {
            if (fileSystem == null)
            {
                throw new NullReferenceException(nameof(fileSystem));
            }

            asyncManager.Initialize(_mainThreadId);

            _isValid   = true;
            _isRunning = true;
            _logger    = logger;
            // _rwlock = new ReaderWriterLockSlim();
            _rt = JSApi.JS_NewRuntime();
            JSApi.JS_SetHostPromiseRejectionTracker(_rt, JSApi.PromiseRejectionTracker, IntPtr.Zero);
#if UNITY_EDITOR
            JSApi.JS_SetInterruptHandler(_rt, _InterruptHandler, IntPtr.Zero);
#else
            if (isWorker)
            {
                JSApi.JS_SetInterruptHandler(_rt, _InterruptHandler, IntPtr.Zero);
            }
#endif
            JSApi.JS_SetRuntimeOpaque(_rt, (IntPtr)_runtimeId);
            JSApi.JS_SetModuleLoaderFunc(_rt, module_normalize, module_loader, IntPtr.Zero);
            CreateContext();
            JSApi.JS_NewClass(_rt, JSApi.JSB_GetBridgeClassID(), "CSharpClass", JSApi.class_finalizer);

            _pathResolver        = resolver;
            _asyncManager        = asyncManager;
            _byteBufferAllocator = byteBufferAllocator;
            _autorelease         = new Utils.AutoReleasePool();
            _fileSystem          = fileSystem;
            _objectCache         = new ObjectCache(_logger);
            _timerManager        = new TimerManager(_logger);
            _typeDB = new TypeDB(this, _mainContext);
#if !JSB_UNITYLESS
            _typeDB.AddType(typeof(Unity.JSBehaviour), JSApi.JS_UNDEFINED);
#endif
#if UNITY_EDITOR
            _typeDB.AddType(Values.FindType("QuickJS.Unity.JSEditorWindow"), JSApi.JS_UNDEFINED);
            _typeDB.AddType(Values.FindType("QuickJS.Unity.JSBehaviourInspector"), JSApi.JS_UNDEFINED);
#endif

            // await Task.Run(() => runner.OnBind(this, register));
            try
            {
                binder?.Bind(this);
            }
            catch (Exception exception)
            {
                _logger?.WriteException(exception);
            }

            var register = new TypeRegister(_mainContext);
            if (!_isWorker)
            {
                JSWorker.Bind(register);
            }
            TimerManager.Bind(register);
            extraBinding?.Invoke(this, register);
            register.Finish();

            AddStaticModule("jsb", ScriptContext.Bind);
            FindModuleResolver <StaticModuleResolver>().Warmup(_mainContext);

            _isInitialized = true;
        }
Ejemplo n.º 22
0
 public DefaultFileSystem(IScriptLogger logger)
 {
     _logger = logger;
 }
Ejemplo n.º 23
0
 public ScriptExecutor(IScriptLogger logger)
 {
     _engineAssemblyName = GetType().Assembly.GetName().Name;
     Logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }