On Mar 2, 1:34 am, "Isaac Z. Schlueter" <[email protected]> wrote:
> I'm trying to write a function that will execute a bit of Javascript
> within an arbitrary global scope. Something like the "evalcx"
> function in the Spidermonkey shell.
>
> I've got a function defined and exposed to the Javascript that takes
> an object as an argument, and stores it as a Handle<Object>. However,
> in order to create a new execution context, I need a
> Handle<ObjectTemplate>.
Do you need a new Context, or just an object to eval the code in? If
you just need an Object to execute the code in...
They way i ended up doing this was getting the 'eval' function from my
local object, then using Call() on that Function object:
TryCatch tryer;
Local<Value> rv;
Local<Function> eval = Function::Cast( *(db->jsobj->Get(String::New
("eval"))) );
// ^^^^^ db->jsobj is my context object
for( int i = 0; i < argc; ++i )
{
char const * cp = reinterpret_cast<char const *>
( sqlite3_value_text( argv[i] ) );
if( ! cp || !*cp ) continue;
Local<Value> arg = String::New( cp, sqlite3_value_bytes( argv
[i] ) );
rv = eval->Call( db->jsobj, 1, &arg );
// ^^^^ that will, in theory, eval the code in the context of db-
>jsobj
if( rv.IsEmpty() )
{
std::string err( CastFromJS<std::string>( tryer.Exception() ) );
sqlite3_result_text( context, err.c_str(),
static_cast<int>(err.size
()), SQLITE_TRANSIENT );
return;
}
}
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---