Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot find function split in object #345

Closed
deepakmalode opened this issue Oct 9, 2017 · 5 comments
Closed

TypeError: Cannot find function split in object #345

deepakmalode opened this issue Oct 9, 2017 · 5 comments

Comments

@deepakmalode
Copy link

following js code is throwing exception saying "TypeError: Cannot find function split in object".

var a = "test";
var b = "case";

var c = a + ':' + b;

var d = c.split(':');

Following is the complete stack trace

Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot find function split in object test:case. (#6)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4142)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4120)
at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:4153)
at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:4172)
at org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:4244)
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2533)
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2515)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1322)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:815)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:109)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:399)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3452)
at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:120)
at org.mozilla.javascript.Context.evaluateReader(Context.java:1275)

@gbrail
Copy link
Collaborator

gbrail commented Oct 10, 2017

This works for me. What version of Rhino are you running? I don't recall how long "split" has been in the code base.

@deepakmalode
Copy link
Author

its failing when all the variables are global scope.

we are using 1.7.7.2

@sainaen
Copy link
Contributor

sainaen commented Oct 14, 2017

I can't reproduce it either.

@deepakmalode Could you please share the code where you're setting up Rhino? Does this also happen if you run your code from Rhino's Shell (something like java -jar rhino-1.7.7.2.jar -opt -1 -f source.js)?

What is printed out if you add

print(c.toSource());
print(String.prototype.split.toSource());

before var d = c.split(':');? (In case print() is missing in your scope, try Packages.java.lang.System.out.println() instead.)

@deepakmalode
Copy link
Author

you are right. The error was due to we using rhino through ScriptEngine through com.sun.phobos:com.sun.phobos package. This issue does not occur when we use rhino directly. Guess something in there is introducing the problem .
As this is not related to rhino directly, you can close the issue.

Thanks for the active response and support !!!

@gbrail
Copy link
Collaborator

gbrail commented Nov 14, 2017

Glad to hear that it's working better for you!

@gbrail gbrail closed this as completed Nov 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants