I just found that the option to call native functions can simply be
passed as an argument to the d8 executable.
Ex:
./d8 --allow_natives_syntax
d8> var f = %CompileString("var x = 2;",false);
d8> f
function var x = 2;
d8> f()
d8>x
2
For other options, simply type:
./d8 --help
As a side note, to read a file as a string from the d8 prompt, simply
do:
var s = read("my_test_file.js");
Erick
Le 10-05-05 14:49 , Erick Lavoie a écrit :
V8 provides a nice developer shell to interactively execute and debug
javascript code using their Engine.
The build instructions as well as the dependencies can be found here.
To allow calling native C++ functions from javascript directly such as
what is done in the standard libraries (see src/v8natives.js), simply
set the "allow_natives_syntax" flag from src/flag-definitions.h to
"true". This will allow calling functions like %CompileString directly.
To see how C++ functions can be exposed to javascript, look at void
Shell::Initialize() from src/d8.cc.
When an error occurs, the d8 shell automatically enters debug mode. The
listing of available commands can be found at "function DebugRequest"
of src/d8.js.
Erick