public V8ArrayBuffer(final V8 v8, ByteBuffer byteBuffer) { super(v8); if (byteBuffer == null) { byteBuffer = ByteBuffer.allocateDirect(0); } if (!byteBuffer.isDirect()) { throw new IllegalArgumentException("ByteBuffer must be a allocated as a direct ByteBuffer"); } initialize(v8.getV8RuntimePtr(), byteBuffer); this.byteBuffer = byteBuffer; byteBuffer.order(ByteOrder.nativeOrder()); }
/** * Creates a new V8ArrayBuffer on a given V8Runtime with a * given capacity. * * @param v8 The runtime on which to create the ArrayBuffer * @param capacity The capacity of the buffer */ public V8ArrayBuffer(final V8 v8, final int capacity) { super(v8); initialize(v8.getV8RuntimePtr(), capacity); byteBuffer = v8.createV8ArrayBufferBackingStore(v8.getV8RuntimePtr(), objectHandle, capacity); byteBuffer.order(ByteOrder.nativeOrder()); }
void registerVoidCallback(final JavaVoidCallback callback, final long objectHandle, final String jsFunctionName) { MethodDescriptor methodDescriptor = new MethodDescriptor(); methodDescriptor.voidCallback = callback; long methodID = registerJavaMethod(getV8RuntimePtr(), objectHandle, jsFunctionName, true); functionRegistry.put(methodID, methodDescriptor); }
/** * Indicates to V8 that the system is low on memory. * V8 may use this to attempt to recover space by running * the garbage collector. */ public void lowMemoryNotification() { checkThread(); lowMemoryNotification(getV8RuntimePtr()); }
protected V8Object(final V8 v8, final Object data) { super(v8); if (v8 != null) { this.v8.checkThread(); initialize(this.v8.getV8RuntimePtr(), data); } }
void registerCallback(final JavaCallback callback, final long objectHandle, final String jsFunctionName) { long methodID = registerJavaMethod(getV8RuntimePtr(), objectHandle, jsFunctionName, false); createAndRegisterMethodDescriptor(callback, methodID); }
void registerCallback(final Object object, final Method method, final long objectHandle, final String jsFunctionName, final boolean includeReceiver) { MethodDescriptor methodDescriptor = new MethodDescriptor(); methodDescriptor.object = object; methodDescriptor.method = method; methodDescriptor.includeReceiver = includeReceiver; long methodID = registerJavaMethod(getV8RuntimePtr(), objectHandle, jsFunctionName, isVoidMethod(method)); functionRegistry.put(methodID, methodDescriptor); }
/** * Returns all the keys associated with this JavaScript Object. * Keys associated with the objects prototype are not returned. * * @return The keys associated with this JavaScript Object. */ public String[] getKeys() { v8.checkThread(); checkReleased(); return v8.getKeys(v8.getV8RuntimePtr(), objectHandle); }
/** * Gets the value at a given index as a Java Object. Primitives are boxed. * * @param index The index to get the value at. * * @return The value at the given index. */ public Object get(final int index) { v8.checkThread(); checkReleased(); return v8.arrayGet(v8.getV8RuntimePtr(), V8_OBJECT, objectHandle, index); }
@Override public void close() { v8.checkThread(); if (!released) { try { v8.releaseObjRef(this); } finally { released = true; v8.release(v8.getV8RuntimePtr(), objectHandle); } } }
/** * Associate NULL with the given key. * * @param key The key to associate NULL with. * * @return The receiver. */ public V8Object addNull(final String key) { v8.checkThread(); checkReleased(); v8.addNull(v8.getV8RuntimePtr(), objectHandle, key); return this; }
/** * If {@link V8Value#setWeak()} has been called on this Object, this method * will return true. Otherwise it will return false. * * @return Returns true if this object has been set 'Weak', return false otherwise. */ public boolean isWeak() { v8.checkThread(); v8.checkReleased(); return v8.isWeak(v8.getV8RuntimePtr(), getHandle()); }
/** * Returns the type of element at this given index. * * @param index The index at which to lookup the type of. * * @return The type of the element at the index. */ public int getType(final int index) { v8.checkThread(); checkReleased(); return v8.getType(v8.getV8RuntimePtr(), getHandle(), index); }
/** * Gets the type of the array. Returns a 'type' if all the elements in the array * have the same type, otherwise UNDEFINED is returned. * * @return The type of all the elements of the array, or UNDEFINED if they * are not all the same type. */ public int getType() { v8.checkThread(); checkReleased(); return v8.getArrayType(v8.getV8RuntimePtr(), getHandle()); }
/** * Returns the length of this array. * * @return The length of the array. */ public int length() { v8.checkThread(); checkReleased(); return v8.arrayGetSize(v8.getV8RuntimePtr(), getHandle()); }
@Override public int hashCode() { v8.checkThread(); checkReleased(); return v8.identityHash(v8.getV8RuntimePtr(), getHandle()); }
/** * Pushes null to the next available spot in the Array. In * particular, this[length] = null; * * @return The receiver. */ public V8Array pushNull() { v8.checkThread(); checkReleased(); v8.addArrayNullItem(v8.getV8RuntimePtr(), getHandle()); return this; }
/** * Pushes undefined to the next available spot in the Array. In * particular, this[length] = undefined; * * @return The receiver. */ public V8Array pushUndefined() { v8.checkThread(); checkReleased(); v8.addArrayUndefinedItem(v8.getV8RuntimePtr(), getHandle()); return this; }
/** * Determine if a key/value pair with this key exists in * the Object. * * @param key The key to check * @return True if the key exists, false otherwise. */ public boolean contains(final String key) { v8.checkThread(); checkReleased(); checkKey(key); return v8.contains(v8.getV8RuntimePtr(), objectHandle, key); }
@Override public String toString() { if (isReleased() || v8.isReleased()) { return "[Object released]"; } v8.checkThread(); return v8.toString(v8.getV8RuntimePtr(), getHandle()); }