Skip to content

Commit 30e5091

Browse files
authored
Handle edge case with no callbackArgs
This is an alternative approach to fixing #23. For chrome functions that pass no arguments to their callbacks, we should try to propagate the function's own return value. Honestly, I'm pretty confused about how it is even able to work. It makes sense, kind of, but I'm surprised that I can access the function return inside an arrow function defined as an inline function argument. In any case, I tested and confirmed that this works. Fixes #23 and closes #26.
1 parent 39f4d72 commit 30e5091

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

chrome-extension-async.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
return new Promise((resolve, reject) => {
3232
try {
3333
// Try to run the original function, with the trimmed args list
34-
f(...safeArgs, (...cbArgs) => {
34+
const ret = f(...safeArgs, (...cbArgs) => {
3535

3636
// If a callback was passed at the end of the original arguments
3737
if (callback) {
@@ -50,7 +50,7 @@
5050
resolve(cbObj);
5151
}
5252
else if (!cbArgs || cbArgs.length === 0)
53-
resolve();
53+
resolve(ret); // if there were no callback args, resolve with the function's own return value
5454
else if (cbArgs.length === 1)
5555
resolve(cbArgs[0]);
5656
else

0 commit comments

Comments
 (0)