Skip to content

Commit

Permalink
Take Value instead of Object for Function.Call receiver
Browse files Browse the repository at this point in the history
E.g. so undefined can be passed in
  • Loading branch information
dylanahsmith committed Sep 8, 2021
1 parent 1e0335d commit 4f38145
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion function.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Function struct {
}

// Call this JavaScript function with the given arguments.
func (fn *Function) Call(recv *Object, args ...Valuer) (*Value, error) {
func (fn *Function) Call(recv *Value, args ...Valuer) (*Value, error) {
var argptr *C.ValuePtr
if len(args) > 0 {
var cArgs = make([]C.ValuePtr, len(args))
Expand Down
2 changes: 1 addition & 1 deletion function_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestFunctionTemplateGetFunction(t *testing.T) {
if err != nil {
t.Fatal(err)
}
ret, err := fn.Call(ctx.Global(), ten)
ret, err := fn.Call(v8go.Undefined(iso), ten)
if err != nil {
t.Fatal(err)
}
Expand Down
11 changes: 6 additions & 5 deletions function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestFunctionCall(t *testing.T) {
failIf(t, err)

fn, _ := addValue.AsFunction()
resultValue, err := fn.Call(ctx.Global(), arg1, arg1)
resultValue, err := fn.Call(v8go.Undefined(iso), arg1, arg1)
failIf(t, err)

if resultValue.Int32() != 2 {
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestFunctionCallToGoFunc(t *testing.T) {
failIf(t, err)
fn, err := val.AsFunction()
failIf(t, err)
resultValue, err := fn.Call(ctx.Global())
resultValue, err := fn.Call(v8go.Undefined(iso))
failIf(t, err)

if !called {
Expand All @@ -87,7 +87,7 @@ func TestFunctionCallWithObjectReceiver(t *testing.T) {
failIf(t, err)
fn, err := fnVal.AsFunction()
failIf(t, err)
resultValue, err := fn.Call(obj)
resultValue, err := fn.Call(obj.Value)
failIf(t, err)

if !resultValue.IsString() || resultValue.String() != "some val" {
Expand All @@ -100,7 +100,8 @@ func TestFunctionCallError(t *testing.T) {

ctx, err := v8go.NewContext()
failIf(t, err)
defer ctx.Isolate().Dispose()
iso := ctx.Isolate()
defer iso.Dispose()
defer ctx.Close()

_, err = ctx.RunScript("function throws() { throw 'error'; }", "script.js")
Expand All @@ -109,7 +110,7 @@ func TestFunctionCallError(t *testing.T) {
failIf(t, err)

fn, _ := addValue.AsFunction()
_, err = fn.Call(ctx.Global())
_, err = fn.Call(v8go.Undefined(iso))
if err == nil {
t.Errorf("expected an error, got none")
}
Expand Down
2 changes: 1 addition & 1 deletion object.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (o *Object) MethodCall(methodName string, args ...Valuer) (*Value, error) {
if err != nil {
return nil, err
}
return fn.Call(o, args...)
return fn.Call(o.Value, args...)
}

// Set will set a property on the Object to a given value.
Expand Down

0 comments on commit 4f38145

Please sign in to comment.