diff --git a/otto.go b/otto.go index fea9adc..b2ff0ba 100644 --- a/otto.go +++ b/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. diff --git a/otto_test.go b/otto_test.go index e17c4ed..41152e1 100644 --- a/otto_test.go +++ b/otto_test.go @@ -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") } diff --git a/value.go b/value.go index 3d65a9e..573aeba 100644 --- a/value.go +++ b/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 }