Skip to content

Commit

Permalink
Merge pull request #51 from tomprince/backport-java-adapter-fix
Browse files Browse the repository at this point in the history
Backport #50: Fixes to re-enable JavaAdapter support.
  • Loading branch information
LatvianModder authored Feb 12, 2025
2 parents 1e50a3a + 5e764f1 commit afe5010
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 64 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ subprojects {
apply plugin: 'architectury-plugin'
apply plugin: "io.github.juuxel.loom-vineflower"
apply plugin: "maven-publish"
apply from: "https://files.latmod.com/public/markdown-git-changelog.gradle"

version = rootProject.version
group = rootProject.group
Expand Down Expand Up @@ -132,4 +131,4 @@ task collectJars(type: Copy) {

assemble {
dependsOn(collectJars)
}
}
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 afe5010

Please sign in to comment.