Esempio n. 1
0
        public void AddNativeModule(string name, object exports)
        {
            if (NativeModules.ContainsKey(name))
            {
                throw new InvalidOperationException("A native module with the same name already exists.");
            }

            NativeModules[name] = new NativeModule(name, loader, exports);
        }
Esempio n. 2
0
        public V8EngineCore(IModulePathResolver pathResolver, IModuleLoaderFactory loaderFactory, int iDebuggingPort)
        {
            // デバッグありモード
            if (iDebuggingPort > 0)
            {
                engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging, iDebuggingPort);
            }
            else
            {
                engine = new V8ScriptEngine();
            }

            engine.DefaultAccess = ScriptAccess.Full;
            engine.SuppressExtensionMethodEnumeration = true;
            engine.AllowReflection = true;

            Engine            = engine;
            this.pathResolver = pathResolver;
            NativeModules     = new Dictionary <string, Module>();
            Compilers         = new Dictionary <string, IModuleCompiler>();
            loader            = loaderFactory.Create(Engine, NativeModules, Compilers, pathResolver);

            var scriptCompiler = new ScriptCompiler();

            Compilers[".js"]   = scriptCompiler;
            Compilers[".json"] = new JsonCompiler();
            Compilers[".dll"]  = new DllCompiler();
            coreModule         = new NativeModule("core", loader, this);

            NativeModules["core"] = coreModule;
            //            NativeModules["host"] = new NativeModule("host", loader, new HostFunctions());
            //            NativeModules["xhost"] = new NativeModule("xhost", loader, new ExtendedHostFunctions());
            NativeModules["host"] = new NativeModule("host", loader, new ExtendedHostFunctions());

            engine.AddHostObject("clr", new HostTypeCollection("mscorlib", "System", "System.Core"));
            engine.AddHostObject("host", new ExtendedHostFunctions());

            foreach (var script in ScriptModules.Scripts.Keys)
            {
                NativeModules.Add(script, new ScriptModule(script, loader));
            }

            engine.Script.core = this;
            engine.Script.EngineInternal.isVoid = new Func <object, bool>(obj => obj is VoidResult);
            ExecuteWrapped(@"
                Object.defineProperty(this, 'global', { value: this, enumerable: true });
                var engineInternal = this.EngineInternal;
                delete this.EngineInternal;
                Object.defineProperty(this, 'EngineInternal', { value: engineInternal });
            ");

            Sleeping = true;
        }