public InternalHandle setInterval(V8Engine engine, bool isConstructCall, InternalHandle _this, params InternalHandle[] args) { if (isConstructCall) { return(_this); } else { if (args != null && args.Length == 2) { InternalHandle timerCallback = args[0]; InternalHandle milliseconds = args[1]; if (milliseconds != null && milliseconds.IsInt32 && timerCallback != null && timerCallback.IsFunction) { int ms = milliseconds.AsInt32; string sourceFragment = timerCallback.Value.ToString(); System.Timers.Timer tmr = new System.Timers.Timer(); tmr.Interval = milliseconds.AsInt32; tmr.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) => { if (!engine.IsDisposed) { try { engine.Execute("____$=" + sourceFragment + ";____$();", ScriptingEngine.SOURCE_NAME, false); } catch { } } else { tmr.Stop(); } }; tmr.Start(); timers.Add(tmr); Handle timerHandle = engine.CreateValue(timers.Count - 1); return(timerHandle); } } } return(InternalHandle.Empty); }
public InternalHandle showDevTools(V8Engine engine, bool isConstructCall, InternalHandle _this, InternalHandle[] args) { if (browser != null) { //var host = browser.GetHost(); //var wi = CefWindowInfo.Create(); //var parentWindowHandle = NativeMethods.gdk_x11_drawable_get_xid(IntPtr.Zero); //wi.SetAsChild(parentWindowHandle, new CefRectangle(0, 0, 0, 0)); //host.ShowDevTools(wi, new WebClient(null), new CefBrowserSettings(), new CefPoint(0, 0)); } return(Engine.CreateNullValue()); }
/// <summary> /// JavaScript callback. Returns character indexes of selected text: object with <code>start</code> /// and <code>end</code> properties.If there's no selection, should return object with /// <code>start</code> and <code>end</code> properties referring to current caret position. /// </summary> public InternalHandle GetSelectionRange( V8Engine engine, bool isConstructCall, InternalHandle self, params InternalHandle[] args) { var selection = _editor.GetSelectionRange(); ObjectHandle retVal = engine.CreateObject(); retVal.SetProperty("start", engine.CreateValue(selection.Start)); retVal.SetProperty("end", engine.CreateValue(selection.End)); return(retVal); }
/// <summary> /// JavaScript callback. Returns current selection. /// </summary> public InternalHandle GetSelection( V8Engine engine, bool isConstructCall, InternalHandle self, params InternalHandle[] args) { string selection = _editor.GetSelection(); if (string.IsNullOrEmpty(selection)) { return(engine.CreateValue(string.Empty)); } return(engine.CreateValue(selection)); }
/// <summary> /// JavaScript callback. Asks user to enter something. /// </summary> public InternalHandle Prompt( V8Engine engine, bool isConstructCall, InternalHandle self, params InternalHandle[] args) { string input = _editor.Prompt(); if (string.IsNullOrWhiteSpace(input)) { return(engine.CreateNullValue()); } return(engine.CreateValue(input)); }
/// <summary> /// 执行js V8方法 /// </summary> /// <param name="reString">Js代码</param> /// <param name="para">参数字符串(使用逗号分隔)</param> /// <param name="MethodName">方法名称</param> public static string V8Method(string reString, string para, string MethodName) { V8Engine engine = V8Engine.Create(); //创建V8对象 V8Script script = engine.Compile(reString); //编译 try { engine.Execute(script); //将编译的脚本加载到V8引擎中 string res = engine.Execute(string.Format("{0}({1})", MethodName, para)).ToString(); //执行结果 return(res); } catch (Exception ex) { return(ex.Message);//异常信息 } }
/// <summary> /// JavaScript callback. Returns file extension in lower case. /// </summary> public InternalHandle GetExtension( V8Engine engine, bool isConstructorCall, InternalHandle self, params InternalHandle[] args) { if (args.Length != 1) { this.TraceError("IEmmetFile getExt called with invalid number of arguments."); return(engine.CreateValue(false)); } string filePath = args[0].AsString; return(engine.CreateValue(Path.GetExtension(filePath).ToLowerInvariant())); }
private void InitializeEngine() { this.Trace("Started initializing Emmet engine."); _engine = new V8Engine(); var compiler = new EngineCompiler(_engine); compiler.CompileCore(); compiler.RegisterCallbacks(_editor); if (null != _extensionsDir) { compiler.LoadExtensions(_extensionsDir); } this.Trace("Emmet engine successfully initialized."); }
/// <summary> /// JavaScript callback. Saves the specified content to the file with the specified name. /// </summary> public InternalHandle Save( V8Engine engine, bool isConstructorCall, InternalHandle self, params InternalHandle[] args) { if (args.Length != 2) { this.TraceError("IEmmetFile save called with invalid number of arguments."); return(engine.CreateValue(false)); } string filePath = args[0].AsString; string content = args[1].AsString; File.WriteAllText(filePath, content); return(engine.CreateValue(true)); }
/// <summary> /// JavaScript callback. Creates selection from <code>start</code> to <code>end</code> character /// indexes. If <code>end</code> is omitted, this method should place caret and <code>start</code> /// index. /// </summary> public InternalHandle CreateSelection( V8Engine engine, bool isConstructCall, InternalHandle self, params InternalHandle[] args) { if (args.Length == 2) { int start = args[0].AsInt32; int end = args[0].AsInt32; _editor.CreateSelection(start, end); } else { return(SetCarretPos(engine, isConstructCall, self, args)); } return(engine.CreateValue(true)); }
public InternalHandle TestJSFunction1(V8Engine engine, bool isConstructCall, InternalHandle _this, params InternalHandle[] args) { // ... there can be two different returns based on the call mode! ... // (tip: if a new object is created and returned instead (such as V8ManagedObject or an object derived from it), then that object will be the new object (instead of "_this")) if (isConstructCall) { var obj = engine.GetObject(_this); obj.AsDynamic.x = args[0]; ((dynamic)obj).y = 0; // (native objects in this case will always be V8NativeObject dynamic objects) obj.SetProperty(0, engine.CreateValue(100)); obj.SetProperty("1", engine.CreateValue(100.2)); obj.SetProperty("2", engine.CreateValue("300")); obj.SetProperty(4, engine.CreateValue(new DateTime(2013, 1, 2, 3, 4, 5, DateTimeKind.Utc))); return(_this); } else { return(args.Length > 0 ? args[0] : InternalHandle.Empty); } }
public static IEngine GetCarEngine(string choice) { IEngine carEngine = null; switch (choice) { case "1": carEngine = new V4Engine(); carEngine.SetEngineType(TypeOfEngine.V4); carEngine.SetMaximumSpeed(100); break; case "2": carEngine = new V8Engine(); carEngine.SetEngineType(TypeOfEngine.V8); carEngine.SetMaximumSpeed(200); break; case "3": carEngine = new GLXEngine(); carEngine.SetEngineType(TypeOfEngine.GLX); carEngine.SetMaximumSpeed(80); break; } return carEngine; }