public PythonEngine(IScriptable callback) { _callback = callback; _scriptHandler = new ScriptHandler(_callback); _engines.Add(callback, this); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag (BOOLEAN_TAG)) { return base.ExecIdCall (f, cx, scope, thisObj, args); } int id = f.MethodId; if (id == Id_constructor) { bool b = ScriptConvert.ToBoolean (args, 0); if (thisObj == null) { return new BuiltinBoolean (b); } return b; } // The rest of Boolean.prototype methods require thisObj to be Boolean if (!(thisObj is BuiltinBoolean)) throw IncompatibleCallError (f); bool value = ((BuiltinBoolean)thisObj).booleanValue; switch (id) { case Id_toString: return value ? "true" : "false"; case Id_toSource: return value ? "(new Boolean(true))" : "(new Boolean(false))"; case Id_valueOf: return value; } throw new ArgumentException (Convert.ToString (id)); }
/// <summary> Convert the value to an object. /// /// See ECMA 9.9. /// </summary> public static IScriptable ToObject(Context cx, IScriptable scope, object val) { if (val is IScriptable) { return((IScriptable)val); } if (val == null) { throw ScriptRuntime.TypeErrorById("msg.null.to.object"); } if (val == Undefined.Value) { throw ScriptRuntime.TypeErrorById("msg.undef.to.object"); } string className = val is string? "String" : (CliHelper.IsNumber(val) ? "Number" : (val is bool? "Boolean" : null)); if (className != null) { object [] args = new object [] { val }; scope = ScriptableObject.GetTopLevelScope(scope); return(ScriptRuntime.NewObject(cx == null ? Context.CurrentContext : cx, scope, className, args)); } // Extension: Wrap as a LiveConnect object. object wrapped = cx.Wrap(scope, val, null); if (wrapped is IScriptable) { return((IScriptable)wrapped); } throw ScriptRuntime.errorWithClassName("msg.invalid.type", val); }
internal BuiltinCall(BuiltinFunction function, IScriptable scope, object [] args) { this.function = function; ParentScope = scope; // leave prototype null this.originalArgs = (args == null) ? ScriptRuntime.EmptyArgs : args; // initialize values of arguments int paramAndVarCount = function.ParamAndVarCount; int paramCount = function.ParamCount; if (paramAndVarCount != 0) { for (int i = 0; i != paramCount; ++i) { string name = function.getParamOrVarName (i); object val = i < args.Length ? args [i] : Undefined.Value; DefineProperty (name, val, PERMANENT); } } // initialize "arguments" property but only if it was not overriden by // the parameter with the same name if (!base.Has ("arguments", this)) { DefineProperty ("arguments", new Arguments (this), PERMANENT); } if (paramAndVarCount != 0) { for (int i = paramCount; i != paramAndVarCount; ++i) { string name = function.getParamOrVarName (i); if (!base.Has (name, this)) { DefineProperty (name, Undefined.Value, PERMANENT); } } } }
private void ListViewContextMenuStrip_Opening(object sender, CancelEventArgs e) { foreach (ToolStripMenuItem mnuItem in this.ListViewContextMenuStrip.Items) { mnuItem.Enabled = false; } if (this.ListView.SelectedItems.Count == 0) { return; } SqlSmoObject smoObject = (SqlSmoObject)this.ListView.SelectedItems[0].Tag; IScriptable scriptableObject = smoObject as IScriptable; if (scriptableObject != null) { this.scriptToolStripMenuItem.Enabled = true; } if (scriptableObject != null && !(smoObject is Database)) { this.scriptwithDependenciesToolStripMenuItem.Enabled = true; this.dependenciesToolStripMenuItem.Enabled = true; } }
public override object Call (Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (script != null) { return script.Exec (cx, scope); } return Undefined.Value; }
internal static void Init(IScriptable scope, bool zealed) { BuiltinBoolean obj = new BuiltinBoolean(false); obj.ExportAsJSClass(MAX_PROTOTYPE_ID, scope, zealed , ScriptableObject.DONTENUM | ScriptableObject.READONLY | ScriptableObject.PERMANENT); }
/// <summary> Create function embedded in script or another function.</summary> internal static InterpretedFunction createFunction(Context cx, IScriptable scope, InterpretedFunction parent, int index) { InterpretedFunction f = new InterpretedFunction(parent, index); f.initInterpretedFunction(cx, scope); return(f); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { int id = f.MethodId; switch (id) { case Id_print: for (int i = 0; i < args.Length; i++) { if (i > 0) Console.Out.Write (" "); Console.Out.Write (ScriptConvert.ToString (args [i])); } Console.Out.WriteLine (); return Undefined.Value; case Id_version: if (args.Length > 0) { if (CliHelper.IsNumber (args [0])) { int newVer = (int)ScriptConvert.ToNumber (args [0]); if (Context.IsValidLanguageVersion (newVer)) { cx.Version = Context.ToValidLanguageVersion (newVer); } } } return (int)cx.Version; case Id_options: StringBuilder sb = new StringBuilder (); if (cx.HasFeature (Context.Features.Strict)) sb.Append ("strict"); return sb.ToString (); case Id_gc: GC.Collect (); return Undefined.Value; } throw f.Unknown (); }
public override object Put(int index, IScriptable start, object value) { if (0 <= index && index < args.Length) { if (args [index] != UniqueTag.NotFound) { if (sharedWithActivation(index)) { string argName; argName = activation.function.getParamOrVarName(index); return(activation.Put(argName, activation, value)); } lock (this) { if (args [index] != UniqueTag.NotFound) { if (args == activation.originalArgs) { args = new object [args.Length]; args.CopyTo(args, 0); } args [index] = value; return(value); } } } } return(base.Put(index, start, value)); }
public static IScriptable ToObject (IScriptable scope, object val) { if (val is IScriptable) { return (IScriptable)val; } return ToObject (null, scope, val); }
protected internal virtual void AddIdFunctionProperty(IScriptable obj, object tag, int id, string name, int arity) { IScriptable scope = ScriptableObject.GetTopLevelScope(obj); IdFunctionObject f = NewIdFunction(tag, id, name, arity, scope); f.AddAsProperty(obj); }
public static void ImportTypes(IScriptable scope, string startsWith) { foreach (Assembly ass in Context.CurrentContext.AppDomain.GetAssemblies()) { ImportAssembly(scope, ass, startsWith); } }
internal void Set(int id, IScriptable start, object value) { if (value == UniqueTag.NotFound) { throw new ArgumentException(); } EnsureId(id); int attr = attributeArray [id - 1]; if ((attr & ScriptableObject.READONLY) == 0) { if (start == obj) { if (value == null) { value = UniqueTag.NullValue; } int valueSlot = (id - 1) * SLOT_SPAN + VALUE_SLOT; lock (this) { valueArray [valueSlot] = value; } } else { int nameSlot = (id - 1) * SLOT_SPAN + NAME_SLOT; string name = (string)valueArray [nameSlot]; start.Put(name, start, value); } } }
public void InitPrototypeMethod(object tag, int id, string name, int arity) { IScriptable scope = ScriptableObject.GetTopLevelScope(this); IdFunctionObject f = NewIdFunction(tag, id, name, arity, scope); prototypeValues.InitValue(id, name, f, DONTENUM); }
public IScriptable Clone() { IScriptable NewScript = (IScriptable)this.MemberwiseClone(); VO_Script_Condition CurrentObject = NewScript as VO_Script_Condition; CurrentObject.IfSubLines = new List <VO_Line>(); //If Line List foreach (VO_Line CurrentIfLine in this.IfSubLines) { IScriptable CurrentScriptLine = CurrentIfLine as IScriptable; VO_Line NewSubLine = CurrentScriptLine.Clone() as VO_Line; CurrentObject.IfSubLines.Add(NewSubLine); } //Else Line List CurrentObject.ElseSubLines = new List <VO_Line>(); foreach (VO_Line CurrentElseLine in this.ElseSubLines) { IScriptable CurrentScriptLine = CurrentElseLine as IScriptable; VO_Line NewSubLine = CurrentScriptLine.Clone() as VO_Line; CurrentObject.ElseSubLines.Add(NewSubLine); } return(NewScript); }
internal static void Init (IScriptable scope, bool zealed) { BuiltinString obj = new BuiltinString (""); obj.ExportAsJSClass (MAX_PROTOTYPE_ID, scope, zealed, ScriptableObject.DONTENUM | ScriptableObject.READONLY | ScriptableObject.PERMANENT); }
public override System.Object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, System.Object [] args) { if (!f.HasTag (XMLCTOR_TAG)) { return base.ExecIdCall (f, cx, scope, thisObj, args); } int id = f.MethodId; switch (id) { case Id_defaultSettings: { lib.SetDefaultSettings (); IScriptable obj = cx.NewObject (scope); WriteSetting (obj); return obj; } case Id_settings: { IScriptable obj = cx.NewObject (scope); WriteSetting (obj); return obj; } case Id_setSettings: { if (args.Length == 0 || args [0] == null || args [0] == Undefined.Value) { lib.SetDefaultSettings (); } else if (args [0] is IScriptable) { ReadSettings ((IScriptable)args [0]); } return Undefined.Value; } } throw new System.ArgumentException (System.Convert.ToString (id)); }
public override object Put (string id, IScriptable start, object value) { // Ignore assignments to "length"--it's readonly. if (!id.Equals ("length")) return base.Put (id, start, value); return Undefined.Value; }
static async Task DoTask(Lang lang, string filePath, string outputDir) { if (!File.Exists(filePath)) { throw new Exception("File does not exist"); } if (!Directory.Exists(outputDir)) { Console.WriteLine("Output directory does not exist. It will be created"); } string fileName = Path.GetFileNameWithoutExtension(filePath); CancellationTokenSource source = new(); CancellationToken token = source.Token; string fileText = await File.ReadAllTextAsync(filePath, Encoding.UTF8, token); JLMLDocument script = JLMLDocumentLoader.Load(fileText); IScriptable transpiler = lang switch { Lang.Html => new HtmlTranspiler(), _ => throw new NotImplementedException(), }; string contents = transpiler.ToScript(script); Directory.CreateDirectory(outputDir); await File.WriteAllTextAsync(Path.Join(outputDir, fileName + ".html"), contents, Encoding.UTF8, token); }
internal static IRef createSpecial(Context cx, object obj, string name) { IScriptable target = ScriptConvert.ToObjectOrNull(cx, obj); if (target == null) { throw ScriptRuntime.UndefReadError(obj, name); } Types type; if (name.Equals("__proto__")) { type = Types.Proto; } else if (name.Equals("__parent__")) { type = Types.Parent; } else { throw new ArgumentException(name); } if (!cx.HasFeature(Context.Features.ParentProtoProperties)) { // Clear special after checking for valid name! type = Types.None; } return(new SpecialRef(target, type, name)); }
/// <summary> /// Scripts a <see cref="IScriptable" /> along with provided options. /// </summary> /// <param name="scriptableObject">Object to script.</param> /// <param name="dropOptions">Drop options; null will ommit.</param> /// <param name="createOptions">Create options.</param> /// <param name="scrubScript">Value indicating whether or not to scrub the script to make it more readable and remove issues that prvent running.</param> /// <returns>Scripted object as a string.</returns> public static string Script(IScriptable scriptableObject, ScriptingOptions dropOptions, ScriptingOptions createOptions, bool scrubScript) { new { scriptableObject }.AsArg().Must().NotBeNull(); new { dropOptions }.AsArg().Must().NotBeNull(); new { createOptions }.AsArg().Must().NotBeNull(); StringCollection dropScript = null; if (dropOptions != null) { dropScript = scriptableObject.Script(dropOptions); dropScript.Add("GO"); } var createScript = scriptableObject.Script(createOptions); createScript.Add("GO"); if (scrubScript) { ScrubScript(createScript); } return(StringCollectionToSingleString(dropScript) + StringCollectionToSingleString(createScript)); }
private void SetScriptable(IScriptable scriptable, string scriptablePath, bool reload = false) { if (reload || scriptable != this.scriptable) { edits.Clear(); savedEditIndex = editIndex = 0; } this.scriptable = scriptable; bool sameFile = scriptablePath == LastFile; this.scriptablePath = LastFile = scriptablePath; AddRecentFile(scriptablePath); UpdateText(); bool loading = scriptable != objectEditor.DataObject || reload; if (reload) { objectEditor.DataObject = null; } objectEditor.DataObject = scriptable; objectEditor.Visible = scriptable != null; if (loading && sameFile) { string indexString = Properties.Settings.Default.LastIndex; EditorIndex index = JsonSerializer.fromJson <EditorIndex>(indexString); if (index != null) { objectEditor.Index = index; } } Properties.Settings.Default.LastIndex = JsonSerializer.toJson(objectEditor.Index); Properties.Settings.Default.Save(); }
public Arguments(BuiltinCall activation) { this.activation = activation; IScriptable parent = activation.ParentScope; ParentScope = parent; SetPrototype(ScriptableObject.GetObjectPrototype(parent)); args = activation.originalArgs; lengthObj = (int)args.Length; BuiltinFunction f = activation.function; calleeObj = f; Context.Versions version = f.LanguageVersion; if (version <= Context.Versions.JS1_3 && version != Context.Versions.Default) { callerObj = null; } else { callerObj = UniqueTag.NotFound; } }
public override IScriptable Construct (Context cx, IScriptable scope, object [] args) { BuiltinRegExp re = new BuiltinRegExp (); re.compile (cx, scope, args); ScriptRuntime.setObjectProtoAndParent (re, scope); return re; }
private void ChangeObject() { object [] ids = null; while (obj != null) { ids = obj.GetIds(); if (ids.Length != 0) { break; } obj = obj.GetPrototype(); } if (obj != null && this.ids != null) { object [] previous = this.ids; int L = previous.Length; if (used == null) { used = new ObjToIntMap(L); } for (int i = 0; i != L; ++i) { used.intern(previous [i]); } } this.ids = ids; this.index = 0; }
public static void ImportAssembly(IScriptable scope, Assembly ass, string startsWith) { foreach (Type type in ass.GetTypes ()) { if (startsWith == null || type.FullName.StartsWith (startsWith)) ImportType (scope, type); } }
public static void WriteToFile(string file, FileMode fileMode, IScriptable scriptable) { List <IScriptable> scriptableList = new List <IScriptable>(); scriptableList.Add(scriptable); WriteToFile(file, fileMode, scriptableList); }
private static void ScriptAndWriteToFile(IScriptable scriptableObject, string basePath, string extensionWithPeriod) { string script = SqlObjectScripter.Script(scriptableObject); if (!string.IsNullOrEmpty(script)) { string fileName = "[Not assigned]"; string filePathAndName = "[Not assigned]"; try { fileName = ((NamedSmoObject)scriptableObject).Name.Replace(@"\", "--"); // for domain names mainly, making sure to not mess up file path fileName = fileName.Replace(":", "_-COLON-_"); filePathAndName = Path.Combine(basePath, fileName); filePathAndName = Path.ChangeExtension(filePathAndName, extensionWithPeriod); using (TextWriter writer = new StreamWriter(filePathAndName, false)) { writer.WriteLine(script); } } catch (Exception e) { Console.WriteLine("Exception encountered."); Console.WriteLine("FileName: {0} FilePathAndName: {1}", fileName, filePathAndName); Console.WriteLine(e); } } }
internal static void ReadObject(IScriptable scriptable, string body) { if (scriptable == null) { return; } if (scriptable is IReadOnlyScriptable) { return; } if (scriptable is ICustomScriptable) { ICustomScriptable s = scriptable as ICustomScriptable; s.Read(body); return; } foreach (Accessor accessor in FieldAccessor.GetForObject(scriptable)) { foreach (FieldTag tag in accessor.GetTags()) { if (tag.flag == FieldTags.Title) { accessor.Set(body); return; } } } }
public override object Call (Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (args.Length > 0 && args [0] is BuiltinRegExp && (args.Length == 1 || args [1] == Undefined.Value)) { return args [0]; } return Construct (cx, scope, args); }
string RecreateObject(IScriptable scriptableObject, ScriptingOptions sCO) { StringBuilder sb = new StringBuilder(); // Generate Drop script ScriptingOptions so = new ScriptingOptions(); so.ScriptDrops = true; so.IncludeIfNotExists = true; foreach (string stmt in scriptableObject.Script(so)) { sb.AppendLine(stmt); } // Add batch separator sb.AppendLine("GO"); // Now generate Crate script and add it to the resulting ScriptCollection sCO.ScriptDrops = false; sCO.IncludeIfNotExists = false; foreach (string stmt in scriptableObject.Script(sCO)) { sb.AppendLine(stmt); if (stmt.Contains("SET ANSI_NULLS") || stmt.Contains("SET QUOTED_IDENTIFIER")) { sb.AppendLine("GO"); } } //for (int i = 0; i < sc.Count; i++) // sb.Append(sc[i]); return(sb.ToString()); }
private static object JsConstructor(Context cx, IScriptable scope, object [] args) { int arglen = args.Length; System.Text.StringBuilder sourceBuf = new System.Text.StringBuilder(); sourceBuf.Append("function "); /* version != 1.2 Function constructor behavior - * print 'anonymous' as the function name if the * version (under which the function was compiled) is * less than 1.2... or if it's greater than 1.2, because * we need to be closer to ECMA. */ if (cx.Version != Context.Versions.JS1_2) { sourceBuf.Append("anonymous"); } sourceBuf.Append('('); // Append arguments as coma separated strings for (int i = 0; i < arglen - 1; i++) { if (i > 0) { sourceBuf.Append(','); } sourceBuf.Append(ScriptConvert.ToString(args [i])); } sourceBuf.Append(") {"); if (arglen != 0) { // append function body string funBody = ScriptConvert.ToString(args [arglen - 1]); sourceBuf.Append(funBody); } sourceBuf.Append('}'); string source = sourceBuf.ToString(); int [] linep = new int [1]; string filename = Context.GetSourcePositionFromStack(linep); if (filename == null) { filename = "<eval'ed string>"; linep [0] = 1; } string sourceURI = ScriptRuntime.makeUrlForGeneratedScript(false, filename, linep [0]); IScriptable global = ScriptableObject.GetTopLevelScope(scope); ErrorReporter reporter; reporter = DefaultErrorReporter.ForEval(cx.ErrorReporter); // Compile with explicit interpreter instance to force interpreter // mode. return(cx.CompileFunction(global, source, new Interpreter(), reporter, sourceURI, 1, (object)null)); }
public virtual bool MoveNext () { // OPT this could be more efficient bool result; for (; ; ) { if (obj == null) { result = false; break; } if (index == ids.Length) { obj = obj.GetPrototype (); this.ChangeObject (); continue; } object id = ids [index++]; if (used != null && used.has (id)) { continue; } if (id is string) { string strId = (string)id; if (!obj.Has (strId, obj)) continue; // must have been deleted currentId = strId; } else { int intId = Convert.ToInt32 (id); if (!obj.Has (intId, obj)) continue; // must have been deleted currentId = Convert.ToString (intId); } result = true; break; } return result; }
internal static void Init(IScriptable scope, bool zealed) { BaseFunction obj = new BaseFunction(); obj.isPrototypePropertyImmune = true; obj.ExportAsJSClass(MAX_PROTOTYPE_ID, scope, zealed); }
// Scripts an item in right window if it is scriptable private void DependenciesTreeView_AfterSelect(object sender, TreeViewEventArgs e) { this.ScriptTextBox.Clear(); if (e.Node.Tag == null) { return; } // Script an object SqlSmoObject o = this.sqlServerSelection.GetSmoObject((Urn)e.Node.Tag); ScriptingOptions so = new ScriptingOptions(); so.DriAll = true; so.Indexes = true; so.IncludeHeaders = true; so.Permissions = true; so.PrimaryObject = true; so.SchemaQualify = true; so.Triggers = true; IScriptable scriptableObject = o as IScriptable; if (scriptableObject != null) { StringBuilder sb = new StringBuilder(); foreach (string s in scriptableObject.Script(so)) { sb.Append(s); sb.Append(Environment.NewLine); } this.ScriptTextBox.Text = sb.ToString(); } }
internal static string WriteObject(IScriptable scriptable, Indent indent = null) { if (scriptable == null) { return(null); } IIgnorable ignorable = scriptable as IIgnorable; if (ignorable != null && ignorable.Ignored) { return(null); } if (scriptable is ICustomScriptable) { ICustomScriptable s = scriptable as ICustomScriptable; string r = s.Write(); if (indent != null) { r = indent.GetIndent(s.Indent()) + r; if (s.Indent() == "#") { r += " `[" + scriptable.GetType().Name + "]`"; } } return(r); } if (scriptable is IReadOnlyScriptable) { string r = scriptable.ToString(); if (indent != null) { indent.Push(null); r = "`" + r + "`"; } return(r); } foreach (Accessor accessor in FieldAccessor.GetForObject(scriptable)) { foreach (FieldTag tag in accessor.GetTags()) { if (tag.flag == FieldTags.Title) { string r = "" + accessor.Get(); if (indent != null) { r = indent.GetIndent(tag.arg) + r; if (tag.arg == "#") { r += " `[" + scriptable.GetType().Name + "]`"; } } return(r); } } } return(null); }
public virtual object Get(string id, IScriptable start) { if (start == this) { start = prototype; } return(prototype.Get(id, start)); }
public override object Put (int index, IScriptable start, object value) { if (0 <= index && index < length) { ((System.Array)array).SetValue (Context.JsToCli (value, cls), index); return value; } return base.Put (index, start, value); }
public virtual object Put(int index, IScriptable start, object value) { if (start == this) { start = prototype; } return(prototype.Put(index, start, value)); }
public override object Get(int index, IScriptable start) { if (!Has(index, start)) { return(base.Get(index, start)); } return(m_Nodes [index]); }
internal static void Init (IScriptable scope, bool zealed) { BuiltinDate obj = new BuiltinDate (); // Set the value of the prototype Date to NaN ('invalid date'); obj.date = double.NaN; obj.ExportAsJSClass (MAX_PROTOTYPE_ID, scope, zealed , ScriptableObject.DONTENUM | ScriptableObject.READONLY | ScriptableObject.PERMANENT); }
public override object Get (int index, IScriptable start) { if (0 <= index && index < length) { object obj = ((System.Array)array).GetValue (index); return Context.CurrentContext.Wrap (this, obj, cls); } return Undefined.Value; }
/// <summary> Creates new script object. /// The default implementation of {@link #construct} uses the method to /// to get the value for <tt>thisObj</tt> argument when invoking /// {@link #call}. /// The methos is allowed to return <tt>null</tt> to indicate that /// {@link #call} will create a new object itself. In this case /// {@link #construct} will set scope and prototype on the result /// {@link #call} unless they are already set. /// </summary> public virtual IScriptable CreateObject(Context cx, IScriptable scope) { IScriptable newInstance = new BuiltinObject(); newInstance.SetPrototype(GetClassPrototype()); newInstance.ParentScope = ParentScope; return(newInstance); }
public virtual object Get(int index, IScriptable start) { if (start == this) { start = prototype; } return(prototype.Get(index, start)); }
public virtual object Perform (Context cx, IScriptable scope, IScriptable thisObj, object [] args, RegExpActions actionType) { GlobData data = new GlobData (); data.mode = actionType; switch ( (RegExpActions)actionType) { case EcmaScript.NET.RegExpActions.Match: { object rval; data.optarg = 1; rval = matchOrReplace (cx, scope, thisObj, args, this, data, false); return data.arrayobj == null ? rval : data.arrayobj; } case EcmaScript.NET.RegExpActions.Search: data.optarg = 1; return matchOrReplace (cx, scope, thisObj, args, this, data, false); case EcmaScript.NET.RegExpActions.Replace: { object arg1 = args.Length < 2 ? Undefined.Value : args [1]; string repstr = null; IFunction lambda = null; if (arg1 is IFunction) { lambda = (IFunction)arg1; } else { repstr = ScriptConvert.ToString (arg1); } data.optarg = 2; data.lambda = lambda; data.repstr = repstr; data.dollar = repstr == null ? -1 : repstr.IndexOf ((char)'$'); data.charBuf = null; data.leftIndex = 0; object val = matchOrReplace (cx, scope, thisObj, args, this, data, true); SubString rc = this.rightContext; if (data.charBuf == null) { if (data.global || val == null || !val.Equals (true)) { /* Didn't match even once. */ return data.str; } SubString lc = this.leftContext; replace_glob (data, cx, scope, this, lc.index, lc.length); } data.charBuf.Append (rc.charArray, rc.index, rc.length); return data.charBuf.ToString (); } default: throw Context.CodeBug (); } }
internal XMLLib BindToScope (IScriptable scope) { ScriptableObject so = ScriptRuntime.getLibraryScopeOrNull (scope); if (so == null) { // standard library should be initialized at this point throw new ApplicationException (); } return (XMLLib)so.AssociateValue (XML_LIB_KEY, this); }
public static XMLLib ExtractFromScope (IScriptable scope) { XMLLib lib = ExtractFromScopeOrNull (scope); if (lib != null) { return lib; } string msg = ScriptRuntime.GetMessage ("msg.XML.not.available"); throw Context.ReportRuntimeError (msg); }
public static XMLLib ExtractFromScopeOrNull (IScriptable scope) { ScriptableObject so = ScriptRuntime.getLibraryScopeOrNull (scope); if (so == null) { return null; } return (XMLLib)so.GetAssociatedValue (XML_LIB_KEY); }
public static void Init (IScriptable scope) { CliPackage obj = new CliPackage (); ScriptableObject.DefineProperty (scope, "cli", obj, ScriptableObject.DONTENUM); obj.ParentScope = scope; }
public virtual void InitFunction (string name, IScriptable scope) { if (name == null) throw new ArgumentException (); if (scope == null) throw new ArgumentException (); this.functionName = name; ParentScope = scope; }
public override bool Has (int index, IScriptable start) { if (0 <= index && index < args.Length) { if (args [index] != UniqueTag.NotFound) { return true; } } return base.Has (index, start); }
public static void Init(IScriptable scope) { var obj = new CliPackage(); DefineProperty(scope, "cli", obj, DONTENUM); obj.ParentScope = scope; }
public override object Get (string id, IScriptable start) { if (id.Equals ("length")) return (int)length; object result = base.Get (id, start); if (result == UniqueTag.NotFound && !ScriptableObject.HasProperty (GetPrototype (), id)) { throw Context.ReportRuntimeErrorById ("msg.java.member.not.found", array.GetType ().FullName, id); } return result; }
public override object Put (int index, IScriptable start, object value) { if (0 <= index && index < length) { ((System.Array)array).SetValue (Context.JsToCli (value, cls), index); return value; } else { throw Context.ReportRuntimeErrorById ("msg.java.array.index.out.of.bounds", index, length - 1); } return base.Put (index, start, value); }
public CliArray (IScriptable scope, object array) : base (array) { Type cl = array.GetType (); if (!cl.IsArray) { throw new ApplicationException ("Array expected"); } this.array = array; this.length = ((System.Array)array).Length; this.cls = cl.GetElementType (); }
internal static void Init (IScriptable scope, bool zealed) { BuiltinMath obj = new BuiltinMath (); obj.ActivatePrototypeMap (MAX_ID); obj.SetPrototype (GetObjectPrototype (scope)); obj.ParentScope = scope; if (zealed) { obj.SealObject (); } ScriptableObject.DefineProperty (scope, "Math", obj, ScriptableObject.DONTENUM | ScriptableObject.READONLY | ScriptableObject.PERMANENT); }
public IdEnumeration(object value, Context cx, bool enumValues) { obj = ScriptConvert.ToObjectOrNull (cx, value); if (obj != null) { // null or undefined do not cause errors but rather lead to empty // "for in" loop this.enumValues = enumValues; // enumInit should read all initial ids before returning // or "for (a.i in a)" would wrongly enumerate i in a as well ChangeObject (); } }