public JsGlobal(ExecutionVisitor visitor, Options options)
        {
            this.Options = options;
            this.Visitor = visitor;

            this["null"] = JsNull.Instance;

            #region Global Classes
            this["Object"]   = ObjectClass = new JsObjectConstructor(this);
            this["Function"] = FunctionClass = new JsFunctionConstructor(this);
            this["Array"]    = ArrayClass = new JsArrayConstructor(this);
            this["Boolean"]  = BooleanClass = new JsBooleanConstructor(this);
            this["Date"]     = DateClass = new JsDateConstructor(this);

            this["Error"]          = ErrorClass = new JsErrorConstructor(this, "Error");
            this["EvalError"]      = EvalErrorClass = new JsErrorConstructor(this, "EvalError");
            this["RangeError"]     = RangeErrorClass = new JsErrorConstructor(this, "RangeError");
            this["ReferenceError"] = ReferenceErrorClass = new JsErrorConstructor(this, "ReferenceError");
            this["SyntaxError"]    = SyntaxErrorClass = new JsErrorConstructor(this, "SyntaxError");
            this["TypeError"]      = TypeErrorClass = new JsErrorConstructor(this, "TypeError");
            this["URIError"]       = URIErrorClass = new JsErrorConstructor(this, "URIError");

            this["Number"] = NumberClass = new JsNumberConstructor(this);
            this["RegExp"] = RegExpClass = new JsRegExpConstructor(this);
            this["String"] = StringClass = new JsStringConstructor(this);
            this["Math"]   = MathClass = new JsMathConstructor(this);
            this.Prototype = ObjectClass.Prototype;
            #endregion


            MathClass.Prototype = ObjectClass.Prototype;

            foreach (JsInstance c in this.GetValues())
            {
                if (c is JsConstructor)
                {
                    ((JsConstructor)c).InitPrototype(this);
                }
            }

            #region Global Properties
            this["NaN"]           = NumberClass["NaN"];               // 15.1.1.1
            this["Infinity"]      = NumberClass["POSITIVE_INFINITY"]; // // 15.1.1.2
            this["undefined"]     = JsUndefined.Instance;             // 15.1.1.3
            this[JsInstance.THIS] = this;
            #endregion

            #region Global Functions
            this["eval"]               = new JsFunctionWrapper(Eval);       // 15.1.2.1
            this["parseInt"]           = new JsFunctionWrapper(ParseInt);   // 15.1.2.2
            this["parseFloat"]         = new JsFunctionWrapper(ParseFloat); // 15.1.2.3
            this["isNaN"]              = new JsFunctionWrapper(IsNaN);
            this["isFinite"]           = new JsFunctionWrapper(isFinite);
            this["decodeURI"]          = new JsFunctionWrapper(DecodeURI);
            this["encodeURI"]          = new JsFunctionWrapper(EncodeURI);
            this["decodeURIComponent"] = new JsFunctionWrapper(DecodeURIComponent);
            this["encodeURIComponent"] = new JsFunctionWrapper(EncodeURIComponent);
            #endregion
        }
        public JsApplyFunction(JsFunctionConstructor constructor)
        {
            if (constructor != null)
            {
                Prototype = new JsObject()
                {
                    Prototype = constructor.Prototype
                }
            }
            ;

            Prototype.DefineOwnProperty("length", new ValueDescriptor(Prototype, "length", constructor.Global.NumberClass.New(2))
            {
                Writable = false
            });
        }
示例#3
0
        public JsGlobal(ExecutionVisitor visitor, Options options)
            : base(JsNull.Instance)
        {
            this.Options = options;
            this.Visitor = visitor;

            this["null"] = JsNull.Instance;
            JsObject objectProrotype = new JsObject(JsNull.Instance);

            JsFunction functionPrototype = new JsFunctionWrapper(
                delegate(JsInstance[] arguments) {
                return(JsUndefined.Instance);
            },
                objectProrotype
                );

            Marshaller = new Marshaller(this);

            #region Global Classes
            this["Function"] = FunctionClass = new JsFunctionConstructor(this, functionPrototype);
            this["Object"]   = ObjectClass = new JsObjectConstructor(this, functionPrototype, objectProrotype);
            ObjectClass.InitPrototype(this);


            this["Array"]   = ArrayClass = new JsArrayConstructor(this);
            this["Boolean"] = BooleanClass = new JsBooleanConstructor(this);
            this["Date"]    = DateClass = new JsDateConstructor(this);

            this["Error"]          = ErrorClass = new JsErrorConstructor(this, "Error");
            this["EvalError"]      = EvalErrorClass = new JsErrorConstructor(this, "EvalError");
            this["RangeError"]     = RangeErrorClass = new JsErrorConstructor(this, "RangeError");
            this["ReferenceError"] = ReferenceErrorClass = new JsErrorConstructor(this, "ReferenceError");
            this["SyntaxError"]    = SyntaxErrorClass = new JsErrorConstructor(this, "SyntaxError");
            this["TypeError"]      = TypeErrorClass = new JsErrorConstructor(this, "TypeError");
            this["URIError"]       = URIErrorClass = new JsErrorConstructor(this, "URIError");

            this["Number"] = NumberClass = new JsNumberConstructor(this);
            this["RegExp"] = RegExpClass = new JsRegExpConstructor(this);
            this["String"] = StringClass = new JsStringConstructor(this);
            this["Math"]   = MathClass = new JsMathConstructor(this);

            // 15.1 prototype of the global object varies on the implementation
            //this.Prototype = ObjectClass.PrototypeProperty;
            #endregion


            foreach (JsInstance c in this.GetValues())
            {
                if (c is JsConstructor)
                {
                    ((JsConstructor)c).InitPrototype(this);
                }
            }

            #region Global Properties
            this["NaN"]        = NumberClass["NaN"];               // 15.1.1.1
            this["Infinity"]   = NumberClass["POSITIVE_INFINITY"]; // // 15.1.1.2
            this["undefined"]  = JsUndefined.Instance;             // 15.1.1.3
            this[JsScope.THIS] = this;
            #endregion

            #region Global Functions
            // every embed function should have a prototype FunctionClass.PrototypeProperty - 15.
            this["eval"]               = new JsFunctionWrapper(Eval, FunctionClass.PrototypeProperty);       // 15.1.2.1
            this["parseInt"]           = new JsFunctionWrapper(ParseInt, FunctionClass.PrototypeProperty);   // 15.1.2.2
            this["parseFloat"]         = new JsFunctionWrapper(ParseFloat, FunctionClass.PrototypeProperty); // 15.1.2.3
            this["isNaN"]              = new JsFunctionWrapper(IsNaN, FunctionClass.PrototypeProperty);
            this["isFinite"]           = new JsFunctionWrapper(isFinite, FunctionClass.PrototypeProperty);
            this["decodeURI"]          = new JsFunctionWrapper(DecodeURI, FunctionClass.PrototypeProperty);
            this["encodeURI"]          = new JsFunctionWrapper(EncodeURI, FunctionClass.PrototypeProperty);
            this["decodeURIComponent"] = new JsFunctionWrapper(DecodeURIComponent, FunctionClass.PrototypeProperty);
            this["encodeURIComponent"] = new JsFunctionWrapper(EncodeURIComponent, FunctionClass.PrototypeProperty);
            #endregion

            Marshaller.InitTypes();
        }
示例#4
0
 public JsApplyFunction(JsFunctionConstructor constructor)
     : base(constructor.PrototypeProperty)
 {
     DefineOwnProperty("length", constructor.Global.NumberClass.New(2), PropertyAttributes.ReadOnly);
 }
示例#5
0
 public JsCallFunction(JsFunctionConstructor constructor)
     : base(constructor.PrototypeProperty)
 {
     this.DefineOwnProperty("length", (JsInstance)constructor.Global.NumberClass.New(1.0), PropertyAttributes.ReadOnly);
 }