Пример #1
0
 public override void Set(JSValue thisValue, JSValue value)
 {
     if (this.Writable)
     {
         this.Value = value;
     }
 }
Пример #2
0
 public override JSValue Get(JSValue thisValue)
 {
     if (this.Getter == null)
     {
         throw new NotSupportedException();
     }
     return this.Getter(thisValue);
 }
Пример #3
0
 public virtual JSValue Call(JSValue ThisObj, params JSValue[] Args)
 {
     if (ThisObj == null)
     {
         ThisObj = JSUndefined.Instance;
     }
     return this.Call(JSContext.CurrentContext, ThisObj, new JSArgs(this, Args));
 }
Пример #4
0
 public override void Set(JSValue thisValue, JSValue value)
 {
     if (this.Setter == null)
     {
         throw new NotSupportedException();
     }
     this.Setter(thisValue, value);
 }
Пример #5
0
 public override JSValue Get(JSValue thisValue)
 {
     if (this.Getter == null)
     {
         throw new NotSupportedException();
     }
     return this.Getter.Call(JSContext.CurrentContext, thisValue, new JSArgs(this.Getter, new JSValue[0]));
 }
Пример #6
0
 public override void Set(JSValue thisValue, JSValue value)
 {
     if (this.Setter == null)
     {
         throw new NotSupportedException();
     }
     this.Setter.Call(JSContext.CurrentContext, thisValue, new JSArgs(this.Setter, new JSValue[] { value }));
 }
Пример #7
0
 public virtual bool TryGetBindingValue(string key, out JSValue r)
 {
     if (this.HasBinding(key))
     {
         r = this.GetBindingValue(key);
         return true;
     }
     r = null;
     return false;
 }
 internal JSValue Call(JSContext Scope, JSValue ThisObj, JSValue fncObject, JSArgs Args)
 {
     JSFunctionContext ctx = new JSFunctionContext(ThisObj, Args, this.ParameterList, Scope, ((JSFunctionObject) fncObject).Scope);
     ctx.Source = this.Source;
     if (this.Name != "[function]")
     {
         ctx.LexicalEnv.CreateMutableBinding(this.Name);
         ctx.LexicalEnv.SetMutableBinding(this.Name, fncObject);
     }
     return this._delegate(ctx);
 }
Пример #9
0
 public override JSValue Call(JSContext Scope, JSValue ThisObj, JSArgs Args)
 {
     if (ThisObj.CheckCoercible())
     {
         ThisObj = ThisObj.ToJSObject();
     }
     else
     {
         ThisObj = JSContext.CurrentGlobalContext.Global;
     }
     return this.FunctionDef.Call(Scope, ThisObj, this, Args);
 }
Пример #10
0
 public override JSValue Call(JSContext Scope, JSValue ThisObj, JSArgs Args)
 {
     if (ThisObj.CheckCoercible())
     {
         ThisObj = ThisObj.ToJSObject();
     }
     else
     {
         ThisObj = JSContext.CurrentGlobalContext.Global;
     }
     JSFunctionContext ctx = new JSFunctionContext(ThisObj, Args, new ParameterList(this.def.param_names), Scope, this.Scope);
     return this.def.del(ctx);
 }
Пример #11
0
 public JSArray(JSValue Prototype, JSValue Constructor)
     : base(Prototype, Constructor)
 {
     base.SetProp("length", new JSDelegateProperty(delegate (JSValue ThisObj) {
         return (double) ((JSArray) ThisObj)._length;
     }, delegate (JSValue ThisObj, JSValue val) {
         double n = val.NumberValue();
         uint i = n.JSToUInt32();
         if (n != i)
         {
             throw new JSRuntimeException("RangeError", "invalid array length");
         }
         JSArray ar = ThisObj as JSArray;
         UpdateLen(i, ar);
     }, true, false, false));
 }
Пример #12
0
 public JSFunctionContext(JSValue ThisObj, JSArgs Args, ParameterList parameterList, JSContext context, JSEnvRec Scope)
     : base(context)
 {
     if (!((ThisObj is JSNull) || (ThisObj is JSUndefined)))
     {
         this.ThisObj = ThisObj;
     }
     this.Args = Args;
     this.parameterList = parameterList;
     base.LexicalEnv = new JSDeclScope(Scope);
     base.VariableEnv = base.LexicalEnv;
     base.CreateMutableBinding("arguments");
     base.SetMutableBinding("arguments", Args);
     int m = parameterList.Names.Length;
     for (int i = 0; i < m; i++)
     {
         base.CreateMutableBinding(parameterList.Names[i]);
         base.SetMutableBinding(parameterList.Names[i], Args[i]);
     }
 }
Пример #13
0
 private void AddFunction()
 {
     this.FunctionCtor = new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         string argNames;
         string sBody;
         if (args.Count > 1)
         {
             string[] ar = new string[args.Count - 1];
             for (int i = 0; i < (args.Count - 1); i++)
             {
                 ar[i] = args[i].StringValue();
             }
             argNames = string.Join(",", ar);
         }
         else
         {
             argNames = "";
         }
         if (args.Count == 0)
         {
             sBody = "";
         }
         else
         {
             sBody = args[args.Count - 1].StringValue();
         }
         JSFunctionObject r = CompiledScript.Compile("(function (" + argNames + ") {" + sBody + "})", false).Run() as JSFunctionObject;
         r.Scope = JSContext.CurrentGlobalContext.LexicalEnv;
         return r;
     }, 1);
     this.FunctionPrototype = new JSFunctionBase();
     this.FunctionPrototype.SetDataProp("constructor", this.FunctionCtor, true, false, true);
     this.FunctionPrototype.SetDataProp("call", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         JSArgs newArgs;
         if (AsConstructor)
         {
             throw new JSRuntimeException("TypeError", "Function.call called as constructor");
         }
         JSFunctionBase fnc = InternalUtilities.JSFunctionCast(ThisObj);
         if (args.Count == 0)
         {
             newArgs = args;
         }
         else
         {
             JSValue[] newAr = new JSValue[args.Count - 1];
             Array.Copy(args.ArgValues, 1, newAr, 0, args.Count - 1);
             newArgs = new JSArgs(ThisObj, newAr);
         }
         return fnc.Call(Scope, args[0], newArgs);
     }, 1), true, false, true);
     this.FunctionPrototype.SetDataProp("apply", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (AsConstructor)
         {
             throw new JSRuntimeException("TypeError", "Function.apply called as constructor");
         }
         JSFunctionBase fnc = InternalUtilities.JSFunctionCast(ThisObj);
         JSValue argArray = args[1];
         if ((argArray is JSUndefined) || (argArray is JSNull))
         {
             return fnc.Call(Scope, args[0], new JSArgs(ThisObj, new JSValue[0]));
         }
         if (!(argArray is JSObject))
         {
             throw new JSRuntimeException("TypeError", "Invalid argument to Function.apply");
         }
         JSValue olen = argArray["length"];
         if (!olen.CheckCoercible())
         {
             throw new JSRuntimeException("TypeError", "Invalid argument to Function.apply");
         }
         double nlen = olen.NumberValue();
         uint len = nlen.JSToUInt32();
         if (len != nlen)
         {
             throw new JSRuntimeException("TypeError", "Invalid argument to Function.apply");
         }
         JSValue[] newAr = new JSValue[len];
         for (int i = 0; i < len; i++)
         {
             newAr[i] = argArray[i.ToString()];
         }
         return fnc.Call(Scope, args[0], new JSArgs(ThisObj, newAr));
     }, 2), true, false, true);
     this.FunctionPrototype.SetDataProp("toString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         return InternalUtilities.JSFunctionCast(ThisObj).GenerateString();
     }), true, false, true);
     this.FunctionPrototype.SetDataProp("length", 0.0, true, false, true);
     this.FunctionCtor.SetDataProp("prototype", this.FunctionPrototype, false, false, false);
 }
Пример #14
0
 protected JSFunctionBase(JSValue Prototype, JSValue Constructor) : base(Prototype, Constructor)
 {
 }
Пример #15
0
 public virtual JSValue Call(JSContext Scope, JSValue ThisObj, JSArgs Args)
 {
     return(JSUndefined.Instance);
 }
Пример #16
0
 public JSRuntimeException(JSValue value)
     : base(value.StringValue())
 {
     this.Line = -1;
     this.value = value;
 }
Пример #17
0
 internal virtual bool TrySetBindingValue(string key, JSValue value)
 {
     if (this.HasBinding(key) || (this is JSGlobalScope))
     {
         this.SetMutableBinding(key, value);
         return true;
     }
     return ((this.Parent != null) && this.Parent.TrySetBindingValue(key, value));
 }
Пример #18
0
        private void AddArrayProperties()
        {
            this.Global.SetDataProp("Array", this.ArrayCtor, false, false, false);
            this.ArrayPrototype.SetDataProp("length", 0.0, true, false, true);
            this.ArrayCtor.SetDataProp("isArray", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                return args[0] is JSArray;
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("toString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor) throw new JSRuntimeException("TypeError", "Array.toString cannot be used as a constructor");
                JSObject array = ThisObj.ToJSObject();
                JSFunctionBase fnc = ThisObj["join"] as JSFunctionBase;
                if (fnc != null)
                {
                    return fnc.Call(Scope, ThisObj, new JSArgs(fnc, new JSValue[0]));
                }
                return "[object " + ThisObj.ClassString + "]";
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("toLocaleString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                JSObject elementObj;
                JSFunctionBase func;
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.toLocaleString called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                uint len = O["length"].NumberValue().JSToUInt32();
                if (len == 0)
                {
                    return string.Empty;
                }
                JSValue firstElement = O["0"];
                StringBuilder R = new StringBuilder();
                if (firstElement.CheckCoercible())
                {
                    elementObj = firstElement.ToJSObject();
                    func = InternalUtilities.JSFunctionCast(elementObj["toLocaleString"]);
                    R.Append(func.Call(Scope, elementObj, new JSArgs(func, new JSValue[0])).StringValue());
                }
                for (uint k = 1; k < len; k++)
                {
                    R.Append(",");
                    JSValue nextElement = O[k.ToString()];
                    if (nextElement.CheckCoercible())
                    {
                        elementObj = nextElement.ToJSObject();
                        func = InternalUtilities.JSFunctionCast(elementObj["toLocaleString"]);
                        R.Append(func.Call(Scope, elementObj, new JSArgs(func, new JSValue[0])).StringValue());
                    }
                }
                return R.ToString();
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("concat", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.concat called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                JSArray A = new JSArray(new JSValue[0]);
                int n = 0;
                _concat_append(A, ref n, O);
                foreach (JSValue E in args.ArgValues)
                {
                    _concat_append(A, ref n, E);
                }
                return A;
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("join", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                string sep;
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.join called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                uint len = O["length"].NumberValue().JSToUInt32();
                if (args[0] is JSUndefined)
                {
                    sep = ",";
                }
                else
                {
                    sep = args[0].StringValue();
                }
                if (len == 0)
                {
                    return string.Empty;
                }
                JSValue element0 = O["0"];
                StringBuilder R = new StringBuilder();
                if (element0.CheckCoercible())
                {
                    R.Append(element0.StringValue());
                }
                for (int k = 1; k < len; k++)
                {
                    R.Append(sep);
                    JSValue element = O[k.ToString()];
                    if (element.CheckCoercible())
                    {
                        R.Append(element.StringValue());
                    }
                }
                return R.ToString();
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("pop", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.pop called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                uint len = O["length"].NumberValue().JSToUInt32();
                if (len == 0)
                {
                    O["length"] = 0.0;
                    return JSUndefined.Instance;
                }
                string indx = (len - 1).ToString();
                JSValue element = O[indx];
                O.DeleteProperty(indx, true);
                O["length"] = (JSValue)(len - 1);
                return element;
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("push", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.push called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                double n = O["length"].NumberValue().JSToUInt32();
                foreach (JSValue E in args.ArgValues)
                {
                    O[n.ToString()] = E;
                    n++;
                }
                O["length"] = n;
                return n;
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("reverse", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.reverse called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                uint len = O["length"].NumberValue().JSToUInt32();
                uint middle = len / 2;
                for (uint lower = 0; lower != middle; lower++)
                {
                    string upperP = ((len - lower) - 1).ToString();
                    string lowerP = lower.ToString();
                    JSValue lowerValue = O[lowerP];
                    JSValue upperValue = O[upperP];
                    bool lowerExists = O.HasProperty(lowerP);
                    bool upperExists = O.HasProperty(upperP);
                    if (lowerExists && upperExists)
                    {
                        O[lowerP] = upperValue;
                        O[upperP] = lowerValue;
                    }
                    else if (!(lowerExists || !upperExists))
                    {
                        O[lowerP] = upperValue;
                        O.DeleteProperty(upperP, true);
                    }
                    else if (!(!lowerExists || upperExists))
                    {
                        O.DeleteProperty(lowerP, true);
                        O[upperP] = lowerValue;
                    }
                }
                return O;
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("shift", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.shift called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                double len = O["length"].NumberValue().JSToUInt32();
                if (len == 0.0)
                {
                    O["length"] = 0.0;
                    return JSUndefined.Instance;
                }
                JSValue first = O["0"];
                for (int k = 1; k < len; k++)
                {
                    string from = k.ToString();
                    string to = (k - 1).ToString();
                    if (O.HasProperty(from))
                    {
                        JSValue fromVal = O[from];
                        O[to] = fromVal;
                    }
                    else
                    {
                        O.DeleteProperty(to, true);
                    }
                }
                O.DeleteProperty((len - 1.0).ToString(), true);
                O["length"] = len - 1.0;
                return first;
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("slice", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                double k;
                double relativeEnd;
                double final;

                if (AsConstructor) throw new JSRuntimeException("TypeError", "Array.slice called as constructor");

                JSObject O = ThisObj.ToJSObject();
                JSArray A = new JSArray(new JSValue[0]);
                uint len = O["length"].NumberValue().JSToUInt32();
                double relativeStart = args[0].NumberValue().JSToInteger();

                if (relativeStart < 0.0)
                    k = Math.Max((double)(len + relativeStart), (double)0.0);
                else
                    k = Math.Min(relativeStart, (double)len);

                if (args[1] is JSUndefined)
                    relativeEnd = len;
                else
                    relativeEnd = args[1].NumberValue().JSToInteger();

                if (relativeEnd < 0.0)
                    final = Math.Max((double)(len + relativeEnd), (double)0.0);
                else
                    final = Math.Min(relativeEnd, (double)len);

                uint ik = (uint)k;
                uint ifinal = (uint)final;
                for (int n = 0; ik < ifinal; n++)
                {
                    string Pk = ik.ToString();
                    if (O.HasProperty(Pk))
                    {
                        JSValue kValue = O[Pk];
                        A[n.ToString()] = kValue;
                    }
                    ik++;
                }
                return A;
            }, 2), true, false, true);
            this.ArrayPrototype.SetDataProp("sort", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.sort called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                uint len = O["length"].NumberValue().JSToUInt32();
                if (len != 0)
                {
                    int i;
                    IEnumerable<JSValue> a2;
                    int nUnset = 0;
                    int nUndef = 0;
                    List<JSValue> a1 = new List<JSValue>();
                    for (i = 0; i < len; i++)
                    {
                        JSValue v;
                        if (!O.TryGetPropertyValue(i.ToString(), out v))
                        {
                            nUnset++;
                        }
                        else if (v is JSUndefined)
                        {
                            nUndef++;
                        }
                        else
                        {
                            a1.Add(v);
                        }
                    }
                    if (args[0] is JSUndefined)
                    {
                        a2 = a1.OrderBy<JSValue, string>(x => x.StringValue(), StringComparer.Ordinal);
                    }
                    else
                    {
                        _sortHelper h = new _sortHelper(InternalUtilities.JSFunctionCast(args[0]), Scope);
                        a2 = a1.OrderBy<JSValue, JSValue>(x => x, h);
                    }
                    i = 0;
                    foreach (JSValue v in a2)
                    {
                        O[i.ToString()] = v;
                        i++;
                    }
                    while (nUndef-- != 0)
                    {
                        O[i.ToString()] = JSUndefined.Instance;
                        i++;
                    }
                    while (nUnset-- != 0)
                    {
                        string s = i.ToString();
                        if (O.HasOwnProperty(s))
                        {
                            O.DeleteProperty(s, false);
                        }
                        i++;
                    }
                }
                return O;
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("splice", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                double actualStart;
                uint k;
                string from;
                JSValue fromValue;
                JSValue[] items;
                string to;
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.splice called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                JSArray A = new JSArray(new JSValue[0]);
                uint len = O["length"].NumberValue().JSToUInt32();
                double relativeStart = args[0].NumberValue().JSToInteger();
                if (relativeStart < 0.0)
                {
                    actualStart = Math.Max((double)(len + relativeStart), (double)0.0);
                }
                else
                {
                    actualStart = Math.Min(relativeStart, (double)len);
                }
                double actualDeleteCount = Math.Min(Math.Max(args[1].NumberValue().JSToInteger(), 0.0), len - actualStart);
                uint iactualStart = (uint)actualStart;
                uint iactualDeleteCount = (uint)actualDeleteCount;
                for (k = 0; k < iactualDeleteCount; k++)
                {
                    from = (iactualStart + k).ToString();
                    if (O.HasProperty(from))
                    {
                        fromValue = O[from];
                        A[k.ToString()] = fromValue;
                    }
                }
                if (args.Count <= 2)
                {
                    items = new JSValue[0];
                }
                else
                {
                    items = args.ArgValues.Skip<JSValue>(2).ToArray<JSValue>();
                }
                int itemCount = items.Length;
                if (itemCount < iactualDeleteCount)
                {
                    for (k = iactualStart; k < (len - iactualDeleteCount); k++)
                    {
                        from = (k + iactualDeleteCount).ToString();
                        to = (k + itemCount).ToString();
                        if (O.HasProperty(from))
                        {
                            fromValue = O[from];
                            O[to] = fromValue;
                        }
                        else
                        {
                            O.DeleteProperty(to, true);
                        }
                    }
                    for (k = len; k > ((len - iactualDeleteCount) + itemCount); k--)
                    {
                        O.DeleteProperty((k - 1).ToString(), true);
                    }
                }
                else if (itemCount > iactualDeleteCount)
                {
                    for (k = len - iactualDeleteCount; k > iactualStart; k--)
                    {
                        from = ((k + iactualDeleteCount) - 1).ToString();
                        to = ((k + itemCount) - 1L).ToString();
                        if (O.HasProperty(from))
                        {
                            fromValue = O[from];
                            O[to] = fromValue;
                        }
                        else
                        {
                            O.DeleteProperty(to, true);
                        }
                    }
                }
                k = iactualStart;
                foreach (JSValue E in items)
                {
                    O[k.ToString()] = E;
                    k++;
                }
                O["length"] = (JSValue)((len - iactualDeleteCount) + itemCount);
                return A;
            }, 2), true, false, true);
            this.ArrayPrototype.SetDataProp("unshift", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.unshift called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                double len = O["length"].NumberValue().JSToUInt32();
                for (double k = len; k > 0.0; k--)
                {
                    string from = (k - 1.0).ToString();
                    string to = ((k + args.Count) - 1.0).ToString();
                    if (O.HasProperty(from))
                    {
                        JSValue fromValue = O[from];
                        O[to] = fromValue;
                    }
                    else
                    {
                        O.DeleteProperty(to, true);
                    }
                }
                int j = 0;
                foreach (JSValue E in args.ArgValues)
                {
                    O[j.ToString()] = E;
                    j++;
                }
                O["length"] = len + args.Count;
                return len + args.Count;
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("indexOf", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.indexOf called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                uint len = O["length"].NumberValue().JSToUInt32();
                if (len != 0)
                {
                    double n;
                    uint k;
                    if (args.Count >= 2)
                    {
                        n = args[1].NumberValue();
                    }
                    else
                    {
                        n = 0.0;
                    }
                    if (n >= len)
                    {
                        return -1.0;
                    }
                    if (n >= 0.0)
                    {
                        k = (uint)n;
                    }
                    else
                    {
                        k = len - ((uint)-n);
                        if (k < 0)
                        {
                            k = 0;
                        }
                    }
                    while (k < len)
                    {
                        if (O.HasProperty(k.ToString()))
                        {
                            JSValue elementK = O[k.ToString()];
                            if (JSValue.JSEqualsExact(args[0], elementK))
                            {
                                return (double)k;
                            }
                        }
                        k++;
                    }
                }
                return -1.0;
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("lastIndexOf", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.lastIndexOf called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                uint len = O["length"].NumberValue().JSToUInt32();
                if (len != 0)
                {
                    double n;
                    uint k;
                    if (args.Count >= 2)
                    {
                        n = args[1].NumberValue();
                    }
                    else
                    {
                        n = len;
                    }
                    if (n >= 0.0)
                    {
                        k = Math.Min((uint)n, len - 1);
                    }
                    else
                    {
                        k = len - ((uint)-n);
                    }
                    while (k >= 0)
                    {
                        if (O.HasProperty(k.ToString()))
                        {
                            JSValue elementK = O[k.ToString()];
                            if (JSValue.JSEqualsExact(args[0], elementK))
                            {
                                return (double)k;
                            }
                        }
                        k--;
                    }
                }
                return -1.0;
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("every", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                throw new Exception();
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("some", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                throw new Exception();
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("forEach", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                throw new Exception();
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("map", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                throw new Exception();
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("filter", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                throw new Exception();
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("reduce", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                throw new Exception();
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("reduceRight", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                throw new Exception();
            }), true, false, true);
        }
Пример #19
0
 public override JSValue Get(JSValue thisValue)
 {
     return this.Value;
 }
Пример #20
0
 internal bool TryGetPropertyValue(string Key, out JSValue prop)
 {
     PropWrapper r;
     if (this.Members.TryGetValue(Key, out r))
     {
         prop = r.Get(this);
         return true;
     }
     prop = JSUndefined.Instance;
     return false;
 }
Пример #21
0
 public DataProperty(JSValue value)
     : this(value, true, true, true)
 {
 }
Пример #22
0
 public DataProperty(JSValue value, bool Writable, bool Enumerable, bool Configurable)
     : base(Writable, Enumerable, Configurable)
 {
     this.Value = value;
 }
Пример #23
0
 public JSObject(JSValue Prototype, JSValue Constructor)
 {
     this._extensible = true;
     this._members = new Dictionary<string, PropWrapper>();
     this._prototype = Prototype;
     if (Constructor != null)
     {
         this.SetDataProp("constructor", Constructor, true, false, true);
     }
 }
Пример #24
0
 internal void SetDataProp(string key, JSValue val, bool Writable, bool Enumerable, bool Configurable)
 {
     if (this.Members.ContainsKey(key))
     {
         this.Members.Remove(key);
     }
     this.Members.Add(key, new DataProperty(val, Writable, Enumerable, Configurable));
 }
Пример #25
0
 public abstract void Set(JSValue thisValue, JSValue value);
Пример #26
0
 internal JSBoxedNumber(JSValue Prototype, JSValue Constructor)
     : base(Prototype, Constructor)
 {
     this._val = JSNumber.Zero;
 }
Пример #27
0
 public JSObject(JSValue Prototype)
     : this(Prototype, null)
 {
 }
Пример #28
0
 public abstract JSValue Get(JSValue thisValue);
Пример #29
0
 internal JSBoxedString(JSValue Prototype, JSValue Constructor)
     : base(Prototype, Constructor)
 {
     this._val = JSString.Empty;
     base.SetDataProp("length", 0.0, false, false, false);
 }
Пример #30
0
 public override JSValue Call(JSContext Scope, JSValue ThisObj, JSArgs Args)
 {
     if (ThisObj.CheckCoercible())
     {
         ThisObj = ThisObj.ToJSObject();
     }
     else
     {
         ThisObj = JSContext.CurrentGlobalContext.Global;
     }
     return this._delegate(Scope, ThisObj, Args, false);
 }
Пример #31
0
 public override void SetMutableBinding(string key, JSValue value)
 {
     this.ScopeObject[key] = value;
 }
Пример #32
0
 public override void SetMutableBinding(string key, JSValue value)
 {
     this.scopeValues[key] = value;
 }
Пример #33
0
 public JSRuntimeException(JSValue value) : base(value.StringValue())
 {
     this.Line  = -1;
     this.value = value;
 }