I want to eval a string and capture the `this` context under which it
executes returning the value as an object.
This would allow me to, for example,
> source = " a = 'b' ; c = 3 ; " ;
> obj = Compile( source );
> obj.a
'b'
> obj.c
3
>
Here is my working code thus far. Hopefully I'm not missing something
simple. I tried using code drawn from the establishment of the global
object in shell.cc, but I seem to have misjudged its functionality.
v8::Handle<v8::Value> CompileModule( const v8::Arguments& args )
{
v8::HandleScope handle_scope ;
v8::Handle<v8::String> source = args[0]->ToString();
v8::Handle<v8::ObjectTemplate> module = v8::ObjectTemplate::New();
v8::Handle<v8::Context> context = v8::Context::New( NULL , module );
v8::Context::Scope context_scope( context );
v8::Handle<v8::Script> script = v8::Script::Compile( source ,
args[1]->ToString() );
v8::Handle<v8::Object> result = module->NewInstance();
return handle_scope.Close( result );
}
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---