Ejemplo n.º 1
0
 internal ScriptValue Call([CanBeNull] ScriptObject function, ScriptValue thisValue, [NotNull] IReadOnlyList <ScriptValue> arguments)
 {
     //https://tc39.github.io/ecma262/#sec-call
     if (function == null || !function.IsCallable)
     {
         throw CreateTypeError();
     }
     return(function.Call(thisValue, arguments));
 }
Ejemplo n.º 2
0
        ScriptObject ParseCall(CodeCallFunction scriptFunction)
        {
            ScriptObject obj = ResolveOperand(scriptFunction.Member);
            int          num = scriptFunction.Parameters.Count;

            ScriptObject[] parameters = new ScriptObject[num];
            for (int i = 0; i < num; ++i)
            {
                parameters[i] = ResolveOperand(scriptFunction.Parameters[i]);
            }
            m_script.PushStackInfo();
            return(obj.Call(parameters));
        }
Ejemplo n.º 3
0
        ScriptObject ParseCall(CodeCallFunction scriptFunction, bool needRet)
        {
            ScriptObject obj = ResolveOperand(scriptFunction.Member);
            int          num = scriptFunction.Parameters.Count;

            ScriptObject[] parameters = new ScriptObject[num];
            for (int i = 0; i < num; ++i)
            {
                parameters[i] = ResolveOperand(scriptFunction.Parameters[i]);
            }
            m_script.PushStackInfo();
            object ret = obj.Call(parameters);

            return(needRet ? m_script.CreateObject(ret) : null);
        }
Ejemplo n.º 4
0
        ScriptObject ParseCall(CodeCallFunction scriptFunction, bool needRet)
        {
            ScriptObject obj = ResolveOperand(scriptFunction.Member);
            int          num = scriptFunction.ParametersCount;

            ScriptObject[] parameters = new ScriptObject[num];
            for (int i = 0; i < num; ++i)
            {
                //此处要调用Assign 如果传入number string等基础类型  在函数内自运算的话 会影响 传入的值
                parameters[i] = ResolveOperand(scriptFunction.Parameters[i]).Assign();
            }
            m_script.PushStackInfo();
            object ret = obj.Call(parameters);

            return(needRet ? m_script.CreateObject(ret) : null);
        }
Ejemplo n.º 5
0
        private ScriptObject ParseCall(CodeCallFunction scriptFunction, bool needRet)
        {
            ScriptObject obj2            = this.ResolveOperand(scriptFunction.Member);
            int          parametersCount = scriptFunction.ParametersCount;

            ScriptObject[] parameters = new ScriptObject[parametersCount];
            for (int i = 0; i < parametersCount; i++)
            {
                parameters[i] = this.ResolveOperand(scriptFunction.Parameters[i]).Assign();
            }
            this.m_script.PushStackInfo();
            object obj3 = obj2.Call(parameters);

            this.m_script.PopStackInfo();
            if (!needRet)
            {
                return(null);
            }
            return(this.m_script.CreateObject(obj3));
        }
Ejemplo n.º 6
0
        ScriptObject ParseCall(CodeCallFunction scriptFunction, bool needRet)
        {
            ScriptObject obj = ResolveOperand(scriptFunction.Member);

            // 安装function this 信息
            if (obj is ScriptScriptFunction)
            {
                ScriptScriptFunction suf = obj as ScriptScriptFunction;
                if (!suf.isCloure)
                {
                    if (scriptFunction.Member is CodeMember)
                    {
                        CodeMember member = scriptFunction.Member as CodeMember;
                        if (member.Parent == null)
                        {
                            suf.SetTable(m_script.GetGlobalTable());
                        }
                        else
                        {
                            ScriptObject sotable = ResolveOperand(member.Parent);
                            if (sotable is ScriptTable)
                            {
                                suf.SetTable(sotable as ScriptTable);
                            }
                        }
                    }
                }
            }

            int num = scriptFunction.ParametersCount;

            ScriptObject[] parameters = new ScriptObject[num];
            for (int i = 0; i < num; ++i)
            {
                //此处要调用Assign 如果传入number string等基础类型  在函数内自运算的话 会影响 传入的值
                parameters[i] = ResolveOperand(scriptFunction.Parameters[i]).Assign();

                // 创建闭包
                if (parameters[i] is ScriptScriptFunction)
                {
                    ScriptScriptFunction ssf = parameters[i] as ScriptScriptFunction;
                    ssf.isCloure = true;
                    if (scriptFunction.Parameters[i] is CodeMember)
                    {
                        CodeMember member = scriptFunction.Parameters[i] as CodeMember;
                        if (member.Parent == null)
                        {
                            ssf.SetTable(m_script.GetGlobalTable());
                        }
                        else
                        {
                            ScriptObject sotable = ResolveOperand(member.Parent);
                            if (sotable is ScriptTable)
                            {
                                ssf.SetTable(sotable as ScriptTable);
                            }
                        }
                    }
                    else if (scriptFunction.Parameters[i] is CodeFunction)
                    {
                        if (obj is ScriptScriptFunction)
                        {
                            ScriptScriptFunction suf = obj as ScriptScriptFunction;
                            ssf.SetTable((ScriptTable)suf.GetValue("this"));
                        }
                    }
                }
            }
            m_script.PushStackInfo();

            object ret = obj.Call(parameters);

            m_script.PopStackInfo();
            return(needRet ? m_script.CreateObject(ret) : null);
        }