예제 #1
0
        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 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
        }
예제 #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
파일: JsGlobal.cs 프로젝트: nate-yocom/jint
        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();
        }
예제 #5
0
        public JsGlobal(IJintVisitor 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); // overriten by 1C function

            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["getType"] = new JsFunctionWrapper(GetType); // AVKugushev
            this["isDefault"] = new JsFunctionWrapper(IsDefault); // AVKugushev
            this["enumToString"] = new JsFunctionWrapper(EnumToString); // AVKugushev
            this["enumToInt"] = new JsFunctionWrapper(EnumToInt); // AVKugushev
            this["validate"] = new JsFunctionWrapper(Validate); // AVKugushev
            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);

            // 1C functions
            // Functions for working with String type values
            this["StrLen"] = new JsFunctionWrapper(StrLen);
            this["TrimL"] = new JsFunctionWrapper(TrimL);
            this["TrimR"] = new JsFunctionWrapper(TrimR);
            this["TrimAll"] = new JsFunctionWrapper(TrimAll);
            this["Left"] = new JsFunctionWrapper(Left);
            this["Right"] = new JsFunctionWrapper(Right);
            this["Mid"] = new JsFunctionWrapper(Mid);
            this["Find"] = new JsFunctionWrapper(Find);
            this["Upper"] = new JsFunctionWrapper(Upper);
            this["Lower"] = new JsFunctionWrapper(Lower);
            this["Char"] = new JsFunctionWrapper(Char);
            this["CharCode"] = new JsFunctionWrapper(CharCode);
            this["IsBlankString"] = new JsFunctionWrapper(IsBlankString);
            this["StrReplace"] = new JsFunctionWrapper(StrReplace);
            this["StrLineCount"] = new JsFunctionWrapper(StrLineCount);
            this["StrGetLine"] = new JsFunctionWrapper(StrGetLine);
            this["StrOccurrenceCount"] = new JsFunctionWrapper(StrOccurrenceCount);
            this["Title"] = new JsFunctionWrapper(Title);
            // Functions for working with Number type values
            this["Int"] = new JsFunctionWrapper(Int);
            this["Round"] = new JsFunctionWrapper(Round);
            this["Log"] = new JsFunctionWrapper(Log);
            this["Log10"] = new JsFunctionWrapper(Log10);
            this["Sin"] = new JsFunctionWrapper(Sin);
            this["Cos"] = new JsFunctionWrapper(Cos);
            this["Tan"] = new JsFunctionWrapper(Tan);
            this["ASin"] = new JsFunctionWrapper(ASin);
            this["ACos"] = new JsFunctionWrapper(ACos);
            this["ATan"] = new JsFunctionWrapper(ATan);
            this["Exp"] = new JsFunctionWrapper(Exp);
            this["Pow"] = new JsFunctionWrapper(Pow);
            this["Sqrt"] = new JsFunctionWrapper(Sqrt);
            // Functions for working with Date type values
            this["Year"] = new JsFunctionWrapper(Year);
            this["Month"] = new JsFunctionWrapper(Month);
            this["Day"] = new JsFunctionWrapper(Day);
            this["Hour"] = new JsFunctionWrapper(Hour);
            this["Minute"] = new JsFunctionWrapper(Minute);
            this["Second"] = new JsFunctionWrapper(Second);
            this["BegOfYear"] = new JsFunctionWrapper(BegOfYear);
            this["BegOfQuarter"] = new JsFunctionWrapper(BegOfQuarter);
            this["BegOfMonth"] = new JsFunctionWrapper(BegOfMonth);
            this["BegOfWeek"] = new JsFunctionWrapper(BegOfWeek);
            this["BegOfDay"] = new JsFunctionWrapper(BegOfDay);
            this["BegOfHour"] = new JsFunctionWrapper(BegOfHour);
            this["BegOfMinute"] = new JsFunctionWrapper(BegOfMinute);
            this["EndOfYear"] = new JsFunctionWrapper(EndOfYear);
            this["EndOfQuarter"] = new JsFunctionWrapper(EndOfQuarter);
            this["EndOfMonth"] = new JsFunctionWrapper(EndOfMonth);
            this["EndOfWeek"] = new JsFunctionWrapper(EndOfWeek);
            this["EndOfDay"] = new JsFunctionWrapper(EndOfDay);
            this["EndOfHour"] = new JsFunctionWrapper(EndOfHour);
            this["EndOfMinute"] = new JsFunctionWrapper(EndOfMinute);
            this["WeekOfYear"] = new JsFunctionWrapper(WeekOfYear);
            this["DayOfYear"] = new JsFunctionWrapper(DayOfYear);
            this["WeekDay"] = new JsFunctionWrapper(WeekDay);
            this["AddMonth"] = new JsFunctionWrapper(AddMonth);
            this["CurrentDate"] = new JsFunctionWrapper(CurrentDate);
            // Value conversion functions
            this["Boolean"] = new JsFunctionWrapper(Boolean);
            this["Number"] = new JsFunctionWrapper(Number);
            this["String"] = new JsFunctionWrapper(String);
            this["Date"] = new JsFunctionWrapper(Date);
            // Formatting functions
            this["Format"] = new JsFunctionWrapper(Format);
            // Others
            this["Type"] = new JsFunctionWrapper(Type);
            this["TypeOf"] = new JsFunctionWrapper(TypeOf);
            this["Min"] = new JsFunctionWrapper(Min);
            this["Max"] = new JsFunctionWrapper(Max);
            this["ErrorDescription"] = new JsFunctionWrapper(ErrorDescription);
            this["Eval"] = new JsFunctionWrapper(Eval1C);
            this["ErrorInfo"] = new JsFunctionWrapper(ErrorInfo);
            this["ToString"] = new JsFunctionWrapper(String);
            #endregion
        }