RESOLVED FIXED 11399
window.eval runs in the global scope of the calling window
https://bugs.webkit.org/show_bug.cgi?id=11399
Summary window.eval runs in the global scope of the calling window
webkit
Reported 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.
Attachments
test case for eval scope (452 bytes, text/html)
2007-05-22 16:55 PDT, Geoffrey Garen
no flags
Mark Rowe (bdash)
Comment 1 2006-10-25 20:05:05 PDT
Confirmed in 418.9 and ToT.
Alexey Proskuryakov
Comment 2 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.
webkit
Comment 3 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.
Mark Rowe (bdash)
Comment 4 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.
webkit
Comment 5 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.
Mark Rowe (bdash)
Comment 6 2007-01-16 19:02:06 PST
Geoffrey Garen
Comment 7 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.
David Kilzer (:ddkilzer)
Comment 8 2007-07-11 21:34:12 PDT
Antti Koivisto
Comment 9 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.
Timothy Hatcher
Comment 10 2008-04-07 09:44:25 PDT
Removed the wworkaround we hand in the Inspector in r31683.
Note You need to log in before you can comment on or make changes to this bug.