Error: unexpected '}' when injecting Javascript in BrowserComponent

17 views
Skip to first unread message

P5music

unread,
Oct 21, 2020, 6:16:55 AM10/21/20
to CodenameOne Discussions
IntelliJ IDEA 2020.2.3 (Community Edition)
Build #IC-202.7660.26, built on October 6, 2020
Runtime version: 11.0.8+10-b944.34 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 5.4.0-48-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 949M
Cores: 4
Non-Bundled Plugins: com.kaylerrenslow.plugin.armaplugin.id, com.codename1.plugin.intellij
Current Desktop: ubuntu:GNOME

I am using the executeAndWait instruction (but there are other similar instructions) on a BrowserComponent (subclass of).
I get the error below when trying to inject Javascript. It complains about unexpected '}' char.
In fact in that code there are 21 '{' hars and 22 '}' chars.

 %28function%28%29%7Bvar%20base%5Furl%3D%27https://www.codenameone.com/!cn1return/';function doCallback(val) {   var url = BASE_URL + encodeURIComponent(JSON.stringify(val));  if (window.cefQuery) { window.cefQuery({request:'shouldNavigate:'+url, onSuccess: function(response){}, onFailure:function(error_code, error_message) { console.log(error_message)}});}  else if (window.cn1application && window.cn1application.shouldNavigate) { window.cn1application.shouldNavigate(url) } else if (true) {window._cn1ready = window._cn1ready || []; window._cn1ready.push(function(){window.cn1application.shouldNavigate(url)});} else {window.location.href=url}} var result = {value:null, type:null, errorMessage:null, errorCode:0, callbackId:1};var callback = {  onSucess: function(val) { this.onSuccess(val);},   onSuccess: function(val) { result.value = val; result.type = typeof(val); if (val !== null && typeof val === 'object') {result.value = val.toString();} doCallback(result);},   onError: function(message, code) { if (message instanceof Error) {result.errorMessage = message.message; result.errorCode = 0;} else {result.errorMessage = message; result.errorCode = code;} doCallback(result);}};try { /* My Javascript code here*/ } catch (e) {try {callback.onError(e.message, 0);} catch (e2) {callback.onError('Unknown error', 0);}}})(); (1)
 
Regards

Steve Hannah

unread,
Oct 21, 2020, 8:32:10 AM10/21/20
to codenameone...@googlegroups.com
Most likely the relevant code - the code that has a syntax error - is the part that you redacted with "/*My Javascript code here*/"

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/42b10660-5eb9-4161-b411-fa99d18c7c70n%40googlegroups.com.


--
Steve Hannah
Software Developer
Codename One

P5music

unread,
Oct 21, 2020, 3:08:37 PM10/21/20
to CodenameOne Discussions
I checked the number of '{' and  '}' chars without my Javascript code, you can count the chars with a text search in any editor, I used gEdit on Linux.
Unless I am somewhere wrong, it is not my code's fault, I think (I checked it too). 
Regards

P5music

unread,
Oct 22, 2020, 7:14:56 AM10/22/20
to CodenameOne Discussions
Ok you were right.
I my code there was an array definition wrong: 
var myArray={0};
while it should be
var myArray=[0];

Now, left that error aside, the braces were paired.

but
was a further '}'  created and detected?
or I am very wrong?
Reply all
Reply to author
Forward
0 new messages