On Mon, Mar 10, 2014 at 3:24 PM, Zinglish <[email protected]> wrote: > Hi guys > > I have an issue when attempting to embed a very simple V8 flow into my > application. Basically I have a wrapper class that holds a global Isolate > (Which I will use everywhere) and also holds the context (Since I want all > events to share any global variables). When I try entering the context I > create in my wrapper class in main, I get this error: > >> # >> # Fatal error in ../src/api.h, line 402 >> # CHECK(that == __null || !(*reinterpret_cast<v8::internal::Context**>( >> const_cast<v8::Context*>(that)))->IsFailure()) failed >> # >> ==== C stack trace =============================== >> 1: V8_Fatal >> 2: v8::Utils::OpenHandle(v8::Context const*, bool) >> 3: v8::Context::Enter() >> 4: init(int, char**) >> 5: ?? >> 6: ?? >> 7: ?? > > > > Here's my wrapper class (JSEngine.cpp): > > JSEngine::Engine() > { > printf("Script | DEBUG | Constructing engine\n"); > V8::Initialize(); > this->isolate = Isolate::GetCurrent(); > HandleScope scope(this->isolate); > this->context = Context::New(this->isolate); > Persistent<Context> persistent_context(this->isolate, this->context); > printf("Script | DEBUG | Done constructing engine, context: %lu\n", > this->context); > } > > All I wanted this to do is initalize the V8 engine and create a single > Isolate and Context. > > > > Here's my Init (Which throws the error shown in the first quote block when > it hits the second line): > > HandleScope handleScope(Server::asEngine->isolate); > printf("Set scope to isolate\n"); > Server::asEngine->context->Enter(); > printf("Set scope to context\n"); > > Handle<String> source = String::NewFromUtf8(Server::asEngine->isolate, "var > test = 5;"); > Handle<Script> script = Script::Compile(source); > Handle<Value> result = script->Run(); > > > I feel like I am doing something really dumb that it doesn't work as I > expect. All I essentially did was attempt to split up the most basic example > into a class so I could grasp the concept and idea of embedding V8. > > Thank you ahead of time if you do post a reply.
I suspect that you need to change this->context from Local<Context> or Handle<Context> to a Persistent<Context>. You can rematerialize the handle in your Init() function with `Local<Context> context = Local<Context>::New(this->isolate, this->context)`. By the way, you can use `Context::Scope context_scope(context)` instead of manually entering and exiting the context. The Context::Scope destructor will automatically exit the context when the context_scope variable goes out of scope. -- -- 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/d/optout.
