You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Got a bit tired of opaque error messages coming from JS library processing when I accidentally introduce a syntax error, so here's a simple but effective improvement made possible by replacing `eval` with `vm.runScriptInContext`.
I'm actually not sure why Node.js doesn't just use the same error output for eval as well, but at least this helps 🤷♂️
While at it, also added filenames to `load` functions used by compiler.js itself, so the stacktrace contains actual filenames instead of nested evals and did few other minor cleanups to avoid error message duplication.
Example preprocessor error message before:
```
parseTools.js preprocessor error in shell_minimal.js:126: "#if MIN_CHROME_VERSION < 45 || MINEDGE_VERSION < 12 || MIN_FIREFOX_VERSION < 34 || MIN_IE_VERSION != TARGET_NOT_SUPPORTED || MIN_SAFARI_VERSION < 90000"!
Internal compiler error in src/compiler.js!
Please create a bug report at https://github.com/emscripten-core/emscripten/issues/
with a log of the build and the input files used to run. Exception message: "ReferenceError: MINEDGE_VERSION is not defined" | ReferenceError: MINEDGE_VERSION is not defined
at eval (eval at preprocess (eval at load (C:\Users\me\Documents\emscripten\src\compiler.js:39:8)), <anonymous>:1:29)
at preprocess (eval at load (C:\Users\me\Documents\emscripten\src\compiler.js:39:8), <anonymous>:97:32)
at finalCombiner (eval at load (C:\Users\me\Documents\emscripten\src\compiler.js:39:8), <anonymous>:475:25)
at runJSify (eval at load (C:\Users\me\Documents\emscripten\src\compiler.js:39:8), <anonymous>:543:3)
...
```
After:
```
Internal compiler error in src/compiler.js!
Please create a bug report at https://github.com/emscripten-core/emscripten/issues/
with a log of the build and the input files used to run. Exception message: "shell_minimal.js:126
MIN_CHROME_VERSION < 45 || MINEDGE_VERSION < 12 || MIN_FIREFOX_VERSION < 34 || MIN_IE_VERSION != TARGET_NOT_SUPPORTED || MIN_SAFARI_VERSION < 90000
^
ReferenceError: MINEDGE_VERSION is not defined
at shell_minimal.js:126:32
at Script.runInThisContext (vm.js:134:12)
at Object.runInThisContext (vm.js:310:38)
at preprocess (C:\Users\me\Documents\emscripten\src\parseTools.js:96:33)
at finalCombiner (C:\Users\me\Documents\emscripten\src\jsifier.js:475:25)
at runJSify (C:\Users\me\Documents\emscripten\src\jsifier.js:543:3)
...
```
Example post-processed JS error message before:
```
error: failure to execute js library "library_pthread.js":
error: use -sVERBOSE to see more details
Internal compiler error in src/compiler.js!
Please create a bug report at https://github.com/emscripten-core/emscripten/issues/
with a log of the build and the input files used to run. Exception message: "SyntaxError: Unexpected token 'function'" | SyntaxError: Unexpected token 'function'
at Object.load (eval at load (C:\Users\me\Documents\emscripten\src\compiler.js:39:8), <anonymous>:215:14)
at runJSify (eval at load (C:\Users\me\Documents\emscripten\src\compiler.js:39:8), <anonymous>:78:18)
...
```
After:
```
error: failure to execute js library "library_pthread.js":
error: use -sVERBOSE to see more details
Internal compiler error in src/compiler.js!
Please create a bug report at https://github.com/emscripten-core/emscripten/issues/
with a log of the build and the input files used to run. Exception message: "library_pthread.preprocessed.js:330
$spawnThread function(threadParams) {
^^^^^^^^
SyntaxError: Unexpected token 'function'
at new Script (vm.js:102:7)
at createScript (vm.js:262:10)
at Object.runInThisContext (vm.js:310:10)
at Object.load (C:\Users\me\Documents\emscripten\src\modules.js:215:12)
at runJSify (C:\Users\me\Documents\emscripten\src\jsifier.js:78:18)
...
```
0 commit comments