3 Star 1 Fork 0

Gitee 极速下载/otto

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/robertkrimen/otto
克隆/下载
type_reference.go 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
Steven Hartland 提交于 2024-04-13 17:05 . chore: update ci versions (#519)
package otto
type referencer interface {
invalid() bool // IsUnresolvableReference
getValue() Value // getValue
putValue(value Value) string // PutValue
delete() bool
}
// PropertyReference
type propertyReference struct {
base *object
runtime *runtime
name string
at at
strict bool
}
func newPropertyReference(rt *runtime, base *object, name string, strict bool, atv at) *propertyReference {
return &propertyReference{
runtime: rt,
name: name,
strict: strict,
base: base,
at: atv,
}
}
func (pr *propertyReference) invalid() bool {
return pr.base == nil
}
func (pr *propertyReference) getValue() Value {
if pr.base == nil {
panic(pr.runtime.panicReferenceError("'%s' is not defined", pr.name, pr.at))
}
return pr.base.get(pr.name)
}
func (pr *propertyReference) putValue(value Value) string {
if pr.base == nil {
return pr.name
}
pr.base.put(pr.name, value, pr.strict)
return ""
}
func (pr *propertyReference) delete() bool {
if pr.base == nil {
// TODO Throw an error if strict
return true
}
return pr.base.delete(pr.name, pr.strict)
}
type stashReference struct {
base stasher
name string
strict bool
}
func (sr *stashReference) invalid() bool {
return false // The base (an environment) will never be nil
}
func (sr *stashReference) getValue() Value {
return sr.base.getBinding(sr.name, sr.strict)
}
func (sr *stashReference) putValue(value Value) string {
sr.base.setValue(sr.name, value, sr.strict)
return ""
}
func (sr *stashReference) delete() bool {
if sr.base == nil {
// This should never be reached, but just in case
return false
}
return sr.base.deleteBinding(sr.name)
}
// getIdentifierReference.
func getIdentifierReference(rt *runtime, stash stasher, name string, strict bool, atv at) referencer {
if stash == nil {
return newPropertyReference(rt, nil, name, strict, atv)
}
if stash.hasBinding(name) {
return stash.newReference(name, strict, atv)
}
return getIdentifierReference(rt, stash.outer(), name, strict, atv)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/otto.git
git@gitee.com:mirrors/otto.git
mirrors
otto
otto
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385