3 Star 1 Fork 0

Gitee 极速下载/otto

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/robertkrimen/otto
克隆/下载
type_arguments.go 2.66 KB
一键复制 编辑 原始数据 按行查看 历史
Steven Hartland 提交于 2024-04-13 17:05 . chore: update ci versions (#519)
package otto
import (
"strconv"
)
func (rt *runtime) newArgumentsObject(indexOfParameterName []string, stash stasher, length int) *object {
obj := rt.newClassObject("Arguments")
for index := range indexOfParameterName {
name := strconv.FormatInt(int64(index), 10)
objectDefineOwnProperty(obj, name, property{Value{}, 0o111}, false)
}
obj.objectClass = classArguments
obj.value = argumentsObject{
indexOfParameterName: indexOfParameterName,
stash: stash,
}
obj.prototype = rt.global.ObjectPrototype
obj.defineProperty(propertyLength, intValue(length), 0o101, false)
return obj
}
type argumentsObject struct {
stash stasher
indexOfParameterName []string
}
func (o argumentsObject) clone(c *cloner) argumentsObject {
indexOfParameterName := make([]string, len(o.indexOfParameterName))
copy(indexOfParameterName, o.indexOfParameterName)
return argumentsObject{
indexOfParameterName: indexOfParameterName,
stash: c.stash(o.stash),
}
}
func (o argumentsObject) get(name string) (Value, bool) {
index := stringToArrayIndex(name)
if index >= 0 && index < int64(len(o.indexOfParameterName)) {
if name = o.indexOfParameterName[index]; name == "" {
return Value{}, false
}
return o.stash.getBinding(name, false), true
}
return Value{}, false
}
func (o argumentsObject) put(name string, value Value) {
index := stringToArrayIndex(name)
name = o.indexOfParameterName[index]
o.stash.setBinding(name, value, false)
}
func (o argumentsObject) delete(name string) {
index := stringToArrayIndex(name)
o.indexOfParameterName[index] = ""
}
func argumentsGet(obj *object, name string) Value {
if value, exists := obj.value.(argumentsObject).get(name); exists {
return value
}
return objectGet(obj, name)
}
func argumentsGetOwnProperty(obj *object, name string) *property {
prop := objectGetOwnProperty(obj, name)
if value, exists := obj.value.(argumentsObject).get(name); exists {
prop.value = value
}
return prop
}
func argumentsDefineOwnProperty(obj *object, name string, descriptor property, throw bool) bool {
if _, exists := obj.value.(argumentsObject).get(name); exists {
if !objectDefineOwnProperty(obj, name, descriptor, false) {
return obj.runtime.typeErrorResult(throw)
}
if value, valid := descriptor.value.(Value); valid {
obj.value.(argumentsObject).put(name, value)
}
return true
}
return objectDefineOwnProperty(obj, name, descriptor, throw)
}
func argumentsDelete(obj *object, name string, throw bool) bool {
if !objectDelete(obj, name, throw) {
return false
}
if _, exists := obj.value.(argumentsObject).get(name); exists {
obj.value.(argumentsObject).delete(name)
}
return true
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/otto.git
git@gitee.com:mirrors/otto.git
mirrors
otto
otto
master

搜索帮助