Created
June 24, 2014 22:14
-
-
Save kovasb/6a9bb54316ff0e0e051e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*static*/ v8::Handle<v8::Value> Java::bufferFromDirect(const v8::Arguments& args) { | |
v8::HandleScope scope; | |
Java* self = node::ObjectWrap::Unwrap<Java>(args.This()); | |
v8::Handle<v8::Value> ensureJvmResults = self->ensureJvm(); | |
if(!ensureJvmResults->IsUndefined()) { | |
return v8::False(); | |
} | |
JNIEnv* env = self->getJavaEnv(); | |
JavaScope javaScope(env); | |
v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(args[0]); | |
jobject instance = v8ToJava(env, obj); | |
if (!instance) { | |
// not even a Java object | |
return v8::False(); | |
} | |
char* data = (char *) env->GetDirectBufferAddress(instance); | |
jlong size = env->GetDirectBufferCapacity(instance); | |
Buffer* buffer = Buffer::New(data, size, Unmap, (void *) size); | |
return scope.Close(buffer->handle_); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment