/// <summary> /// Finds and compiles Emmet source file. /// </summary> /// <exception cref="FileNotFoundException"> /// Indicates that Emmet script was not found. /// </exception> public void CompileCore() { string extensionFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string emmetScript = Path.Combine(extensionFolder, @"emmet-min.js"); if (!File.Exists(emmetScript)) { throw new FileNotFoundException("Emmet script not found.", emmetScript); } ObjectHandle window = _engine.CreateObject(); _engine.DynamicGlobalObject.window = window; Handle script = _engine.LoadScript(emmetScript, "Emmet"); if (script.IsError) { this.TraceError(script.AsString); throw new Exception <EmmetEngineExceptionArgs>( new EmmetEngineExceptionArgs("Failed to compile Emmet", script)); } else { this.Trace("Emmet core compiled successfully."); } }
internal void OnKeyDown(int keyCode, int charCode) { if (v8.IsDisposed) { return; } using (Handle functHandle = v8.Execute("document.onkeydown", SOURCE_NAME, false)) { if (functHandle.ValueType != JSValueType.CompilerError && functHandle.IsFunction) { InternalHandle obj = v8.CreateObject(); obj.SetProperty("keyCode", keyCode); obj.SetProperty("charCode", charCode); functHandle.AsInternalHandle.StaticCall(obj); } } }
/// <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); }
public V8EngineObject(CefBrowser browser, CefFrame frame, CefV8Context context) { configuration = Extension.GetConfiguration(); try { engine = new V8Engine(); engine.RegisterType(typeof(System.Object), "Object", true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(Type), "Type", true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(String), "String", true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(Boolean), "Boolean", true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(Array), "Array", true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(System.Collections.ArrayList), null, true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(char), null, true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(int), null, true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(Int16), null, true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(Int32), null, true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(Int64), null, true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(UInt16), null, true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(UInt32), null, true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(UInt64), null, true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(Enumerable), null, true, ScriptMemberSecurity.Locked); engine.RegisterType(typeof(File), null, true, ScriptMemberSecurity.Locked); InternalHandle hSystem = engine.CreateObject(); engine.DynamicGlobalObject.System = hSystem; hSystem.SetProperty(typeof(System.Object)); // (Note: No optional parameters used, so this will simply lookup and apply the existing registered type details above.) hSystem.SetProperty(typeof(String)); hSystem.SetProperty(typeof(Boolean)); hSystem.SetProperty(typeof(Array)); engine.GlobalObject.SetProperty(typeof(Type)); engine.GlobalObject.SetProperty(typeof(System.Collections.ArrayList)); engine.GlobalObject.SetProperty(typeof(char)); engine.GlobalObject.SetProperty(typeof(int)); engine.GlobalObject.SetProperty(typeof(Int16)); engine.GlobalObject.SetProperty(typeof(Int32)); engine.GlobalObject.SetProperty(typeof(Int64)); engine.GlobalObject.SetProperty(typeof(UInt16)); engine.GlobalObject.SetProperty(typeof(UInt32)); engine.GlobalObject.SetProperty(typeof(UInt64)); engine.GlobalObject.SetProperty(typeof(Enumerable)); engine.GlobalObject.SetProperty(typeof(Environment)); engine.GlobalObject.SetProperty(typeof(File)); engine.GlobalObject.SetProperty(typeof(Console), V8PropertyAttributes.Locked, null, true, ScriptMemberSecurity.Locked); var db = engine.CreateObject <V8.DatabaseObject>(); var console = engine.CreateObject <V8.ConsoleObject>(); var window = engine.CreateObject <V8.WindowObject>(); var server = engine.CreateObject <V8.ServerObject>(); var xhr = engine.CreateObject <V8.xhrObject>(); //db.AddParent(this.Parent); //console.AddParent(this.Parent); //server.AddParent(this.Parent); window.AddBrowser(browser); engine.DynamicGlobalObject.db = db; engine.DynamicGlobalObject.console = console; engine.DynamicGlobalObject.window = window; engine.DynamicGlobalObject.Server = server; engine.DynamicGlobalObject.jsXHR = xhr; } catch (Exception ex) { Log.Trace(ex.Message, ex.StackTrace, configuration.Verbose); } }