On Tue, Jan 28, 2014 at 10:45 PM, Dave Nicponski <[email protected]>wrote:
> Hello, > > Thanks for the response. > > > On Tue, Jan 28, 2014 at 7:28 PM, Alon Zakai <[email protected]> wrote: > >> The HEADLESS option is not much tested, and used for testing purposes >> mainly. But I think that you need to call window.runEventLoop() manually. >> Even then I imagine there would need to be some minor fixes. >> >> > Hrm... OK i can do this, but doing this conditionally for nodejs from C++ > code seems strange. > Yeah, this doesn't work out-of-the-box. Adding: emscripten_run_script("window.runEventLoop()"); at the end of main fails because headless.js 's runEventLoop triggers: exception thrown: TypeError: Object function Date() { [native code] } has no method 'realNow',TypeError: Object function Date() { [native code] } has no method 'realNow' at Object.window.runEventLoop (/home/daven/src/jsminer/jsminer/jsminer/build/trash/poc/headless_main_loop.js:5671:24) [...] I'll go with a different approach for the moment, and try to loop back to help fixing this when i have some free time. This is a pretty simple repro / use case which should probably be supported, and i can't imagine this test case would be too hard to fix. Thanks for looking in to this. -dave- > >> If there is a use case that we should support here though, we can >> consider that - why do you want to run headless in node? >> > > Basically, i've got a C++ application, some of which is compiled to > javascript and run in a client browser. However, much of what's being > executed isn't browser-related. Being able to factor out the browser > element for code testing is the idea. It's easier to make assertions about > code correctness when the application components are run in nodejs headless > than when they are executed in a browser, or so it seems to me. > > I don't want an entire browser to be emulated in headless mode obviously, > but basic infrastructure functionality like "reasonably correctly emulate > main event loops and web worker threads in headless mode" would be very > useful to have. > > Thanks, > -dave- > > > >> - Alon >> >> >> >> On Tue, Jan 28, 2014 at 1:51 PM, Dave Nicponski <[email protected] >> > wrote: >> >>> Sorry for the noob question, but here goes. >>> >>> # Source code >>> $ cat headless_main_loop.cc >>> >>> #include <stdio.h> >>> >>> #include "emscripten/emscripten.h" >>> >>> int foo = 0; >>> >>> void dummy_loop() { >>> printf("dummy loop: %d\n", foo++); >>> if (foo >= 5) >>> emscripten_cancel_main_loop(); >>> } >>> >>> int main(int argc, char **argv) { >>> printf("Start\n"); >>> >>> emscripten_set_main_loop(dummy_loop, 0, true); // XXX >>> >>> printf("Main done.\n"); >>> return 0; >>> } >>> >>> # Build command for nodejs >>> $ ~/src/emscripen/emscripten/emcc -Qunused-arguments -Wall -Wextra >>> -Werror -Wno-unused-parameter -fexceptions -std=c++11 -x c++ -iquote ./src >>> -iquote ~/src/emscripen/emscripten/system/include/ -I . -DNDEBUG -O2 >>> src/trash/poc/headless_main_loop.cc -o >>> build/trash/poc/headless_main_loop.js -s HEADLESS=1 >>> >>> # Try with nodejs >>> $ (dev-test_pb) nodejs trash/poc/headless_main_loop.js >>> Start >>> >>> # Change line XXX from true to false (infinite loop), rebuild >>> # Try again >>> $ (dev-test_pb) nodejs trash/poc/headless_main_loop.js >>> Start >>> Main done. >>> >>> >>> In both cases, it works as expected if i compile to html and run in a >>> browser (obviously, without the HEADLESS=1 option). >>> Specifically, I see this in the console: >>> >>> Start >>> Main done. >>> dummy loop: 0 >>> dummy loop: 1 >>> dummy loop: 2 >>> dummy loop: 3 >>> dummy loop: 4 >>> >>> ...which is exactly what i'd expect from both node and browser. >>> >>> Am I crazy, or shouldn't this work? >>> >>> Note that this is both with the default ubuntu install (1.4.9, old) and >>> the version i'm actually using from head (1.9.0 (commit >>> 7dc8c2ff08e46c9d9a88ba44bf221a404eeb1e5e)) >>> >>> Thanks, >>> -dave- >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "emscripten-discuss" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "emscripten-discuss" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/emscripten-discuss/2-rxY9ob3aY/unsubscribe >> . >> To unsubscribe from this group and all its topics, send an email to >> [email protected]. >> For more options, visit https://groups.google.com/groups/opt_out. >> > > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
