A major web browser does not fire window.onerror for iframes when the iframe's document

contains a JavaScript syntax error (major test area).  Added a workaround.
This commit is contained in:
David Fugate 2011-04-20 15:39:50 -07:00
parent b055423983
commit ef45786a21
2 changed files with 24 additions and 10 deletions

View File

@ -91,7 +91,7 @@ function BrowserRunner() {
// Set up some globals.
win.testRun = testRun;
win.testFinished = testFinished;
win.iframeError = undefined;
//TODO: these should be moved to sta.js
win.SputnikError = SputnikError;
win.$ERROR = $ERROR;
@ -125,16 +125,23 @@ function BrowserRunner() {
//--Scenario 1: we're dealing with a global scope test case
if (GlobalScopeTests[id]!==undefined) {
win.iframeError = undefined;
win.onerror = undefined;
win.onErrorHack = undefined;
var testDescrip = GlobalScopeTests[id];
//Add an error handler
doc.writeln("<script type='text/javascript'>window.onerror = function(errorMsg, url, lineNumber) {window.iframeError = errorMsg;};" + "</script>");
//Parse and execute the code
doc.writeln("<script type='text/javascript'>try{" + code + "}catch(test262RuntimeError){window.iframeError=test262RuntimeError.message || \"None\";}</script>");
doc.writeln("<script type='text/javascript'>onErrorHack = true;try{" + code + "}catch(test262RuntimeError){window.iframeError=test262RuntimeError.message || \"None\";}</script>");
//validation
if (testDescrip.negative!==undefined) { //An exception is expected
if (win.iframeError===undefined) { //no exception was thrown
if (win.onErrorHack===undefined) { //Hack for browsers not supporting window.onerror WRT early parse errors
testRun(testDescrip.id, testDescrip.path, testDescrip.description, code, typeof testDescrip.precondition !== 'undefined' ? testDescrip.precondition.toString() : '',
'pass', 'Not parsable');
}
else if (win.iframeError===undefined) { //no exception was thrown
testRun(testDescrip.id, testDescrip.path, testDescrip.description, code, typeof testDescrip.precondition !== 'undefined' ? testDescrip.precondition.toString() : '',
'fail', 'No Exception Thrown');
} else if(! (new RegExp(testDescrip.negative, "i").test(win.iframeError))) { //wrong type of exception thrown
@ -150,7 +157,7 @@ function BrowserRunner() {
} else {
testRun(testDescrip.id, testDescrip.path, testDescrip.description, code, typeof testDescrip.precondition !== 'undefined' ? testDescrip.precondition.toString() : '',
'pass', undefined);
}
}
}
//--Scenario 2: we're dealing with a normal positive(?) test case
else {

View File

@ -91,7 +91,7 @@ function BrowserRunner() {
// Set up some globals.
win.testRun = testRun;
win.testFinished = testFinished;
win.iframeError = undefined;
//TODO: these should be moved to sta.js
win.SputnikError = SputnikError;
win.$ERROR = $ERROR;
@ -125,16 +125,23 @@ function BrowserRunner() {
//--Scenario 1: we're dealing with a global scope test case
if (GlobalScopeTests[id]!==undefined) {
win.iframeError = undefined;
win.onerror = undefined;
win.onErrorHack = undefined;
var testDescrip = GlobalScopeTests[id];
//Add an error handler
doc.writeln("<script type='text/javascript'>window.onerror = function(errorMsg, url, lineNumber) {window.iframeError = errorMsg;};" + "</script>");
//Parse and execute the code
doc.writeln("<script type='text/javascript'>try{" + code + "}catch(test262RuntimeError){window.iframeError=test262RuntimeError.message || \"None\";}</script>");
doc.writeln("<script type='text/javascript'>onErrorHack = true;try{" + code + "}catch(test262RuntimeError){window.iframeError=test262RuntimeError.message || \"None\";}</script>");
//validation
if (testDescrip.negative!==undefined) { //An exception is expected
if (win.iframeError===undefined) { //no exception was thrown
if (win.onErrorHack===undefined) { //Hack for browsers not supporting window.onerror WRT early parse errors
testRun(testDescrip.id, testDescrip.path, testDescrip.description, code, typeof testDescrip.precondition !== 'undefined' ? testDescrip.precondition.toString() : '',
'pass', 'Not parsable');
}
else if (win.iframeError===undefined) { //no exception was thrown
testRun(testDescrip.id, testDescrip.path, testDescrip.description, code, typeof testDescrip.precondition !== 'undefined' ? testDescrip.precondition.toString() : '',
'fail', 'No Exception Thrown');
} else if(! (new RegExp(testDescrip.negative, "i").test(win.iframeError))) { //wrong type of exception thrown
@ -150,7 +157,7 @@ function BrowserRunner() {
} else {
testRun(testDescrip.id, testDescrip.path, testDescrip.description, code, typeof testDescrip.precondition !== 'undefined' ? testDescrip.precondition.toString() : '',
'pass', undefined);
}
}
}
//--Scenario 2: we're dealing with a normal positive(?) test case
else {