Skip to content

Commit

Permalink
Re-use Test262Error
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 `Test262Error`.
  • Loading branch information
jugglinmike committed Jul 20, 2015
1 parent b4d8adc commit ac95cc8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 48 deletions.
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 = ['assert.js'];
var autoIncludes = ['Test262Error.js', 'assert.js'];

function Runner(opts) {
this.opts = opts
Expand Down
14 changes: 0 additions & 14 deletions lib/runners/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ var fs = require('fs');
var cp = require('child_process');
var counter = 0;

var test262Error = function() {
function Test262Error(message) {
if (message) this.message = message;
}

Test262Error.prototype.name = "Test262Error";

Test262Error.prototype.toString = function () {
return "Test262Error: " + this.message;
};
}.toString().slice(14, -1);

var doneFn = function $DONE(err) {
if(err) $ERROR(err);
$LOG('test262/done');
Expand Down Expand Up @@ -52,7 +40,6 @@ function ConsoleRunner(args) {
if(args.batch) {
// Done comes from the parent context
this.deps = [
test262Error,
errorFn,
this.logFn
]
Expand All @@ -64,7 +51,6 @@ function ConsoleRunner(args) {
}
} else {
this.deps = [
test262Error,
doneFn,
errorFn,
this.logFn
Expand Down
22 changes: 6 additions & 16 deletions lib/runners/node-ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,17 @@ module.exports = NodeRunner;
var vm = require('vm');
var Runner = require('../runner');

function Test262Error(message) {
if (message) this.message = message;
}

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

function NodeRunner() { Runner.apply(this, arguments); }
NodeRunner.prototype = Object.create(Runner.prototype);
NodeRunner.prototype.execute = function(test, cb) {
var contents = test.contents;
var error;
var result = {log: []};

var context = {
var context = vm.createContext({
$ERROR: function(err) {
if(typeof err === "object" && err !== null && "name" in err)
throw err;
else throw new Test262Error(err);
var Test262Error = vm.runInContext('Test262Error', context);
throw new Test262Error(err);
},
$DONE: function(err) {
error = err;
Expand All @@ -34,12 +25,11 @@ NodeRunner.prototype.execute = function(test, cb) {
$LOG: function(log) {
result.log.push(log);
},
process: process,
Test262Error: Test262Error
}
process: process
});

try {
vm.runInNewContext(contents, context, {displayErrors: false});
vm.runInContext(contents, context, {displayErrors: false});
} catch(e) {
error = e;
}
Expand Down
24 changes: 7 additions & 17 deletions lib/runners/nodehost.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
var vm = require('vm');

function Test262Error(message) {
if (message) this.message = message;
}

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

process.stdin.resume();
process.stdin.on('data', function(test) {
var result = { log: [] }
var context = {
$ERROR: function(err) {
if(typeof err === "object" && err !== null && "name" in err)
throw err;
else throw new Test262Error(err);
var context = vm.createContext({
$ERROR: function(msg) {
var Test262Error = vm.runInContext('Test262Error', context);
throw new Test262Error(msg);
},
$DONE: function(error) {
if(error) {
Expand All @@ -34,12 +25,11 @@ process.stdin.on('data', function(test) {
$LOG: function(log) {
console.log(log);
},
process: process,
Test262Error: Test262Error
}
process: process
});

try {
vm.runInNewContext(test, context, {displayErrors: false});
vm.runInContext(test, context, {displayErrors: false});
} catch(e) {
context.$DONE(e);
}
Expand Down
1 change: 1 addition & 0 deletions test/test262alike/badHarness/Test262Error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// dummy assert file
1 change: 1 addition & 0 deletions test/test262alike/harness/Test262Error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// dummy assert file

0 comments on commit ac95cc8

Please sign in to comment.