Skip to content

Commit

Permalink
Support empty ArrayBuffers
Browse files Browse the repository at this point in the history
If an ArrayBuffer was empty, we were returning null. We now return
an empty ArrayBuffer.

Change-Id: Ie9014e81d4f46261024c906548d6da058a04babe
  • Loading branch information
irbull committed Oct 12, 2018
1 parent ac976e7 commit 319816a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 6 additions & 1 deletion jni/com_eclipsesource_v8_V8Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,12 @@ jobject getResult(JNIEnv *env, jobject &v8, jlong v8RuntimePtr, Handle<Value> &r
else if (result->IsArrayBuffer()) {
ArrayBuffer* arrayBuffer = ArrayBuffer::Cast(*result);
if ( arrayBuffer->GetContents().Data() == NULL ) {
return NULL;
jobject byteBuffer = env->NewDirectByteBuffer(arrayBuffer->GetContents().Data(), 0);
jobject objectResult = env->NewObject(v8ArrayBufferCls, v8ArrayBufferInitMethodID, v8, byteBuffer);
jlong resultHandle = getHandle(env, objectResult);
v8::Isolate* isolate = reinterpret_cast<V8Runtime*>(v8RuntimePtr)->isolate;
reinterpret_cast<Persistent<Object>*>(resultHandle)->Reset(isolate, result->ToObject(isolate));
return objectResult;
}
jobject byteBuffer = env->NewDirectByteBuffer(arrayBuffer->GetContents().Data(), arrayBuffer->ByteLength());
jobject objectResult = env->NewObject(v8ArrayBufferCls, v8ArrayBufferInitMethodID, v8, byteBuffer);
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/eclipsesource/v8/V8ArrayBufferTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public class V8ArrayBufferTest {
Expand All @@ -43,7 +42,6 @@ public void tearDown() {
}

@Test
@Ignore
public void testEmptyArrayBufferReturned() {
V8ArrayBuffer arrayBuffer = (V8ArrayBuffer) v8.executeScript("new ArrayBuffer(0);");

Expand Down

0 comments on commit 319816a

Please sign in to comment.