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

ClassCastException in Node.getString #662

Open
jon-bell opened this issue May 7, 2020 · 5 comments
Open

ClassCastException in Node.getString #662

jon-bell opened this issue May 7, 2020 · 5 comments
Labels
bug Issues considered a bug Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec

Comments

@jon-bell
Copy link

jon-bell commented May 7, 2020

We ran into an unexpected ClassCastException when attempting to compile the following string using Rhino 1.7.12: ["".h]=y

Output:

	at org.mozilla.javascript.Node.getString(Node.java:537)
	at org.mozilla.javascript.optimizer.BodyCodegen.generateExpression(Codegen.java:2262)
	at org.mozilla.javascript.optimizer.BodyCodegen.visitSetProp(Codegen.java:5132)
	at org.mozilla.javascript.optimizer.BodyCodegen.generateExpression(Codegen.java:2610)
	at org.mozilla.javascript.optimizer.BodyCodegen.generateExpression(Codegen.java:2309)
	at org.mozilla.javascript.optimizer.BodyCodegen.generateExpression(Codegen.java:2807)
	at org.mozilla.javascript.optimizer.BodyCodegen.generateExpression(Codegen.java:2309)
	at org.mozilla.javascript.optimizer.BodyCodegen.generateExpression(Codegen.java:2807)
	at org.mozilla.javascript.optimizer.BodyCodegen.generateStatement(Codegen.java:2059)
	at org.mozilla.javascript.optimizer.BodyCodegen.generateStatement(Codegen.java:1870)
	at org.mozilla.javascript.optimizer.BodyCodegen.generateBodyCode(Codegen.java:1292)
	at org.mozilla.javascript.optimizer.Codegen.generateCode(Codegen.java:307)
	at org.mozilla.javascript.optimizer.Codegen.compileToClassFile(Codegen.java:166)
	at org.mozilla.javascript.optimizer.Codegen.compile(Codegen.java:75)
	at org.mozilla.javascript.Context.compileImpl(Context.java:2551)
	at org.mozilla.javascript.Context.compileString(Context.java:1507)
	at org.mozilla.javascript.Context.compileString(Context.java:1496)
	at edu.berkeley.cs.jqf.examples.rhino.CompilerTest.main(CompilerTest.java:123)
@rbri
Copy link
Collaborator

rbri commented May 31, 2020

Can you please prepare a simple test case to make it easy for us to reproduce this.

You can have a look at the packages org.mozilla.javascript.tests.es5 or org.mozilla.javascript.tests.es6 for sample tests.

@p-bakker p-bakker added the bug Issues considered a bug label Jun 30, 2021
@p-bakker p-bakker added the Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec label Oct 14, 2021
@p-bakker p-bakker added this to To do in v2.0.0 via automation Oct 14, 2021
@p-bakker p-bakker moved this from To do to bugs in v2.0.0 Oct 14, 2021
@p-bakker p-bakker added this to To do in v1.7.xx via automation Oct 14, 2021
@p-bakker p-bakker moved this from To do to To do: bugs (v2.0.0 prep) in v1.7.xx Oct 14, 2021
@tuchida
Copy link
Contributor

tuchida commented Mar 9, 2022

["".h]=""
// Exception in thread "main" java.lang.ClassCastException: org.mozilla.javascript.ast.StringLiteral cannot be cast to org.mozilla.javascript.ast.Name

[1..h]="" // no error

[0..toString.h] = [123] // // expect: Number.prototype.toString.h === 123
// Exception in thread "main" java.lang.NullPointerException

Perhaps it has something to do with this code.

if (nodeType == Token.GETPROP) {
type = Token.SETPROP;
// TODO(stevey) - see https://bugzilla.mozilla.org/show_bug.cgi?id=492036
// The new AST code generates NAME tokens for GETPROP ids where the old
// parser
// generated STRING nodes. If we don't set the type to STRING below, this
// will
// cause java.lang.VerifyError in codegen for code like
// "var obj={p:3};[obj.p]=[9];"
id.setType(Token.STRING);

@p-bakker
Copy link
Collaborator

p-bakker commented Mar 9, 2022

You sure those double dots (..) are correct in your examples? As I think that makes it E4X-specific syntax and thus completely different codePaths, no?

@tuchida
Copy link
Contributor

tuchida commented Mar 9, 2022

Yes. The first dot is a decimal point. The second dot is a member operator.
http://adripofjavascript.com/blog/drips/numbers-and-javascripts-dot-notation.html

@p-bakker
Copy link
Collaborator

es. The first dot is a decimal point. The second dot is a member operator.

Right... learned something new about JavaScript :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues considered a bug Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec
Projects
v1.7.xx
To do: bugs (v2.0.0 prep)
v2.0.0
To do: bugs
Development

No branches or pull requests

4 participants