/** * Clears any weak reference set on this V8Value and makes this a strong * reference. Strong references will not be garbage collected and this * Object must be explicitly released. * * Calling clearWeak does nothing if the object is not currently set * to weak. * * @return The receiver. */ public V8Value clearWeak() { v8.checkThread(); v8.checkReleased(); v8.v8WeakReferences.remove(getHandle()); v8.clearWeak(v8.getV8RuntimePtr(), getHandle()); return this; }
/** * Sets the V8Value as weak reference. A weak reference will eventually * be closed when no more references exist to this object. Once setWeak * is called, you should check if {@link V8Value#isReleased()} is true * before invoking any methods on this object. * * If any other references exist to this object, the object will not be * reclaimed. Even if no reference exist, V8 does not give any guarantee * the object will be closed, so this should only be used if there is no * other way to track object usage. * * @return The receiver. */ public V8Value setWeak() { v8.checkThread(); v8.checkReleased(); v8.v8WeakReferences.put(getHandle(), this); v8.setWeak(v8.getV8RuntimePtr(), getHandle()); 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()); }
@Override public int hashCode() { v8.checkThread(); checkReleased(); return v8.identityHash(v8.getV8RuntimePtr(), getHandle()); }
/** * Performs a JS === on the parameter and the receiver. * * @param that The Object to compare this object against. * @return Returns true iff this === that */ public boolean strictEquals(final Object that) { v8.checkThread(); checkReleased(); if (that == this) { return true; } if (that == null) { return false; } if (!(that instanceof V8Value)) { return false; } if (isUndefined() && ((V8Value) that).isUndefined()) { return true; } if (((V8Value) that).isUndefined()) { return false; } return v8.strictEquals(v8.getV8RuntimePtr(), getHandle(), ((V8Value) that).getHandle()); }
/** * Performs a JS == on the parameter and the receiver. * * @param that The Object to compare this object against. * @return Returns true iff this == that */ public boolean jsEquals(final Object that) { v8.checkThread(); checkReleased(); if (that == this) { return true; } if (that == null) { return false; } if (!(that instanceof V8Value)) { return false; } if (isUndefined() && ((V8Value) that).isUndefined()) { return true; } if (((V8Value) that).isUndefined()) { return false; } return v8.equals(v8.getV8RuntimePtr(), getHandle(), ((V8Value) that).getHandle()); }
/** * Adds a key value pair to the receiver where the value is a V8Value. * * @param key The key to associate the value with. * @param value The value to add. * * @return The receiver. */ public V8Object add(final String key, final V8Value value) { v8.checkThread(); checkReleased(); v8.checkRuntime(value); if (value == null) { v8.addNull(v8.getV8RuntimePtr(), objectHandle, key); } else if (value.equals(V8.getUndefined())) { v8.addUndefined(v8.getV8RuntimePtr(), objectHandle, key); } else { v8.addObject(v8.getV8RuntimePtr(), objectHandle, key, value.getHandle()); } return this; }
/** * Pushes a V8Value to the next available spot in the Array. In * particular, this[length] = value; * * @param value The value to push to the array. * * @return The receiver. */ public V8Array push(final V8Value value) { v8.checkThread(); checkReleased(); v8.checkRuntime(value); if (value == null) { v8.addArrayNullItem(v8.getV8RuntimePtr(), getHandle()); } else if (value.equals(V8.getUndefined())) { v8.addArrayUndefinedItem(v8.getV8RuntimePtr(), getHandle()); } else { v8.addArrayObjectItem(v8.getV8RuntimePtr(), getHandle(), value.getHandle()); } return this; }
v8.addArrayStringItem(v8.getV8RuntimePtr(), getHandle(), (String) value); } else if (value instanceof V8Value) { v8.addArrayObjectItem(v8.getV8RuntimePtr(), getHandle(), ((V8Value) value).getHandle()); } else { throw new IllegalArgumentException();
/** * Clears any weak reference set on this V8Value and makes this a strong * reference. Strong references will not be garbage collected and this * Object must be explicitly released. * * Calling clearWeak does nothing if the object is not currently set * to weak. * * @return The receiver. */ public V8Value clearWeak() { v8.checkThread(); v8.checkReleased(); v8.v8WeakReferences.remove(getHandle()); v8.clearWeak(v8.getV8RuntimePtr(), getHandle()); return this; }
/** * Sets the V8Value as weak reference. A weak reference will eventually * be closed when no more references exist to this object. Once setWeak * is called, you should check if {@link V8Value#isReleased()} is true * before invoking any methods on this object. * * If any other references exist to this object, the object will not be * reclaimed. Even if no reference exist, V8 does not give any guarantee * the object will be closed, so this should only be used if there is no * other way to track object usage. * * @return The receiver. */ public V8Value setWeak() { v8.checkThread(); v8.checkReleased(); v8.v8WeakReferences.put(getHandle(), this); v8.setWeak(v8.getV8RuntimePtr(), getHandle()); return this; }
@Override public int hashCode() { v8.checkThread(); checkReleased(); return v8.identityHash(v8.getV8RuntimePtr(), getHandle()); }
/** * 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()); }
/** * Performs a JS === on the parameter and the receiver. * * @param that The Object to compare this object against. * @return Returns true iff this === that */ public boolean strictEquals(final Object that) { v8.checkThread(); checkReleased(); if (that == this) { return true; } if (that == null) { return false; } if (!(that instanceof V8Value)) { return false; } if (isUndefined() && ((V8Value) that).isUndefined()) { return true; } if (((V8Value) that).isUndefined()) { return false; } return v8.strictEquals(v8.getV8RuntimePtr(), getHandle(), ((V8Value) that).getHandle()); }
/** * Performs a JS == on the parameter and the receiver. * * @param that The Object to compare this object against. * @return Returns true iff this == that */ public boolean jsEquals(final Object that) { v8.checkThread(); checkReleased(); if (that == this) { return true; } if (that == null) { return false; } if (!(that instanceof V8Value)) { return false; } if (isUndefined() && ((V8Value) that).isUndefined()) { return true; } if (((V8Value) that).isUndefined()) { return false; } return v8.equals(v8.getV8RuntimePtr(), getHandle(), ((V8Value) that).getHandle()); }
/** * Adds a key value pair to the receiver where the value is a V8Value. * * @param key The key to associate the value with. * @param value The value to add. * * @return The receiver. */ public V8Object add(final String key, final V8Value value) { v8.checkThread(); checkReleased(); v8.checkRuntime(value); if (value == null) { v8.addNull(v8.getV8RuntimePtr(), objectHandle, key); } else if (value.equals(V8.getUndefined())) { v8.addUndefined(v8.getV8RuntimePtr(), objectHandle, key); } else { v8.addObject(v8.getV8RuntimePtr(), objectHandle, key, value.getHandle()); } return this; }
v8.addArrayStringItem(v8.getV8RuntimePtr(), getHandle(), (String) value); } else if (value instanceof V8Value) { v8.addArrayObjectItem(v8.getV8RuntimePtr(), getHandle(), ((V8Value) value).getHandle()); } else { throw new IllegalArgumentException();
/** * Pushes a V8Value to the next available spot in the Array. In * particular, this[length] = value; * * @param value The value to push to the array. * * @return The receiver. */ public V8Array push(final V8Value value) { v8.checkThread(); checkReleased(); v8.checkRuntime(value); if (value == null) { v8.addArrayNullItem(v8.getV8RuntimePtr(), getHandle()); } else if (value.equals(V8.getUndefined())) { v8.addArrayUndefinedItem(v8.getV8RuntimePtr(), getHandle()); } else { v8.addArrayObjectItem(v8.getV8RuntimePtr(), getHandle(), value.getHandle()); } return this; }