On Thu, Jun 4, 2009 at 12:45 AM, Luis Furquim <[email protected]> wrote:
> No, the problem is not with the C++ functions registered
> to JS before the script->Run() call. The problem occurs
> when, "during the JS run", the JS program calls a C++
> function which in turn tries to register new functions
> via global->set.
>
> Actually what I am trying to do is create a function
> called import that, as python's import, makes new
> modules available to the running script.
>
> I attached the files. The javascript program starts with
> a call to import("./rename.so"); which calls a function
> named "ImportJSModule" in the v8js.cc program.
>
> This function uses dlopen to dynamically link rename.so
> (which came, obviously, from rename.cc), then it calls
> a function named startup which tells ImportJSModule
> that it has the symbol "rename". So, ImportJSModule
> call dlsym to get a pointer to it. Then, ImportJSModule
> calls global->set to register "rename" and make it

You are manipulating the global object *template* after creating the
context. The context's global object made a *copy* of the template's
properties, so changing the template afterwards will not modify the
already existing global object. You rather need to do
"context->Global()->Set(String::New("rename"), function)" .

Matthias

> available to the javascript program. There's no error
> until there. But, when the javascript program tries to
> call "rename", it gets the ReferenceError message.
>
> That's the problem.
>
> Thank you
>
> Luis Otavio de Colla Furquim
>
> On Wed, Jun 3, 2009 at 7:18 PM, Dennis Honeyman <[email protected]> wrote:
>>
>> Umm, I think you need to put the global->Set(...) before creating the
>> context and entering the context scope...
>>
>> ---
>> v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
>> global->Set(v8::String::New("print"), v8::FunctionTemplate::New(Print));
>> v8::Handle<v8::Context> context = v8::Context::New(NULL, global);
>> v8::Context::Scope context_scope(context);
>> ---
>>
>> I think that'll work, provided you use the proper format for the function...
>>
>> >
>>
>
>
>
> --
> Luis Otavio de Colla Furquim
> Não alimente os pingos
> Don't feed the tribbles - http://www.thinkgeek.com/geektoys/plush/ac6e/
> By the nice edges of dataly graphs I shall walk
> http://www.furquim.org/chironfs/
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to