コード例 #1
0
        private InterpretedFunction(InterpreterData idata, object staticSecurityDomain)
        {
            this.idata = idata;

            // Always get Context from the current thread to
            // avoid security breaches via passing mangled Context instances
            // with bogus SecurityController
            Context            cx = Context.CurrentContext;
            SecurityController sc = cx.SecurityController;
            object             dynamicDomain;

            if (sc != null)
            {
                dynamicDomain = sc.getDynamicSecurityDomain(staticSecurityDomain);
            }
            else
            {
                if (staticSecurityDomain != null)
                {
                    throw new ArgumentException();
                }
                dynamicDomain = null;
            }

            this.securityController = sc;
            this.securityDomain     = dynamicDomain;
        }
コード例 #2
0
        /// <summary> Create script from compiled bytecode.</summary>
        internal static InterpretedFunction createScript(InterpreterData idata, object staticSecurityDomain)
        {
            InterpretedFunction f;

            f = new InterpretedFunction(idata, staticSecurityDomain);
            return(f);
        }
コード例 #3
0
        internal InterpreterData(InterpreterData parent)
        {
            this.parentData      = parent;
            this.languageVersion = parent.languageVersion;
            this.itsSourceFile   = parent.itsSourceFile;
            this.encodedSource   = parent.encodedSource;

            Init();
        }
コード例 #4
0
        internal InterpreterData(InterpreterData parent)
        {
            this.parentData = parent;
            this.languageVersion = parent.languageVersion;
            this.itsSourceFile = parent.itsSourceFile;
            this.encodedSource = parent.encodedSource;

            Init ();
        }
コード例 #5
0
        private InterpretedFunction(InterpreterData idata, object staticSecurityDomain)
        {
            this.idata = idata;

            // Always get Context from the current thread to
            // avoid security breaches via passing mangled Context instances
            // with bogus SecurityController
            Context cx = Context.CurrentContext;
            SecurityController sc = cx.SecurityController;
            object dynamicDomain;
            if (sc != null) {
                dynamicDomain = sc.getDynamicSecurityDomain (staticSecurityDomain);
            }
            else {
                if (staticSecurityDomain != null) {
                    throw new ArgumentException ();
                }
                dynamicDomain = null;
            }

            this.securityController = sc;
            this.securityDomain = dynamicDomain;
        }
コード例 #6
0
 private InterpretedFunction(InterpretedFunction parent, int index)
 {
     this.idata = parent.idata.itsNestedFunctions [index];
     this.securityController = parent.securityController;
     this.securityDomain     = parent.securityDomain;
 }
コード例 #7
0
        /// <summary> Create function compiled from Function(...) constructor.</summary>
        internal static InterpretedFunction createFunction(Context cx, IScriptable scope, InterpreterData idata, object staticSecurityDomain)
        {
            InterpretedFunction f;

            f = new InterpretedFunction(idata, staticSecurityDomain);
            f.initInterpretedFunction(cx, scope);
            return(f);
        }
コード例 #8
0
        void generateNestedFunctions ()
        {
            int functionCount = scriptOrFn.FunctionCount;
            if (functionCount == 0)
                return;

            InterpreterData [] array = new InterpreterData [functionCount];
            for (int i = 0; i != functionCount; i++) {
                FunctionNode def = scriptOrFn.getFunctionNode (i);
                Interpreter jsi = new Interpreter ();
                jsi.compilerEnv = compilerEnv;
                jsi.scriptOrFn = def;
                jsi.itsData = new InterpreterData (itsData);
                jsi.generateFunctionICode ();
                array [i] = jsi.itsData;
            }
            itsData.itsNestedFunctions = array;
        }
コード例 #9
0
        public virtual object Compile (CompilerEnvirons compilerEnv, ScriptOrFnNode tree, string encodedSource, bool returnFunction)
        {
            this.compilerEnv = compilerEnv;
            new NodeTransformer ().transform (tree);

            if (Token.printTrees) {
                System.Console.Out.WriteLine (tree.toStringTree (tree));
            }

            if (returnFunction) {
                tree = tree.getFunctionNode (0);
            }

            scriptOrFn = tree;
            itsData = new InterpreterData (compilerEnv.LanguageVersion, scriptOrFn.SourceName, encodedSource);
            itsData.topLevel = true;

            if (returnFunction) {
                generateFunctionICode ();
            }
            else {
                generateICodeFromTree (scriptOrFn);
            }

            return itsData;
        }
コード例 #10
0
 internal static string GetEncodedSource (InterpreterData idata)
 {
     if (idata.encodedSource == null) {
         return null;
     }
     return idata.encodedSource.Substring (idata.encodedSourceStart, (idata.encodedSourceEnd) - (idata.encodedSourceStart));
 }
コード例 #11
0
        internal static int [] getLineNumbers (InterpreterData data)
        {
            UintMap presentLines = new UintMap ();

            sbyte [] iCode = data.itsICode;
            int iCodeLength = iCode.Length;
            for (int pc = 0; pc != iCodeLength; ) {
                int bytecode = iCode [pc];
                int span = bytecodeSpan (bytecode);
                if (bytecode == Icode_LINE) {
                    if (span != 3)
                        Context.CodeBug ();
                    int line = GetIndex (iCode, pc + 1);
                    presentLines.put (line, 0);
                }
                pc += span;
            }

            return presentLines.Keys;
        }
コード例 #12
0
        static void dumpICode (InterpreterData idata)
        {
            if (!Token.printICode) {
                return;
            }

            sbyte [] iCode = idata.itsICode;
            int iCodeLength = iCode.Length;
            string [] strings = idata.itsStringTable;

            System.IO.TextWriter sw = Console.Out;
            sw.WriteLine ("ICode dump, for " + idata.itsName + ", length = " + iCodeLength);
            sw.WriteLine ("MaxStack = " + idata.itsMaxStack);

            int indexReg = 0;
            for (int pc = 0; pc < iCodeLength; ) {
                sw.Flush ();
                sw.Write (" [" + pc + "] ");
                int token = iCode [pc];
                int icodeLength = bytecodeSpan (token);
                string tname = bytecodeName (token);
                int old_pc = pc;
                ++pc;
                switch (token) {

                    default:
                        if (icodeLength != 1)
                            Context.CodeBug ();
                        sw.WriteLine (tname);
                        break;



                    case Icode_GOSUB:
                    case Token.GOTO:
                    case Token.IFEQ:
                    case Token.IFNE:
                    case Icode_IFEQ_POP:
                    case Icode_LEAVEDQ: {
                            int newPC = pc + GetShort (iCode, pc) - 1;
                            sw.WriteLine (tname + " " + newPC);
                            pc += 2;
                            break;
                        }

                    case Icode_VAR_INC_DEC:
                    case Icode_NAME_INC_DEC:
                    case Icode_PROP_INC_DEC:
                    case Icode_ELEM_INC_DEC:
                    case Icode_REF_INC_DEC: {
                            int incrDecrType = iCode [pc];
                            sw.WriteLine (tname + " " + incrDecrType);
                            ++pc;
                            break;
                        }


                    case Icode_CALLSPECIAL: {
                            int callType = iCode [pc] & 0xFF;
                            bool isNew = (iCode [pc + 1] != 0);
                            int line = GetIndex (iCode, pc + 2);
                            sw.WriteLine (tname + " " + callType + " " + isNew + " " + indexReg + " " + line);
                            pc += 4;
                            break;
                        }


                    case Token.CATCH_SCOPE: {
                            bool afterFisrtFlag = (iCode [pc] != 0);
                            sw.WriteLine (tname + " " + afterFisrtFlag);
                            ++pc;
                        }
                        break;

                    case Token.REGEXP:
                        sw.WriteLine (tname + " " + idata.itsRegExpLiterals [indexReg]);
                        break;

                    case Token.OBJECTLIT:
                    case Icode_SPARE_ARRAYLIT:
                        sw.WriteLine (tname + " " + idata.literalIds [indexReg]);
                        break;

                    case Icode_CLOSURE_EXPR:
                    case Icode_CLOSURE_STMT:
                        sw.WriteLine (tname + " " + idata.itsNestedFunctions [indexReg]);
                        break;

                    case Token.CALL:
                    case Icode_TAIL_CALL:
                    case Token.REF_CALL:
                    case Token.NEW:
                        sw.WriteLine (tname + ' ' + indexReg);
                        break;

                    case Token.THROW: {
                            int line = GetIndex (iCode, pc);
                            sw.WriteLine (tname + " : " + line);
                            pc += 2;
                            break;
                        }

                    case Icode_SHORTNUMBER: {
                            int value = GetShort (iCode, pc);
                            sw.WriteLine (tname + " " + value);
                            pc += 2;
                            break;
                        }

                    case Icode_INTNUMBER: {
                            int value = GetInt (iCode, pc);
                            sw.WriteLine (tname + " " + value);
                            pc += 4;
                            break;
                        }

                    case Token.NUMBER: {
                            double value = idata.itsDoubleTable [indexReg];
                            sw.WriteLine (tname + " " + value);
                            pc += 2;
                            break;
                        }

                    case Icode_LINE: {
                            int line = GetIndex (iCode, pc);
                            sw.WriteLine (tname + " : " + line);
                            pc += 2;
                            break;
                        }

                    case Icode_REG_STR1: {
                            string str = strings [0xFF & iCode [pc]];
                            sw.WriteLine (tname + " \"" + str + '"');
                            ++pc;
                            break;
                        }

                    case Icode_REG_STR2: {
                            string str = strings [GetIndex (iCode, pc)];
                            sw.WriteLine (tname + " \"" + str + '"');
                            pc += 2;
                            break;
                        }

                    case Icode_REG_STR4: {
                            string str = strings [GetInt (iCode, pc)];
                            sw.WriteLine (tname + " \"" + str + '"');
                            pc += 4;
                            break;
                        }

                    case Icode_REG_IND1: {
                            indexReg = 0xFF & iCode [pc];
                            sw.WriteLine (tname + " " + indexReg);
                            ++pc;
                            break;
                        }

                    case Icode_REG_IND2: {
                            indexReg = GetIndex (iCode, pc);
                            sw.WriteLine (tname + " " + indexReg);
                            pc += 2;
                            break;
                        }

                    case Icode_REG_IND4: {
                            indexReg = GetInt (iCode, pc);
                            sw.WriteLine (tname + " " + indexReg);
                            pc += 4;
                            break;
                        }

                    case Icode_GETVAR1:
                    case Icode_SETVAR1:
                        indexReg = iCode [pc];
                        sw.WriteLine (tname + " " + indexReg);
                        ++pc;
                        break;
                }
                if (old_pc + icodeLength != pc)
                    Context.CodeBug ();
            }

            int [] table = idata.itsExceptionTable;
            if (table != null) {
                sw.WriteLine ("Exception handlers: " + table.Length / EXCEPTION_SLOT_SIZE);
                for (int i = 0; i != table.Length; i += EXCEPTION_SLOT_SIZE) {
                    int tryStart = table [i + EXCEPTION_TRY_START_SLOT];
                    int tryEnd = table [i + EXCEPTION_TRY_END_SLOT];
                    int handlerStart = table [i + EXCEPTION_HANDLER_SLOT];
                    int type = table [i + EXCEPTION_TYPE_SLOT];
                    int exceptionLocal = table [i + EXCEPTION_LOCAL_SLOT];
                    int scopeLocal = table [i + EXCEPTION_SCOPE_SLOT];

                    sw.WriteLine (" tryStart=" + tryStart + " tryEnd=" + tryEnd + " handlerStart=" + handlerStart + " type=" + (type == 0 ? "catch" : "finally") + " exceptionLocal=" + exceptionLocal);
                }
            }
            sw.Flush ();
        }
コード例 #13
0
 private InterpretedFunction(InterpretedFunction parent, int index)
 {
     this.idata = parent.idata.itsNestedFunctions [index];
     this.securityController = parent.securityController;
     this.securityDomain = parent.securityDomain;
 }
コード例 #14
0
 /// <summary> Create script from compiled bytecode.</summary>
 internal static InterpretedFunction createScript(InterpreterData idata, object staticSecurityDomain)
 {
     InterpretedFunction f;
     f = new InterpretedFunction (idata, staticSecurityDomain);
     return f;
 }
コード例 #15
0
 /// <summary> Create function compiled from Function(...) constructor.</summary>
 internal static InterpretedFunction createFunction(Context cx, IScriptable scope, InterpreterData idata, object staticSecurityDomain)
 {
     InterpretedFunction f;
     f = new InterpretedFunction (idata, staticSecurityDomain);
     f.initInterpretedFunction (cx, scope);
     return f;
 }