beamjs / erlv8

Erlang interface for V8

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Odd behaviour

gleber opened this issue · comments

I am trying to bring back beamjs to life and I've fixed many issues already. But now I have stumbled at a problem with "require.main" not being set. After fiddling with this problem I have found it to behave very weird:

(<0.2.0>) call beamjs:args(<0.40.0>,load)
(<0.2.0>) call beamjs:'-args/2-fun-2-'("deps/commonjs/tests/unit-testing/1.0/program.js",<0.40.0>)
(<0.2.0>) call erlv8_vm:enqueue_tick(<0.40.0>,{set,<<>>,"xyz","def222"})
(<0.2.0>) returned from erlv8_vm:enqueue_tick/2 -> "def222"
(<0.2.0>) call erlv8_vm:enqueue_tick(<0.40.0>,{get,<<>>,"require"})
(<0.2.0>) returned from erlv8_vm:enqueue_tick/2 -> {erlv8_fun,<<>>,<0.40.0>}
(<0.2.0>) call erlv8_vm:enqueue_tick(<0.40.0>,{call,<<>>,["deps/commonjs/tests/unit-testing/1.0/program.js"]})
(<0.63.0>) call erlv8_vm:enqueue_tick(<0.40.0>,{get,<<>>,"xyz"})
(<0.63.0>) returned from erlv8_vm:enqueue_tick/2 -> <<"def">>

I am setting test global variable "xyz" to "def" initially (right after VM is started), but later on, just before (Global:get_value("require")):call(...), I am setting it to "def222". But inside of "fun require_fun/2" I do Global:get_value("xyz") again and it returns "def".

Any ideas what it could be?

Another weird thing is that if I run Global:get_value("xyz") at the very end of the program, it is actually changed to "def222"

Here's more debug output: http://pastebin.com/Z6tugSSJ

It include traced gets and sets with pointer of the global object. And it changes a lot, not sure if it is helpful.

I've solved this problem with this commit in beamjs:

gleber/beamjs@fbdb748

But source of the problem still persists in erlv8.

But this "fix" screws up exports object, which is shared because of my changes. I need to figure out problems with context switching not working properly.

JFYI, I received the message, I'm just a bit overloaded at the moment :-)

But anyway, I am monitoring this.

I'll prepare a test case for this problem so you can at least reproduce it

I wasn't able to prepare the test case for this problem and I've worked around the problem by replacing explicit use of V8 Contexts with wrapping required file into anonymous JS function, running it and returning module's exports. Code says it all: https://github.com/gleber/beamjs/blob/master/src/beamjs_mod_require.erl#L126