Skip to content

Commit

Permalink
Backport KubeJS-Mods#50: Fixes to re-enable JavaAdapter support.
Browse files Browse the repository at this point in the history
Fixes to re-enable JavaAdapter support
  • Loading branch information
LatvianModder authored and tomprince committed Jan 24, 2025
1 parent 1e50a3a commit c2a807b
Show file tree
Hide file tree
Showing 2 changed files with 254 additions and 55 deletions.
71 changes: 69 additions & 2 deletions common/src/main/java/dev/latvian/mods/rhino/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,6 @@ public Scriptable newArray(Scriptable scope, Object[] elements) {
return result;
}


/**
* Returns the maximum stack depth (in terms of number of call frames)
* allowed in a single invocation of interpreter. If the set depth would be
Expand Down Expand Up @@ -797,6 +796,74 @@ public final void setMaximumInterpreterStackDepth(int max) {
maximumInterpreterStackDepth = max;
}

//--------------------------
// Primitive conversion methods
//--------------------------

/**
* Convert the value to a JavaScript boolean value.
* <p>
* See ECMA 9.2.
*
* @param value a JavaScript value
* @return the corresponding boolean value converted using
* the ECMA rules
*/
public boolean toBoolean(Object value) {
return ScriptRuntime.toBoolean(this, value);
}

/**
* Convert the value to a JavaScript Number value.
* <p>
* Returns a Java double for the JavaScript Number.
* <p>
* See ECMA 9.3.
*
* @param value a JavaScript value
* @return the corresponding double value converted using
* the ECMA rules
*/
public double toNumber(Object value) {
return ScriptRuntime.toNumber(this, value);
}

/**
* Convert the value to a JavaScript String value.
* <p>
* See ECMA 9.8.
* <p>
*
* @param value a JavaScript value
* @return the corresponding String value converted using
* the ECMA rules
*/
public String toString(Object value) {
return ScriptRuntime.toString(this, value);
}

/**
* Convert the value to an JavaScript object value.
* <p>
* Note that a scope must be provided to look up the constructors
* for Number, Boolean, and String.
* <p>
* See ECMA 9.9.
* <p>
* Additionally, arbitrary Java objects and classes will be
* wrapped in a Scriptable object with its Java fields and methods
* reflected as JavaScript properties of the object.
*
* @param value any Java object
* @param scope global scope containing constructors for Number,
* Boolean, and String
* @return new JavaScript object
*/
public Scriptable toObject(Object value, Scriptable scope) {
return ScriptRuntime.toObject(this, scope, value);
}


/**
* Get a value corresponding to a key.
* <p>
Expand Down Expand Up @@ -1322,4 +1389,4 @@ public Object doTopCall(Scriptable scope, Callable callable, Scriptable thisObj,
}
return result;
}
}
}
Loading

0 comments on commit c2a807b

Please sign in to comment.