diff --git a/object.go b/object.go index c4392993..e563b3d9 100644 --- a/object.go +++ b/object.go @@ -28,9 +28,7 @@ func (o *Object) MethodCall(methodName string, args ...Valuer) (*Value, error) { if err != nil { return nil, err } - fnVal := getValue(o.ctx, getRtn) - - fn, err := fnVal.AsFunction() + fn, err := getValue(o.ctx, getRtn).AsFunction() if err != nil { return nil, err } diff --git a/object_test.go b/object_test.go index fc584cbd..041d6fca 100644 --- a/object_test.go +++ b/object_test.go @@ -14,22 +14,23 @@ import ( func TestObjectMethodCall(t *testing.T) { t.Parallel() - ctx, err := v8go.NewContext() - failIf(t, err) - val, err := ctx.RunScript(`class Obj { constructor(input) { this.input = input, this.prop = "" } print() { return this.input.toString() } }; new Obj("some val")`, "") - failIf(t, err) - obj, err := val.AsObject() - failIf(t, err) - val, err = obj.MethodCall("print") + ctx, _ := v8go.NewContext() + iso, _ := ctx.Isolate() + val, _ := ctx.RunScript(`class Obj { constructor(input) { this.input = input, this.prop = "" } print() { return this.input.toString() } }; new Obj("some val")`, "") + obj, _ := val.AsObject() + val, err := obj.MethodCall("print") failIf(t, err) if val.String() != "some val" { t.Errorf("unexpected value: %q", val) } - _, err = obj.MethodCall("prop") - if err == nil { - t.Errorf("expected an error, got none") - } - _, err = obj.MethodCall("nope") + + val, err = ctx.RunScript(`class Obj2 { print(str) { return str.toString() } }; new Obj2()`, "") + failIf(t, err) + obj, _ = val.AsObject() + arg, _ := v8go.NewValue(iso, "arg") + _, err = obj.MethodCall("print", arg) + failIf(t, err) + _, err = obj.MethodCall("notamethod") if err == nil { t.Errorf("expected an error, got none") }