3 Star 1 Fork 0

Gitee 极速下载/otto

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/robertkrimen/otto
克隆/下载
cmpl_evaluate.go 2.45 KB
一键复制 编辑 原始数据 按行查看 历史
package otto
import (
"strconv"
)
func (rt *runtime) cmplEvaluateNodeProgram(node *nodeProgram, eval bool) Value {
if !eval {
rt.enterGlobalScope()
defer rt.leaveScope()
}
rt.cmplFunctionDeclaration(node.functionList)
rt.cmplVariableDeclaration(node.varList)
rt.scope.frame.file = node.file
return rt.cmplEvaluateNodeStatementList(node.body)
}
func (rt *runtime) cmplCallNodeFunction(function *object, stash *fnStash, node *nodeFunctionLiteral, argumentList []Value) Value {
indexOfParameterName := make([]string, len(argumentList))
// function(abc, def, ghi)
// indexOfParameterName[0] = "abc"
// indexOfParameterName[1] = "def"
// indexOfParameterName[2] = "ghi"
// ...
argumentsFound := false
for index, name := range node.parameterList {
if name == "arguments" {
argumentsFound = true
}
value := Value{}
if index < len(argumentList) {
value = argumentList[index]
indexOfParameterName[index] = name
}
// strict = false
rt.scope.lexical.setValue(name, value, false)
}
if !argumentsFound {
arguments := rt.newArgumentsObject(indexOfParameterName, stash, len(argumentList))
arguments.defineProperty("callee", objectValue(function), 0o101, false)
stash.arguments = arguments
// strict = false
rt.scope.lexical.setValue("arguments", objectValue(arguments), false)
for index := range argumentList {
if index < len(node.parameterList) {
continue
}
indexAsString := strconv.FormatInt(int64(index), 10)
arguments.defineProperty(indexAsString, argumentList[index], 0o111, false)
}
}
rt.cmplFunctionDeclaration(node.functionList)
rt.cmplVariableDeclaration(node.varList)
result := rt.cmplEvaluateNodeStatement(node.body)
if result.kind == valueResult {
return result
}
return Value{}
}
func (rt *runtime) cmplFunctionDeclaration(list []*nodeFunctionLiteral) {
executionContext := rt.scope
eval := executionContext.eval
stash := executionContext.variable
for _, function := range list {
name := function.name
value := rt.cmplEvaluateNodeExpression(function)
if !stash.hasBinding(name) {
stash.createBinding(name, eval, value)
} else {
// TODO 10.5.5.e
stash.setBinding(name, value, false) // TODO strict
}
}
}
func (rt *runtime) cmplVariableDeclaration(list []string) {
executionContext := rt.scope
eval := executionContext.eval
stash := executionContext.variable
for _, name := range list {
if !stash.hasBinding(name) {
stash.createBinding(name, eval, Value{}) // TODO strict?
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/otto.git
git@gitee.com:mirrors/otto.git
mirrors
otto
otto
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385