Bug 11399 - window.eval runs in the global scope of the calling window
Summary: window.eval runs in the global scope of the calling window
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 419.x
Hardware: Macintosh PowerPC OS X 10.4
: P2 Normal
Assignee: Nobody
URL: http://www.fredck.com/bugs/safari/win...
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2006-10-24 06:47 PDT by Frederico Caldeira Knabben
Modified: 2008-04-07 09:44 PDT (History)
3 users (show)

See Also:


Attachments
test case for eval scope (452 bytes, text/html)
2007-05-22 16:55 PDT, Geoffrey Garen
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Frederico Caldeira Knabben 2006-10-24 06:47:12 PDT
If you call the following code in a window loaded inside an IFRAME:

    window.parent.eval( 'var MyObject = new Object();' )

... "MyObject" is created at the "window" global scope, not at "window.parent".

The URL points to a simple test case. It works well with IE, Firefox and Opera.

Any temporary workaround to evaluate a script in a specific window is welcome.
Comment 1 Mark Rowe (bdash) 2006-10-25 20:05:05 PDT
Confirmed in 418.9 and ToT.
Comment 2 Alexey Proskuryakov 2006-11-14 22:05:27 PST
(In reply to comment #0)
> Any temporary workaround to evaluate a script in a specific window is welcome.

Will document.write()'ing it there work?

May be related to bugs 3791, 7783.
Comment 3 Frederico Caldeira Knabben 2006-11-15 15:47:08 PST
document.write will not work because the parent document has already been loaded. So, when calling document.write, the document will be cleared and a new stream will be opened.
Comment 4 Mark Rowe (bdash) 2006-11-20 21:02:40 PST
A workaround that will work is to insert a script element via DOM manipulation.  See <http://bdash.net.nz/files/bug-11399-1.html> for an example of a document in an iframe evaluating a script in the context of its parent document.
Comment 5 Frederico Caldeira Knabben 2006-11-21 02:12:05 PST
Nice move Mark... your workaround worked like a charm. I was too concentrated on making eval working.

I'll be committing the changes I've made on FCKeditor today, so the next nightly (of FCKeditor) will finally load in Safari (420+) (See bug #9915). It will not work properly, but at least will load. Now we can continue debugging further.

Thanks for it.
Comment 6 Mark Rowe (bdash) 2007-01-16 19:02:06 PST
<rdar://problem/4928617>
Comment 7 Geoffrey Garen 2007-05-22 16:55:26 PDT
Created attachment 14669 [details]
test case for eval scope

Firefox, IE, Opera, and Safari all disagree about this.

IE has no eval method in inner windows.

Firefox uses the inner window as the front of the scope chain, the variable object, but not 'this'.

Opera uses the inner window as the front of the scope chain, the variable object, and 'this'.

Safari uses the outer window as the front of the scope chain and 'this', and a separate object that is not the inner window as the variable object.
Comment 8 David Kilzer (:ddkilzer) 2007-07-11 21:34:12 PDT
See also: http://bugs.webkit.org/show_bug.cgi?id=12912#c6

Comment 9 Antti Koivisto 2007-09-13 07:59:04 PDT
Fixed along with <rdar://problem/5445058>

Sending        JavaScriptCore/ChangeLog
Sending        JavaScriptCore/kjs/function.cpp
Sending        LayoutTests/ChangeLog
Sending        LayoutTests/fast/js/window-eval-context-expected.txt
Sending        LayoutTests/fast/js/window-eval-context.html
Transmitting file data .....
Committed revision 25535.
Comment 10 Timothy Hatcher 2008-04-07 09:44:25 PDT
Removed the wworkaround we hand in the Inspector in r31683.