Skip to content

Commit

Permalink
WARNING: build broken in this commit. Iframes now have their own
Browse files Browse the repository at this point in the history
separate global-window objects and execution environments.  Unfortunately,
something is broken in the "timer" group of tests.  Normally, I wouldn't
submit these changes with a broken regression test, but there are so
many changes involved in the iframe fix that I wanted a clean slate
that I could revert to before I start pursuing the problem I've introduced.
  • Loading branch information
gleneivey committed Jul 21, 2009
1 parent 44d99a9 commit d8f9ab4
Show file tree
Hide file tree
Showing 13 changed files with 513 additions and 196 deletions.
139 changes: 114 additions & 25 deletions dist/env.js
Expand Up @@ -8,8 +8,9 @@
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, $initTop){
this.__proto__._$envjs$makeObjectIntoWindow$_ = function($w, $env,
$parentWindow,
$initTop){

// The Window Object
var __this__ = $w;
Expand Down Expand Up @@ -3763,27 +3764,60 @@ function __parseLoop__(impl, doc, p) {
if (iNodeParent.src.length > 0){
$debug("getting content document for (i)frame from " +
iNodeParent.src);
var frameWindow = createAGlobalObject(); //EnvjsRhinoGlobal.java


// create a new global/window object, such that its methods and
// objects are defined within the scope of the new global
try {
_$envjs$globalObjectStack$_.push(
getThisScopesGlobalObject()); //EnvjsRhinoGlobal.java
setThisScopesGlobalObject(frameWindow); //EnvjsRhinoGlobal.java
{ // **** CAREFUL: use no global references in this block ****
_$envjs$makeObjectIntoWindow$_(frameWindow, $env,
window, window.top);
iNodeParent._content = frameWindow;
frameWindow.location = iNodeParent.src;
}
setThisScopesGlobalObject( //EnvjsRhinoGlobal.java
_$envjs$globalObjectStack$_.pop());

/* this code semi-duplicated in html/frame.js -- sorry */
// a blank object, pre-configured to inherit from original global
var frameWindow = createAGlobalObject(); // EnvjsRhinoSupraGlobal

// define local variables with content of things that are
// in current global/window, because when the following
// function executes we'll have a new/blank
// global/window and won't be able to get at them....
var localCopy_mkWinFn = _$envjs$makeObjectIntoWindow$_;
var localCopy_$env = $env;
var localCopy_window = window;

// a local function gives us something whose scope is easy to change
var mkAndLoadNewWindow = function(){
localCopy_mkWinFn(frameWindow, localCopy_$env,
localCopy_window, localCopy_window.top);
iNodeParent._content = frameWindow;
frameWindow.location = iNodeParent.src;
}



// change scope of window object creation functions, so that
// functions/code they create will be scoped to new window object
// *FunctionObjectsScope() from EnvjsRhinoSupraGlobal.java
var oldMkWinScope = getFunctionObjectsScope(localCopy_mkWinFn);
var oldLoadScope = getFunctionObjectsScope(load);
var oldLoadScriptScope = getFunctionObjectsScope(
$env.loadLocalScript);

setFunctionObjectsScope(mkAndLoadNewWindow, frameWindow);
setFunctionObjectsScope(localCopy_mkWinFn, frameWindow);
setFunctionObjectsScope(load, frameWindow);
setFunctionObjectsScope($env.loadLocalScript, frameWindow);

mkAndLoadNewWindow();

// now restore the scope
setFunctionObjectsScope(localCopy_mkWinFn, oldMkWinScope);
setFunctionObjectsScope(load, oldLoadScope);
setFunctionObjectsScope($env.loadLocalScript, oldLoadScriptScope);
} catch(e){
$error("failed to load frame content: from " + iNodeParent.src, e);
}
}
}

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

}

else if(iEvt == XMLP._ELM_EMP) { // Empty Element Event
Expand Down Expand Up @@ -4171,6 +4205,14 @@ __extend__(DOMDocument.prototype, {
}
// populate Document with Parsed Nodes
try {
// make sure thid document object is empty before we try to load ...
this.childNodes = new DOMNodeList(this, this);
this.firstChild = null;
this.lastChild = null;
this.attributes = new DOMNamedNodeMap(this, this);
this._namespaces = new DOMNamespaceNodeMap(this, this);
this._readonly = false;

__parseLoop__(this.implementation, this, parser);
//doc = html2dom(xmlStr+"", doc);
//$log("\nhtml2xml\n" + doc.xml);
Expand Down Expand Up @@ -5911,18 +5953,65 @@ __extend__(HTMLFrameElement.prototype, {
this.setAttribute('src', value);

if (value.length > 0){
if (!this._content){
var frameWindow = {};
try {
_$envjs$makeObjectIntoWindow$_(frameWindow, $env, window);
this._content = frameWindow;
try {

/* this code semi-duplicated in dom/implementation.js -- sorry */
var frameWindow;
var makingNewWinFlag = !(this._content);
if (makingNewWinFlag)
// a blank object, inherits from original global
// v EnvjsRhinoSupraGlobal.java
frameWindow = createAGlobalObject();
else
frameWindow = this._content;


// define local variables with content of things that are
// in current global/window, because when the following
// function executes we'll have a new/blank
// global/window and won't be able to get at them....
var localCopy_mkWinFn = _$envjs$makeObjectIntoWindow$_;
var localCopy_$env = $env;
var localCopy_parent = window.parent;
var localCopy_top = window.top;

// a local function gives us something whose scope
// is easy to change
var mkAndLoadNewWindow = function(){
if (makingNewWinFlag){
localCopy_mkWinFn(frameWindow, localCopy_$env,
localCopy_parent, localCopy_top);
}

frameWindow.location = value;
} catch(e){
$error("failed to load frame content: from " + value, e);
}
}

this._content.location = value;

// change scope of window object creation
// functions, so that functions/code they create
// will be scoped to new window object
// *FunctionObjectsScope() from EnvjsRhinoSupraGlobal.java
var oldLoadScope = getFunctionObjectsScope(load);
var oldLoadScriptScope = getFunctionObjectsScope(
$env.loadLocalScript);
var oldMkWinScope = getFunctionObjectsScope(
localCopy_mkWinFn);

setFunctionObjectsScope(localCopy_mkWinFn, frameWindow);
setFunctionObjectsScope(mkAndLoadNewWindow, frameWindow);
setFunctionObjectsScope(load, frameWindow);
setFunctionObjectsScope($env.loadLocalScript, frameWindow);

mkAndLoadNewWindow();
this._content = frameWindow;

// now restore the scope
setFunctionObjectsScope(load, oldLoadScope);
setFunctionObjectsScope($env.loadLocalScript,
oldLoadScriptScope);
} catch(e){
$error("failed to load frame content: from " + value, e);
}
}
},
get contentDocument(){
Expand Down Expand Up @@ -9411,7 +9500,7 @@ window.$profiler.stats = function(raw){
};
};

if(Envjs.profile){
if($env.profile){
/**
* CSS2Properties
*/
Expand Down
139 changes: 114 additions & 25 deletions dist/env.rhino.js
Expand Up @@ -445,8 +445,9 @@ 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, $initTop){
this.__proto__._$envjs$makeObjectIntoWindow$_ = function($w, $env,
$parentWindow,
$initTop){

// The Window Object
var __this__ = $w;
Expand Down Expand Up @@ -4200,27 +4201,60 @@ function __parseLoop__(impl, doc, p) {
if (iNodeParent.src.length > 0){
$debug("getting content document for (i)frame from " +
iNodeParent.src);
var frameWindow = createAGlobalObject(); //EnvjsRhinoGlobal.java


// create a new global/window object, such that its methods and
// objects are defined within the scope of the new global
try {
_$envjs$globalObjectStack$_.push(
getThisScopesGlobalObject()); //EnvjsRhinoGlobal.java
setThisScopesGlobalObject(frameWindow); //EnvjsRhinoGlobal.java
{ // **** CAREFUL: use no global references in this block ****
_$envjs$makeObjectIntoWindow$_(frameWindow, $env,
window, window.top);
iNodeParent._content = frameWindow;
frameWindow.location = iNodeParent.src;
}
setThisScopesGlobalObject( //EnvjsRhinoGlobal.java
_$envjs$globalObjectStack$_.pop());

/* this code semi-duplicated in html/frame.js -- sorry */
// a blank object, pre-configured to inherit from original global
var frameWindow = createAGlobalObject(); // EnvjsRhinoSupraGlobal

// define local variables with content of things that are
// in current global/window, because when the following
// function executes we'll have a new/blank
// global/window and won't be able to get at them....
var localCopy_mkWinFn = _$envjs$makeObjectIntoWindow$_;
var localCopy_$env = $env;
var localCopy_window = window;

// a local function gives us something whose scope is easy to change
var mkAndLoadNewWindow = function(){
localCopy_mkWinFn(frameWindow, localCopy_$env,
localCopy_window, localCopy_window.top);
iNodeParent._content = frameWindow;
frameWindow.location = iNodeParent.src;
}



// change scope of window object creation functions, so that
// functions/code they create will be scoped to new window object
// *FunctionObjectsScope() from EnvjsRhinoSupraGlobal.java
var oldMkWinScope = getFunctionObjectsScope(localCopy_mkWinFn);
var oldLoadScope = getFunctionObjectsScope(load);
var oldLoadScriptScope = getFunctionObjectsScope(
$env.loadLocalScript);

setFunctionObjectsScope(mkAndLoadNewWindow, frameWindow);
setFunctionObjectsScope(localCopy_mkWinFn, frameWindow);
setFunctionObjectsScope(load, frameWindow);
setFunctionObjectsScope($env.loadLocalScript, frameWindow);

mkAndLoadNewWindow();

// now restore the scope
setFunctionObjectsScope(localCopy_mkWinFn, oldMkWinScope);
setFunctionObjectsScope(load, oldLoadScope);
setFunctionObjectsScope($env.loadLocalScript, oldLoadScriptScope);
} catch(e){
$error("failed to load frame content: from " + iNodeParent.src, e);
}
}
}

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

}

else if(iEvt == XMLP._ELM_EMP) { // Empty Element Event
Expand Down Expand Up @@ -4608,6 +4642,14 @@ __extend__(DOMDocument.prototype, {
}
// populate Document with Parsed Nodes
try {
// make sure thid document object is empty before we try to load ...
this.childNodes = new DOMNodeList(this, this);
this.firstChild = null;
this.lastChild = null;
this.attributes = new DOMNamedNodeMap(this, this);
this._namespaces = new DOMNamespaceNodeMap(this, this);
this._readonly = false;

__parseLoop__(this.implementation, this, parser);
//doc = html2dom(xmlStr+"", doc);
//$log("\nhtml2xml\n" + doc.xml);
Expand Down Expand Up @@ -6348,18 +6390,65 @@ __extend__(HTMLFrameElement.prototype, {
this.setAttribute('src', value);

if (value.length > 0){
if (!this._content){
var frameWindow = {};
try {
_$envjs$makeObjectIntoWindow$_(frameWindow, $env, window);
this._content = frameWindow;
try {

/* this code semi-duplicated in dom/implementation.js -- sorry */
var frameWindow;
var makingNewWinFlag = !(this._content);
if (makingNewWinFlag)
// a blank object, inherits from original global
// v EnvjsRhinoSupraGlobal.java
frameWindow = createAGlobalObject();
else
frameWindow = this._content;


// define local variables with content of things that are
// in current global/window, because when the following
// function executes we'll have a new/blank
// global/window and won't be able to get at them....
var localCopy_mkWinFn = _$envjs$makeObjectIntoWindow$_;
var localCopy_$env = $env;
var localCopy_parent = window.parent;
var localCopy_top = window.top;

// a local function gives us something whose scope
// is easy to change
var mkAndLoadNewWindow = function(){
if (makingNewWinFlag){
localCopy_mkWinFn(frameWindow, localCopy_$env,
localCopy_parent, localCopy_top);
}

frameWindow.location = value;
} catch(e){
$error("failed to load frame content: from " + value, e);
}
}

this._content.location = value;

// change scope of window object creation
// functions, so that functions/code they create
// will be scoped to new window object
// *FunctionObjectsScope() from EnvjsRhinoSupraGlobal.java
var oldLoadScope = getFunctionObjectsScope(load);
var oldLoadScriptScope = getFunctionObjectsScope(
$env.loadLocalScript);
var oldMkWinScope = getFunctionObjectsScope(
localCopy_mkWinFn);

setFunctionObjectsScope(localCopy_mkWinFn, frameWindow);
setFunctionObjectsScope(mkAndLoadNewWindow, frameWindow);
setFunctionObjectsScope(load, frameWindow);
setFunctionObjectsScope($env.loadLocalScript, frameWindow);

mkAndLoadNewWindow();
this._content = frameWindow;

// now restore the scope
setFunctionObjectsScope(load, oldLoadScope);
setFunctionObjectsScope($env.loadLocalScript,
oldLoadScriptScope);
} catch(e){
$error("failed to load frame content: from " + value, e);
}
}
},
get contentDocument(){
Expand Down Expand Up @@ -9848,7 +9937,7 @@ window.$profiler.stats = function(raw){
};
};

if(Envjs.profile){
if($env.profile){
/**
* CSS2Properties
*/
Expand Down
Binary file modified rhino/js.jar
Binary file not shown.
Binary file modified rhino/mainForEnvjs.jar
Binary file not shown.

0 comments on commit d8f9ab4

Please sign in to comment.