本文整理了Java中com.eclipsesource.v8.V8.addReferenceHandler()
方法的一些代码示例,展示了V8.addReferenceHandler()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。V8.addReferenceHandler()
方法的具体详情如下:
包路径:com.eclipsesource.v8.V8
类名称:V8
方法名:addReferenceHandler
[英]Adds a ReferenceHandler to track when new V8Objects are created.
[中]添加ReferenceHandler以跟踪新V8对象的创建时间。
代码示例来源:origin: eclipsesource/J2V8
/**
* Creates and registered a Memory Manager. After this, all V8 handles will be
* tracked until release is called.
*
* @param v8 The V8 runtime to register this Memory Manager on
*/
public MemoryManager(final V8 v8) {
this.v8 = v8;
memoryManagerReferenceHandler = new MemoryManagerReferenceHandler();
v8.addReferenceHandler(memoryManagerReferenceHandler);
}
代码示例来源:origin: eclipsesource/J2V8
/**
* Creates and registered a Memory Manager. After this, all V8 handles will be
* tracked until release is called.
*
* @param v8 The V8 runtime to register this Memory Manager on
*/
public MemoryManager(final V8 v8) {
this.v8 = v8;
memoryManagerReferenceHandler = new MemoryManagerReferenceHandler();
v8.addReferenceHandler(memoryManagerReferenceHandler);
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testV8MultipleReferenceHandlers() {
ReferenceHandler referenceHandler1 = mock(ReferenceHandler.class);
ReferenceHandler referenceHandler2 = mock(ReferenceHandler.class);
v8.addReferenceHandler(referenceHandler1);
v8.addReferenceHandler(referenceHandler2);
V8Object object = new V8Object(v8);
verify(referenceHandler1, times(1)).v8HandleCreated(object);
verify(referenceHandler2, times(1)).v8HandleCreated(object);
object.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testV8HandleDisposed() {
ReferenceHandler referenceHandler = mock(ReferenceHandler.class);
v8.addReferenceHandler(referenceHandler);
V8Object object = new V8Object(v8);
object.close();
verify(referenceHandler, times(1)).v8HandleDisposed(any(V8Object.class)); // Can't test the actual one because it's disposed
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testV8HandleCreated_V8Array() {
ReferenceHandler referenceHandler = mock(ReferenceHandler.class);
v8.addReferenceHandler(referenceHandler);
V8Array object = new V8Array(v8);
verify(referenceHandler, times(1)).v8HandleCreated(object);
object.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testV8HandleCreated_AccessedObject() {
ReferenceHandler referenceHandler = mock(ReferenceHandler.class);
v8.addReferenceHandler(referenceHandler);
V8Object object = v8.executeObjectScript("foo = {}; foo;");
verify(referenceHandler, times(1)).v8HandleCreated(object);
object.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testV8HandleCreated_AccessedArray() {
ReferenceHandler referenceHandler = mock(ReferenceHandler.class);
v8.addReferenceHandler(referenceHandler);
V8Array object = (V8Array) v8.executeScript("[1,2,3];");
verify(referenceHandler, times(1)).v8HandleCreated(object);
object.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testV8HandleCreated_V8Object() {
ReferenceHandler referenceHandler = mock(ReferenceHandler.class);
v8.addReferenceHandler(referenceHandler);
V8Object object = new V8Object(v8);
verify(referenceHandler, times(1)).v8HandleCreated(object);
object.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testV8HandleCreated_V8ArrayBuffer() {
ReferenceHandler referenceHandler = mock(ReferenceHandler.class);
v8.addReferenceHandler(referenceHandler);
V8ArrayBuffer object = new V8ArrayBuffer(v8, 100);
verify(referenceHandler, times(1)).v8HandleCreated(object);
object.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testV8UnknownReferenceHandleRemoved() {
ReferenceHandler referenceHandler1 = mock(ReferenceHandler.class);
ReferenceHandler referenceHandler2 = mock(ReferenceHandler.class);
v8.addReferenceHandler(referenceHandler1);
v8.removeReferenceHandler(referenceHandler2);
V8Object object = new V8Object(v8);
verify(referenceHandler1, times(1)).v8HandleCreated(object);
object.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testV8HandleCreated_V8Function() {
ReferenceHandler referenceHandler = mock(ReferenceHandler.class);
v8.addReferenceHandler(referenceHandler);
V8Function object = new V8Function(v8);
verify(referenceHandler, times(1)).v8HandleCreated(object);
object.close();
}
代码示例来源:origin: eclipsesource/J2V8
@SuppressWarnings("resource")
@Test
public void testV8ArrayHandlerExceptionDuringCreation() {
ReferenceHandler referenceHandler = mock(ReferenceHandler.class);
doThrow(new RuntimeException()).when(referenceHandler).v8HandleCreated(any(V8Object.class));
v8.addReferenceHandler(referenceHandler);
try {
new V8Array(v8);
} catch (Exception e) {
assertEquals(0, v8.getObjectReferenceCount());
return;
}
fail("Exception should have been caught.");
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testV8ReferenceHandleRemoved() {
ReferenceHandler referenceHandler = mock(ReferenceHandler.class);
v8.addReferenceHandler(referenceHandler);
v8.removeReferenceHandler(referenceHandler);
V8Object object = new V8Object(v8);
verify(referenceHandler, never()).v8HandleCreated(object);
object.close();
}
代码示例来源:origin: eclipsesource/J2V8
@SuppressWarnings("resource")
@Test
public void testV8ObjectHandlerExceptionDuringCreation() {
ReferenceHandler referenceHandler = mock(ReferenceHandler.class);
doThrow(new RuntimeException()).when(referenceHandler).v8HandleCreated(any(V8Object.class));
v8.addReferenceHandler(referenceHandler);
try {
new V8Object(v8);
} catch (Exception e) {
assertEquals(0, v8.getObjectReferenceCount());
return;
}
fail("Exception should have been caught.");
}
代码示例来源:origin: eclipsesource/J2V8
@SuppressWarnings("resource")
@Test
public void testV8ArrayBufferHandlerExceptionDuringCreation() {
ReferenceHandler referenceHandler = mock(ReferenceHandler.class);
doThrow(new RuntimeException()).when(referenceHandler).v8HandleCreated(any(V8Value.class));
v8.addReferenceHandler(referenceHandler);
try {
new V8ArrayBuffer(v8, 100);
} catch (Exception e) {
assertEquals(0, v8.getObjectReferenceCount());
return;
}
fail("Exception should have been caught.");
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testV8HandleCreated_V8TypedArray() {
ReferenceHandler referenceHandler = mock(ReferenceHandler.class);
v8.addReferenceHandler(referenceHandler);
V8ArrayBuffer buffer = new V8ArrayBuffer(v8, 100);
V8TypedArray object = new V8TypedArray(v8, buffer, V8Value.INT_16_ARRAY, 0, 50);
verify(referenceHandler, times(1)).v8HandleCreated(buffer);
verify(referenceHandler, times(1)).v8HandleCreated(object);
buffer.close();
object.close();
}
代码示例来源:origin: com.eclipsesource.j2v8/j2v8_win32_x86_64
/**
* Creates and registered a Memory Manager. After this, all V8 handles will be
* tracked until release is called.
*
* @param v8 The V8 runtime to register this Memory Manager on
*/
public MemoryManager(final V8 v8) {
this.v8 = v8;
memoryManagerReferenceHandler = new MemoryManagerReferenceHandler();
v8.addReferenceHandler(memoryManagerReferenceHandler);
}
代码示例来源:origin: com.eclipsesource.j2v8/j2v8_macosx_x86_64
/**
* Creates and registered a Memory Manager. After this, all V8 handles will be
* tracked until release is called.
*
* @param v8 The V8 runtime to register this Memory Manager on
*/
public MemoryManager(final V8 v8) {
this.v8 = v8;
memoryManagerReferenceHandler = new MemoryManagerReferenceHandler();
v8.addReferenceHandler(memoryManagerReferenceHandler);
}
代码示例来源:origin: eclipsesource/J2V8
@SuppressWarnings("resource")
public void testExceptionDuringReleaseDoesNotReleaseMemoryManager() {
memoryManager = new MemoryManager(v8);
ReferenceHandler handler = new ReferenceHandler() {
@Override
public void v8HandleDisposed(final V8Value object) {
// Throws CME
memoryManager.persist(object);
}
@Override
public void v8HandleCreated(final V8Value object) {
}
};
v8.addReferenceHandler(handler);
new V8Object(v8);
try {
memoryManager.release();
} catch (ConcurrentModificationException e) {
}
assertFalse(memoryManager.isReleased());
v8.removeReferenceHandler(handler);
memoryManager.release();
assertTrue(memoryManager.isReleased());
}
内容来源于网络,如有侵权,请联系作者删除!