flutter_js
flutter_js copied to clipboard
Eval method could accept sourceURL and lineNumber
Hi, thank you for this package! If https://github.com/abner/flutter_js/blob/aa0813676355d3b754db6a34886a7c2048b61ef0/lib/javascriptcore/jscore_runtime.dart#L68 would accept soureURL and lineNumber. Stack traces would include lines as well which could be very handy when debugging javascript.
Now when loading js like this
js.evaluate('''
try { $jsCode }
catch (e) {
console.log('ERROR IN `assets/js/index.js`!!');
console.log(e + '');
console.log(e.stack + '');
}
''');
Stacktraces lack linenumbers
flutter: TypeError: TypedArray.of requires its this argument to subclass a TypedArray constructor
flutter: of@[native code]
node_modules/bitcoinjs-lib/src/taproot.js
__require2
node_modules/bitcoinjs-lib/src/transaction.js
__require2
node_modules/bitcoinjs-lib/src/script.js
Oops closed with wrong button. What i wanted to say is even if a fake file path is provided, and a linenumber of 1 stacktraces will most likely have linenumbers.
I'm beginning to doubt myself, been debugging for too long 🤓. As you do seem to pass a linenumber at least in javascriptcore.
But its unclear how to pass a filename from the public JavascriptRuntime interface.
Anyway wanted to mention this was done on IOS simulator and I'm on a Mac. So above stacktrace came from javascriptcore.
It would be added to eval calls, but how you said, it is only supported by JavascriptCore. So these should be passed as optional arguments and it needs of course to be expected on the abstract JavascriptRuntime evaluate and evaluateAsync. And also, the implementations of all descendents should be changed as well. In the JavascriptCore implementation it would be passed to the actual eval calls, and in the another implementations it will be of no use. If someone provide a Pull Request I would be happy to review and accept it if properly implemented.
Hello @abner thank you for your reply. We found that the solution in the OP with the try/catch and without linenumbers provides sufficient details to debug our code.
The solution to the problem above for any onlookers was the fact that JSCore does not allow certain use of Buffer class. This fixes that.. Thank you for sharing your project with us.
// To prevent
// TypeError: TypedArray.of requires its this argument to subclass a TypedArray constructor
// Caused by node_modules/bitcoinjs-lib/src/taproot.js
// Applies only to JavascriptCore
Buffer.of = (...items) => Buffer.from(items);