From 3701d37135ab415940499d7016c1f7cd6bc66c74 Mon Sep 17 00:00:00 2001 From: "Glen E. Ivey" Date: Wed, 22 Jul 2009 07:21:56 -0700 Subject: [PATCH] Ha! All green. The content of iframe elements (and likely frames within frame sets, although that is untested) now have their own private JS global object and execution environment, though code in one window can access the DOM in others using the standard window properties correctly. As a side effect, a document object can now be correctly reloaded with new content, the document.parentWindow property will work in all contexts, and there are new Rhino-provided global functions to manipulate the scope chain of JS Function objects. --- dist/env.js | 36 ++++++++------ dist/env.rhino.js | 44 +++++++++++------- rhino/mainForEnvjs.jar | Bin 4079 -> 4191 bytes .../rhino/envjs/EnvjsRhinoSupraGlobal.java | 9 +++- src/dom/document.js | 5 +- src/dom/implementation.js | 5 +- src/html/document.js | 4 +- src/html/frame.js | 20 ++++---- src/window/document.js | 2 +- 9 files changed, 75 insertions(+), 50 deletions(-) diff --git a/dist/env.js b/dist/env.js index b34741bd..e86be688 100644 --- a/dist/env.js +++ b/dist/env.js @@ -3549,7 +3549,7 @@ __extend__(DOMImplementation.prototype,{ createDocument : function(nsuri, qname, doctype){ //TODO - this currently returns an empty doc //but needs to handle the args - return new HTMLDocument($implementation); + return new HTMLDocument($implementation, null); }, translateErrCode : function(code) { //convert DOMException Code to human readable error message; @@ -3795,6 +3795,8 @@ function __parseLoop__(impl, doc, p) { // 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 oldMalnwScope = getFunctionObjectsScope( + mkAndLoadNewWindow); var oldMkWinScope = getFunctionObjectsScope(localCopy_mkWinFn); var oldLoadScope = getFunctionObjectsScope(load); var oldLoadScriptScope = getFunctionObjectsScope( @@ -3808,6 +3810,7 @@ function __parseLoop__(impl, doc, p) { mkAndLoadNewWindow(); // now restore the scope + setFunctionObjectsScope(mkAndLoadNewWindow, oldMalnwScope); setFunctionObjectsScope(localCopy_mkWinFn, oldMkWinScope); setFunctionObjectsScope(load, oldLoadScope); setFunctionObjectsScope($env.loadLocalScript, oldLoadScriptScope); @@ -4153,7 +4156,7 @@ $implementation.errorChecking = false;$debug("Defining Document"); * @author Jon van Noort (jon@webarcana.com.au) * @param implementation : DOMImplementation - the creator Implementation */ -var DOMDocument = function(implementation) { +var DOMDocument = function(implementation, docParentWindow) { //$log("\tcreating dom document"); this.DOMNode = DOMNode; this.DOMNode(this); @@ -4161,7 +4164,7 @@ var DOMDocument = function(implementation) { this.doctype = null; // The Document Type Declaration (see DocumentType) associated with this document this.implementation = implementation; // The DOMImplementation object that handles this document. this._documentElement = null; // "private" variable providing the read-only document.documentElement property - this._parentWindow = null; // "private" variable providing the read-only document.parentWindow property + this._parentWindow = docParentWindow; // "private" variable providing the read-only document.parentWindow property this.nodeName = "#document"; this._id = 0; @@ -4227,7 +4230,6 @@ __extend__(DOMDocument.prototype, { }, load: function(url){ $debug("Loading url into DOM Document: "+ url + " - (Asynch? "+$w.document.async+")"); - this._parentWindow = $w; var scripts, _this = this; var xhr = new XMLHttpRequest(); xhr.open("GET", url, $w.document.async); @@ -4887,9 +4889,9 @@ $debug("Defining HTMLDocument"); * * @extends DOMDocument */ -var HTMLDocument = function(implementation) { +var HTMLDocument = function(implementation, docParentWindow) { this.DOMDocument = DOMDocument; - this.DOMDocument(implementation); + this.DOMDocument(implementation, docParentWindow); this._refferer = ""; this._domain; @@ -5972,15 +5974,15 @@ __extend__(HTMLFrameElement.prototype, { // 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; + var localCopy_window = window; // 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); + localCopy_window, + localCopy_window.top); } frameWindow.location = value; @@ -5991,14 +5993,16 @@ __extend__(HTMLFrameElement.prototype, { // functions, so that functions/code they create // will be scoped to new window object // *FunctionObjectsScope() from EnvjsRhinoSupraGlobal.java + var oldMalnwScope = getFunctionObjectsScope( + mkAndLoadNewWindow); + var oldMkWinScope = getFunctionObjectsScope( + localCopy_mkWinFn); var oldLoadScope = getFunctionObjectsScope(load); var oldLoadScriptScope = getFunctionObjectsScope( - $env.loadLocalScript); - var oldMkWinScope = getFunctionObjectsScope( - localCopy_mkWinFn); + $env.loadLocalScript); - setFunctionObjectsScope(localCopy_mkWinFn, frameWindow); setFunctionObjectsScope(mkAndLoadNewWindow, frameWindow); + setFunctionObjectsScope(localCopy_mkWinFn, frameWindow); setFunctionObjectsScope(load, frameWindow); setFunctionObjectsScope($env.loadLocalScript, frameWindow); @@ -6006,9 +6010,11 @@ __extend__(HTMLFrameElement.prototype, { this._content = frameWindow; // now restore the scope + setFunctionObjectsScope(mkAndLoadNewWindow, oldMalnwScope); + setFunctionObjectsScope(localCopy_mkWinFn, oldMkWinScope); setFunctionObjectsScope(load, oldLoadScope); setFunctionObjectsScope($env.loadLocalScript, - oldLoadScriptScope); + oldLoadScriptScope); } catch(e){ $error("failed to load frame content: from " + value, e); } @@ -9882,7 +9888,7 @@ __extend__(HTMLDocument.prototype, { -var $document = new HTMLDocument($implementation); +var $document = new HTMLDocument($implementation, $w); $w.__defineGetter__("document", function(){ return $document; }); diff --git a/dist/env.rhino.js b/dist/env.rhino.js index 8fb1f37f..b72e3cc2 100644 --- a/dist/env.rhino.js +++ b/dist/env.rhino.js @@ -231,20 +231,22 @@ var Envjs = function(){ if (timer.at <= now){ f = timer.fn; f(); - timer.at = Date.now() + timer.interval; + timer.at += timer.interval; } } empty = true; sleep = null; now = Date.now(); for (i in timers){ - empty = false; + empty = false; timer = timers[i]; after = timer.at - now sleep = (sleep === null || after < sleep) ? after : sleep; } sleep = sleep < 0 ? 0 : sleep; - if (empty || ( wait !== 0 ) && ( ( sleep > 0 && !wait ) || ( Date.now() + sleep > wait ) ) ) { + if (empty || + ( wait !== 0 ) && + ( ( sleep > 0 && !wait ) || ( Date.now() + sleep > wait ) ) ) { break; } if (sleep) { @@ -3986,7 +3988,7 @@ __extend__(DOMImplementation.prototype,{ createDocument : function(nsuri, qname, doctype){ //TODO - this currently returns an empty doc //but needs to handle the args - return new HTMLDocument($implementation); + return new HTMLDocument($implementation, null); }, translateErrCode : function(code) { //convert DOMException Code to human readable error message; @@ -4232,6 +4234,8 @@ function __parseLoop__(impl, doc, p) { // 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 oldMalnwScope = getFunctionObjectsScope( + mkAndLoadNewWindow); var oldMkWinScope = getFunctionObjectsScope(localCopy_mkWinFn); var oldLoadScope = getFunctionObjectsScope(load); var oldLoadScriptScope = getFunctionObjectsScope( @@ -4245,6 +4249,7 @@ function __parseLoop__(impl, doc, p) { mkAndLoadNewWindow(); // now restore the scope + setFunctionObjectsScope(mkAndLoadNewWindow, oldMalnwScope); setFunctionObjectsScope(localCopy_mkWinFn, oldMkWinScope); setFunctionObjectsScope(load, oldLoadScope); setFunctionObjectsScope($env.loadLocalScript, oldLoadScriptScope); @@ -4590,7 +4595,7 @@ $implementation.errorChecking = false;$debug("Defining Document"); * @author Jon van Noort (jon@webarcana.com.au) * @param implementation : DOMImplementation - the creator Implementation */ -var DOMDocument = function(implementation) { +var DOMDocument = function(implementation, docParentWindow) { //$log("\tcreating dom document"); this.DOMNode = DOMNode; this.DOMNode(this); @@ -4598,7 +4603,7 @@ var DOMDocument = function(implementation) { this.doctype = null; // The Document Type Declaration (see DocumentType) associated with this document this.implementation = implementation; // The DOMImplementation object that handles this document. this._documentElement = null; // "private" variable providing the read-only document.documentElement property - this._parentWindow = null; // "private" variable providing the read-only document.parentWindow property + this._parentWindow = docParentWindow; // "private" variable providing the read-only document.parentWindow property this.nodeName = "#document"; this._id = 0; @@ -4664,7 +4669,6 @@ __extend__(DOMDocument.prototype, { }, load: function(url){ $debug("Loading url into DOM Document: "+ url + " - (Asynch? "+$w.document.async+")"); - this._parentWindow = $w; var scripts, _this = this; var xhr = new XMLHttpRequest(); xhr.open("GET", url, $w.document.async); @@ -5324,9 +5328,9 @@ $debug("Defining HTMLDocument"); * * @extends DOMDocument */ -var HTMLDocument = function(implementation) { +var HTMLDocument = function(implementation, docParentWindow) { this.DOMDocument = DOMDocument; - this.DOMDocument(implementation); + this.DOMDocument(implementation, docParentWindow); this._refferer = ""; this._domain; @@ -6409,15 +6413,15 @@ __extend__(HTMLFrameElement.prototype, { // 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; + var localCopy_window = window; // 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); + localCopy_window, + localCopy_window.top); } frameWindow.location = value; @@ -6428,14 +6432,16 @@ __extend__(HTMLFrameElement.prototype, { // functions, so that functions/code they create // will be scoped to new window object // *FunctionObjectsScope() from EnvjsRhinoSupraGlobal.java + var oldMalnwScope = getFunctionObjectsScope( + mkAndLoadNewWindow); + var oldMkWinScope = getFunctionObjectsScope( + localCopy_mkWinFn); var oldLoadScope = getFunctionObjectsScope(load); var oldLoadScriptScope = getFunctionObjectsScope( - $env.loadLocalScript); - var oldMkWinScope = getFunctionObjectsScope( - localCopy_mkWinFn); + $env.loadLocalScript); - setFunctionObjectsScope(localCopy_mkWinFn, frameWindow); setFunctionObjectsScope(mkAndLoadNewWindow, frameWindow); + setFunctionObjectsScope(localCopy_mkWinFn, frameWindow); setFunctionObjectsScope(load, frameWindow); setFunctionObjectsScope($env.loadLocalScript, frameWindow); @@ -6443,9 +6449,11 @@ __extend__(HTMLFrameElement.prototype, { this._content = frameWindow; // now restore the scope + setFunctionObjectsScope(mkAndLoadNewWindow, oldMalnwScope); + setFunctionObjectsScope(localCopy_mkWinFn, oldMkWinScope); setFunctionObjectsScope(load, oldLoadScope); setFunctionObjectsScope($env.loadLocalScript, - oldLoadScriptScope); + oldLoadScriptScope); } catch(e){ $error("failed to load frame content: from " + value, e); } @@ -10319,7 +10327,7 @@ __extend__(HTMLDocument.prototype, { -var $document = new HTMLDocument($implementation); +var $document = new HTMLDocument($implementation, $w); $w.__defineGetter__("document", function(){ return $document; }); diff --git a/rhino/mainForEnvjs.jar b/rhino/mainForEnvjs.jar index 9b2eb117bdd9e65c53aa1e9e7ad772a8b89857cb..b630fed281b5cf24ad55f0ccd7e31b5f55821afd 100644 GIT binary patch delta 2065 zcmY+FdpOgJ8^GOnuo=sx$R%2qjO8--5@%b|v$^Dw&=HQyWVtlt@;y#2C9T%n$)y#M z{5nW(6^b#pUpAB6T1Y2THp6hzDV^u{d(Qj3&-;1b_j#Z9-_K|586Aj=v!s-q*!So+ zU!y`0lFV;4lOkJ-HFk>oM7 z>7yK$m-aFnn)8)_3;tN_CJmov`M zt708>9&7G#i^|3{w009a*A1%%Tpv4>Zdg&EQi9QW0}=L5cxnZHIs`o9W5Tc-_LjZb zB6DzR(sSJCWrX8XR&8IAyWG#YvhF}|!UYGNbA_?GV?_LNJ20`quAD2(AW_D~$7bc) zzfhGv)_lx~?jYTz{qeb#Y<}jp#d(_vAL%>$9|aPx*8_3m!eag+>OuOgGu*BTza_If z8#zUnDfVZ(P4f+(coL2^o?5YG@h^i$E8LDb=LZa{k8W&s0bl5}xIla8FKBT>7wpf%$A?AIQB2t^ASFJ8WtbnPL7x`1Wiy$O&#(Bjl=k2Oo?;u zWRcy%UcUPnGQ_A`x$5I=b&cV>9Gf=O0n<%lDx+=K*ECE|1cA3hKR0{TA?vp-j-^!E z%_%%E%J*6Gttv55r|g$!Xw%UXY%;@MQ#FcVZ}aJluJv>$2@cH9$npwJ4_1u}5yK}~ zE69X_yR7p=gU*KN-ZJP?&3FbPW%@2sS|+`3ZA6y5Z?idm zZZ!g3->e%W0y>n@cfrxS50L^A5mSEu)tgW^zrhvHXy$oV4#HWHQdSeWcm24#Uo)?n zSR6_-mig+gIrzdYPjOV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