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

JSONata 1.2, 1.3 jsonata-es5 on Nashord fails fo group expression with error: Caused by: jdk.nashorn.internal.runtime.ECMAException: TypeError: Cannot call undefined #78

Closed
MaciejHadam opened this issue Sep 13, 2017 · 4 comments
Labels

Comments

@MaciejHadam
Copy link

HI,

I've came into a problem with updating JSONata version that is used in Java Nashorn.
Simple expressions (without {}) are properly evaluated, but the execution of complex expressions (with {}) ends with an exception: Caused by: jdk.nashorn.internal.runtime.ECMAException: TypeError: Cannot call undefined

Simple expression is evaluated correctly.

@Test
  public void testJsonMerge(){

	String actual = nashornJsonataEvaluator.evaluateString("{\"name\":\"John\"}", "$.name");
	Assert.assertEquals("Name should be john", "John", actual);
	
  }

Complex expression that fails.

  @Test
  public void testJsonMergeComplex(){

	String actual = nashornJsonataEvaluator.evaluateString("{\"name\":\"John\"}", "$.{\"name\": name}");
	Assert.assertEquals("Name should be JSOn with name John", "{\"name\":\"John\"}", actual);
	
  }

Below there is a stacktrace of failed execution:

	at jdk.nashorn.internal.scripts.Script$Recompilation$245$90543A$jsonata_es5.L:1$L:1-1$L:1$L:2$jsonata$evaluateGroupExpression$evaluateGroupExpression$(/jsonata/jsonata-es5.js:2384) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$209$262558AAA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$tryCatch(/jsonata/jsonata-es5.js:6925) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$208$270231AA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$makeInvokeMethod$invoke(/jsonata/jsonata-es5.js:7163) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$207$264651A$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$defineIteratorMethods$L:6975$L:6976(/jsonata/jsonata-es5.js:6977) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$209$262558AAA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$tryCatch(/jsonata/jsonata-es5.js:6925) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$236$272741AA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$maybeInvokeDelegate(/jsonata/jsonata-es5.js:7225) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$208$270231AA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$makeInvokeMethod$invoke(/jsonata/jsonata-es5.js:7137) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$207$264651A$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$defineIteratorMethods$L:6975$L:6976(/jsonata/jsonata-es5.js:6977) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$209$262558AAA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$tryCatch(/jsonata/jsonata-es5.js:6925) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$236$272741AA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$maybeInvokeDelegate(/jsonata/jsonata-es5.js:7225) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$208$270231AA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$makeInvokeMethod$invoke(/jsonata/jsonata-es5.js:7137) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$207$264651A$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$defineIteratorMethods$L:6975$L:6976(/jsonata/jsonata-es5.js:6977) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$209$262558AAA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$tryCatch(/jsonata/jsonata-es5.js:6925) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$236$272741AA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$maybeInvokeDelegate(/jsonata/jsonata-es5.js:7225) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$208$270231AA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$makeInvokeMethod$invoke(/jsonata/jsonata-es5.js:7137) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$207$264651A$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$defineIteratorMethods$L:6975$L:6976(/jsonata/jsonata-es5.js:6977) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$209$262558AAA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$tryCatch(/jsonata/jsonata-es5.js:6925) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$236$272741AA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$maybeInvokeDelegate(/jsonata/jsonata-es5.js:7225) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$208$270231AA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$makeInvokeMethod$invoke(/jsonata/jsonata-es5.js:7137) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$207$264651A$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$defineIteratorMethods$L:6975$L:6976(/jsonata/jsonata-es5.js:6977) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$209$262558AAA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$tryCatch(/jsonata/jsonata-es5.js:6925) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$236$272741AA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$maybeInvokeDelegate(/jsonata/jsonata-es5.js:7225) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$208$270231AA$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$makeInvokeMethod$invoke(/jsonata/jsonata-es5.js:7137) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$207$264651A$jsonata_es5.L:1$L:1-1$L:6859$L:6860$L:6871$defineIteratorMethods$L:6975$L:6976(/jsonata/jsonata-es5.js:6977) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$232$188977AAA$jsonata_es5.L:1$L:1-1$L:1$L:2$jsonata$jsonata$evaluate(/jsonata/jsonata-es5.js:5096) ~[?:?]

I'n using jsonata-es5.js file and nashorn-commonjs-modules.

The previous version of JSONata (currently 1.1.1) works well and this issue is blocking migration to higher version of JSONata library.

Thanks for help

@MaciejHadam
Copy link
Author

MaciejHadam commented Sep 14, 2017

The problem is caused by the line 2384 it = allPromises.values(); and the values() function is an ES6 syntax.
It's all about lack of polyfill for iterable in ES5.

@andrew-coleman
Copy link
Member

I've just recreated this in node v0.10 and come to the same conclusion as you on the polyfill. It was falling over on the allPromises.entries() call for me.

@blgm
Copy link
Contributor

blgm commented Sep 17, 2017

Object.entries() and Object.values() are in ES2017, which is one of the things that the Babel env preset (which is being used) should transform. Adding:

require('core-js');

To the top of jsonata.js fixes the problem. We could introduce a build step to do that, but that's what I though Babel (specifically babel-plugin-transform-runtime) is meant to be for.

There might be a bug in Babel, but more likely there is a subtle usage error. Perhaps the next step would be to find a project that has this working, and compare.

@andrew-coleman
Copy link
Member

The problem was due to the use of array iterators. I've rewritten that section of code.
The fix is now available in v1.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants