mirror of
https://github.com/robertkrimen/otto
synced 2025-09-28 18:45:22 +08:00
Shortcut the production of Object.Value()
This commit is contained in:
parent
c57edbfe2b
commit
02929cbeb1
7
otto.go
7
otto.go
|
@ -232,11 +232,14 @@ func (self Otto) Object(source string) (*Object, error) {
|
|||
// Object is the representation of a JavaScript object.
|
||||
type Object struct {
|
||||
object *_object
|
||||
value Value
|
||||
}
|
||||
|
||||
func _newObject(object *_object) *Object {
|
||||
func _newObject(object *_object, value Value) *Object {
|
||||
// value MUST contain object!
|
||||
return &Object{
|
||||
object: object,
|
||||
value: value,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -261,7 +264,7 @@ func (self Object) Call(name string, argumentList... interface{}) (Value, error)
|
|||
|
||||
// Value will return self as a value.
|
||||
func (self Object) Value() Value {
|
||||
return toValue(self.object)
|
||||
return self.value
|
||||
}
|
||||
|
||||
// Get the value of the property with the given name.
|
||||
|
|
|
@ -1826,4 +1826,7 @@ func TestAPI(t *testing.T) {
|
|||
Is(result, "27")
|
||||
result, _ = value.Call(def, 3)
|
||||
Is(result, "30")
|
||||
object = value.Object() // Object xyzzy
|
||||
result, _ = object.Value().Call(def, 3)
|
||||
Is(result, "30")
|
||||
}
|
||||
|
|
4
value.go
4
value.go
|
@ -379,9 +379,9 @@ func (value Value) _object() *_object {
|
|||
//
|
||||
// This method will not do any implicit conversion. For example, calling this method on a string primitive value will not return a String object.
|
||||
func (value Value) Object() *Object {
|
||||
switch value := value.value.(type) {
|
||||
switch object := value.value.(type) {
|
||||
case *_object:
|
||||
return _newObject(value)
|
||||
return _newObject(object, value)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user