public static IntPtr DestroyScope() { if (engine != null) { // FreeLibrary直前の関数の呼び出し。 try { DoString("DestroyScope()", "DestroyScope"); } catch (Exception) { } engine = null; } SetCodePage((IntPtr)default_codepage); iDllBindHandle = 0; tmpVar = null; iDebuggingPort = 0; dpr = null; core.Dispose(); core = null; return((IntPtr)0); }
public static string JSON2RJSON(string inpJson) { using (var engine = new Microsoft.ClearScript.V8.V8ScriptEngine()) { var script = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\RJSON.js"; if (!File.Exists(script)) script = Machines.rootPath + @"JsLib\JS\External\RJSON.js"; engine.Execute(script, File.ReadAllText(script)); var par = new rjsonObj { inpJson = inpJson }; engine.AddHostObject("inpJson", par); return (string)engine.Evaluate("JSON.stringify(RJSON.pack(JSON.parse(inpJson.inpJson)))"); } }
public void Compile(string source, object external) { _dispatcher.BeginInvoke(new Action(() => { var engine = new Microsoft.ClearScript.V8.V8ScriptEngine(); engine.AddHostObject("external", external); engine.Execute(source); engine.Dispose(); }), DispatcherPriority.ApplicationIdle, null); }
public static void JsReflection(string tsFileName, string jsonMapFn) { using (var engine = new Microsoft.ClearScript.V8.V8ScriptEngine()) { engine.Execute("typescript.js", File.ReadAllText(@"d:\LMCom\rew\Web4\JsLib\Scripts\typescript.js")); engine.Execute("underscore.js", File.ReadAllText(@"d:\LMCom\rew\Web4\JsLib\Scripts\underscore.js")); engine.Execute("GenerateReflection.js", File.ReadAllText(@"d:\LMCom\rew\Web4\Author\GenerateReflection.js")); var par = new reflectionObj { inpTSCode = File.ReadAllText(tsFileName) }; engine.AddHostObject("inpTSCode", par); File.WriteAllText(jsonMapFn + ".json", (string)engine.Evaluate("author.parseReflection(inpTSCode.inpTSCode, false)")); File.WriteAllText(jsonMapFn + ".debug.json", (string)engine.Evaluate("author.parseReflection(inpTSCode.inpTSCode, true)")); } }
public bool IsAvailable() { Trace.WriteLine("Checking to see if V8 is available"); if (V8ScriptEngine._isAvailable.HasValue) return V8ScriptEngine._isAvailable.Value; try { var engine = new Microsoft.ClearScript.V8.V8ScriptEngine(); engine.Dispose(); V8ScriptEngine._isAvailable = true; } catch (Exception) { V8ScriptEngine._isAvailable = false; } Trace.WriteLine(string.Format("V8 Engine is available: {0}", V8ScriptEngine._isAvailable.Value)); return V8ScriptEngine._isAvailable.Value; }
protected V8ArrayBufferView(V8ScriptEngine engine, IV8Object target) : base(engine, target) { }
public V8ArrayBuffer(V8ScriptEngine engine, IV8Object target) : base(engine, target) { }
public static object Wrap(V8ScriptEngine engine, object obj) { Debug.Assert(!(obj is IScriptMarshalWrapper)); if (obj == null) { return(null); } if (obj is IV8Object target) { if (target.IsArray()) { return(new V8Array(engine, target)); } if (!target.IsArrayBufferOrView()) { return(new V8ScriptItem(engine, target)); } switch (target.GetArrayBufferOrViewKind()) { case V8ArrayBufferOrViewKind.ArrayBuffer: return(new V8ArrayBuffer(engine, target)); case V8ArrayBufferOrViewKind.DataView: return(new V8DataView(engine, target)); case V8ArrayBufferOrViewKind.Uint8Array: case V8ArrayBufferOrViewKind.Uint8ClampedArray: return(new V8TypedArray <byte>(engine, target)); case V8ArrayBufferOrViewKind.Int8Array: return(new V8TypedArray <sbyte>(engine, target)); case V8ArrayBufferOrViewKind.Uint16Array: return(new V8UInt16Array(engine, target)); case V8ArrayBufferOrViewKind.Int16Array: return(new V8TypedArray <short>(engine, target)); case V8ArrayBufferOrViewKind.Uint32Array: return(new V8TypedArray <uint>(engine, target)); case V8ArrayBufferOrViewKind.Int32Array: return(new V8TypedArray <int>(engine, target)); case V8ArrayBufferOrViewKind.Float32Array: return(new V8TypedArray <float>(engine, target)); case V8ArrayBufferOrViewKind.Float64Array: return(new V8TypedArray <double>(engine, target)); default: return(new V8ScriptItem(engine, target)); } } return(obj); }
private V8ScriptItem(V8ScriptEngine engine, IV8Object target) { this.engine = engine; this.target = target; }
public V8UInt16Array(V8ScriptEngine engine, IV8Object target) : base(engine, target) { }
protected V8TypedArray(V8ScriptEngine engine, IV8Object target) : base(engine, target) { }
public V8DataView(V8ScriptEngine engine, IV8Object target) : base(engine, target) { }
private V8ScriptItem(V8ScriptEngine engine, IV8Object target) { this.engine = engine; this.target = target; engine.OnScriptItemCreate(this); }
//---------------------------------------------------------------------------------------------- public static IntPtr CreateScope() { // まだエンジンが作られていなければ if (engine == null) { try { core = CreateCore(); engine = core.Engine; core.ExposeGlobalRequire(); // requireが使えるように // 秀丸クラスの登録 hm = new Hidemaru(); engine.AddHostType("hm", typeof(Hidemaru)); // consoleの簡易版 console = new hmV8Console(); engine.AddHostType("console", typeof(hmV8Console)); // ①ヒアドキュメント用の関数 // ②:空のDestory関数 String expression = @" function R(text){ return text.toString().match(/\/\*([\s\S]*)\*\//)[1].toString(); } hm.Macro.Var = new Proxy(()=>{}, { apply: function(target, that, args) { if (args.length > 1 ) { return hm.Macro.__Var(args[0], args[1]); } else if (args.length == 1 ) { return hm.Macro.__Var(args[0]); } }, get(target, prop, receiver) { return hm.Macro.__Var(prop); }, set(target, prop, val, receiver) { return hm.Macro.__Var(prop, val); } } ) "; engine.Execute(expression); engine.Script.DestroyScope = new Action(() => { }); dpr = new DllPathResolver(); engine.AddHostObject("AssemblyPath", new List <String>()); // ヒアドキュメント用の関数 R(text) return((IntPtr)1); } catch (Exception e) { OutputDebugStream(e.Message); return((IntPtr)0); } } return((IntPtr)1); }