browser runner: check negative regex

1. use negative regex (instead of ".") to check iframeError
2. make Test262Error.prototype.toString() always include
   the string Test262Error (no spaces) so it matches /Test262Error/
3. modify check for supportsWindowOnerror - require that
   first argument (message) to onerror() contains the error name
   by checking for /Error:/.

Change (3) above forces IE11 onto the !supportsWindowOnerror path.
Test262 tests are run inside an eval() on IE11, and errors are
caught and explicitly have toString() called.  Without this,
IE11 passes only the `message` property to onerror(), and regexes
that expect to match error name fail.

sth: revert to simple `onerror` checking

gs: refactor function `$DONE`

refactor logic tree
add support for async test failures

ed.js: crude support for error typing

S8.7.1_A2: cache result of delete

`delete` has a side-effect and its
return value depends on this; cache result of
delete so when reporting result, we are always
reporting the result that made us fail, not the
result of a new delete
[pedantic]

ed: explicitly pass cooked error to $DONE

gs: only let $DONE be called once
This commit is contained in:
Sam Mikes 2014-08-07 16:16:29 -06:00
parent a794e0eb54
commit 4debe08707
5 changed files with 69 additions and 59 deletions

View File

@ -6,9 +6,20 @@
//Error Detector
if (this.window!==undefined) { //for console support
this.window.onerror = function(errorMsg, url, lineNumber) {
this.window.iframeError = errorMsg;
if(typeof $DONE === 'function') $DONE();
this.window.onerror = function(errorMsg, url, lineNumber, colNumber, error) {
var cookedError;
if (error) {
cookedError = error.toString();
} else {
if (/Error:/.test(errorMsg)) {
cookedError = errorMsg;
} else {
cookedError = "UnknownError: " + errorMsg;
}
}
$DONE(cookedError);
};
}

View File

@ -5,68 +5,66 @@
/// copyright and this notice and otherwise comply with the Use Terms.
//Global Scope Test Case Validator
function $DONE() {
var doneCalled;
function $DONE(argError) {
var testError;
var result, resultError;
if (argError) {
testError = argError.toString();
}
if (doneCalled) {
// ? log called twice
return;
}
doneCalled = true;
//An exception is expected
if (testDescrip.negative !== undefined) {
//TODO - come up with a generic way of catching the error type
//from this.onerror
testDescrip.negative = testDescrip.negative === "NotEarlyError" ?
testDescrip.negative :
(testDescrip.negative === "^((?!NotEarlyError).)*$" ?
testDescrip.negative : ".");
if (this.iframeError === undefined) { //no exception was thrown
testRun(testDescrip.id,
testDescrip.path,
testDescrip.description,
testDescrip.code,
'fail',
Error('No exception was thrown; expected an error "message"' +
' property matching the regular expression "' +
testDescrip.negative + '".'));
} else if (!(new RegExp(testDescrip.negative,
"i").test(this.iframeError))) {
var negRegexp = new RegExp(testDescrip.negative, "i"),
unkRegexp = /^UnknownError:/;
if (!testError) { //no exception was thrown
result = 'fail';
resultError = Error('No exception was thrown; expected an error "message"' +
' property matching the regular expression "' +
testDescrip.negative + '".');
} else if (!negRegexp.test(testError) &&
!unkRegexp.test(testError)) {
//wrong type of exception thrown
testRun(testDescrip.id,
testDescrip.path,
testDescrip.description,
testDescrip.code,
'fail',
Error('Expected an exception with a "message"' +
' property matching the regular expression "' +
testDescrip.negative +
'" to be thrown; actual was "' +
this.iframeError + '".'));
result = 'fail';
resultError = Error('Expected an exception with a "message"' +
' property matching the regular expression "' +
testDescrip.negative +
'" to be thrown; actual was "' +
testError + '".');
} else {
testRun(testDescrip.id,
testDescrip.path,
testDescrip.description,
testDescrip.code,
'pass',
undefined);
result = 'pass';
resultError = 'undefined';
}
} else if (testError) {
//Exception was not expected to be thrown
result = 'fail';
resultError = Error('Unexpected exception, "' + testError + '" was thrown.');
} else {
result = 'pass';
resultError = undefined;
}
//Exception was not expected to be thrown
else if (this.iframeError !== undefined) {
testRun(testDescrip.id,
testDescrip.path,
testDescrip.description,
testDescrip.code,
'fail',
Error('Unexpected exception, "' +
this.iframeError + '" was thrown.'));
}
else {
testRun(testDescrip.id,
testDescrip.path,
testDescrip.description,
testDescrip.code,
'pass',
undefined);
}
testRun(testDescrip.id,
testDescrip.path,
testDescrip.description,
testDescrip.code,
result,
resultError);
//teardown
testFinished();
}
}

View File

@ -13,7 +13,7 @@ function Test262Error(message) {
}
Test262Error.prototype.toString = function () {
return "Test262 Error: " + this.message;
return "Test262Error: " + this.message;
};
var $ERROR;

View File

@ -129,7 +129,7 @@ function BrowserRunner() {
//TODO - 500ms *should* be a sufficient delay
setTimeout(function() {
instance.supportsWindowOnerror = iwinPrereqs.failCount === 2;
instance.supportsWindowOnerror = (iwinPrereqs.failCount === 2);
//alert(iwinPrereqs.failCount);
document.body.removeChild(iframePrereqs);
instance.run(test, code);

View File

@ -14,8 +14,9 @@ var y = 1;
//////////////////////////////////////////////////////////////////////////////
//CHECK#1
if(delete y){
$ERROR('#1: y = 1; (delete y) === false. Actual: ' + ((delete y)));
var result = delete y;
if(result){
$ERROR('#1: y = 1; (delete y) === false. Actual: ' + result);
};
//
//////////////////////////////////////////////////////////////////////////////