Index: polyfill.js |
=================================================================== |
--- a/polyfill.js |
+++ b/polyfill.js |
@@ -55,16 +55,18 @@ |
if (!object) |
return; |
} |
let func = object[name]; |
object[name] = function(...args) |
{ |
+ let callStack = new Error().stack; |
+ |
if (typeof args[args.length - 1] == "function") |
return func.apply(object, args); |
// If the last argument is undefined, we drop it from the list assuming |
// it stands for the optional callback. We must do this, because we have |
// to replace it with our own callback. If we simply append our own |
// callback to the list, it won't match the signature of the function and |
// will cause an exception. |
@@ -72,19 +74,31 @@ |
args.pop(); |
return new Promise((resolve, reject) => |
{ |
func.call(object, ...args, result => |
{ |
let error = browser.runtime.lastError; |
if (error) |
+ { |
+ // runtime.lastError on Chrome is a plain object with only a |
+ // message property. |
Sebastian Noack
2017/10/19 18:09:56
Perhaps, this comment could be a little bit more e
Manish Jethani
2017/10/20 00:04:23
Done.
|
+ if (!(error instanceof Error)) |
+ error = new Error(error.message); |
+ |
+ // Add a more helpful stack trace. |
+ error.stack = callStack; |
Sebastian Noack
2017/10/19 18:09:56
How does the stack on Microsoft Edge (where browse
Manish Jethani
2017/10/20 00:04:23
I'm not sure, but I think we should just move it i
|
+ |
reject(error); |
+ } |
else |
+ { |
resolve(result); |
+ } |
}); |
}); |
}; |
} |
function shouldWrapAPIs() |
{ |
try |