Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Request.js - eval not in global scope for IE
Request.js - eval not in global scope for IE [message #521940] Fri, 19 March 2010 12:06 Go to next message
Onno  is currently offline Onno Friend
Messages: 7
Registered: September 2009
Junior Member
Hi,

i encountered a strange behaviour in RAP using the Internet Explorer. I use the JSWriter to deliver additional qooxdoo classes and some other JS code to the client, which may be dynamically added at runtime.

It seems like the devlired code is executed in the global scope in Chrome and Firefox, but not in the IE. This then leads to different behaviour which is hard to deal with.

So my question is: Is this considered in newer versions of RAP or should i file a bug or am i doing something wrong?


Some details to the problem:
In Request.js, the code is executed with "window.eval(...)". This operation is handled different in all major browsers. See for example this article.
To solve the problem in my case, i changed window.eval(...) to
if (window.execScript) {
   window.execScript(text); // eval in global scope for IE
} else {  
   window.eval(text);	
}


But I'm not sure right now, if this has further implications.

Regards,
Onno Hensgen
Re: Request.js - eval not in global scope for IE [message #522020 is a reply to message #521940] Fri, 19 March 2010 11:38 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim BuschtoensFriend
Messages: 396
Registered: July 2009
Senior Member
Hello Onno.

Can you be more specific on what problem you encounter with IE?
I know eval doesn't behave the same in all browser reagarding its scope;
But as far as i can tell the current implementation of Request.js
allowes you access the global scope, no matter what browser is used.
Otherwise it wouldn't work at all.

Greetings,
Tim

Onno schrieb:
> Hi,
>
> i encountered a strange behaviour in RAP using the Internet Explorer. I
> use the JSWriter to deliver additional qooxdoo classes and some other JS
> code to the client, which may be dynamically added at runtime.
>
> It seems like the devlired code is executed in the global scope in
> Chrome and Firefox, but not in the IE. This then leads to different
> behaviour which is hard to deal with.
>
> So my question is: Is this considered in newer versions of RAP or should
> i file a bug or am i doing something wrong?
>
>
> Some details to the problem:
> In Request.js, the code is executed with "window.eval(...)". This
> operation is handled different in all major browsers. See for example
> http://piecesofrakesh.blogspot.com/2008/10/understanding-eva l-scope-spoiler-its.html
>
> To solve the problem in my case, i changed window.eval(...) to
> if (window.execScript) {
> window.execScript(text); // eval in global scope for IE
> } else { window.eval(text);
> }
>
> But I'm not sure right now, if this has further implications.
>
> Regards,
> Onno Hensgen
Re: Request.js - eval not in global scope for IE [message #522223 is a reply to message #521940] Sun, 21 March 2010 13:38 Go to previous messageGo to next message
Onno  is currently offline Onno Friend
Messages: 7
Registered: September 2009
Junior Member
Hi Tim,

my scenario is a bit complicated, but the essential part not working is the following:

I declare a global var in javascript and deliver the code to the client with the JSWriter. The code gets evaled, so the var should be in global scope now.

Later, i deliver another piece of code to the client, which refers to this defined global var. Now, i get the error that the var is not defined in IE, but in Firefox and Chrome this works fine.

I also tested this with pasting 'javascript:alert(var_name)' in the url bar. This also leads to an undefined error (only in IE).
With my posted solution, this works fine.

You can also observe this behaviour in another scenario:

In the JSWriter class, the method "ensureWidgetManager()" writes the js-code in the response, which sets the global var "wm" to the WidgetManager singleton.
But there is a check in the code ("currentPhaseIsRender()"), which prevents this, if the JSWriter is called in another phase than the render phase.

So if you now use the JSWriter in e.g. the process phase, every operation which relies on the WidgetManager fails and leads to an error, which says that "wm" is not defined.

This again happens only in the IE. In Firefox, the assignment of the WidgetManager singleton to the global var "wm" really takes place in the global scope, therefore it's still present - even if the assignment is skipped because of the phase-check, i mentioned before.


So why does RAP still work in the IE in common situations? I think, that's because the qx code is deliverd to the client with the help of a script tag up front, so all the qx stuff is available in global scope and can be accessed when ever it's needed. And in normal cases, it's not neccessary to add anything to the global scope afterwards (or can be done by adding script tags). As normal manipulations of the client gui take place in the render phase, the WidgetManager is assigned as first statement in the delivered code, so everythings fine - except you do something unusual.

I'm curious if you agree with me or if i'm missing something.

Regards
Onno

[Updated on: Sun, 21 March 2010 13:40]

Report message to a moderator

Re: Request.js - eval not in global scope for IE [message #522313 is a reply to message #522223] Mon, 22 March 2010 04:48 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim BuschtoensFriend
Messages: 396
Registered: July 2009
Senior Member
Hello again.

The reason why "wm" exists only in some browser after eval has been
executed, is because it is defined using "var"; This should create a
local variable instead of a global one, but as you discovered yourself,
eval does not behave the same in every browser. Example:

Execute this

function foo(){ window.eval( "var bar = 1;") };foo();alert(bar);

in FF and IE, and you will get different results.

However, if you don't use "var" to create a variable, it will in any
case be global:

function foo(){ window.eval( "bar = 1;") };foo();alert(bar);

So if you want to define a global variable using the JSWriter, don't use
"var foo = " but only "foo = ". If you don't use "var", or your problem
still persists anyway, let me know!

Greetings,
Tim
Re: Request.js - eval not in global scope for IE [message #523400 is a reply to message #521940] Fri, 26 March 2010 10:23 Go to previous messageGo to next message
Onno  is currently offline Onno Friend
Messages: 7
Registered: September 2009
Junior Member
Hi Tim,

thanks for your explanations. My custom JS code is working now after i defined the global variables without the keyword var.

But the problem with "wm" still exists, because it's defined with the keyword "var" as you said. Like i described in my previous post, the WidgetManager instance is only assigned to the "wm" var in the render phase. So actions, which rely on the WidgetManager outside the render phase, fail in the IE.

So perhabs the assignment should be changed, not using "var", or the check "currentPhaseIsRender" in the JSWriter should be removed / changed (which seems to be a workaround anyway - at least the comment in the code says so). Or as a temporary solution, i could make the "wm" assignment myself with the JSWriter.

Another question:
Do you know the reason why the global JSON object is not available in IE8 in RAP applications? It's native to the IE8 and is present if i check in other webpages.

Greetings,
Onno
Re: Request.js - eval not in global scope for IE [message #523769 is a reply to message #523400] Mon, 29 March 2010 09:12 Go to previous message
Tim Buschtoens is currently offline Tim BuschtoensFriend
Messages: 396
Registered: July 2009
Senior Member
Hi.

> thanks for your explanations. My custom JS code is working now after i
> defined the global variables without the keyword var.

Good to hear.

> But the problem with "wm" still exists, because it's defined with the
> keyword "var" as you said. Like i described in my previous post, the
> WidgetManager instance is only assigned to the "wm" var in the render
> phase. So actions, which rely on the WidgetManager outside the render
> phase, fail in the IE.

The JSWriter is not supposed to be used outside the render phase. There
should also be no reason to do so. Some more info on the different
phases can be found in the RAP Developer Guide > "Advanced Topics" >
"Custom Widget".

> Another question:
> Do you know the reason why the global JSON object is not available in
> IE8 in RAP applications? It's native to the IE8 and is present if i
> check in other webpages.

Probably because RAP-Applications set IE to Quirks mode.

Greetings,
Tim
Previous Topic:page.showEditor( Editor.ID) & page.hideEditor(Editor.ID)
Next Topic:JPA EntityManager
Goto Forum:
  


Current Time: Wed Dec 01 03:36:29 GMT 2021

Powered by FUDForum. Page generated in 0.02880 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top