Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/main/java/com/eclipsesource/v8/V8Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ abstract public class V8Value implements Releasable {
public static final int FLOAT_32_ARRAY = 16;
public static final int UNDEFINED = 99;

protected V8 v8;
protected long objectHandle;
protected boolean released = true;
protected V8 v8;
protected long objectHandle;
protected boolean released = true;

protected V8Value() {
super();
Expand Down Expand Up @@ -83,7 +83,6 @@ protected void addObjectReference(final long objectHandle) throws Error {
}
}


/**
* Returns a string representation of the V8 Type.
* @param type Type to return as a string. See constants in V8Value.
Expand Down Expand Up @@ -272,6 +271,9 @@ public void close() {
v8.checkThread();
if (!released) {
try {
if (isWeak()) {
v8.v8WeakReferences.remove(getHandle());
}
v8.releaseObjRef(this);
} finally {
released = true;
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/com/eclipsesource/v8/V8ObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ public void testGetTypeFunction() {
public void testGetKeysOnObject() {
V8Object v8Object = new V8Object(v8);
v8Object.add("integer", 1).add("double", 1.1).add("boolean", true)
.add("string", "hello, world!");
.add("string", "hello, world!");

String[] keys = v8Object.getKeys();

Expand Down Expand Up @@ -1842,13 +1842,20 @@ public void testSetWeakMakesObjectWeak() {

@SuppressWarnings("resource")
@Test
public void testClearWeakMakesObjectWeak() {
public void testClearWeakMakesObjectNonWeak() {
V8Value object = new V8Object(v8).setWeak().clearWeak();

assertFalse(object.isWeak());
object.close();
}

@SuppressWarnings("resource")
@Test
public void testReleaseWeakObjectDoesNotAffectReferenceCount() {
new V8Object(v8).setWeak().close();

assertEquals(0, v8.getObjectReferenceCount());

@Test
public void testConstructorNameFunction() {
v8.executeVoidScript("function Foo() {} var foo = new Foo();");
Expand Down