Skip to content

Commit

Permalink
Incremental step toward having separate global/window/scope for the t…
Browse files Browse the repository at this point in the history
…op-level

document and any included frames/iframes.  Loading of the document within
the (i)frame now occurs when the FRAME/IFRAME tag is parsed (like scripts)
rather than waiting until the contentDocument property is referenced.  A
new window object is created and the (i)frame's content is loaded by
window.location="" just like a top-level document, rather than the
frame-specific parser invokation we used to have.
  • Loading branch information
gleneivey committed Jul 13, 2009
1 parent 3daaf5e commit 110e978
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 81 deletions.
64 changes: 39 additions & 25 deletions dist/env.js
Expand Up @@ -5,15 +5,18 @@
*/


// The Window Object
var __this__ = this;
this.__defineGetter__('window', function(){
return __this__;
});
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){

// The Window Object
var __this__ = $w;
$w.__defineGetter__('window', function(){
return __this__;
});

try{
(function($w, $env){
/*
/*
* window.js
* - this file will be wrapped in a closure providing the window object as $w
*/
Expand Down Expand Up @@ -3748,10 +3751,26 @@ function __parseLoop__(impl, doc, p) {

else if(iEvt == XMLP._ELM_E) { // End-Element Event
//handle script tag
if(iNodeParent.nodeName.toLowerCase() == 'script'){
if (iNodeParent.nodeName.toLowerCase() == 'script'){
p.replaceEntities = true;
$env.loadLocalScript(iNodeParent, p);
}
else if (iNodeParent.nodeName.toLowerCase() == 'frame' ||
iNodeParent.nodeName.toLowerCase() == 'iframe' ){
if (iNodeParent.src.length > 0){
$debug("getting content document for (i)frame from " +
iNodeParent.src);
var frameWindow = {}; // temporary, will replace with a new global
try {
_$envjs$makeObjectIntoWindow$_(frameWindow, $env);
frameWindow.location = iNodeParent.src;
iNodeParent._content = frameWindow;
} catch(e){
$error("failed to load frame content: from " + iNodeParent.src, e);
}
}
}

iNodeParent = iNodeParent.parentNode; // ascend one level of the DOM Tree

}
Expand Down Expand Up @@ -5873,19 +5892,7 @@ __extend__(HTMLFrameElement.prototype, {
this.setAttribute('src', value);
},
get contentDocument(){
$debug("getting content document for (i)frame");
if(!this._content){
this._content = new HTMLDocument($implementation);
if(this.src.length > 0){
$info("Loading frame content from " + this.src);
try{
this._content.load(this.src);
}catch(e){
$error("failed to load frame content: from " + this.src, e);
}
}
}
return this._content;
return this._content.document;
}
});

Expand Down Expand Up @@ -9888,8 +9895,15 @@ try{
* outro.js
*/

})(window, Envjs);

}catch(e){
Envjs.error("ERROR LOADING ENV : " + e + "\nLINE SOURCE:\n" + Envjs.lineSource(e));
}; // close function definition begun in 'intro.js'


// turn "original" JS interpreter global object into the
// "root" window object
_$envjs$makeObjectIntoWindow$_(this, Envjs);

} catch(e){
Envjs.error("ERROR LOADING ENV : " + e + "\nLINE SOURCE:\n" +
Envjs.lineSource(e));
}
68 changes: 41 additions & 27 deletions dist/env.rhino.js
Expand Up @@ -36,9 +36,9 @@ var Envjs = function(){
$env.error = function(){};

//uncomment these if you want to get some internal log statementes
/*$env.debug = function(msg){
/**/$env.debug = function(msg){
$env.log(msg,"DEBUG");
};*/
};
$env.info = function(msg){
$env.log(msg,"INFO");
};
Expand Down Expand Up @@ -442,15 +442,18 @@ var Envjs = function(){
*/


// The Window Object
var __this__ = this;
this.__defineGetter__('window', function(){
return __this__;
});
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){

try{
(function($w, $env){
/*
// The Window Object
var __this__ = $w;
$w.__defineGetter__('window', function(){
return __this__;
});

/*
* window.js
* - this file will be wrapped in a closure providing the window object as $w
*/
Expand Down Expand Up @@ -4185,10 +4188,26 @@ function __parseLoop__(impl, doc, p) {

else if(iEvt == XMLP._ELM_E) { // End-Element Event
//handle script tag
if(iNodeParent.nodeName.toLowerCase() == 'script'){
if (iNodeParent.nodeName.toLowerCase() == 'script'){
p.replaceEntities = true;
$env.loadLocalScript(iNodeParent, p);
}
else if (iNodeParent.nodeName.toLowerCase() == 'frame' ||
iNodeParent.nodeName.toLowerCase() == 'iframe' ){
if (iNodeParent.src.length > 0){
$debug("getting content document for (i)frame from " +
iNodeParent.src);
var frameWindow = {}; // temporary, will replace with a new global
try {
_$envjs$makeObjectIntoWindow$_(frameWindow, $env);
frameWindow.location = iNodeParent.src;
iNodeParent._content = frameWindow;
} catch(e){
$error("failed to load frame content: from " + iNodeParent.src, e);
}
}
}

iNodeParent = iNodeParent.parentNode; // ascend one level of the DOM Tree

}
Expand Down Expand Up @@ -6310,19 +6329,7 @@ __extend__(HTMLFrameElement.prototype, {
this.setAttribute('src', value);
},
get contentDocument(){
$debug("getting content document for (i)frame");
if(!this._content){
this._content = new HTMLDocument($implementation);
if(this.src.length > 0){
$info("Loading frame content from " + this.src);
try{
this._content.load(this.src);
}catch(e){
$error("failed to load frame content: from " + this.src, e);
}
}
}
return this._content;
return this._content.document;
}
});

Expand Down Expand Up @@ -10325,8 +10332,15 @@ try{
* outro.js
*/

})(window, Envjs);

}catch(e){
Envjs.error("ERROR LOADING ENV : " + e + "\nLINE SOURCE:\n" + Envjs.lineSource(e));
}; // close function definition begun in 'intro.js'


// turn "original" JS interpreter global object into the
// "root" window object
_$envjs$makeObjectIntoWindow$_(this, Envjs);

} catch(e){
Envjs.error("ERROR LOADING ENV : " + e + "\nLINE SOURCE:\n" +
Envjs.lineSource(e));
}
18 changes: 17 additions & 1 deletion src/dom/implementation.js
Expand Up @@ -238,10 +238,26 @@ function __parseLoop__(impl, doc, p) {

else if(iEvt == XMLP._ELM_E) { // End-Element Event
//handle script tag
if(iNodeParent.nodeName.toLowerCase() == 'script'){
if (iNodeParent.nodeName.toLowerCase() == 'script'){
p.replaceEntities = true;
$env.loadLocalScript(iNodeParent, p);
}
else if (iNodeParent.nodeName.toLowerCase() == 'frame' ||
iNodeParent.nodeName.toLowerCase() == 'iframe' ){
if (iNodeParent.src.length > 0){
$debug("getting content document for (i)frame from " +
iNodeParent.src);
var frameWindow = {}; // temporary, will replace with a new global
try {
_$envjs$makeObjectIntoWindow$_(frameWindow, $env);
frameWindow.location = iNodeParent.src;
iNodeParent._content = frameWindow;
} catch(e){
$error("failed to load frame content: from " + iNodeParent.src, e);
}
}
}

iNodeParent = iNodeParent.parentNode; // ascend one level of the DOM Tree

}
Expand Down
14 changes: 1 addition & 13 deletions src/html/frame.js
Expand Up @@ -57,19 +57,7 @@ __extend__(HTMLFrameElement.prototype, {
this.setAttribute('src', value);
},
get contentDocument(){
$debug("getting content document for (i)frame");
if(!this._content){
this._content = new HTMLDocument($implementation);
if(this.src.length > 0){
$info("Loading frame content from " + this.src);
try{
this._content.load(this.src);
}catch(e){
$error("failed to load frame content: from " + this.src, e);
}
}
}
return this._content;
return this._content.document;
}
});

Expand Down
18 changes: 10 additions & 8 deletions src/intro.js
Expand Up @@ -5,12 +5,14 @@
*/


// The Window Object
var __this__ = this;
this.__defineGetter__('window', function(){
return __this__;
});
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){

// The Window Object
var __this__ = $w;
$w.__defineGetter__('window', function(){
return __this__;
});

try{
(function($w, $env){

13 changes: 10 additions & 3 deletions src/outro.js
Expand Up @@ -2,8 +2,15 @@
* outro.js
*/

})(window, Envjs);

}catch(e){
Envjs.error("ERROR LOADING ENV : " + e + "\nLINE SOURCE:\n" + Envjs.lineSource(e));
}; // close function definition begun in 'intro.js'


// turn "original" JS interpreter global object into the
// "root" window object
_$envjs$makeObjectIntoWindow$_(this, Envjs);

} catch(e){
Envjs.error("ERROR LOADING ENV : " + e + "\nLINE SOURCE:\n" +
Envjs.lineSource(e));
}
4 changes: 0 additions & 4 deletions test/test.js
Expand Up @@ -16,10 +16,6 @@ load("dist/env.rhino.js");
window.onload = function(){
print("Handling onload for test.js");

// env.js doesn't load IFRAMEs until their content is referenced, so...
document.getElementById('loadediframe').contentDocument;
print("Forced loading of iframe in test page.");

// Load the test runner
load("test/testrunner.js");
print("Loaded test runner.");
Expand Down

0 comments on commit 110e978

Please sign in to comment.