/// <summary> Implements the instanceof operator for JavaScript Function objects. /// <p> /// <code> /// foo = new Foo();<br> /// foo instanceof Foo; // true<br> /// </code> /// /// </summary> /// <param name="instance">The value that appeared on the LHS of the instanceof /// operator /// </param> /// <returns> true if the "prototype" property of "this" appears in /// value's prototype chain /// /// </returns> public override bool HasInstance(IScriptable instance) { object protoProp = ScriptableObject.GetProperty(this, "prototype"); if (protoProp is IScriptable) { return(ScriptRuntime.jsDelegatesTo(instance, (IScriptable)protoProp)); } throw ScriptRuntime.TypeErrorById("msg.instanceof.bad.prototype", FunctionName); }
private static string getString(IScriptable obj, string id) { object value = ScriptableObject.GetProperty(obj, id); if (value == UniqueTag.NotFound) { return(""); } return(ScriptConvert.ToString(value)); }
private static string js_toSource(Context cx, IScriptable scope, IScriptable thisObj) { // Emulation of SpiderMonkey behavior object name = ScriptableObject.GetProperty(thisObj, "name"); object message = ScriptableObject.GetProperty(thisObj, "message"); object fileName = ScriptableObject.GetProperty(thisObj, "fileName"); object lineNumber = ScriptableObject.GetProperty(thisObj, "lineNumber"); System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("(new "); if (name == UniqueTag.NotFound) { name = Undefined.Value; } sb.Append(ScriptConvert.ToString(name)); sb.Append("("); if (message != UniqueTag.NotFound || fileName != UniqueTag.NotFound || lineNumber != UniqueTag.NotFound) { if (message == UniqueTag.NotFound) { message = ""; } sb.Append(ScriptRuntime.uneval(cx, scope, message)); if (fileName != UniqueTag.NotFound || lineNumber != UniqueTag.NotFound) { sb.Append(", "); if (fileName == UniqueTag.NotFound) { fileName = ""; } sb.Append(ScriptRuntime.uneval(cx, scope, fileName)); if (lineNumber != UniqueTag.NotFound) { int line = ScriptConvert.ToInt32(lineNumber); if (line != 0) { sb.Append(", "); sb.Append(ScriptConvert.ToString(line)); } } } } sb.Append("))"); return(sb.ToString()); }
protected internal string Render(object value, string templateScript) { try { string json = value.ToJson(); StringBuilder script = CreateBaseScript(); script.Append("dust.loadSource(compiledSource);"); script.Append(@"dust.render(templateName, JSON.parse(jsonData), function(err, result){ error = err; output = result; })"); EcmaScript.NET.Context ctx = EcmaScript.NET.Context.Enter(); ScriptableObject scope = ctx.InitStandardObjects(); SetParameters(scope); ScriptableObject.PutProperty(scope, "jsonData", json); ScriptableObject.PutProperty(scope, "compiledSource", Regex.Unescape(templateScript)); ScriptableObject.PutProperty(scope, "error", null); ScriptableObject.PutProperty(scope, "output", ""); ctx.EvaluateString(scope, script.ToString(), "render", 0, null); object error = ScriptableObject.GetProperty(scope, "error"); if (error != null) { throw new InvalidOperationException("An error occurred during dust.render: " + error.ToString()); } string result = ((string)ScriptableObject.GetProperty(scope, "output")); return(Regex.Unescape(result)); } catch (Exception ex) { string sig = "An error occurred rendering template ({0}) : {1}"; string msg = ex.Message; this.Exception = Args.Exception <DustException>(sig, Name, msg); return(string.Format(sig, Name, msg)); } }
private void SetCompiledScript() { try { StringBuilder script = CreateBaseScript(); script.Append("compiledTemplate = dust.compile(templateSource, templateName);"); EcmaScript.NET.Context ctx = EcmaScript.NET.Context.Enter(); ScriptableObject scope = ctx.InitStandardObjects(); SetParameters(scope); ScriptableObject.PutProperty(scope, "compiledTemplate", null); ctx.EvaluateString(scope, script.ToString(), "Compile", 0, null); CompiledScript = (string)ScriptableObject.GetProperty(scope, "compiledTemplate"); SetCompiledTemplate(); } catch (Exception ex) { CompiledScript = string.Format("alert('An error occurred compiling {0}: {1}');", Name, ex.Message); Exception = Args.Exception <DustException>("An error occurred compiling script ({0}) :{1}", ex, Name, ex.Message); } }
private void ReadSettings(IScriptable source) { for (int i = 1; i <= MAX_INSTANCE_ID; ++i) { int id = base.MaxInstanceId + i; string name = GetInstanceIdName(id); object value = ScriptableObject.GetProperty(source, name); if (value == UniqueTag.NotFound) { continue; } switch (i) { case Id_ignoreComments: case Id_ignoreProcessingInstructions: case Id_ignoreWhitespace: case Id_prettyPrinting: if (!(value is bool)) { continue; } break; case Id_prettyIndent: if (!(CliHelper.IsNumber(value))) { continue; } break; default: throw new System.SystemException(); } SetInstanceIdValue(id, value); } }
public T GetValue <T>(string varName) { return((T)ScriptableObject.GetProperty(_scope, varName)); }