On Mon, Aug 19, 2013 at 6:35 AM, Luke <[email protected]> wrote:
> I'm trying to convert Persistent<Context> to a void* to be passed to C, then
> back. I understand that there are a lot of changes happening to Persistent.
>
> This is what I have so far, which is probably wrong:
>
>
> void* isolate_new() {
> Isolate *isolate = Isolate::New();
> return (void*)(isolate);
> }
>
> void* context_new(void* iso) {
> Isolate *isolate = (Isolate*)(iso);
> isolate->Enter();
> HandleScope handle_scope(isolate);
> Handle<Context> context = Context::New(isolate);
> Persistent<Context> pcontext(isolate, context);
> isolate->Exit();
> return (void*)(&Persistent<Context>::Cast(pcontext));
> }
>
> void test(void *iso, void *ctx) {
> Isolate *isolate = (Isolate*)(iso);
> isolate->Enter();
> Handle<Context> context = *(Handle<Context>*)(ctx); // Needs to be
> Persistent<Context>, but can't figure out how to get it back.
>
> HandleScope handle_scope(isolate);
> Context::Scope context_scope(context); // This needs to be
> context_scope(isolate, context) w/ Persistent
>
> Local<String> source = String::New("'Hello' + ', World!'");
> Local<Script> script = Script::Compile(source);
> Local<Value> result = script->Run();
>
> String::AsciiValue ascii(result);
> isolate->Exit();
> printf("%s\n", *ascii);
> }
>
>
> I'm having difficulty getting things to compile. This is the closest I was
> able to get, but it crashes. How do I do this correctly? Should I pretty
> much give up on this until all the changes are made?
>
> Luke
It depends on whether you're targeting the old or the new Persistent
API. With the new API, you'd create the pointer-to-Context like this:
Local<Context> context = Context::New(isolate);
Persistent<Context>* persistent = new Persistent(isolate, context);
// ...
return persistent;
And this is how you'd unwrap it again:
Persistent<Context>* persistent = /* ... */;
Local<Context> context = Local<Context>::New(isolate, *persistent);
--
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.