Skip to content

Commit

Permalink
Added stub functions to allow env.rhino.js to run with unmodified js.…
Browse files Browse the repository at this point in the history
…jar.

Reorganized tests so that those not dependent on the Java scope-manipulation
functions are re-run with rhino/js.jar rather than our repacked jar.
  • Loading branch information
gleneivey committed Sep 2, 2009
1 parent b99dad8 commit c0ade02
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 32 deletions.
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 c0ade02

Please sign in to comment.