Skip to content

Commit

Permalink
Merge branch 'glen/multi-window'
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcher committed Sep 3, 2009
2 parents be3eb23 + 504ce1f commit b4c35ca
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 32 deletions.
18 changes: 18 additions & 0 deletions README
Expand Up @@ -62,6 +62,24 @@ Installing:
// tell env.js the base DOM to model
// run any setup code for your framework
// tell the framework that the document is loaded

Java command line:

env.rhino.js can be run either with a "generic" version of the Rhino
library (js.jar), or with the repackaged/extended version of Rhino
supplied with env.js (env-js.jar). If your application uses multiple
windows, frames, or iframes, or if it depends on precise adherence to
JavaScript object scoping in event handlers, you will have to use
env-js.jar. Simple applications may be able to run with the generic
version of Rhino.

The command line used for testing env.js can be found in build.xml,
although the general form is:
java -jar [jar file] [javascript file]
Where "jar file" is either "dist/env-js.jar", "rhino/js.jar", or your
local path to a different version of the Rhino js.jar file. The
"javascript file" is the path to the JavaScript you wish to execute.


Testing jQuery Compatibility:
* run ./bin/test-jquery.sh 1.3.2
Expand Down
6 changes: 5 additions & 1 deletion build.xml
Expand Up @@ -167,7 +167,11 @@

<target name="test" description="Run the tests">
<java fork="true" jar="${DIST_DIR}/env-js.jar" failonerror="true">
<arg value="test/test.js"/>
<arg value="test/test-with-envs-jar.js"/>
<jvmarg value="-Dfile.encoding=utf-8"/>
</java>
<java fork="true" jar="${RHINO_JAR}" failonerror="true">
<arg value="test/test-with-rhino-jar.js"/>
<jvmarg value="-Dfile.encoding=utf-8"/>
</java>
</target>
Expand Down
29 changes: 25 additions & 4 deletions dist/env.rhino.js
Expand Up @@ -59,7 +59,29 @@ var Envjs = function(){
};

$env.info("Initializing Core Platform Env");



// if we're running in an environment without env.js' custom extensions
// for manipulating the JavaScript scope chain, put in trivial emulations
$env.debug("performing check for custom Java methods in env-js.jar");
var countOfMissing = 0, dontCare;
try { dontCare = globalize; }
catch (ex){ globalize = function(){ return {}; };
countOfMissing++; }
try { dontCare = getScope; }
catch (ex){ getScope = function(){}; countOfMissing++; }
try { dontCare = setScope; }
catch (ex){ setScope = function(){}; countOfMissing++; }
try { dontCare = configureScope; }
catch (ex){ configureScope = function(){}; countOfMissing++; }
try { dontCare = restoreScope; }
catch (ex){ restoreScope = function(){}; countOfMissing++; }
if (countOfMissing != 0 && countOfMissing != 5)
$env.warning("Some but not all of scope-manipulation functions were " +
"not present in environment. JavaScript execution may " +
"not occur correctly.");


$env.lineSource = function(e){};

$env.hashCode = function(obj){};
Expand Down Expand Up @@ -190,7 +212,7 @@ var Envjs = function(){
try {

var frameWindow,
makingNewWinFlag = !(frame._content);
makingNewWinFlag = !(frame._content);
if (makingNewWinFlag)
// a blank object, inherits from original global
// see org.mozilla.javascript.tools.envjs.Window.java
Expand All @@ -204,7 +226,7 @@ var Envjs = function(){
// function executes we'll have a new/blank
// global/window and won't be able to get at them....
var local__window__ = $env.window,
local_env = $env,
local_env = $env,
local_window = frame.ownerDocument.parentWindow;

// a local function gives us something whose scope
Expand Down Expand Up @@ -245,7 +267,6 @@ var Envjs = function(){
$env.setScope(local__window__, scopes.window);
$env.setScope($env.load, scopes.global_load);
$env.setScope($env.loadLocalScript, scopes.local_load);

} catch(e){
$env.error("failed to load frame content: from " + url, e);
}
Expand Down
29 changes: 25 additions & 4 deletions src/platform/core.js
Expand Up @@ -54,7 +54,29 @@ var Envjs = function(){
};

$env.info("Initializing Core Platform Env");



// if we're running in an environment without env.js' custom extensions
// for manipulating the JavaScript scope chain, put in trivial emulations
$env.debug("performing check for custom Java methods in env-js.jar");
var countOfMissing = 0, dontCare;
try { dontCare = globalize; }
catch (ex){ globalize = function(){ return {}; };
countOfMissing++; }
try { dontCare = getScope; }
catch (ex){ getScope = function(){}; countOfMissing++; }
try { dontCare = setScope; }
catch (ex){ setScope = function(){}; countOfMissing++; }
try { dontCare = configureScope; }
catch (ex){ configureScope = function(){}; countOfMissing++; }
try { dontCare = restoreScope; }
catch (ex){ restoreScope = function(){}; countOfMissing++; }
if (countOfMissing != 0 && countOfMissing != 5)
$env.warning("Some but not all of scope-manipulation functions were " +
"not present in environment. JavaScript execution may " +
"not occur correctly.");


$env.lineSource = function(e){};

$env.hashCode = function(obj){};
Expand Down Expand Up @@ -185,7 +207,7 @@ var Envjs = function(){
try {

var frameWindow,
makingNewWinFlag = !(frame._content);
makingNewWinFlag = !(frame._content);
if (makingNewWinFlag)
// a blank object, inherits from original global
// see org.mozilla.javascript.tools.envjs.Window.java
Expand All @@ -199,7 +221,7 @@ var Envjs = function(){
// function executes we'll have a new/blank
// global/window and won't be able to get at them....
var local__window__ = $env.window,
local_env = $env,
local_env = $env,
local_window = frame.ownerDocument.parentWindow;

// a local function gives us something whose scope
Expand Down Expand Up @@ -240,7 +262,6 @@ var Envjs = function(){
$env.setScope(local__window__, scopes.window);
$env.setScope($env.load, scopes.global_load);
$env.setScope($env.loadLocalScript, scopes.local_load);

} catch(e){
$env.error("failed to load frame content: from " + url, e);
}
Expand Down
2 changes: 1 addition & 1 deletion test/html/iframe1.html
Expand Up @@ -13,7 +13,7 @@
<head>
<title>Content document for IFRAME element in env.js unit test suite</title>
</head>
<body onload="checkEventsWithinIframe();">
<body onload="try{checkEventsWithinIframe();}catch(e){;}">
<p id="anElementWithText">
This is the text content of a paragraph element.
</p>
Expand Down
32 changes: 21 additions & 11 deletions test/index.html
Expand Up @@ -15,7 +15,7 @@
}
</script>
<link rel="Stylesheet" media="screen" href="data/testsuite.css"
onload="testLinkOnload();" />
onload="try{testLinkOnload();}catch(e){;}" />

<script>var jQuery = "jQuery", $ = "$"; // For testing .noConflict()</script>
<script type="text/javascript" src="../dist/jquery.js"></script>
Expand Down Expand Up @@ -61,14 +61,23 @@ <h2 id="userAgent"></h2>
<iframe id="emptyiframe" name="emtpyiframe" style="display:none;"></iframe>

<script>
eventFrameLoaded = eventFrameClicked = 0;
function eventOnloadHandler(){ eventFrameLoaded += 1;}
function eventOnclickHandler(){ eventFrameClicked += 1;}
if (whichJarFile == "envjs"){
eventFrameLoaded = eventFrameClicked = 0;
function eventOnloadHandler(){ eventFrameLoaded += 1;}
function eventOnclickHandler(){ eventFrameClicked += 1;}

document.write(' \
\x3ciframe id="eventsFrame" name="eventsFrame" \
src="html/events.html" \
onload="eventOnloadHandler();" \
onclick="eventOnclickHandler();" \
\x3e\x3c/iframe\x3e \
\x3ciframe id="scopeFrame" name="scopeFrame" \
src="html/scope.html" \
\x3e\x3c/iframe\x3e \
');
}
</script>
<iframe id="eventsFrame" name="eventsFrame" src="html/events.html"
onload="eventOnloadHandler();" onclick="eventOnclickHandler()";
></iframe>
<iframe id="scopeFrame" name="scopeFrame" src="html/scope.html"></iframe>

<script>
function imgOnloadEventHandler(){
Expand All @@ -80,7 +89,8 @@ <h2 id="userAgent"></h2>
document.getElementsByTagName('body')[0].appendChild(p);
}
</script>
<img id="anImg" src="html/img1.png" onload="imgOnloadEventHandler();" />
<img id="anImg" src="html/img1.png"
onload="try{imgOnloadEventHandler();}catch(e){;}" />

<script>
function onloadHandlerThatShouldntExecute(){
Expand All @@ -103,9 +113,9 @@ <h2 id="userAgent"></h2>
}
</script>
<script src="html/missingScript.js"
onload="scriptOnloadEventHandler('A');" />
onload="try{scriptOnloadEventHandler('A');}catch(e){;}" />
<script src="html/missingScript.js"
onload="scriptOnloadEventHandler('B');"></script>
onload="try{scriptOnloadEventHandler('B');}catch(e){;}"></script>


<dl id="dl" style="display:none;">
Expand Down
6 changes: 6 additions & 0 deletions test/test-with-envs-jar.js
@@ -0,0 +1,6 @@
// Run 'test.js', letting it know that we're running with our customized
// version of the JS interpreter: env-js.jar

whichJarFile = "envjs";
load("test/test.js");

6 changes: 6 additions & 0 deletions test/test-with-rhino-jar.js
@@ -0,0 +1,6 @@
// Run 'test.js', letting it know that we're running with the vanilla
// unmodified version of the Rhino JS interpreter: rhino.jar

whichJarFile = "rhino";
load("test/test.js");

28 changes: 17 additions & 11 deletions test/test.js
Expand Up @@ -14,6 +14,7 @@ load("dist/env.rhino.js");
// }

window.onload = function(){
print("\n\nTesting with '" + whichJarFile + "' JavaScript interpreter jar");
print("Handling onload for test.js");

// Load the test runner
Expand All @@ -24,17 +25,22 @@ window.onload = function(){
print("Loading tests.");
// Load the tests
load(
"test/unit/dom.js",
"test/unit/window.js",
"test/unit/onload.js",
"test/unit/scope.js", // must come before frame.js changes page content
"test/unit/frame.js",
"test/unit/events.js",
"test/unit/parser.js",
"test/unit/timer.js",
//NOTE: keep this test last because Prototype pollutes
//the namespace and several DOM objects
"test/unit/prototypecompat.js"
"test/unit/dom.js",
"test/unit/window.js"
);
if (whichJarFile == "envjs")
load(
"test/unit/onload.js",
"test/unit/scope.js", // must come before frame.js changes page content
"test/unit/frame.js",
"test/unit/events.js"
);
load(
"test/unit/parser.js",
"test/unit/timer.js",
//NOTE: keep this test last because Prototype pollutes
//the namespace and several DOM objects
"test/unit/prototypecompat.js"
);
var end = new Date().getTime();

Expand Down

0 comments on commit b4c35ca

Please sign in to comment.