Beispiel #1
0
 public override object Construct(ExecutionContext GLOBAL, JSObjectBase args, ExecutionContext x)
 {
     JSObject result;
     if (JSObject.ToNumber(GLOBAL, args.GetItem(GLOBAL, "length").GetValue(GLOBAL)) > 0)
         result = new NumberObject(GLOBAL, JSObject.ToNumber(GLOBAL, args.GetItem(GLOBAL, "0").GetValue(GLOBAL)));
     else result = new NumberObject(GLOBAL, 0.0);
     result.DefProp(GLOBAL, "prototype", this.GetItem(GLOBAL, "prototype").GetValue(GLOBAL));
     result.DefProp(GLOBAL, "constructor", this);
     return result;
 }
Beispiel #2
0
 public NumberFun(ExecutionContext GLOBAL)
 {
     DefProp(GLOBAL, "MAX_VALUE", double.MaxValue, true, false, false, true);
     DefProp(GLOBAL, "MIN_VALUE", double.Epsilon, true, false, false, true);
     DefProp(GLOBAL, "NaN", double.NaN, true, false, false, true);
     DefProp(GLOBAL, "NEGATIVE_INFINITY", double.NegativeInfinity, true, false, false, true);
     DefProp(GLOBAL, "POSITIVE_INFINITY", double.PositiveInfinity, true, false, false, true);
     DefProp(GLOBAL, "length", (double)1, false, false, false, false);
     JSObject prototype = new NumberObject(GLOBAL, 0.0);
     prototype.SetItem(GLOBAL, "toString", new JSNativeMethod(typeof(JSObject), "ToString"));
     prototype.SetItem(GLOBAL, "valueOf", new JSNativeMethod(typeof(JSObject), "ToPrimitive"));
     DefProp(GLOBAL, "prototype", prototype, false, false, false);
     prototype.DefProp(GLOBAL, "constructor", this);
 }
Beispiel #3
0
        public NumberFun(ExecutionContext GLOBAL)
        {
            DefProp(GLOBAL, "MAX_VALUE", double.MaxValue, true, false, false, true);
            DefProp(GLOBAL, "MIN_VALUE", double.Epsilon, true, false, false, true);
            DefProp(GLOBAL, "NaN", double.NaN, true, false, false, true);
            DefProp(GLOBAL, "NEGATIVE_INFINITY", double.NegativeInfinity, true, false, false, true);
            DefProp(GLOBAL, "POSITIVE_INFINITY", double.PositiveInfinity, true, false, false, true);
            DefProp(GLOBAL, "length", (double)1, false, false, false, false);
            JSObject prototype = new NumberObject(GLOBAL, 0.0);

            prototype.SetItem(GLOBAL, "toString", new JSNativeMethod(typeof(JSObject), "ToString"));
            prototype.SetItem(GLOBAL, "valueOf", new JSNativeMethod(typeof(JSObject), "ToPrimitive"));
            DefProp(GLOBAL, "prototype", prototype, false, false, false);
            prototype.DefProp(GLOBAL, "constructor", this);
        }
Beispiel #4
0
        public override object Construct(ExecutionContext GLOBAL, JSObjectBase args, ExecutionContext x)
        {
            JSObject result;

            if (JSObject.ToNumber(GLOBAL, args.GetItem(GLOBAL, "length").GetValue(GLOBAL)) > 0)
            {
                result = new NumberObject(GLOBAL, JSObject.ToNumber(GLOBAL, args.GetItem(GLOBAL, "0").GetValue(GLOBAL)));
            }
            else
            {
                result = new NumberObject(GLOBAL, 0.0);
            }
            result.DefProp(GLOBAL, "prototype", this.GetItem(GLOBAL, "prototype").GetValue(GLOBAL));
            result.DefProp(GLOBAL, "constructor", this);
            return(result);
        }
Beispiel #5
0
        public jsexec()
        {
            GLOBAL.jobject = new JSObject();
            GLOBAL.jobject = GLOBAL.thisOb = new JSObject();

            StaticObjectFun = new ObjectFun(GLOBAL);
            GLOBAL.jobject.SetItem(GLOBAL, "StaticObjectFun", new JSSimpleProperty("StaticObjectFun", StaticObjectFun));
            StaticStringFun = new StringFun(GLOBAL);
            GLOBAL.jobject.SetItem(GLOBAL, "StaticStringFun", new JSSimpleProperty("StaticStringFun", StaticStringFun));
            StaticBooleanFun = new BooleanFun(GLOBAL);
            GLOBAL.jobject.SetItem(GLOBAL, "StaticBooleanFun", new JSSimpleProperty("StaticBooleanFun", StaticBooleanFun));
            StaticArrayFun = new ArrayFun(GLOBAL);
            GLOBAL.jobject.SetItem(GLOBAL, "StaticArrayFun", new JSSimpleProperty("StaticArrayFun", StaticArrayFun));
            StaticNumberFun = new NumberFun(GLOBAL);
            GLOBAL.jobject.SetItem(GLOBAL, "StaticNumberFun", new JSSimpleProperty("StaticNumberFun", StaticNumberFun));
            StaticFunctionFun = new FunctionFun(GLOBAL);
            GLOBAL.jobject.SetItem(GLOBAL, "StaticFunctionFun", new JSSimpleProperty("StaticFunctionFun", StaticFunctionFun));
            StaticNumberObject = new NumberObject(GLOBAL, 0.0);
            DatePrototype = new JSDate(GLOBAL);
            GLOBAL.jobject.SetItem(GLOBAL, "DatePrototype", new JSSimpleProperty("DatePrototype", DatePrototype));
            JSDate.SetupPrototype(GLOBAL, DatePrototype);

            GLOBAL.jobject.SetItem(GLOBAL, "toString", new JSNativeMethod(typeof(JSObject), "StaticToString"));

            /* Core types */
            JSObject thisOb = (JSObject)GLOBAL.thisOb;
            thisOb.DefProp(GLOBAL, "Object", StaticObjectFun);
            thisOb.DefProp(GLOBAL, "Function", StaticFunctionFun);
            thisOb.DefProp(GLOBAL, "Boolean", StaticBooleanFun);
            thisOb.DefProp(GLOBAL, "Number", StaticNumberFun);
            thisOb.DefProp(GLOBAL, "String", StaticStringFun);
            thisOb.DefProp(GLOBAL, "Array", StaticArrayFun);

            /* Types that work like classes */
            thisOb.DefProp(GLOBAL, "Math", JSClassWrapper.RegisterClass(GLOBAL, typeof(pygmalion.JSMath)));
            thisOb.DefProp(GLOBAL, "Date", JSClassWrapper.RegisterClass(GLOBAL, typeof(pygmalion.JSDate)));

            /* Standard library */
            thisOb.DefProp(GLOBAL, "decodeURI", new DecodeURIFun());
            thisOb.DefProp(GLOBAL, "decodeURIComponent", new DecodeURIComponentFun());
            thisOb.DefProp(GLOBAL, "encodeURI", new EncodeURIFun());
            thisOb.DefProp(GLOBAL, "encodeURIComponent", new EncodeURIComponentFun());
            thisOb.DefProp(GLOBAL, "escape", new EscapeFun());
            thisOb.DefProp(GLOBAL, "eval", new EvalFun());
            thisOb.DefProp(GLOBAL, "gc", new GcFun());
            thisOb.DefProp(GLOBAL, "Infinity", double.PositiveInfinity, false, false, false);
            thisOb.DefProp(GLOBAL, "isFinite", new isFiniteFun());
            thisOb.SetItem(GLOBAL, "isNaN", new JSNativeMethod(typeof(Double), "IsNaN"));
            thisOb.DefProp(GLOBAL, "parseFloat", new ParseFloat(), false, false, false);
            thisOb.DefProp(GLOBAL, "parseInt", new ParseInt(), false, false, false);
            thisOb.DefProp(GLOBAL, "NaN", double.NaN, false, false, false);
            thisOb.DefProp(GLOBAL, "unescape", new UnescapeFun());
            thisOb.DefProp(GLOBAL, "version", new VersionFun());

            GLOBAL.jobject.SetItem(GLOBAL, "JSExec", new JSSimpleProperty("JSExec", this));
            GLOBAL.thisOb = GLOBAL.jobject;
            GLOBAL.currentContext = new ExecutionContext(GLOBAL);
            GLOBAL.scope = GLOBAL.currentContext;
        }