Skip to content

Commit

Permalink
Implemented support for window.top property, matching test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
gleneivey committed Jul 14, 2009
1 parent c620c9e commit 91ab5a2
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 16 deletions.
10 changes: 6 additions & 4 deletions dist/env.js
Expand Up @@ -8,7 +8,8 @@
try {
// this goes into the global namespace, but less likely to collide with
// client JS code than methods in Rhino shell (load, print, etc.)
_$envjs$makeObjectIntoWindow$_ = function($w, $env, $parentWindow){
_$envjs$makeObjectIntoWindow$_ = function($w, $env,
$parentWindow, $initTop){

// The Window Object
var __this__ = $w;
Expand Down Expand Up @@ -100,7 +101,7 @@ var $status = '';
// a read-only reference to the top-level window that contains this window. If this
// window is a top-level window it is simply a refernce to itself. If this window
// is a frame, the top property refers to the top-level window that contains the frame.
var $top;
var $top = $initTop;

// the window property is identical to the self property and to this obj
var $window = $w;
Expand Down Expand Up @@ -3764,7 +3765,8 @@ function __parseLoop__(impl, doc, p) {
iNodeParent.src);
var frameWindow = {}; // temporary, will replace with a new global
try {
_$envjs$makeObjectIntoWindow$_(frameWindow, $env, window);
_$envjs$makeObjectIntoWindow$_(frameWindow, $env,
window, window.top);
frameWindow.location = iNodeParent.src;
iNodeParent._content = frameWindow;
} catch(e){
Expand Down Expand Up @@ -9931,7 +9933,7 @@ try{

// turn "original" JS interpreter global object into the
// "root" window object; third param value for new window's "parent"
_$envjs$makeObjectIntoWindow$_(this, Envjs, null);
_$envjs$makeObjectIntoWindow$_(this, Envjs, null, this);

} catch(e){
Envjs.error("ERROR LOADING ENV : " + e + "\nLINE SOURCE:\n" +
Expand Down
10 changes: 6 additions & 4 deletions dist/env.rhino.js
Expand Up @@ -445,7 +445,8 @@ var Envjs = function(){
try {
// this goes into the global namespace, but less likely to collide with
// client JS code than methods in Rhino shell (load, print, etc.)
_$envjs$makeObjectIntoWindow$_ = function($w, $env, $parentWindow){
_$envjs$makeObjectIntoWindow$_ = function($w, $env,
$parentWindow, $initTop){

// The Window Object
var __this__ = $w;
Expand Down Expand Up @@ -537,7 +538,7 @@ var $status = '';
// a read-only reference to the top-level window that contains this window. If this
// window is a top-level window it is simply a refernce to itself. If this window
// is a frame, the top property refers to the top-level window that contains the frame.
var $top;
var $top = $initTop;

// the window property is identical to the self property and to this obj
var $window = $w;
Expand Down Expand Up @@ -4201,7 +4202,8 @@ function __parseLoop__(impl, doc, p) {
iNodeParent.src);
var frameWindow = {}; // temporary, will replace with a new global
try {
_$envjs$makeObjectIntoWindow$_(frameWindow, $env, window);
_$envjs$makeObjectIntoWindow$_(frameWindow, $env,
window, window.top);
frameWindow.location = iNodeParent.src;
iNodeParent._content = frameWindow;
} catch(e){
Expand Down Expand Up @@ -10368,7 +10370,7 @@ try{

// turn "original" JS interpreter global object into the
// "root" window object; third param value for new window's "parent"
_$envjs$makeObjectIntoWindow$_(this, Envjs, null);
_$envjs$makeObjectIntoWindow$_(this, Envjs, null, this);

} catch(e){
Envjs.error("ERROR LOADING ENV : " + e + "\nLINE SOURCE:\n" +
Expand Down
3 changes: 2 additions & 1 deletion src/dom/implementation.js
Expand Up @@ -250,7 +250,8 @@ function __parseLoop__(impl, doc, p) {
iNodeParent.src);
var frameWindow = {}; // temporary, will replace with a new global
try {
_$envjs$makeObjectIntoWindow$_(frameWindow, $env, window);
_$envjs$makeObjectIntoWindow$_(frameWindow, $env,
window, window.top);
frameWindow.location = iNodeParent.src;
iNodeParent._content = frameWindow;
} catch(e){
Expand Down
3 changes: 2 additions & 1 deletion src/intro.js
Expand Up @@ -8,7 +8,8 @@
try {
// this goes into the global namespace, but less likely to collide with
// client JS code than methods in Rhino shell (load, print, etc.)
_$envjs$makeObjectIntoWindow$_ = function($w, $env, $parentWindow){
_$envjs$makeObjectIntoWindow$_ = function($w, $env,
$parentWindow, $initTop){

// The Window Object
var __this__ = $w;
Expand Down
2 changes: 1 addition & 1 deletion src/outro.js
Expand Up @@ -8,7 +8,7 @@

// turn "original" JS interpreter global object into the
// "root" window object; third param value for new window's "parent"
_$envjs$makeObjectIntoWindow$_(this, Envjs, null);
_$envjs$makeObjectIntoWindow$_(this, Envjs, null, this);

} catch(e){
Envjs.error("ERROR LOADING ENV : " + e + "\nLINE SOURCE:\n" +
Expand Down
2 changes: 1 addition & 1 deletion src/window/window.js
Expand Up @@ -82,7 +82,7 @@ var $status = '';
// a read-only reference to the top-level window that contains this window. If this
// window is a top-level window it is simply a refernce to itself. If this window
// is a frame, the top property refers to the top-level window that contains the frame.
var $top;
var $top = $initTop;

// the window property is identical to the self property and to this obj
var $window = $w;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/dom.js
@@ -1,7 +1,7 @@
// dependencies for the tests
$w = { }
$env = { debug: function() {} }
$parentWindow = null;
$parentWindow = $initTop = null;
load("src/window/window.js", "src/dom/node.js");


Expand Down
8 changes: 6 additions & 2 deletions test/unit/frame.js
Expand Up @@ -12,7 +12,7 @@ module("frame");

// all tests to next comment rely on content of ../html/iframe.html
test("IFRAMEs load with accessible content", function() {
expect(4);
expect(5);

var iframe = document.getElementById('loadediframe');
try{ok (iframe.src == "html/iframe.html",
Expand All @@ -32,7 +32,11 @@ test("IFRAMEs load with accessible content", function() {
}catch(e){print(e);}

try{ok (idoc.parentWindow.parent == window,
"can follow chain from iframe's doc to containing window");
"Can follow chain from iframe's doc to containing window");
}catch(e){print(e);}

try{ok (iframe.contentWindow.top == window,
"'.top' from iframe does point to top window");
}catch(e){print(e);}
});

Expand Down
2 changes: 1 addition & 1 deletion test/unit/parser.js
@@ -1,7 +1,7 @@
// environment mocking for parser
$w = { }
$env = { debug: function() {} }
$parentWindow = null;
$parentWindow = $initTop = null;

load("src/window/window.js", "src/dom/parser.js", "src/dom/entities.js");

Expand Down
15 changes: 15 additions & 0 deletions test/unit/window.js
Expand Up @@ -24,3 +24,18 @@ test("Window Global Scope Equivalence", function() {
"'window' provides Math.* when referenced implicitly/global");
}catch(e){print(e);}
});


test("References to the window object", function() {
expect(3);

try{ ok(window == window.window,
"'window' is property of the window object");
}catch(e){print(e);}
try{ ok(window == self,
"'self' refers to the current window");
}catch(e){print(e);}
try{ ok(window == window.top,
"for top-level document 'window.top' refers to itself");
}catch(e){print(e);}
});

0 comments on commit 91ab5a2

Please sign in to comment.