Skip to content

Commit

Permalink
Return self on 0 arguments, and ignore args > 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Figueiredo committed Apr 23, 2021
1 parent 18d40f2 commit 4f067ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 3 additions & 4 deletions promise.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,15 @@ func (p *Promise) Then(cbs ...FunctionCallback) *Promise {

var ptr C.ValuePtr
switch len(cbs) {
case 0:
return p
case 1:
cbID := p.ctx.iso.registerCallback(cbs[0])
ptr = C.PromiseThen(p.ptr, C.int(cbID))
case 2:
default:
cbID1 := p.ctx.iso.registerCallback(cbs[0])
cbID2 := p.ctx.iso.registerCallback(cbs[1])
ptr = C.PromiseThen2(p.ptr, C.int(cbID1), C.int(cbID2))

default:
panic("1 or 2 callbacks required")
}
return &Promise{&Object{&Value{ptr, p.ctx}}}
}
Expand Down
1 change: 1 addition & 0 deletions promise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestPromiseRejected(t *testing.T) {
thenInfo = info
return nil
}).
Then().
Then(
func(_ *v8go.FunctionCallbackInfo) *v8go.Value {
then2Fulfilled = true
Expand Down

0 comments on commit 4f067ab

Please sign in to comment.