コード例 #1
0
ファイル: JSGlobalObject.cs プロジェクト: vrajeshbhavsar/mcjs
        internal static void EvalString(string inputString, ref mdr.DValue result, mdr.DFunction callerFunction = null, mdr.DObject callerContext = null, mdr.DObject thisArg = null)
        {
            var funcMetadata = JSParser.ParseScript(inputString).Expression.Metadata;
            var func         = new mdr.DFunction(funcMetadata, null);

            var  tempCallFrame = new mdr.CallFrame();
            bool isDirectEval  = callerContext != null;

            if (isDirectEval)
            {
                //function will behave as if it was the caller
                Debug.Assert(thisArg != null && callerFunction != null && callerContext != null, "Invalid situation! Direct eval call must have thisArg, callerFunction, callerContext set");
                funcMetadata.Scope.IsProgram      = false;
                funcMetadata.Scope.IsEvalFunction = true;
                funcMetadata.ParentFunction       = (JSFunctionMetadata)callerFunction.Metadata;
                tempCallFrame.CallerContext       = callerContext;
                tempCallFrame.This = thisArg;
            }
            else
            {
                //This will behave just like a program code
                tempCallFrame.CallerContext = mdr.Runtime.Instance.GlobalContext;
                tempCallFrame.This          = (mdr.Runtime.Instance.GlobalContext);
            }

            //TODO: find a way to assign a name to this
            //funcMetadata.Name += "_eval"; //After we know the ParentFunction

            tempCallFrame.Function  = func;
            tempCallFrame.Signature = mdr.DFunctionSignature.EmptySignature;
            func.Call(ref tempCallFrame);
            result.Set(ref tempCallFrame.Return);
        }