Skip to content

Commit

Permalink
🦄 refactor: Redesign IV8ValueObject.bindFunction()
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed May 19, 2023
1 parent 9622b72 commit a81f31b
Show file tree
Hide file tree
Showing 13 changed files with 632 additions and 161 deletions.
2 changes: 2 additions & 0 deletions docs/release_notes/release_notes_2_2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ Release Notes 2.2.x

* Improved the performance of ``V8FunctionCallback.receiveCallback()``, ``IV8ValueObject.forEach()``, ``IV8ValueMap.forEach()``, ``IV8ValueArray.forEach()``, ``IV8ValueArray.push()``, ``IV8ValueObject.set()``, ``IV8ValueMap.set()``,
* Added ``IV8ValueObject.batchGet()``, ``IV8ValueMap.batchGet()``, ``IV8ValueArray.batchGet()``
* Added ``JavetCallbackType``, ``IJavetDirectCallable`` to allow callback without reflection
* Redesigned ``IV8ValueObject.bindFunction()``, ``JavetCallbackContext``
* Created `JavetPerf <https://github.com/caoccao/JavetPerf>`_ for tracking the performance among various Javet releases
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.caoccao.javet.interception.logging;

import com.caoccao.javet.enums.V8ValueSymbolType;
import com.caoccao.javet.exceptions.JavetError;
import com.caoccao.javet.exceptions.JavetException;
import com.caoccao.javet.interception.BaseJavetInterceptor;
Expand Down Expand Up @@ -215,10 +216,11 @@ public boolean register(IV8ValueObject... iV8ValueObjects) throws JavetException
protected void register(IV8ValueObject iV8ValueObject, String jsFunctionName, String javaFunctionName)
throws JavetException {
try {
iV8ValueObject.bindFunction(
iV8ValueObject.bindFunction(new JavetCallbackContext(
jsFunctionName,
new JavetCallbackContext(this,
getClass().getMethod(javaFunctionName, V8Value[].class)));
V8ValueSymbolType.None,
this,
getClass().getMethod(javaFunctionName, V8Value[].class)));
} catch (NoSuchMethodException e) {
throw new JavetException(
JavetError.CallbackRegistrationFailure,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.caoccao.javet.exceptions.JavetException;
import com.caoccao.javet.values.V8Value;

import java.io.Serializable;

/**
* The interface Javet direct callable is for converting the calls
* from reflection calls to direct calls.
Expand All @@ -27,31 +29,62 @@
*/
public interface IJavetDirectCallable {
/**
* Call.
* Get supported callback contexts.
*
* @param name the name
* @param thisObject the this object
* @param v8Values the V8 values
* @return the V8 value
* @throws JavetException the javet exception
* @return the supported callback contexts
* @since 2.2.0
*/
V8Value call(String name, V8Value thisObject, V8Value... v8Values) throws JavetException;
JavetCallbackContext[] getCallbackContexts();

/**
* Get supported callback contexts.
* The interface Direct call.
*
* @return the supported callback contexts
* @since 2.2.0
*/
JavetCallbackContext[] getCallbackContexts();
interface DirectCall extends Serializable {
}

/**
* The interface GetterAndNoThis gets the property value by a property key without this object passed in.
*
* @since 2.2.0
*/
interface GetterAndNoThis extends DirectCall {
/**
* Get the property value by a property key without this object passed in.
*
* @param v8ValueKey the V8 value key
* @return the V8 value
* @throws JavetException the javet exception
* @since 2.2.0
*/
V8Value get(V8Value v8ValueKey) throws JavetException;
}

/**
* The interface GetterAndThis gets the property value by a property key with this object passed in.
*
* @since 2.2.0
*/
interface GetterAndThis extends DirectCall {
/**
* Get the property value by a property key with this object passed in.
*
* @param thisObject the this object
* @param v8ValueKey the V8 value key
* @return the V8 value
* @throws JavetException the javet exception
* @since 2.2.0
*/
V8Value get(V8Value thisObject, V8Value v8ValueKey) throws JavetException;
}

/**
* The interface NoThisAndNoResult does not accept this object and return the result.
*
* @since 2.2.0
*/
interface NoThisAndNoResult {
interface NoThisAndNoResult extends DirectCall {
/**
* Call.
*
Expand All @@ -67,7 +100,7 @@ interface NoThisAndNoResult {
*
* @since 2.2.0
*/
interface NoThisAndResult {
interface NoThisAndResult extends DirectCall {
/**
* Call and return the result.
*
Expand All @@ -79,12 +112,49 @@ interface NoThisAndResult {
V8Value call(V8Value... v8Values) throws JavetException;
}

/**
* The interface SetterAndNoThis gets the property value by a property key without this object passed in.
*
* @since 2.2.0
*/
interface SetterAndNoThis extends DirectCall {
/**
* Set the property value by a property key without this object passed in.
*
* @param v8ValueKey the V8 value key
* @param v8ValueValue the V8 value value
* @return the V8 value
* @throws JavetException the javet exception
* @since 2.2.0
*/
V8Value set(V8Value v8ValueKey, V8Value v8ValueValue) throws JavetException;
}

/**
* The interface SetterAndThis gets the property value by a property key with this object passed in.
*
* @since 2.2.0
*/
interface SetterAndThis extends DirectCall {
/**
* Set the property value by a property key with this object passed in.
*
* @param thisObject the this object
* @param v8ValueKey the V8 value key
* @param v8ValueValue the V8 value value
* @return the V8 value
* @throws JavetException the javet exception
* @since 2.2.0
*/
V8Value set(V8Value thisObject, V8Value v8ValueKey, V8Value v8ValueValue) throws JavetException;
}

/**
* The interface ThisAndNoResult accepts this object.
*
* @since 2.2.0
*/
interface ThisAndNoResult {
interface ThisAndNoResult extends DirectCall {
/**
* Call by this object.
*
Expand All @@ -101,7 +171,7 @@ interface ThisAndNoResult {
*
* @since 2.2.0
*/
interface ThisAndResult {
interface ThisAndResult extends DirectCall {
/**
* Call by this object and return the result.
*
Expand Down
Loading

0 comments on commit a81f31b

Please sign in to comment.