daurnimator / lua.vm.js

The project is superceded by Fengari. See https://fengari.io/
MIT License
835 stars 101 forks source link

Javascript messages are hijacked/wrong after loading lua.vm.js #50

Closed fabriziobertocci closed 8 years ago

fabriziobertocci commented 8 years ago

This problem occur only when invoking a script from a file, and does not show when invoking node interactively.

Suppose you have a javascript file (i.e. named 'undefTest.js') with an error inside (i.e. calling an undefined function):

functionNotDefined();

If you launch it:

$ node undefTest.js 
/home/fabrizio/working/git/lua.vm.js/undefTest.js:1
functionNotDefined();
^
ReferenceError: functionNotDefined is not defined
    at Object.<anonymous> (/home/fabrizio/working/git/lua.vm.js/undefTest.js:1:1)
    at Module._compile (module.js:460:26)
   ...

But suppose in this undefTest.js you load lua.vm.js before invoking the undefined function:

var L=require('./dist/lua.vm.js').L
functionNotDefined();

Now, when launching it, node shows some different error message generated by lua.vm.js:

$ node undefTest.js 
/home/fabrizio/working/git/lua.vm.js/dist/lua.vm.js:2
aughtException",(function(ex){if(!(ex instanceof ExitStatus)){throw ex}}));Mod
                                                                    ^
ReferenceError: functionNotDefined is not defined
    at Object.<anonymous> (/home/fabrizio/working/git/lua.vm.js/undefTest.js:2:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
daurnimator commented 8 years ago

This seems to be a side effect of the following code that emscripten adds:

process['on']('uncaughtException', function(ex) {
    // suppress ExitStatus exceptions from showing an error
    if (!(ex instanceof ExitStatus)) {
      throw ex;
    }
  });

from https://github.com/kripken/emscripten/blob/07b87426f898d6e9c677db291d9088c839197291/src/shell.js#L125

It doesn't seem to be configurable, so it's not really within control of this project.

fabriziobertocci commented 8 years ago

Hmm thanks for finding the culprit. That's unfortunate you can't remove an uncaughtException handler (or at least I did not find the way to do it).

daurnimator commented 8 years ago

That's unfortunate you can't remove an uncaughtException handler (or at least I did not find the way to do it).

I'm curious what harm it's causing you.

fabriziobertocci commented 8 years ago

No harm at all... it's just annoying, especially when you do development. But understand it's emscriptem that's installing the devilish uncaughtException... I guess we can close the ticket.