philmasterplus
Active member
- KoLmafia revision: r20672
require()
and call user-defined ASH functions in the top-level scope. However, the script fails if there exists an ASH function with a leading underscore.For example, given the following ASH script:
Code:
void _foo() {
print("foo bar");
}
Importing this from JavaScript results in an error :
Code:
> js require("funcname.ash");
Unexpected error, debug log printed.
The debug log looks like this:
Code:
class java.lang.StringIndexOutOfBoundsException: String index out of range: 0
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:47)
at java.base/java.lang.String.charAt(String.java:693)
at net.sourceforge.kolmafia.textui.javascript.JavascriptRuntime.toCamelCase(JavascriptRuntime.java:99)
at net.sourceforge.kolmafia.textui.javascript.SafeRequire.call(SafeRequire.java:79)
at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:76)
at org.mozilla.javascript.gen.command_line_3._c_script_0(command line:1)
at org.mozilla.javascript.gen.command_line_3.call(command line)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:412)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3578)
at org.mozilla.javascript.gen.command_line_3.call(command line)
at org.mozilla.javascript.gen.command_line_3.exec(command line)
at org.mozilla.javascript.Context.evaluateString(Context.java:1234)
at net.sourceforge.kolmafia.textui.javascript.JavascriptRuntime.executeRun(JavascriptRuntime.java:267)
at net.sourceforge.kolmafia.textui.javascript.JavascriptRuntime.execute(JavascriptRuntime.java:231)
at net.sourceforge.kolmafia.textui.AbstractRuntime.execute(AbstractRuntime.java:61)
at net.sourceforge.kolmafia.textui.command.JavaScriptCommand.run(JavaScriptCommand.java:56)
at net.sourceforge.kolmafia.KoLmafiaCLI.doExecuteCommand(KoLmafiaCLI.java:593)
at net.sourceforge.kolmafia.KoLmafiaCLI.executeCommand(KoLmafiaCLI.java:546)
at net.sourceforge.kolmafia.KoLmafiaCLI.executeLine(KoLmafiaCLI.java:448)
at net.sourceforge.kolmafia.KoLmafiaCLI.executeLine(KoLmafiaCLI.java:316)
at net.sourceforge.kolmafia.KoLmafiaCLI$CommandProcessorThread.run(KoLmafiaCLI.java:238)
...which can be traced to
JavaScriptRuntime.java
:
Java:
public static String toCamelCase( String name )
{
if ( name == null )
{
return null;
}
boolean first = true;
StringBuilder result = new StringBuilder();
for ( String word : name.split( "_" ) )
{
if ( first )
{
result.append( word.charAt( 0 ) ); // StringIndexOutOfBoundsException: String index out of range
first = false;
}
else
{
result.append( Character.toUpperCase( word.charAt( 0 ) ) );
}
result.append( word.substring( 1 ) );
}
return result.toString();
}
It seems to be caused by an empty string token.
Edit: Some more edge cases I tested:
Code:
void _this_crashes() {}
void this__crashes() {}
void noCrash_() {}
void noCrash__() {}
void noCrash___() {}
Last edited: