I think the problem is that the handle value returned is part of the
HandleScope in the wcLookupNameCallback. When returning from that function
the HandleScope is destructed and all handles in it are no longer valid.
However the HandleScope has a facility to let a handle escape into the outer
HandleScope. Try to change the return statement to:
  return scope.Close(result);

Regards,
Søren

On Mon, Sep 15, 2008 at 6:58 AM, Hector <[EMAIL PROTECTED]> wrote:

>
> I have a API function whose original WIN32 header prototype is:
>
>  BOOL  APIENTRY wcLookupName(const char *name, TUserInfo &uinfo);
>
> If it returns true, then it fills in TUserInfo structure, otherwise
> false, read extended error, etc.
>
> For V8 (javascript), I don't think we can output via parameters,  so I
> want it to return the TUserInfo as a json object, so that V8 script
> writers can do
>
> // in V8:
>
>   var ui = wcLookupName(name);
>   if (ui) {
>        // do something useful
>   } else {
>        // not found
>   }
>
> So I have the RTE call back like so:
>
> static Handle<Value> wcLookupNameCallback(const Arguments& args)
> {
>        if (args.Length() != 1) {
>                // throw exception???
>                return v8::Undefined();
>        }
>
>        HandleScope scope;
>        v8::String::AsciiValue username(args[0]);
>        wc::TUserInfo ui = {0};
>        if (!WildcatV8Processor::wcLookupName(*username,ui)) {
>                return v8::Undefined();
>        }
>        v8::Handle<v8::Object> result = v8::Object::New();
>        result->Set(v8_str("Id"),    v8_num(ui.Id));
>        result->Set(v8_str("Name"),  v8_str(ui.Name));
>        result->Set(v8_str("Title"), v8_str(ui.Title));
>        return result;
> }
>
> However, this creates a fault when it exits the routine.
>
> Obviously, I am missing some fundamental understanding.  I "think" its
> a matter of a lost pointer.  What do I need do here?
>
> TIA
>
> --
> >
>

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

Reply via email to