Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js.typeof is broken #50

Open
s-ol opened this issue Oct 11, 2019 · 2 comments
Open

js.typeof is broken #50

s-ol opened this issue Oct 11, 2019 · 2 comments

Comments

@s-ol
Copy link

s-ol commented Oct 11, 2019

Minimal example, e.g. in the https://fengari.io REPL:

js.typeof(js.global)
Uncaught exception TypeError: Cannot read property 'funcOff' of undefined
    at rt (javascript:8)
    at Et (javascript:8)
    at It (javascript:8)
    at t (javascript:8)
    at t (javascript:8)
    at Object.t [as luaD_precall] (javascript:8)
    at Object.t.exports.luaV_execute (javascript:8)
    at ut (javascript:8)
    at Object.ht [as luaD_callnoyield] (javascript:8)
    at Object.b [as luaT_callTM] (javascript:8)
@daurnimator
Copy link
Member

This seems to be a minifier bug. For some reason,

	"typeof": function(L) {
		let u = tojs(L, 1);
		lua_pushliteral(L, typeof u);
		return 1;
	}

is getting compiled to:

  "typeof": function _typeof(L) {
    var u = tojs(L, 1);
    lua_pushliteral(L, _typeof(u));
    return 1;
  }

Which ends up calling itself with invalid parameters.

Next steps:

  1. try with newer version of minifier/webpack
  2. play with syntax to see if there is a way around it
  3. change the code to avoid using typeof directly

@mrunderhill89
Copy link

mrunderhill89 commented Mar 11, 2020

I've got the same issue, and it also seems to affect instanceof (same issue of calling itself instead of the internal function), so there is currently no way to check JS types from Lua. I'm working on a pull request right now, and aliasing it to jstypeof seems to work, though I haven't gotten jsinstanceof working yet.

Update: So instanceof was working after all, I just forgot to use class objects instead of strings on the right-hand side. Can't create pull requests, but the following code seems to fix typeof seamlessly.

	"jstypeof": function(L) {
		let u = tojs(L, 1);
		lua_pushliteral(L, typeof u);
		return 1;
	}
};
jslib["typeof"] = jslib["jstypeof"];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants