Skip to content

Commit 4f067ab

Browse files
author
Rob Figueiredo
committed
Return self on 0 arguments, and ignore args > 2
1 parent 18d40f2 commit 4f067ab

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

promise.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,15 @@ func (p *Promise) Then(cbs ...FunctionCallback) *Promise {
100100

101101
var ptr C.ValuePtr
102102
switch len(cbs) {
103+
case 0:
104+
return p
103105
case 1:
104106
cbID := p.ctx.iso.registerCallback(cbs[0])
105107
ptr = C.PromiseThen(p.ptr, C.int(cbID))
106-
case 2:
108+
default:
107109
cbID1 := p.ctx.iso.registerCallback(cbs[0])
108110
cbID2 := p.ctx.iso.registerCallback(cbs[1])
109111
ptr = C.PromiseThen2(p.ptr, C.int(cbID1), C.int(cbID2))
110-
111-
default:
112-
panic("1 or 2 callbacks required")
113112
}
114113
return &Promise{&Object{&Value{ptr, p.ctx}}}
115114
}

promise_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func TestPromiseRejected(t *testing.T) {
7979
thenInfo = info
8080
return nil
8181
}).
82+
Then().
8283
Then(
8384
func(_ *v8go.FunctionCallbackInfo) *v8go.Value {
8485
then2Fulfilled = true

0 commit comments

Comments
 (0)