Skip to content

Commit

Permalink
馃 refactor: Adjust JavetCallbackContext()
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed May 22, 2023
1 parent b8f5e39 commit 4678a41
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 60 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/caoccao/javet/annotations/V8Convert.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@
*/
V8ConversionMode mode() default V8ConversionMode.Transparent;

/**
* Proxy mode.
*
* @return the proxy mode
* @since 1.1.7
*/
V8ProxyMode proxyMode() default V8ProxyMode.Object;
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,24 @@ public final class JavetCallbackContext {
public JavetCallbackContext(
String name,
IJavetDirectCallable.GetterAndNoThis<?> directCall) {
this(name, V8ValueSymbolType.None, directCall, JavetCallbackType.DirectCallGetterAndNoThis, false, true);
this(name, (Object) null, directCall);
}

/**
* Instantiates a new Javet callback context that takes a direct call as the getter.
*
* @param name the name
* @param symbolType the symbol type
* @param directCall the direct call
* @param name the name
* @param callbackReceiver the callback receiver
* @param directCall the direct call
* @since 2.2.0
*/
public JavetCallbackContext(
String name,
V8ValueSymbolType symbolType,
Object callbackReceiver,
IJavetDirectCallable.GetterAndNoThis<?> directCall) {
this(name, symbolType, directCall, JavetCallbackType.DirectCallGetterAndNoThis, false, true);
this(name, V8ValueSymbolType.None, callbackReceiver,
JavetCallbackType.DirectCallGetterAndNoThis, directCall,
false, true);
}

/**
Expand All @@ -86,22 +88,24 @@ public JavetCallbackContext(
public JavetCallbackContext(
String name,
IJavetDirectCallable.GetterAndThis<?> directCall) {
this(name, V8ValueSymbolType.None, directCall, JavetCallbackType.DirectCallGetterAndThis, true, true);
this(name, (Object) null, directCall);
}

/**
* Instantiates a new Javet callback context that takes a direct call as the getter.
*
* @param name the name
* @param symbolType the symbol type
* @param directCall the direct call
* @param name the name
* @param callbackReceiver the callback receiver
* @param directCall the direct call
* @since 2.2.0
*/
public JavetCallbackContext(
String name,
V8ValueSymbolType symbolType,
Object callbackReceiver,
IJavetDirectCallable.GetterAndThis<?> directCall) {
this(name, symbolType, directCall, JavetCallbackType.DirectCallGetterAndThis, true, true);
this(name, V8ValueSymbolType.None, callbackReceiver,
JavetCallbackType.DirectCallGetterAndThis, directCall,
true, true);
}

/**
Expand All @@ -114,22 +118,24 @@ public JavetCallbackContext(
public JavetCallbackContext(
String name,
IJavetDirectCallable.SetterAndNoThis<?> directCall) {
this(name, V8ValueSymbolType.None, directCall, JavetCallbackType.DirectCallSetterAndNoThis, false, false);
this(name, (Object) null, directCall);
}

/**
* Instantiates a new Javet callback context that takes a direct call as the setter.
*
* @param name the name
* @param symbolType the symbol type
* @param directCall the direct call
* @param name the name
* @param callbackReceiver the callback receiver
* @param directCall the direct call
* @since 2.2.0
*/
public JavetCallbackContext(
String name,
V8ValueSymbolType symbolType,
Object callbackReceiver,
IJavetDirectCallable.SetterAndNoThis<?> directCall) {
this(name, symbolType, directCall, JavetCallbackType.DirectCallSetterAndNoThis, false, false);
this(name, V8ValueSymbolType.None, callbackReceiver,
JavetCallbackType.DirectCallSetterAndNoThis, directCall,
false, false);
}

/**
Expand All @@ -142,22 +148,24 @@ public JavetCallbackContext(
public JavetCallbackContext(
String name,
IJavetDirectCallable.SetterAndThis<?> directCall) {
this(name, V8ValueSymbolType.None, directCall, JavetCallbackType.DirectCallSetterAndThis, true, false);
this(name, (Object) null, directCall);
}

/**
* Instantiates a new Javet callback context that takes a direct call as the setter.
*
* @param name the name
* @param symbolType the symbol type
* @param directCall the direct call
* @param name the name
* @param callbackReceiver the callback receiver
* @param directCall the direct call
* @since 2.2.0
*/
public JavetCallbackContext(
String name,
V8ValueSymbolType symbolType,
Object callbackReceiver,
IJavetDirectCallable.SetterAndThis<?> directCall) {
this(name, symbolType, directCall, JavetCallbackType.DirectCallSetterAndThis, true, false);
this(name, V8ValueSymbolType.None, callbackReceiver,
JavetCallbackType.DirectCallSetterAndThis, directCall,
true, false);
}

/**
Expand All @@ -170,22 +178,24 @@ public JavetCallbackContext(
public JavetCallbackContext(
String name,
IJavetDirectCallable.NoThisAndNoResult<?> directCall) {
this(name, V8ValueSymbolType.None, directCall, JavetCallbackType.DirectCallNoThisAndNoResult, false, false);
this(name, (Object) null, directCall);
}

/**
* Instantiates a new Javet callback context that takes a direct call.
*
* @param name the name
* @param symbolType the symbol type
* @param directCall the direct call
* @param name the name
* @param callbackReceiver the callback receiver
* @param directCall the direct call
* @since 2.2.0
*/
public JavetCallbackContext(
String name,
V8ValueSymbolType symbolType,
Object callbackReceiver,
IJavetDirectCallable.NoThisAndNoResult<?> directCall) {
this(name, symbolType, directCall, JavetCallbackType.DirectCallNoThisAndNoResult, false, false);
this(name, V8ValueSymbolType.None, callbackReceiver,
JavetCallbackType.DirectCallNoThisAndNoResult, directCall,
false, false);
}

/**
Expand All @@ -198,22 +208,24 @@ public JavetCallbackContext(
public JavetCallbackContext(
String name,
IJavetDirectCallable.NoThisAndResult<?> directCall) {
this(name, V8ValueSymbolType.None, directCall, JavetCallbackType.DirectCallNoThisAndResult, false, true);
this(name, (Object) null, directCall);
}

/**
* Instantiates a new Javet callback context that takes a direct call.
*
* @param name the name
* @param symbolType the symbol type
* @param directCall the direct call
* @param name the name
* @param callbackReceiver the callback receiver
* @param directCall the direct call
* @since 2.2.0
*/
public JavetCallbackContext(
String name,
V8ValueSymbolType symbolType,
Object callbackReceiver,
IJavetDirectCallable.NoThisAndResult<?> directCall) {
this(name, symbolType, directCall, JavetCallbackType.DirectCallNoThisAndResult, false, true);
this(name, V8ValueSymbolType.None, callbackReceiver,
JavetCallbackType.DirectCallNoThisAndResult, directCall,
false, true);
}

/**
Expand All @@ -226,22 +238,24 @@ public JavetCallbackContext(
public JavetCallbackContext(
String name,
IJavetDirectCallable.ThisAndNoResult<?> directCall) {
this(name, V8ValueSymbolType.None, directCall, JavetCallbackType.DirectCallThisAndNoResult, true, false);
this(name, (Object) null, directCall);
}

/**
* Instantiates a new Javet callback context that takes a direct call.
*
* @param name the name
* @param symbolType the symbol type
* @param directCall the direct call
* @param name the name
* @param callbackReceiver the callback receiver
* @param directCall the direct call
* @since 2.2.0
*/
public JavetCallbackContext(
String name,
V8ValueSymbolType symbolType,
Object callbackReceiver,
IJavetDirectCallable.ThisAndNoResult<?> directCall) {
this(name, symbolType, directCall, JavetCallbackType.DirectCallThisAndNoResult, true, false);
this(name, V8ValueSymbolType.None, callbackReceiver,
JavetCallbackType.DirectCallThisAndNoResult, directCall,
true, false);
}

/**
Expand All @@ -254,33 +268,24 @@ public JavetCallbackContext(
public JavetCallbackContext(
String name,
IJavetDirectCallable.ThisAndResult<?> directCall) {
this(name, V8ValueSymbolType.None, directCall, JavetCallbackType.DirectCallThisAndResult, true, true);
this(name, (Object) null, directCall);
}

/**
* Instantiates a new Javet callback context that takes a direct call.
*
* @param name the name
* @param symbolType the symbol type
* @param directCall the direct call
* @param name the name
* @param callbackReceiver the callback receiver
* @param directCall the direct call
* @since 2.2.0
*/
public JavetCallbackContext(
String name,
V8ValueSymbolType symbolType,
Object callbackReceiver,
IJavetDirectCallable.ThisAndResult<?> directCall) {
this(name, symbolType, directCall, JavetCallbackType.DirectCallThisAndResult, true, true);
}

private JavetCallbackContext(
String name,
V8ValueSymbolType symbolType,
IJavetDirectCallable.DirectCall directCall,
JavetCallbackType callbackType,
boolean thisObjectRequired,
boolean returnResult) {
this(name, symbolType, null, callbackType, directCall, thisObjectRequired);
this.returnResult = returnResult;
this(name, V8ValueSymbolType.None, callbackReceiver,
JavetCallbackType.DirectCallThisAndResult, directCall,
true, true);
}

/**
Expand Down Expand Up @@ -371,6 +376,18 @@ private JavetCallbackContext(
this.symbolType = Objects.requireNonNull(symbolType);
}

private JavetCallbackContext(
String name,
V8ValueSymbolType symbolType,
Object callbackReceiver,
JavetCallbackType callbackType,
IJavetDirectCallable.DirectCall directCall,
boolean thisObjectRequired,
boolean returnResult) {
this(name, symbolType, callbackReceiver, callbackType, directCall, thisObjectRequired);
this.returnResult = returnResult;
}

/**
* Gets callback method.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
/**
* The interface Javet proxy handler.
* <p>
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
* Please refer to this <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy">doc</a>
* for more details.
*
* @param <T> the type parameter
* @since 0.9.6
Expand Down

0 comments on commit 4678a41

Please sign in to comment.