V8 Android crashes when using Function::New to bind a function

-1

I'm modifying the J2V8 library in order to do my WebGL -> OpenGL bindings in C++ for performance. I've had some success with the OpenGL headers, creating an object, and binding the GL properties to that object. However, when I attempt to bind a function, the code compiles but crashes immediately when initialized. I've isolated it to the Function::New call below.

J2V8 initializes the isolate here:

JNIEXPORT jlong JNICALL Java_com_eclipsesource_v8_V8__1createIsolate
 (JNIEnv *env, jobject v8, jstring globalAlias) {
  V8Runtime* runtime = new V8Runtime();
  v8::Isolate::CreateParams create_params;
  create_params.array_buffer_allocator = &array_buffer_allocator;
  runtime->isolate = v8::Isolate::New(create_params);
  runtime->locker = new Locker(runtime->isolate);
  v8::Isolate::Scope isolate_scope(runtime->isolate);
  runtime->v8 = env->NewGlobalRef(v8);
  runtime->pendingException = NULL;
  HandleScope handle_scope(runtime->isolate);
  Handle<ObjectTemplate> globalObject = ObjectTemplate::New();
  Handle<Context> context_;
  if (globalAlias == NULL) {
    Handle<Context> context = Context::New(runtime->isolate, NULL, globalObject);
    context_ = context;
    runtime->context_.Reset(runtime->isolate, context);
    runtime->globalObject = new Persistent<Object>;
    runtime->globalObject->Reset(runtime->isolate, context->Global()->GetPrototype()->ToObject(runtime->isolate));
  }
  else {
    Local<String> utfAlias = createV8String(env, runtime->isolate, globalAlias);
    globalObject->SetAccessor(utfAlias, jsWindowObjectAccessor);
    Handle<Context> context = Context::New(runtime->isolate, NULL, globalObject);
    runtime->context_.Reset(runtime->isolate, context);
    runtime->globalObject = new Persistent<Object>;
    runtime->globalObject->Reset(runtime->isolate, context->Global()->GetPrototype()->ToObject(runtime->isolate));
  }

  delete(runtime->locker);
  initializeAura(runtime);
  return reinterpret_cast<jlong>(runtime);
}

initializeAura is what I've added and here's what that looks like:

void v8Bind_ActiveTexture (const v8::FunctionCallbackInfo<v8::Value>& args) {

}

void initializeAura(V8Runtime* runtime) {
    v8::Isolate* isolate = runtime->isolate;

    Isolate::Scope isolateScope(isolate);
    // HandleScope handle_scope(isolate);
    Local<Context> context = Local<Context>::New(isolate,runtime->context_);
    Context::Scope context_scope(context);

    Local<Object> gl = Object::New(isolate);
    context->Global()->Set(v8::String::NewFromUtf8(isolate, "_gl"), gl);

    gl->Set( String::NewFromUtf8(isolate, "DEPTH_BUFFER_BIT"), Integer::New(isolate, 0x00000100) );
    //This line causes the crash -> gl->Set( String::NewFromUtf8(isolate, "activeTexture"), Function::New(isolate, v8Bind_ActiveTexture) );
}

I'm mostly stabbing in the dark when it comes to V8, and I feel like the answer has something to do with scoping. When I uncomment the HandleScope line, that one causes a crash as well. Unfortunately the crashes are pretty cryptic on Android, just throwing a generic SIGILL

android
c++
v8
asked on Stack Overflow Oct 22, 2018 by michaeltheory

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0