Skip to content

Commit

Permalink
Re-use $ERROR
Browse files Browse the repository at this point in the history
Reduce coupling between runner implementations and Test262 itself by
automatically injecting Test262's definition of `$ERROR`.
  • Loading branch information
jugglinmike committed Jul 20, 2015
1 parent ac95cc8 commit 81244a5
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 29 deletions.
10 changes: 0 additions & 10 deletions lib/helpers/Test262Error.js

This file was deleted.

26 changes: 26 additions & 0 deletions lib/helpers/sta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// Copyright (c) 2012 Ecma International. All rights reserved.
/// Ecma International makes this code available under the terms and conditions set
/// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
/// "Use Terms"). Any redistribution of this code must retain the above
/// copyright and this notice and otherwise comply with the Use Terms.

var NotEarlyErrorString = "NotEarlyError";
var EarlyErrorRePat = "^((?!" + NotEarlyErrorString + ").)*$";
var NotEarlyError = new Error(NotEarlyErrorString);

function Test262Error(message) {
this.message = message || "";
}

Test262Error.prototype.toString = function () {
return "Test262Error: " + this.message;
};

var $ERROR;
$ERROR = function $ERROR(message) {
throw new Test262Error(message);
};

function testFailed(message) {
$ERROR(message);
}
2 changes: 1 addition & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var fs = require('fs');
var path = require('path');
var parseFile = require('test262-parser').parseFile;

var autoIncludes = ['Test262Error.js', 'assert.js'];
var autoIncludes = ['sta.js', 'assert.js'];

function Runner(opts) {
this.opts = opts
Expand Down
11 changes: 2 additions & 9 deletions lib/runners/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@ var doneFn = function $DONE(err) {
$LOG('test262/done');
}.toString()

var errorFn = function $ERROR(err) {
if(typeof err === "object" && err !== null && "name" in err)
throw err;
else throw new Test262Error(err);
}.toString()

var batchDoneFn = function $DONE(err) {
if(err) {
if(typeof err === "object" && err !== null && "name" in err) {
if(typeof err === "object" && err !== null) {
err.name = err.name || "Test262Error";
if("stack" in err) $LOG("test262/error " + err.stack)
else $LOG("test262/error " + err.name + ": " + err.message)
}
Expand All @@ -40,7 +35,6 @@ function ConsoleRunner(args) {
if(args.batch) {
// Done comes from the parent context
this.deps = [
errorFn,
this.logFn
]

Expand All @@ -52,7 +46,6 @@ function ConsoleRunner(args) {
} else {
this.deps = [
doneFn,
errorFn,
this.logFn
]
}
Expand Down
4 changes: 0 additions & 4 deletions lib/runners/node-ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ NodeRunner.prototype.execute = function(test, cb) {
var result = {log: []};

var context = vm.createContext({
$ERROR: function(err) {
var Test262Error = vm.runInContext('Test262Error', context);
throw new Test262Error(err);
},
$DONE: function(err) {
error = err;
result.doneCalled = true;
Expand Down
4 changes: 0 additions & 4 deletions lib/runners/nodehost.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ process.stdin.resume();
process.stdin.on('data', function(test) {
var result = { log: [] }
var context = vm.createContext({
$ERROR: function(msg) {
var Test262Error = vm.runInContext('Test262Error', context);
throw new Test262Error(msg);
},
$DONE: function(error) {
if(error) {
if(typeof error === 'object') {
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion test/test262alike/harness/Test262Error.js

This file was deleted.

26 changes: 26 additions & 0 deletions test/test262alike/harness/sta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// Copyright (c) 2012 Ecma International. All rights reserved.
/// Ecma International makes this code available under the terms and conditions set
/// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
/// "Use Terms"). Any redistribution of this code must retain the above
/// copyright and this notice and otherwise comply with the Use Terms.

var NotEarlyErrorString = "NotEarlyError";
var EarlyErrorRePat = "^((?!" + NotEarlyErrorString + ").)*$";
var NotEarlyError = new Error(NotEarlyErrorString);

function Test262Error(message) {
this.message = message || "";
}

Test262Error.prototype.toString = function () {
return "Test262Error: " + this.message;
};

var $ERROR;
$ERROR = function $ERROR(message) {
throw new Test262Error(message);
};

function testFailed(message) {
$ERROR(message);
}

0 comments on commit 81244a5

Please sign in to comment.