public ActiveScriptWrapper64(string progID, WindowsScriptEngineFlags flags) { // ReSharper disable SuspiciousTypeConversion.Global pActiveScript = RawCOMHelpers.CreateInstance <IActiveScript>(progID); pActiveScriptParse = RawCOMHelpers.QueryInterface <IActiveScriptParse64>(pActiveScript); pActiveScriptDebug = RawCOMHelpers.QueryInterface <IActiveScriptDebug64>(pActiveScript); pActiveScriptGarbageCollector = RawCOMHelpers.QueryInterfaceNoThrow <IActiveScriptGarbageCollector>(pActiveScript); pDebugStackFrameSniffer = RawCOMHelpers.QueryInterface <IDebugStackFrameSnifferEx64>(pActiveScript); activeScript = (IActiveScript)Marshal.GetObjectForIUnknown(pActiveScript); activeScriptParse = (IActiveScriptParse64)activeScript; activeScriptDebug = (IActiveScriptDebug64)activeScript; activeScriptGarbageCollector = activeScript as IActiveScriptGarbageCollector; debugStackFrameSniffer = (IDebugStackFrameSnifferEx64)activeScript; if (flags.HasFlag(WindowsScriptEngineFlags.EnableStandardsMode)) { var activeScriptProperty = activeScript as IActiveScriptProperty; if (activeScriptProperty != null) { object name; activeScriptProperty.GetProperty(ScriptProp.Name, IntPtr.Zero, out name); if (Equals(name, "JScript")) { object value = ScriptLanguageVersion.Standards; activeScriptProperty.SetProperty(ScriptProp.InvokeVersioning, IntPtr.Zero, ref value); } } } // ReSharper restore SuspiciousTypeConversion.Global }
private void InitialiseScriptFlags() { if (_debug) { _scriptFlags = WindowsScriptEngineFlags.EnableDebugging; } }
/// <summary> /// Initializes a new Windows Script engine instance with the specified list of supported file name extensions and synchronous invoker. /// </summary> /// <param name="progID">The programmatic identifier (ProgID) of the Windows Script engine class.</param> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="fileNameExtensions">A semicolon-delimited list of supported file name extensions.</param> /// <param name="flags">A value that selects options for the operation.</param> /// <param name="syncInvoker">An object that enforces thread affinity for the instance.</param> /// <remarks> /// The <paramref name="progID"/> argument can be a class identifier (CLSID) in standard /// GUID format with braces (e.g., "{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}"). /// </remarks> protected WindowsScriptEngine(string progID, string name, string fileNameExtensions, WindowsScriptEngineFlags flags, ISyncInvoker syncInvoker) : base(name, fileNameExtensions) { MiscHelpers.VerifyNonNullArgument(syncInvoker, nameof(syncInvoker)); this.syncInvoker = syncInvoker; script = base.ScriptInvoke(() => { activeScript = ActiveScriptWrapper.Create(progID, flags); engineFlags = flags; if (flags.HasFlag(WindowsScriptEngineFlags.EnableDebugging) && ProcessDebugManagerWrapper.TryCreate(out processDebugManager)) { processDebugManager.CreateApplication(out debugApplication); debugApplication.SetName(Name); if (processDebugManager.TryAddApplication(debugApplication, out debugApplicationCookie)) { sourceManagement = !flags.HasFlag(WindowsScriptEngineFlags.DisableSourceManagement); } else { debugApplication.Close(); debugApplication = null; processDebugManager = null; } } activeScript.SetScriptSite(new ScriptSite(this)); activeScript.InitNew(); activeScript.SetScriptState(ScriptState.Started); return(WindowsScriptItem.Wrap(this, GetScriptDispatch())); }); }
/// <summary> /// Initializes a new Windows Script engine instance. /// </summary> /// <param name="progID">The programmatic identifier (ProgID) of the Windows Script engine class.</param> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="flags">A value that selects options for the operation.</param> /// <remarks> /// The <paramref name="progID"/> argument can be a class identifier (CLSID) in standard /// GUID format with braces (e.g., "{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}"). /// </remarks> protected WindowsScriptEngine(string progID, string name, WindowsScriptEngineFlags flags) : base(name) { AccessContext = typeof(ScriptEngine); script = base.ScriptInvoke(() => { activeScript = ActiveScriptWrapper.Create(progID, flags); engineFlags = flags; if (flags.HasFlag(WindowsScriptEngineFlags.EnableDebugging) && ProcessDebugManagerWrapper.TryCreate(out processDebugManager)) { processDebugManager.CreateApplication(out debugApplication); debugApplication.SetName(Name); if (processDebugManager.TryAddApplication(debugApplication, out debugApplicationCookie)) { sourceManagement = !flags.HasFlag(WindowsScriptEngineFlags.DisableSourceManagement); } else { debugApplication.Close(); debugApplication = null; processDebugManager = null; } } activeScript.SetScriptSite(new ScriptSite(this)); activeScript.InitNew(); activeScript.SetScriptState(ScriptState.Started); return(WindowsScriptItem.Wrap(this, GetScriptDispatch())); }); }
public static ActiveScriptWrapper Create(string progID, WindowsScriptEngineFlags flags) { if (Environment.Is64BitProcess) { return new ActiveScriptWrapper64(progID, flags); } return new ActiveScriptWrapper32(progID, flags); }
public static ActiveScriptWrapper Create(string progID, WindowsScriptEngineFlags flags) { if (Environment.Is64BitProcess) { return(new ActiveScriptWrapper64(progID, flags)); } return(new ActiveScriptWrapper32(progID, flags)); }
/// <summary> /// Initializes a new JScript engine instance with the specified programmatic /// identifier, name, and options. /// </summary> /// <param name="progID">The programmatic identifier (ProgID) of the JScript engine class.</param> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="flags">A Content that selects options for the operation.</param> /// <remarks> /// The <paramref name="progID"/> argument can be a class identifier (CLSID) in standard /// GUID format with braces (e.g., "{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}"). /// </remarks> protected JScriptEngine(string progID, string name, WindowsScriptEngineFlags flags) : base(progID, name, flags) { Execute( MiscHelpers.FormatInvariant("{0} [internal]", GetType().Name), @" EngineInternal = (function () { function convertArgs(args) { var result = []; var count = args.Length; for (var i = 0; i < count; i++) { result.push(args[i]); } return result; } function construct(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15) { return new this(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); } return { getCommandResult: function (Content) { if (Content != null) { if ((typeof(Content) == 'object') || (typeof(Content) == 'function')) { if (typeof(Content.toString) == 'function') { return Content.toString(); } } } return Content; }, invokeConstructor: function (constructor, args) { if (typeof(constructor) != 'function') { throw new Error('Function expected'); } return construct.apply(constructor, convertArgs(args)); }, invokeMethod: function (target, method, args) { if (typeof(method) != 'function') { throw new Error('Function expected'); } return method.apply(target, convertArgs(args)); } }; })(); " ); }
/// <summary> /// Creates a new instance of the specified <paramref name="type"/>. /// </summary> /// <param name="type">The <see cref="EncodingType"/> to create.</param> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="v8constraints">An optional instance of <see cref="V8RuntimeConstraints"/> used to initialize the <see cref="EngineType.V8"/> script engine.</param> /// <param name="v8flags">An optional combination of <see cref="V8ScriptEngineFlags"/> flags used to initialize the <see cref="EngineType.V8"/> script engine.</param> /// <param name="windowsflags">An optional combination of <see cref="WindowsScriptEngineFlags"/> flags used to initialize the /// <see cref="EngineType.JScript"/> or <see cref="EngineType.VBScript"/> engines. /// </param> /// <returns>The requested <see cref="ScriptEngine"/> implementation.</returns> public static ScriptEngine Create( EngineType type, string name = null, V8RuntimeConstraints v8constraints = null, V8ScriptEngineFlags v8flags = V8ScriptEngineFlags.None, WindowsScriptEngineFlags windowsflags = WindowsScriptEngineFlags.None) { switch (type) { case EngineType.JScript: case EngineType.VBScript: return(CreateThreadBoundEngine(type, name, windowsflags)); case EngineType.V8: return(new V8JavaScriptEngine(name, v8constraints, v8flags)); default: throw new NotSupportedException(); } }
/// <summary> /// Initializes a new VBScript engine instance with the specified programmatic /// identifier, name, and options. /// </summary> /// <param name="progID">The programmatic identifier (ProgID) of the VBScript engine class.</param> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="flags">A value that selects options for the operation.</param> /// <remarks> /// The <paramref name="progID"/> argument can be a class identifier (CLSID) in standard /// GUID format with braces (e.g., "{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}"). /// </remarks> protected VBScriptEngine(string progID, string name, WindowsScriptEngineFlags flags) : base(progID, name, flags) { Execute( MiscHelpers.FormatInvariant("{0} [internal]", GetType().Name), @" class EngineInternalImpl public function getCommandResult(value) if IsObject(value) then if value is nothing then getCommandResult = ""[nothing]"" else dim ValueTypeName ValueTypeName = TypeName(value) if (ValueTypeName = ""Object"" or ValueTypeName = ""Unknown"") then set getCommandResult = value else getCommandResult = ""[ScriptObject:"" + ValueTypeName + ""]"" end if end if elseif IsArray(value) then getCommandResult = ""[array]"" elseif IsNull(value) then getCommandResult = ""[null]"" elseif IsEmpty(value) then getCommandResult = ""[empty]"" else getCommandResult = CStr(value) end if end function public function invokeConstructor(constructor, args) Err.Raise 445 end function public function invokeMethod(target, method, args) Err.Raise 445 end function end class set EngineInternal = new EngineInternalImpl " ); }
public ActiveScriptWrapper32(string progID, WindowsScriptEngineFlags flags) { // ReSharper disable SuspiciousTypeConversion.Global pActiveScript = ActivationHelpers.CreateInstance <IActiveScript>(progID); pActiveScriptParse = UnknownHelpers.QueryInterface <IActiveScriptParse32>(pActiveScript); pActiveScriptDebug = UnknownHelpers.QueryInterface <IActiveScriptDebug32>(pActiveScript); pActiveScriptGarbageCollector = UnknownHelpers.QueryInterfaceNoThrow <IActiveScriptGarbageCollector>(pActiveScript); pDebugStackFrameSniffer = UnknownHelpers.QueryInterfaceNoThrow <IDebugStackFrameSnifferEx32>(pActiveScript); activeScript = (IActiveScript)Marshal.GetObjectForIUnknown(pActiveScript); activeScriptParse = (IActiveScriptParse32)activeScript; activeScriptDebug = (IActiveScriptDebug32)activeScript; activeScriptGarbageCollector = activeScript as IActiveScriptGarbageCollector; debugStackFrameSniffer = activeScript as IDebugStackFrameSnifferEx32; if (flags.HasFlag(WindowsScriptEngineFlags.EnableStandardsMode)) { var activeScriptProperty = activeScript as IActiveScriptProperty; if (activeScriptProperty != null) { object name; activeScriptProperty.GetProperty(ScriptProp.Name, IntPtr.Zero, out name); if (Equals(name, "JScript")) { object value = ScriptLanguageVersion.Standards; activeScriptProperty.SetProperty(ScriptProp.InvokeVersioning, IntPtr.Zero, ref value); } } if (!flags.HasFlag(WindowsScriptEngineFlags.DoNotEnableVTablePatching) && MiscHelpers.IsX86InstructionSet()) { HostItem.EnableVTablePatching = true; } } // ReSharper restore SuspiciousTypeConversion.Global }
/// <summary> /// Initializes a new JScript engine instance with the specified name, options, and /// synchronous invoker. /// </summary> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="flags">A value that selects options for the operation.</param> /// <param name="syncInvoker">An object that enforces thread affinity for the instance.</param> public JScriptEngine(string name, WindowsScriptEngineFlags flags, ISyncInvoker syncInvoker) : this("JScript", name, "js", flags, syncInvoker) { }
/// <summary> /// Initializes a new JScript engine instance with the specified options. /// </summary> /// <param name="flags">A value that selects options for the operation.</param> /// <param name="syncInvoker">An object that enforces thread affinity for the instance.</param> public JScriptEngine(WindowsScriptEngineFlags flags, ISyncInvoker syncInvoker) : this(null, flags, syncInvoker) { }
/// <summary> /// Initializes a new JScript engine instance with the specified programmatic /// identifier, name, and options. /// </summary> /// <param name="progID">The programmatic identifier (ProgID) of the JScript engine class.</param> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="flags">A value that selects options for the operation.</param> /// <remarks> /// The <paramref name="progID"/> argument can be a class identifier (CLSID) in standard /// GUID format with braces (e.g., "{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}"). /// </remarks> protected JScriptEngine(string progID, string name, WindowsScriptEngineFlags flags) : base(progID, name, flags) { Execute( MiscHelpers.FormatInvariant("{0} [internal]", GetType().Name), @" EngineInternal = (function () { function convertArgs(args) { var result = []; var count = args.Length; for (var i = 0; i < count; i++) { result.push(args[i]); } return result; } function construct(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15) { return new this(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); } return { getCommandResult: function (value) { if (value != null) { if ((typeof(value) == 'object') || (typeof(value) == 'function')) { if (typeof(value.toString) == 'function') { return value.toString(); } } } return value; }, invokeConstructor: function (constructor, args) { if (typeof(constructor) != 'function') { throw new Error('Function expected'); } return construct.apply(constructor, convertArgs(args)); }, invokeMethod: function (target, method, args) { if (typeof(method) != 'function') { throw new Error('Function expected'); } return method.apply(target, convertArgs(args)); } }; })(); " ); }
/// <summary> /// Initializes a new JScript engine instance with the specified name and options. /// </summary> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="flags">A value that selects options for the operation.</param> public JScriptEngine(string name, WindowsScriptEngineFlags flags) : this("JScript", name, flags) { }
/// <summary> /// Initializes a new JScript engine instance with the specified options. /// </summary> /// <param name="flags">A value that selects options for the operation.</param> public JScriptEngine(WindowsScriptEngineFlags flags) : this(null, flags) { }
protected WindowsScriptEngine(string progID, string name, WindowsScriptEngineFlags flags) : this(progID, name, null, flags) { }
// creates the Microsoft engines on their own // thread bound to the current Wisej session. private static ScriptEngine CreateThreadBoundEngine(EngineType type, string name, WindowsScriptEngineFlags flags) { ScriptEngine engine = null; var checkPoint = new ManualResetEventSlim(); ApplicationBase.StartTask(() => { switch (type) { case EngineType.JScript: engine = new JScriptEngine(name, flags); break; case EngineType.VBScript: engine = new VBScriptEngine(name, flags); break; default: throw new InvalidOperationException(); } checkPoint.Set(); Dispatcher.Run(); }); checkPoint.Wait(); checkPoint.Reset(); return(engine); }
/// <summary> /// Initializes a new JScript engine instance with the specified programmatic /// identifier, name, list of supported file name extensions, and options. /// </summary> /// <param name="progID">The programmatic identifier (ProgID) of the JScript engine class.</param> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="fileNameExtensions">A semicolon-delimited list of supported file name extensions.</param> /// <param name="flags">A value that selects options for the operation.</param> /// <remarks> /// The <paramref name="progID"/> argument can be a class identifier (CLSID) in standard /// GUID format with braces (e.g., "{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}"). /// </remarks> protected JScriptEngine(string progID, string name, string fileNameExtensions, WindowsScriptEngineFlags flags) : base(progID, name, fileNameExtensions, flags) { Execute(MiscHelpers.FormatInvariant("{0} [internal]", GetType().Name), Core.JScriptEngine.InitScript); }
public VBScriptEngine(string name, WindowsScriptEngineFlags flags) : base(name, flags, NullSyncInvoker.Instance) { }
public ActiveScriptWrapper64(string progID, WindowsScriptEngineFlags flags) { pActiveScript = RawCOMHelpers.CreateInstance<IActiveScript>(progID); pActiveScriptParse = RawCOMHelpers.QueryInterface<IActiveScriptParse64>(pActiveScript); pActiveScriptDebug = RawCOMHelpers.QueryInterface<IActiveScriptDebug64>(pActiveScript); pActiveScriptGarbageCollector = RawCOMHelpers.QueryInterfaceNoThrow<IActiveScriptGarbageCollector>(pActiveScript); pDebugStackFrameSniffer = RawCOMHelpers.QueryInterface<IDebugStackFrameSnifferEx64>(pActiveScript); activeScript = (IActiveScript)Marshal.GetObjectForIUnknown(pActiveScript); activeScriptParse = (IActiveScriptParse64)activeScript; activeScriptDebug = (IActiveScriptDebug64)activeScript; activeScriptGarbageCollector = activeScript as IActiveScriptGarbageCollector; debugStackFrameSniffer = (IDebugStackFrameSnifferEx64)activeScript; if (flags.HasFlag(WindowsScriptEngineFlags.EnableStandardsMode)) { var activeScriptProperty = activeScript as IActiveScriptProperty; if (activeScriptProperty != null) { object name; activeScriptProperty.GetProperty(ScriptProp.Name, IntPtr.Zero, out name); if (Equals(name, "JScript")) { object value = ScriptLanguageVersion.Standards; activeScriptProperty.SetProperty(ScriptProp.InvokeVersioning, IntPtr.Zero, ref value); } } } }
/// <summary> /// Initializes a new JScript engine instance with the specified programmatic /// identifier, name, list of supported file name extensions, and options. /// </summary> /// <param name="progID">The programmatic identifier (ProgID) of the JScript engine class.</param> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="fileNameExtensions">A semicolon-delimited list of supported file name extensions.</param> /// <param name="flags">A value that selects options for the operation.</param> /// <remarks> /// The <paramref name="progID"/> argument can be a class identifier (CLSID) in standard /// GUID format with braces (e.g., "{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}"). /// </remarks> protected JScriptEngine(string progID, string name, string fileNameExtensions, WindowsScriptEngineFlags flags) : base(progID, name, fileNameExtensions, flags) { Execute( MiscHelpers.FormatInvariant("{0} [internal]", GetType().Name), @" EngineInternal = (function () { function convertArgs(args) { var result = []; if (args.GetValue) { var count = args.Length; for (var i = 0; i < count; i++) { result.push(args[i]); } } else { args = new VBArray(args); var count = args.ubound(1) + 1; for (var i = 0; i < count; i++) { result.push(args.getItem(i)); } } return result; } function construct(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15) { return new this(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); } return { getCommandResult: function (value) { if (value != null) { if ((typeof(value) == 'object') || (typeof(value) == 'function')) { if (typeof(value.toString) == 'function') { return value.toString(); } } } return value; }, invokeConstructor: function (constructor, args) { if (typeof(constructor) != 'function') { throw new Error('Function expected'); } return construct.apply(constructor, convertArgs(args)); }, invokeMethod: function (target, method, args) { if (typeof(method) != 'function') { throw new Error('Function expected'); } return method.apply(target, convertArgs(args)); }, isPromise: function (value) { return false; }, throwValue: function (value) { throw value; } }; })(); " ); }
public JScriptEngine(string name, WindowsScriptEngineFlags flags) : base(name, flags) { }
/// <summary> /// Initializes a new VBScript engine instance with the specified programmatic /// identifier, name, and options. /// </summary> /// <param name="progID">The programmatic identifier (ProgID) of the VBScript engine class.</param> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="flags">A value that selects options for the operation.</param> /// <remarks> /// The <paramref name="progID"/> argument can be a class identifier (CLSID) in standard /// GUID format with braces (e.g., "{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}"). /// </remarks> protected VBScriptEngine(string progID, string name, WindowsScriptEngineFlags flags) : base(progID, name, flags) { Execute( MiscHelpers.FormatInvariant("{0} [internal]", GetType().Name), @" class EngineInternalImpl public function getCommandResult(value) if IsObject(value) then if value is nothing then getCommandResult = ""[nothing]"" else dim valueTypeName valueTypeName = TypeName(value) if (valueTypeName = ""Object"" or valueTypeName = ""Unknown"") then set getCommandResult = value else getCommandResult = ""[ScriptObject:"" & valueTypeName & ""]"" end if end if elseif IsArray(value) then getCommandResult = ""[array]"" elseif IsNull(value) then getCommandResult = ""[null]"" elseif IsEmpty(value) then getCommandResult = ""[empty]"" else getCommandResult = CStr(value) end if end function public function invokeConstructor(constructor, args) Err.Raise 445 end function public function invokeMethod(target, method, args) if IsObject(target) then if target is nothing then else Err.Raise 445 end if elseif IsNull(target) then elseif IsEmpty(target) then else Err.Raise 445 end if dim count if IsArray(args) then count = UBound(args) + 1 if count < 1 then invokeMethod = method() elseif count = 1 then invokeMethod = method(args(0)) elseif count = 2 then invokeMethod = method(args(0), args(1)) elseif count = 3 then invokeMethod = method(args(0), args(1), args(2)) elseif count = 4 then invokeMethod = method(args(0), args(1), args(2), args(3)) elseif count = 5 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4)) elseif count = 6 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5)) elseif count = 7 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6)) elseif count = 8 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7)) elseif count = 9 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8)) elseif count = 10 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8), args(9)) elseif count = 11 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8), args(9), args(10)) elseif count = 12 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8), args(9), args(10), args(11)) elseif count = 13 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8), args(9), args(10), args(11), args(12)) elseif count = 14 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8), args(9), args(10), args(11), args(12), args(13)) elseif count = 15 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8), args(9), args(10), args(11), args(12), args(13), args(14)) elseif count = 16 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8), args(9), args(10), args(11), args(12), args(13), args(14), args(15)) else Err.Raise 450 end if else count = args.Length if count < 1 then invokeMethod = method() elseif count = 1 then invokeMethod = method(args.GetValue(0)) elseif count = 2 then invokeMethod = method(args.GetValue(0), args.GetValue(1)) elseif count = 3 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2)) elseif count = 4 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3)) elseif count = 5 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4)) elseif count = 6 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5)) elseif count = 7 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6)) elseif count = 8 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7)) elseif count = 9 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8)) elseif count = 10 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8), args.GetValue(9)) elseif count = 11 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8), args.GetValue(9), args.GetValue(10)) elseif count = 12 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8), args.GetValue(9), args.GetValue(10), args.GetValue(11)) elseif count = 13 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8), args.GetValue(9), args.GetValue(10), args.GetValue(11), args.GetValue(12)) elseif count = 14 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8), args.GetValue(9), args.GetValue(10), args.GetValue(11), args.GetValue(12), args.GetValue(13)) elseif count = 15 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8), args.GetValue(9), args.GetValue(10), args.GetValue(11), args.GetValue(12), args.GetValue(13), args.GetValue(14)) elseif count = 16 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8), args.GetValue(9), args.GetValue(10), args.GetValue(11), args.GetValue(12), args.GetValue(13), args.GetValue(14), args.GetValue(15)) else Err.Raise 450 end if end if end function end class set EngineInternal = new EngineInternalImpl " ); }
/// <summary> /// Initializes a new VBScript engine instance with the specified programmatic /// identifier, name, list of supported file name extensions, and options. /// </summary> /// <param name="progID">The programmatic identifier (ProgID) of the VBScript engine class.</param> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="fileNameExtensions">A semicolon-delimited list of supported file name extensions.</param> /// <param name="flags">A value that selects options for the operation.</param> /// <remarks> /// The <paramref name="progID"/> argument can be a class identifier (CLSID) in standard /// GUID format with braces (e.g., "{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}"). /// </remarks> protected VBScriptEngine(string progID, string name, string fileNameExtensions, WindowsScriptEngineFlags flags) : base(progID, name, fileNameExtensions, flags) { Execute( MiscHelpers.FormatInvariant("{0} [internal]", GetType().Name), @" class EngineInternalImpl public function getCommandResult(value) if IsObject(value) then if value is nothing then getCommandResult = ""[nothing]"" else dim valueTypeName valueTypeName = TypeName(value) if (valueTypeName = ""Object"" or valueTypeName = ""Unknown"") then set getCommandResult = value else getCommandResult = ""[ScriptObject:"" & valueTypeName & ""]"" end if end if elseif IsArray(value) then getCommandResult = ""[array]"" elseif IsNull(value) then getCommandResult = ""[null]"" elseif IsEmpty(value) then getCommandResult = ""[empty]"" else getCommandResult = CStr(value) end if end function public function invokeConstructor(constructor, args) Err.Raise 445 end function public function invokeMethod(target, method, args) if IsObject(target) then if target is nothing then else Err.Raise 445 end if elseif IsNull(target) then elseif IsEmpty(target) then else Err.Raise 445 end if dim count if IsArray(args) then count = UBound(args) + 1 if count < 1 then invokeMethod = method() elseif count = 1 then invokeMethod = method(args(0)) elseif count = 2 then invokeMethod = method(args(0), args(1)) elseif count = 3 then invokeMethod = method(args(0), args(1), args(2)) elseif count = 4 then invokeMethod = method(args(0), args(1), args(2), args(3)) elseif count = 5 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4)) elseif count = 6 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5)) elseif count = 7 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6)) elseif count = 8 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7)) elseif count = 9 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8)) elseif count = 10 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8), args(9)) elseif count = 11 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8), args(9), args(10)) elseif count = 12 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8), args(9), args(10), args(11)) elseif count = 13 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8), args(9), args(10), args(11), args(12)) elseif count = 14 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8), args(9), args(10), args(11), args(12), args(13)) elseif count = 15 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8), args(9), args(10), args(11), args(12), args(13), args(14)) elseif count = 16 then invokeMethod = method(args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7), args(8), args(9), args(10), args(11), args(12), args(13), args(14), args(15)) else Err.Raise 450 end if else count = args.Length if count < 1 then invokeMethod = method() elseif count = 1 then invokeMethod = method(args.GetValue(0)) elseif count = 2 then invokeMethod = method(args.GetValue(0), args.GetValue(1)) elseif count = 3 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2)) elseif count = 4 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3)) elseif count = 5 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4)) elseif count = 6 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5)) elseif count = 7 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6)) elseif count = 8 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7)) elseif count = 9 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8)) elseif count = 10 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8), args.GetValue(9)) elseif count = 11 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8), args.GetValue(9), args.GetValue(10)) elseif count = 12 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8), args.GetValue(9), args.GetValue(10), args.GetValue(11)) elseif count = 13 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8), args.GetValue(9), args.GetValue(10), args.GetValue(11), args.GetValue(12)) elseif count = 14 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8), args.GetValue(9), args.GetValue(10), args.GetValue(11), args.GetValue(12), args.GetValue(13)) elseif count = 15 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8), args.GetValue(9), args.GetValue(10), args.GetValue(11), args.GetValue(12), args.GetValue(13), args.GetValue(14)) elseif count = 16 then invokeMethod = method(args.GetValue(0), args.GetValue(1), args.GetValue(2), args.GetValue(3), args.GetValue(4), args.GetValue(5), args.GetValue(6), args.GetValue(7), args.GetValue(8), args.GetValue(9), args.GetValue(10), args.GetValue(11), args.GetValue(12), args.GetValue(13), args.GetValue(14), args.GetValue(15)) else Err.Raise 450 end if end if end function public function isPromise(value) isPromise = false end function public function throwValue(value) Err.Raise 445 end function end class set EngineInternal = new EngineInternalImpl " ); }
/// <summary> /// Initializes a new Windows Script engine instance with the specified list of supported file name extensions. /// </summary> /// <param name="progID">The programmatic identifier (ProgID) of the Windows Script engine class.</param> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="fileNameExtensions">A semicolon-delimited list of supported file name extensions.</param> /// <param name="flags">A value that selects options for the operation.</param> protected WindowsScriptEngine(string progID, string name, string fileNameExtensions, WindowsScriptEngineFlags flags) : base(name, fileNameExtensions) { }
/// <summary> /// Initializes a new Windows Script engine instance with the specified list of supported file name extensions. /// </summary> /// <param name="progID">The programmatic identifier (ProgID) of the Windows Script engine class.</param> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="fileNameExtensions">A semicolon-delimited list of supported file name extensions.</param> /// <param name="flags">A value that selects options for the operation.</param> /// <remarks> /// The <paramref name="progID"/> argument can be a class identifier (CLSID) in standard /// GUID format with braces (e.g., "{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}"). /// </remarks> protected WindowsScriptEngine(string progID, string name, string fileNameExtensions, WindowsScriptEngineFlags flags) : base(progID, name, fileNameExtensions, flags, new DispatcherSyncInvoker()) { }
/// <summary> /// Initializes a new JScript engine instance with the specified name and options. /// </summary> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="flags">A value that selects options for the operation.</param> public JScriptEngine(string name, WindowsScriptEngineFlags flags) : this("JScript", name, "js", flags) { }
public VBScriptEngine(string name, WindowsScriptEngineFlags flags) : base(name, flags, new DispatcherSyncInvoker()) { }
/// <summary> /// Initializes a new VBScript engine instance with the specified name and options. /// </summary> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="flags">A value that selects options for the operation.</param> public VBScriptEngine(string name, WindowsScriptEngineFlags flags) : this("VBScript", name, flags) { }
/// <summary> /// Initializes a new VBScript engine instance with the specified programmatic /// identifier, name, and options. /// </summary> /// <param name="progID">The programmatic identifier (ProgID) of the VBScript engine class.</param> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="flags">A value that selects options for the operation.</param> /// <remarks> /// The <paramref name="progID"/> argument can be a class identifier (CLSID) in standard /// GUID format with braces (e.g., "{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}"). /// </remarks> protected VBScriptEngine(string progID, string name, WindowsScriptEngineFlags flags) : this(progID, name, "vbs", flags) { }
public void ProcessRequest(HttpContext context) { DateTime start = DateTime.Now; string[] paths = context.Request.Params.GetValues("path"); string[] scripts = context.Request.Params.GetValues("script"); int pathIndex = -1; context.Response.ContentType = "text/plain"; context.Response.Write("Connected to SINJ handler on " + Environment.MachineName + "\r\n"); context.Response.Write("Sinj Version " + Assembly.GetExecutingAssembly().GetName().Version + "\r\n"); context.Response.Write("Num Paths = " + GetDebugString(paths) + "\r\n"); context.Response.Write("Num Scripts = " + GetDebugString(scripts) + "\r\n"); WindowsScriptEngineFlags flags = WindowsScriptEngineFlags.None; if (context.Request.Params["debug"] == "true") { flags = WindowsScriptEngineFlags.EnableDebugging; } using (ScriptEngine engine = new JScriptEngine(flags)) { var pushContext = new PushContext(); engine.AddHostObject("$sc", pushContext); //these global variables should not be here polluting the global namespace in javascript //they should hang off $sc, that's what PushContext is for - KW engine.AddHostType("$scItemManager", typeof(Sitecore.Data.Managers.ItemManager)); engine.AddHostType("$scTemplateManager", typeof(Sitecore.Data.Managers.TemplateManager)); engine.AddHostType("$scLanguage", typeof(Sitecore.Globalization.Language)); engine.AddHostType("$scVersion", typeof(Sitecore.Data.Version)); engine.AddHostType("$scID", typeof(Sitecore.Data.ID)); engine.AddHostType("$scTemplateIDs", typeof(Sitecore.TemplateIDs)); engine.AddHostType("$scTemplateFieldIDs", typeof(Sitecore.TemplateFieldIDs)); engine.AddHostType("$scTemplateFieldSharing", typeof(Sitecore.Data.Templates.TemplateFieldSharing)); engine.AddHostObject("$scMediaItem", new MediaItem()); engine.AddHostType("$scFieldIDs", typeof(Sitecore.FieldIDs)); if (scripts != null && paths != null) { try { using (new Sitecore.SecurityModel.SecurityDisabler()) { foreach (string script in scripts) { pathIndex++; engine.Execute(script); pushContext.RunAsUser(null); } } TimeSpan duration = DateTime.Now - start; context.Response.Write(String.Format("Sinj.PushHandler Completed Successfully in {0} seconds.", duration.TotalSeconds)); } catch (ScriptEngineException e) { context.Response.Write("PushHandler error in script file' " + paths[pathIndex] + "'. "); context.Response.Write(e.ErrorDetails + "\r\n\r\n" + e.InnerException + "\r\n\r\n"); } } else { engine.Execute("$sc.log('Hello from Sinj...')"); } } }
/// <summary> /// Initializes a new VBScript engine instance with the specified programmatic /// identifier, name, list of supported file name extensions, options, and synchronous /// invoker. /// </summary> /// <param name="progID">The programmatic identifier (ProgID) of the VBScript engine class.</param> /// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param> /// <param name="fileNameExtensions">A semicolon-delimited list of supported file name extensions.</param> /// <param name="flags">A value that selects options for the operation.</param> /// <param name="syncInvoker">An object that enforces thread affinity for the instance.</param> /// <remarks> /// The <paramref name="progID"/> argument can be a class identifier (CLSID) in standard /// GUID format with braces (e.g., "{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}"). /// </remarks> protected VBScriptEngine(string progID, string name, string fileNameExtensions, WindowsScriptEngineFlags flags, ISyncInvoker syncInvoker) : base(progID, name, fileNameExtensions, flags, syncInvoker) { Execute(MiscHelpers.FormatInvariant("{0} [internal]", GetType().Name), InitScript); }