public VsaEngine(bool fast) : base("JScript", "7.0.3300", true) { vsaItems = new VsaItems(this); detached = false; printSupported = false; engineInstance = new EngineInstance(this); engineInstance.Init(); // Set the global context to this engine if we are // the only engine instance in the system. Globals.SetContextEngine(this); // Create the global object that contains all of // the definitions in the engine's global scope. lenientGlobalObject = new LenientGlobalObject(this); // Create the global scope object. globalScope = new GlobalScope (null, lenientGlobalObject.globalObject); // Initialize the scope stack. scopeStack = new Object [8]; scopeStack[0] = globalScope; scopeStackSize = 1; currentScope = globalScope; }
// Constructor. internal ArrayPrototype(ObjectPrototype parent, EngineInstance inst) : base(parent) { // Add the builtin "Array" properties to the prototype. Put("constructor", inst.GetArrayConstructor()); AddBuiltin(inst, "concat"); AddBuiltin(inst, "join"); AddBuiltin(inst, "pop"); AddBuiltin(inst, "push"); AddBuiltin(inst, "reverse"); AddBuiltin(inst, "shift"); AddBuiltin(inst, "slice"); AddBuiltin(inst, "sort"); AddBuiltin(inst, "splice"); AddBuiltin(inst, "toLocaleString"); AddBuiltin(inst, "toString"); AddBuiltin(inst, "unshift"); }
internal LenientMathObject(ScriptObject parent, FunctionPrototype prototype) : base(parent) { EngineInstance inst = EngineInstance.GetEngineInstance(engine); abs = Get("abs"); acos = Get("acos"); asin = Get("asin"); atan = Get("atan"); atan2 = Get("atan2"); ceil = Get("ceil"); cos = Get("cos"); exp = Get("exp"); floor = Get("floor"); log = Get("log"); max = Get("max"); min = Get("min"); pow = Get("pow"); random = Get("random"); round = Get("round"); sin = Get("sin"); sqrt = Get("sqrt"); tan = Get("tan"); }
// Constructor. internal LenientArrayPrototype(ObjectPrototype parent, EngineInstance inst) : base(parent, inst) { constructor = inst.GetArrayConstructor(); concat = Get("concat"); join = Get("join"); pop = Get("pop"); push = Get("push"); reverse = Get("reverse"); shift = Get("shift"); slice = Get("slice"); sort = Get("sort"); splice = Get("splice"); toLocaleString = Get("toLocaleString"); toString = Get("toString"); unshift = Get("unshift"); }
// Construct a new "Object" instance. private static JSObject ConstructNewObject(VsaEngine engine) { return(new JSObject (EngineInstance.GetEngineInstance(engine) .GetObjectPrototype())); }
// Constructor. internal GlobalObject(VsaEngine engine) { // Record the engine for later. this.engine = engine; // Create the actual storage value, with no prototype. globalObject = new JSObject(null, engine); // Get the instance object for the engine. EngineInstance inst = EngineInstance.GetEngineInstance(engine); // Add all of the properties to the global object. AddBuiltin(inst, "CollectGarbage"); AddBuiltin(inst, "decodeURI"); AddBuiltin(inst, "decodeURIComponent"); AddBuiltin(inst, "encodeURI"); AddBuiltin(inst, "encodeURIComponent"); AddBuiltin(inst, "escape"); AddBuiltin(inst, "eval"); AddBuiltin(inst, "GetObject"); AddBuiltin(inst, "isFinite"); AddBuiltin(inst, "isNaN"); AddBuiltin(inst, "parseFloat"); AddBuiltin(inst, "parseInt"); AddBuiltin(inst, "ScriptEngine"); AddBuiltin(inst, "ScriptEngineBuildVersion"); AddBuiltin(inst, "ScriptEngineMajorVersion"); AddBuiltin(inst, "ScriptEngineMinorVersion"); AddBuiltin(inst, "unescape"); globalObject.Put("Infinity", Double.PositiveInfinity, PropertyAttributes.DontEnum | PropertyAttributes.DontDelete); globalObject.Put("NaN", Double.NaN, PropertyAttributes.DontEnum | PropertyAttributes.DontDelete); globalObject.Put("undefined", null, PropertyAttributes.DontEnum | PropertyAttributes.DontDelete); #if false AddProperty("ActiveXObject", ActiveXObject); #endif AddProperty("Array", Array); #if false AddProperty("Boolean", Boolean); AddProperty("Date", Date); AddProperty("Enumerator", Enumerator); AddProperty("Error", Error); AddProperty("EvalError", EvalError); #endif AddProperty("Function", Function); AddProperty("Math", Math); AddProperty("Number", Number); AddProperty("Object", Object); #if false AddProperty("RangeError", RangeError); AddProperty("ReferenceError", ReferenceError); AddProperty("RegExp", RegExp); #endif AddProperty("String", String); #if false AddProperty("SyntaxError", SyntaxError); AddProperty("TypeError", TypeError); AddProperty("URIError", URIError); AddProperty("VBArray", VBArray); #endif }
// Perform a constructor call on this object. internal override Object Construct(VsaEngine engine, Object[] args) { ArrayObject obj; int index, len; if (args.Length != 1) { // Construct an array from a list of values. obj = new ArrayObject (EngineInstance.GetEngineInstance(engine) .GetArrayPrototype(), (uint)(args.Length)); len = args.Length; for (index = 0; index < len; ++index) { obj.PutIndex(index, args[index]); } } else if (args[0] is Array) { // Wrap an existing array. Array array = (Array)(args[0]); if (array.Rank != 1) { throw new JScriptException(JSError.TypeMismatch); } obj = new ArrayObject.Wrapper (EngineInstance.GetEngineInstance(engine) .GetArrayPrototype(), (Array)(args[0])); } else { // Construct an array from a length value. switch (Support.TypeCodeForObject(args[0])) { case TypeCode.Byte: case TypeCode.SByte: case TypeCode.Char: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: { double num = Convert.ToNumber(args[0]); uint inum = Convert.ToUInt32(args[0]); if (num == (double)inum) { return(new ArrayObject (EngineInstance.GetEngineInstance(engine) .GetArrayPrototype(), inum)); } else { throw new JScriptException (JSError.ArrayLengthConstructIncorrect); } } // Not reached. } // The length is not numeric, so it is actually a value. obj = new ArrayObject (EngineInstance.GetEngineInstance(engine) .GetArrayPrototype()); obj.PutIndex(0, args[0]); } return(obj); }
// Add a builtin method to a prototype. internal void AddBuiltin(EngineInstance inst, String name) { MethodInfo method = GetType().GetMethod(name); Put(name, new BuiltinFunction (inst.GetFunctionPrototype(), name, method), PropertyAttributes.None); }
// internal constructor internal MathObject(ScriptObject parent) : base(parent) { EngineInstance inst = EngineInstance.GetEngineInstance(engine); Put("E", E, PropertyAttributes.DontEnum | PropertyAttributes.DontDelete | PropertyAttributes.ReadOnly); Put("LN10", LN10, PropertyAttributes.DontEnum | PropertyAttributes.DontDelete | PropertyAttributes.ReadOnly); Put("LN2", LN2, PropertyAttributes.DontEnum | PropertyAttributes.DontDelete | PropertyAttributes.ReadOnly); Put("LOG2E", LOG2E, PropertyAttributes.DontEnum | PropertyAttributes.DontDelete | PropertyAttributes.ReadOnly); Put("LOG10E", LOG10E, PropertyAttributes.DontEnum | PropertyAttributes.DontDelete | PropertyAttributes.ReadOnly); Put("PI", PI, PropertyAttributes.DontEnum | PropertyAttributes.DontDelete | PropertyAttributes.ReadOnly); Put("SQRT1_2", SQRT1_2, PropertyAttributes.DontEnum | PropertyAttributes.DontDelete | PropertyAttributes.ReadOnly); Put("SQRT2", SQRT2, PropertyAttributes.DontEnum | PropertyAttributes.DontDelete | PropertyAttributes.ReadOnly); AddBuiltin(inst, "abs"); AddBuiltin(inst, "acos"); AddBuiltin(inst, "asin"); AddBuiltin(inst, "atan"); AddBuiltin(inst, "atan2"); AddBuiltin(inst, "ceil"); AddBuiltin(inst, "exp"); AddBuiltin(inst, "floor"); AddBuiltin(inst, "log"); AddBuiltin(inst, "max"); AddBuiltin(inst, "min"); AddBuiltin(inst, "pow"); AddBuiltin(inst, "random"); AddBuiltin(inst, "round"); AddBuiltin(inst, "sin"); AddBuiltin(inst, "sqrt"); AddBuiltin(inst, "tan"); }
// Add a builtin function to the global object. private void AddBuiltin(EngineInstance inst, string name) { MethodInfo method = typeof(GlobalObject).GetMethod(name); globalObject.Put(name, new BuiltinFunction (inst.GetFunctionPrototype(), name, method), PropertyAttributes.None); }