From fb42dd0a7e20a16768a2380d523c28ef30c0764a Mon Sep 17 00:00:00 2001 From: Genevieve L'Esperance Date: Thu, 2 Sep 2021 10:48:37 -0700 Subject: [PATCH] Test no-op method and methodcall with args. --- object.go | 4 +--- object_test.go | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/object.go b/object.go index c43929933..e563b3d90 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 fc584cbdd..041d6fca2 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") }