It is not possible to store the handle to Context in a class or a
structure. You need to store a Permanent handle, and then make it Local on
every entry (before you use it).
On Monday, March 14, 2016 at 10:33:04 PM UTC+2, Daniel Burchardt wrote:
>
> Hi i try create simple module for python:
> class Browser
> {
> public:
> Browser();
> void getContext();
> const char* execute(const char* data);
> int test;
> private:
> v8::Isolate* _isolate;
> v8::Handle<v8::Context> _context;
> };
>
>
> Browser::Browser()
> {
> v8::V8::InitializeICU();
> v8::V8::InitializeExternalStartupData("/opt/v8build/");
> v8::Platform* platform = v8::platform::CreateDefaultPlatform();
> v8::V8::InitializePlatform(platform);
> v8::V8::Initialize();
>
> ArrayBufferAllocator allocator;
> v8::Isolate::CreateParams create_params;
> create_params.array_buffer_allocator = &allocator;
>
> _isolate = v8::Isolate::New(create_params);
> }
>
> const char* Browser::execute(const char* data)
> {
> v8::Isolate::Scope isolate_scope(_isolate);
> v8::HandleScope handle_scope(_isolate);
>
> if (test != 1) {
> printf("%s\n", "New context");
> test = 1;
> _context = v8::Context::New(_isolate);
> }
>
> const char* result;
> {
> // v8::Handle<v8::Context> context = v8::Context::New(_isolate);
>
> v8::Context::Scope context_scope(_context);
>
> v8::Local<v8::String> source =
> v8::String::NewFromUtf8(_isolate, data,
> v8::NewStringType::kNormal).ToLocalChecked();
>
> v8::Local<v8::Script> script = v8::Script::Compile(_context, source).
> ToLocalChecked();
> v8::Local<v8::Value> result = script->Run(_context).ToLocalChecked();
> v8::String::Utf8Value utf8(result);
>
> // Konwersja danych do char*
> int len = utf8.length() + 1;
> char *str = (char *) calloc(sizeof(char), len);
> strncpy(str, *utf8, len);
>
> return str;
> }
>
> return result;
> }
> Tutaj wprowadź kod...
>
> First run execute is ok, but second run execute return error
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x00007ffff5998a7a in v8::Context::Enter()
>
> Anyone can help me? Thanks :)
>
--
--
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.