protected virtual void ResetScriptEngine(ScriptSource source, IJinxBotClient client) { _jsEngine = new ScriptEngine(); _host = new JsHost(_jsEngine, client); _jsEngine.Execute(source); __accountCreated = GetFunc("accountCreated"); __accountCreationFailed = GetFunc("accountCreationFailed"); __adChanged = GetFunc("adChanged"); __channelDidNotExist = GetFunc("channelDidNotExist"); __channelListReceived = GetFunc("channelListReceived"); __channelWasFull = GetFunc("channelWasFull"); __channelWasRestricted = GetFunc("channelWasRestricted"); __clientCheckFailed = GetFunc("clientCheckFailed"); __clientCheckPassed = GetFunc("clientCheckPassed"); __commandSent = GetFunc("commandSent"); __connected = GetFunc("connected"); __disconnected = GetFunc("disconnected"); __enteredChat = GetFunc("enteredChat"); __error = GetFunc("error"); __friendAdded = GetFunc("friendAdded"); __friendListReceived = GetFunc("friendListReceived"); __friendMoved = GetFunc("friendMoved"); __friendRemoved = GetFunc("friendRemoved"); __friendUpdated = GetFunc("friendUpdated"); __information = GetFunc("information"); __informationReceived = GetFunc("informationReceived"); __joinedChannel = GetFunc("joinedChannel"); __loginFailed = GetFunc("loginFailed"); __loginSucceeded = GetFunc("loginSucceeded"); __messageSent = GetFunc("messageSent"); __profileLookupFailed = GetFunc("profileLookupFailed"); __serverBroadcast = GetFunc("serverBroadcast"); __serverErrorReceived = GetFunc("serverErrorReceived"); __serverNews = GetFunc("serverNews"); __userEmoted = GetFunc("userEmoted"); __userFlagsChanged = GetFunc("userFlagsChanged"); __userJoined = GetFunc("userJoined"); __userLeft = GetFunc("userLeft"); __userProfileReceived = GetFunc("userProfileReceived"); __userShown = GetFunc("userShown"); __userSpoke = GetFunc("userSpoke"); __warcraftProfileReceived = GetFunc("warcraftProfileReceived"); __whisperReceived = GetFunc("whisperReceived"); __whisperSent = GetFunc("whisperSent"); }
public override object Run() { if (Source == null) { Validate(Code); Source = new StringScriptSource(Wrap(Code), Path); Code = null; Path = null; } FunctionInstance wrap = (FunctionInstance)Engine.Evaluate(Source); ObjectInstance module = Engine.Object.Construct(); ObjectInstance exports = Engine.Object.Construct(); module.SetPropertyValue("exports", exports, true); string filename = System.IO.Path.GetFullPath(Source.Path); string dirname = System.IO.Path.GetDirectoryName(filename); wrap.CallLateBound(this, new object[] { module, exports, Require, filename, dirname }); return module.GetPropertyValue("exports"); }
static ScriptEngine initializeMinificationEngine() { if (_uglifyJsCode == null) { _uglifyJsCode = new StringScriptSource(Utility.ResourceAsString("SassAndCoffee.lib.uglify.js")); } ScriptEngine se = null; var t = new Thread(() => { se = new ScriptEngine(); se.Execute(_uglifyJsCode); }, 10 * 1048576); t.Start(); t.Join(); return se; }
static ScriptEngine initializeCoffeeScriptEngine() { if (_coffeeScriptCode == null) { _coffeeScriptCode = new StringScriptSource(Utility.ResourceAsString("SassAndCoffee.lib.coffee-script.js")); } ScriptEngine se = null; var t = new Thread(() => { se = new ScriptEngine(); se.Execute(_coffeeScriptCode); }, 10 * 1048576); t.Start(); t.Join(); const string compilifyFunction = @"function compilify(code) { return CoffeeScript.compile(code, {bare: true}); }"; se.Execute(compilifyFunction); return se; }
/// <summary> /// Compiles source code into a quickly executed form. /// </summary> /// <param name="source"> The javascript source code to execute. </param> /// <returns> A CompiledScript instance, which can be executed as many times as needed. </returns> /// <exception cref="ArgumentNullException"> <paramref name="source"/> is a <c>null</c> reference. </exception> public static CompiledScript Compile(ScriptSource source) { return(Compile(source, null)); }
/// <summary> /// Executes the given source code. Execution is bound to the global scope. /// </summary> /// <typeparam name="T"> The type to convert the result to. </typeparam> /// <param name="source"> The javascript source code to execute. </param> /// <returns> The result of executing the source code. </returns> /// <exception cref="ArgumentNullException"> <paramref name="code"/> is a <c>null</c> reference. </exception> public T Evaluate <T>(ScriptSource source) { return(TypeConverter.ConvertTo <T>(this, Evaluate(source))); }