Beispiel #1
0
        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;
        }
Beispiel #2
0
    // Test the global object properties.
    public void TestEngineGlobals()
    {
        // Create a new engine instance.
        VsaEngine engine = VsaEngine.CreateEngine();

        // Get the global object.
        LenientGlobalObject global = engine.LenientGlobalObject;

        AssertNotNull("Globals (1)", global);

        // Check that the "Object" and "Function" objects
        // appear to be of the right form.
        Object objectConstructor = global.Object;

        AssertNotNull("Globals (2)", objectConstructor);
        Assert("Globals (3)", objectConstructor is ObjectConstructor);
        Object functionConstructor = global.Function;

        AssertNotNull("Globals (4)", functionConstructor);
        Assert("Globals (5)",
               functionConstructor is FunctionConstructor);

        // Check the type information.
        AssertSame("Type (1)", typeof(Boolean), global.boolean);
        AssertSame("Type (2)", typeof(Byte), global.@byte);
        AssertSame("Type (3)", typeof(SByte), global.@sbyte);
        AssertSame("Type (4)", typeof(Char), global.@char);
        AssertSame("Type (5)", typeof(Int16), global.@short);
        AssertSame("Type (6)", typeof(UInt16), global.@ushort);
        AssertSame("Type (7)", typeof(Int32), global.@int);
        AssertSame("Type (8)", typeof(UInt32), global.@uint);
        AssertSame("Type (9)", typeof(Int64), global.@long);
        AssertSame("Type (10)", typeof(UInt64), global.@ulong);
        AssertSame("Type (11)", typeof(Single), global.@float);
        AssertSame("Type (12)", typeof(Double), global.@double);
        AssertSame("Type (13)", typeof(Decimal), global.@decimal);
        AssertSame("Type (14)", typeof(Void), global.@void);

        // Check the global functions.
        CheckScriptFunction("CollectGarbage",
                            global.CollectGarbage, 0);
        CheckScriptFunction("decodeURI",
                            global.decodeURI, 1);
        CheckScriptFunction("decodeURIComponent",
                            global.decodeURIComponent, 1);
        CheckScriptFunction("encodeURI",
                            global.encodeURI, 1);
        CheckScriptFunction("encodeURIComponent",
                            global.encodeURIComponent, 1);
        CheckScriptFunction("escape",
                            global.escape, 1);
        CheckScriptFunction("eval",
                            global.eval, 1);
        CheckScriptFunction("isFinite",
                            global.isFinite, 1);
        CheckScriptFunction("isNaN",
                            global.isNaN, 1);
        CheckScriptFunction("parseFloat",
                            global.parseFloat, 1);
        CheckScriptFunction("parseInt",
                            global.parseInt, 2);
        CheckScriptFunction("ScriptEngine",
                            global.ScriptEngine, 0);
        CheckScriptFunction("ScriptEngineBuildVersion",
                            global.ScriptEngineBuildVersion, 0);
        CheckScriptFunction("ScriptEngineMajorVersion",
                            global.ScriptEngineMajorVersion, 0);
        CheckScriptFunction("ScriptEngineMinorVersion",
                            global.ScriptEngineMinorVersion, 0);
        CheckScriptFunction("unescape",
                            global.unescape, 1);

        // Check the global values.
        Assert("Value (1)",
               Double.IsPositiveInfinity((double)(global.Infinity)));
        Assert("Value (2)", Double.IsNaN((double)(global.NaN)));
        AssertNull("Value (3)", global.undefined);

        // Close the engine and exit.
        engine.Close();
    }