On Tue, Jun 1, 2010 at 10:30 PM, vlad vladbph <[email protected]> wrote:

> Thanks Stephan,
> But if you look at the way I create an object in the original e-mail
> casting to a function fails in the callback - when I get the object from
> args[0]...
>

As far as i can see:

static v8::Handle<v8::Value> func(const v8::Arguments& args) {
   if (args.IsConstructCall())
       return v8::Undefined();

   v8::Local<v8::Object> obj = args[0]->ToObject();
   int* pThis = static_cast<int*>(v8::Local<v8::External>::Cast(obj-
>GetInternalField(0))->Value()); <-- CRASH
   return v8::Undefined();
}

you're never casting to a function there. You're fetching the internal field
with no regard for the type of args[0] (other than that it be-a Object).
(Which, as far as i can tell, should work for what you're doing.)

:-?

i don't know why the V8RUN() bit is failing to behave as you expect - as far
as i can tell, the code "should" do what you're describing. But without
seeing definitions of V8RUN() and the g object, i can only speculate as to
what's really happening there.

i've never used the SetCallAsFunctionHandler() API, but i'm guessing that
understanding it's behaviour is key to answering your question. i don't
personally see much point in creating a non-function object which behaves
like-a function. Why not create a Function in the first place, using
FunctionTemplate::New(func)->GetFunction()?

-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/

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

Reply via email to