mirror of
https://github.com/robertkrimen/otto
synced 2025-10-19 19:55:30 +08:00
Minor cloning adjustments
Mostly cosmetic.
This commit is contained in:
parent
9cd045ef04
commit
526d3b2fd5
85
clone.go
85
clone.go
|
|
@ -14,7 +14,7 @@ type _clone struct {
|
||||||
func (runtime *_runtime) clone() *_runtime {
|
func (runtime *_runtime) clone() *_runtime {
|
||||||
|
|
||||||
self := &_runtime{}
|
self := &_runtime{}
|
||||||
clone := &_clone{
|
clone := _clone{
|
||||||
runtime: self,
|
runtime: self,
|
||||||
_object: make(map[*_object]*_object),
|
_object: make(map[*_object]*_object),
|
||||||
_objectStash: make(map[*_objectStash]*_objectStash),
|
_objectStash: make(map[*_objectStash]*_objectStash),
|
||||||
|
|
@ -65,50 +65,57 @@ func (runtime *_runtime) clone() *_runtime {
|
||||||
self.eval = self.globalObject.property["eval"].value.(Value).value.(*_object)
|
self.eval = self.globalObject.property["eval"].value.(Value).value.(*_object)
|
||||||
self.globalObject.prototype = self.global.ObjectPrototype
|
self.globalObject.prototype = self.global.ObjectPrototype
|
||||||
|
|
||||||
|
// Not sure if this is necessary, but give some help to the GC
|
||||||
|
clone.runtime = nil
|
||||||
|
clone._object = nil
|
||||||
|
clone._objectStash = nil
|
||||||
|
clone._dclStash = nil
|
||||||
|
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
func (clone *_clone) object(self0 *_object) *_object {
|
|
||||||
if self1, exists := clone._object[self0]; exists {
|
func (clone *_clone) object(in *_object) *_object {
|
||||||
return self1
|
if out, exists := clone._object[in]; exists {
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
self1 := &_object{}
|
out := &_object{}
|
||||||
clone._object[self0] = self1
|
clone._object[in] = out
|
||||||
return self0.objectClass.clone(self0, self1, clone)
|
return in.objectClass.clone(in, out, clone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clone *_clone) dclStash(self0 *_dclStash) (*_dclStash, bool) {
|
func (clone *_clone) dclStash(in *_dclStash) (*_dclStash, bool) {
|
||||||
if self1, exists := clone._dclStash[self0]; exists {
|
if out, exists := clone._dclStash[in]; exists {
|
||||||
return self1, true
|
return out, true
|
||||||
}
|
}
|
||||||
self1 := &_dclStash{}
|
out := &_dclStash{}
|
||||||
clone._dclStash[self0] = self1
|
clone._dclStash[in] = out
|
||||||
return self1, false
|
return out, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clone *_clone) objectStash(self0 *_objectStash) (*_objectStash, bool) {
|
func (clone *_clone) objectStash(in *_objectStash) (*_objectStash, bool) {
|
||||||
if self1, exists := clone._objectStash[self0]; exists {
|
if out, exists := clone._objectStash[in]; exists {
|
||||||
return self1, true
|
return out, true
|
||||||
}
|
}
|
||||||
self1 := &_objectStash{}
|
out := &_objectStash{}
|
||||||
clone._objectStash[self0] = self1
|
clone._objectStash[in] = out
|
||||||
return self1, false
|
return out, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clone *_clone) value(self0 Value) Value {
|
func (clone *_clone) value(in Value) Value {
|
||||||
self1 := self0
|
out := in
|
||||||
switch value := self0.value.(type) {
|
switch value := in.value.(type) {
|
||||||
case *_object:
|
case *_object:
|
||||||
self1.value = clone.object(value)
|
out.value = clone.object(value)
|
||||||
}
|
}
|
||||||
return self1
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clone *_clone) valueArray(self0 []Value) []Value {
|
func (clone *_clone) valueArray(in []Value) []Value {
|
||||||
self1 := make([]Value, len(self0))
|
out := make([]Value, len(in))
|
||||||
for index, value := range self0 {
|
for index, value := range in {
|
||||||
self1[index] = clone.value(value)
|
out[index] = clone.value(value)
|
||||||
}
|
}
|
||||||
return self1
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clone *_clone) stash(in _stash) _stash {
|
func (clone *_clone) stash(in _stash) _stash {
|
||||||
|
|
@ -118,18 +125,18 @@ func (clone *_clone) stash(in _stash) _stash {
|
||||||
return in.clone(clone)
|
return in.clone(clone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clone *_clone) property(self0 _property) _property {
|
func (clone *_clone) property(in _property) _property {
|
||||||
self1 := self0
|
out := in
|
||||||
if value, valid := self0.value.(Value); valid {
|
if value, valid := in.value.(Value); valid {
|
||||||
self1.value = clone.value(value)
|
out.value = clone.value(value)
|
||||||
} else {
|
} else {
|
||||||
panic(fmt.Errorf("self0.value.(Value) != true"))
|
panic(fmt.Errorf("in.value.(Value) != true"))
|
||||||
}
|
}
|
||||||
return self1
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clone *_clone) dclProperty(self0 _dclProperty) _dclProperty {
|
func (clone *_clone) dclProperty(in _dclProperty) _dclProperty {
|
||||||
self1 := self0
|
out := in
|
||||||
self1.value = clone.value(self0.value)
|
out.value = clone.value(in.value)
|
||||||
return self1
|
return out
|
||||||
}
|
}
|
||||||
|
|
|
||||||
38
stash.go
38
stash.go
|
|
@ -50,17 +50,17 @@ func (runtime *_runtime) newObjectStash(object *_object, outer _stash) *_objectS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self0 *_objectStash) clone(clone *_clone) _stash {
|
func (in *_objectStash) clone(clone *_clone) _stash {
|
||||||
self1, exists := clone.objectStash(self0)
|
out, exists := clone.objectStash(in)
|
||||||
if exists {
|
if exists {
|
||||||
return self1
|
return out
|
||||||
}
|
}
|
||||||
*self1 = _objectStash{
|
*out = _objectStash{
|
||||||
clone.runtime,
|
clone.runtime,
|
||||||
clone.stash(self0._outer),
|
clone.stash(in._outer),
|
||||||
clone.object(self0.object),
|
clone.object(in.object),
|
||||||
}
|
}
|
||||||
return self1
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *_objectStash) hasBinding(name string) bool {
|
func (self *_objectStash) hasBinding(name string) bool {
|
||||||
|
|
@ -138,21 +138,21 @@ func (runtime *_runtime) newDeclarationStash(outer _stash) *_dclStash {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self0 *_dclStash) clone(clone *_clone) _stash {
|
func (in *_dclStash) clone(clone *_clone) _stash {
|
||||||
self1, exists := clone.dclStash(self0)
|
out, exists := clone.dclStash(in)
|
||||||
if exists {
|
if exists {
|
||||||
return self1
|
return out
|
||||||
}
|
}
|
||||||
property := make(map[string]_dclProperty, len(self0.property))
|
property := make(map[string]_dclProperty, len(in.property))
|
||||||
for index, value := range self0.property {
|
for index, value := range in.property {
|
||||||
property[index] = clone.dclProperty(value)
|
property[index] = clone.dclProperty(value)
|
||||||
}
|
}
|
||||||
*self1 = _dclStash{
|
*out = _dclStash{
|
||||||
clone.runtime,
|
clone.runtime,
|
||||||
clone.stash(self0._outer),
|
clone.stash(in._outer),
|
||||||
property,
|
property,
|
||||||
}
|
}
|
||||||
return self1
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *_dclStash) hasBinding(name string) bool {
|
func (self *_dclStash) hasBinding(name string) bool {
|
||||||
|
|
@ -256,11 +256,11 @@ func (runtime *_runtime) newFunctionStash(outer _stash) *_fnStash {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self0 _fnStash) clone(clone *_clone) _stash {
|
func (in _fnStash) clone(clone *_clone) _stash {
|
||||||
// FIXME Memory leak issue here?
|
// FIXME Memory leak issue here?
|
||||||
return &_fnStash{
|
return &_fnStash{
|
||||||
*(self0._dclStash.clone(clone).(*_dclStash)),
|
*(in._dclStash.clone(clone).(*_dclStash)),
|
||||||
clone.object(self0.arguments),
|
clone.object(in.arguments),
|
||||||
self0.indexOfArgumentName,
|
in.indexOfArgumentName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,12 +35,12 @@ type _argumentsObject struct {
|
||||||
stash _stash
|
stash _stash
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self0 _argumentsObject) clone(clone *_clone) _argumentsObject {
|
func (in _argumentsObject) clone(clone *_clone) _argumentsObject {
|
||||||
indexOfParameterName := make([]string, len(self0.indexOfParameterName))
|
indexOfParameterName := make([]string, len(in.indexOfParameterName))
|
||||||
copy(indexOfParameterName, self0.indexOfParameterName)
|
copy(indexOfParameterName, in.indexOfParameterName)
|
||||||
return _argumentsObject{
|
return _argumentsObject{
|
||||||
indexOfParameterName,
|
indexOfParameterName,
|
||||||
clone.stash(self0.stash),
|
clone.stash(in.stash),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user