mirror of https://github.com/ethereum/go-ethereum
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.6 KiB
97 lines
2.6 KiB
10 years ago
|
package otto
|
||
|
|
||
|
import (
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
10 years ago
|
func (self *_runtime) cmpl_evaluate_nodeProgram(node *_nodeProgram, eval bool) Value {
|
||
|
if !eval {
|
||
|
self.enterGlobalScope()
|
||
|
defer func() {
|
||
|
self.leaveScope()
|
||
|
}()
|
||
|
}
|
||
10 years ago
|
self.cmpl_functionDeclaration(node.functionList)
|
||
|
self.cmpl_variableDeclaration(node.varList)
|
||
10 years ago
|
self.scope.frame.file = node.file
|
||
10 years ago
|
return self.cmpl_evaluate_nodeStatementList(node.body)
|
||
|
}
|
||
|
|
||
10 years ago
|
func (self *_runtime) cmpl_call_nodeFunction(function *_object, stash *_fnStash, node *_nodeFunctionLiteral, this Value, argumentList []Value) Value {
|
||
10 years ago
|
|
||
|
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
|
||
|
}
|
||
10 years ago
|
value := Value{}
|
||
10 years ago
|
if index < len(argumentList) {
|
||
|
value = argumentList[index]
|
||
|
indexOfParameterName[index] = name
|
||
|
}
|
||
10 years ago
|
// strict = false
|
||
|
self.scope.lexical.setValue(name, value, false)
|
||
10 years ago
|
}
|
||
|
|
||
|
if !argumentsFound {
|
||
10 years ago
|
arguments := self.newArgumentsObject(indexOfParameterName, stash, len(argumentList))
|
||
10 years ago
|
arguments.defineProperty("callee", toValue_object(function), 0101, false)
|
||
10 years ago
|
stash.arguments = arguments
|
||
|
// strict = false
|
||
|
self.scope.lexical.setValue("arguments", toValue_object(arguments), false)
|
||
10 years ago
|
for index, _ := range argumentList {
|
||
|
if index < len(node.parameterList) {
|
||
|
continue
|
||
|
}
|
||
|
indexAsString := strconv.FormatInt(int64(index), 10)
|
||
|
arguments.defineProperty(indexAsString, argumentList[index], 0111, false)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
self.cmpl_functionDeclaration(node.functionList)
|
||
|
self.cmpl_variableDeclaration(node.varList)
|
||
|
|
||
|
result := self.cmpl_evaluate_nodeStatement(node.body)
|
||
10 years ago
|
if result.kind == valueResult {
|
||
10 years ago
|
return result
|
||
|
}
|
||
|
|
||
10 years ago
|
return Value{}
|
||
10 years ago
|
}
|
||
|
|
||
|
func (self *_runtime) cmpl_functionDeclaration(list []*_nodeFunctionLiteral) {
|
||
10 years ago
|
executionContext := self.scope
|
||
10 years ago
|
eval := executionContext.eval
|
||
10 years ago
|
stash := executionContext.variable
|
||
10 years ago
|
|
||
|
for _, function := range list {
|
||
|
name := function.name
|
||
|
value := self.cmpl_evaluate_nodeExpression(function)
|
||
10 years ago
|
if !stash.hasBinding(name) {
|
||
|
stash.createBinding(name, eval == true, value)
|
||
|
} else {
|
||
|
// TODO 10.5.5.e
|
||
|
stash.setBinding(name, value, false) // TODO strict
|
||
10 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (self *_runtime) cmpl_variableDeclaration(list []string) {
|
||
10 years ago
|
executionContext := self.scope
|
||
10 years ago
|
eval := executionContext.eval
|
||
10 years ago
|
stash := executionContext.variable
|
||
10 years ago
|
|
||
|
for _, name := range list {
|
||
10 years ago
|
if !stash.hasBinding(name) {
|
||
|
stash.createBinding(name, eval == true, Value{}) // TODO strict?
|
||
10 years ago
|
}
|
||
|
}
|
||
|
}
|