Skip to content

Commit 81244a5

Browse files
committed
Re-use $ERROR
Reduce coupling between runner implementations and Test262 itself by automatically injecting Test262's definition of `$ERROR`.
1 parent ac95cc8 commit 81244a5

File tree

9 files changed

+55
-29
lines changed

9 files changed

+55
-29
lines changed

lib/helpers/Test262Error.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

lib/helpers/sta.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// Copyright (c) 2012 Ecma International. All rights reserved.
2+
/// Ecma International makes this code available under the terms and conditions set
3+
/// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
4+
/// "Use Terms"). Any redistribution of this code must retain the above
5+
/// copyright and this notice and otherwise comply with the Use Terms.
6+
7+
var NotEarlyErrorString = "NotEarlyError";
8+
var EarlyErrorRePat = "^((?!" + NotEarlyErrorString + ").)*$";
9+
var NotEarlyError = new Error(NotEarlyErrorString);
10+
11+
function Test262Error(message) {
12+
this.message = message || "";
13+
}
14+
15+
Test262Error.prototype.toString = function () {
16+
return "Test262Error: " + this.message;
17+
};
18+
19+
var $ERROR;
20+
$ERROR = function $ERROR(message) {
21+
throw new Test262Error(message);
22+
};
23+
24+
function testFailed(message) {
25+
$ERROR(message);
26+
}

lib/runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var fs = require('fs');
77
var path = require('path');
88
var parseFile = require('test262-parser').parseFile;
99

10-
var autoIncludes = ['Test262Error.js', 'assert.js'];
10+
var autoIncludes = ['sta.js', 'assert.js'];
1111

1212
function Runner(opts) {
1313
this.opts = opts

lib/runners/console.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,10 @@ var doneFn = function $DONE(err) {
1313
$LOG('test262/done');
1414
}.toString()
1515

16-
var errorFn = function $ERROR(err) {
17-
if(typeof err === "object" && err !== null && "name" in err)
18-
throw err;
19-
else throw new Test262Error(err);
20-
}.toString()
21-
2216
var batchDoneFn = function $DONE(err) {
2317
if(err) {
24-
if(typeof err === "object" && err !== null && "name" in err) {
18+
if(typeof err === "object" && err !== null) {
19+
err.name = err.name || "Test262Error";
2520
if("stack" in err) $LOG("test262/error " + err.stack)
2621
else $LOG("test262/error " + err.name + ": " + err.message)
2722
}
@@ -40,7 +35,6 @@ function ConsoleRunner(args) {
4035
if(args.batch) {
4136
// Done comes from the parent context
4237
this.deps = [
43-
errorFn,
4438
this.logFn
4539
]
4640

@@ -52,7 +46,6 @@ function ConsoleRunner(args) {
5246
} else {
5347
this.deps = [
5448
doneFn,
55-
errorFn,
5649
this.logFn
5750
]
5851
}

lib/runners/node-ip.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ NodeRunner.prototype.execute = function(test, cb) {
1414
var result = {log: []};
1515

1616
var context = vm.createContext({
17-
$ERROR: function(err) {
18-
var Test262Error = vm.runInContext('Test262Error', context);
19-
throw new Test262Error(err);
20-
},
2117
$DONE: function(err) {
2218
error = err;
2319
result.doneCalled = true;

lib/runners/nodehost.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ process.stdin.resume();
44
process.stdin.on('data', function(test) {
55
var result = { log: [] }
66
var context = vm.createContext({
7-
$ERROR: function(msg) {
8-
var Test262Error = vm.runInContext('Test262Error', context);
9-
throw new Test262Error(msg);
10-
},
117
$DONE: function(error) {
128
if(error) {
139
if(typeof error === 'object') {
File renamed without changes.

test/test262alike/harness/Test262Error.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/test262alike/harness/sta.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// Copyright (c) 2012 Ecma International. All rights reserved.
2+
/// Ecma International makes this code available under the terms and conditions set
3+
/// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
4+
/// "Use Terms"). Any redistribution of this code must retain the above
5+
/// copyright and this notice and otherwise comply with the Use Terms.
6+
7+
var NotEarlyErrorString = "NotEarlyError";
8+
var EarlyErrorRePat = "^((?!" + NotEarlyErrorString + ").)*$";
9+
var NotEarlyError = new Error(NotEarlyErrorString);
10+
11+
function Test262Error(message) {
12+
this.message = message || "";
13+
}
14+
15+
Test262Error.prototype.toString = function () {
16+
return "Test262Error: " + this.message;
17+
};
18+
19+
var $ERROR;
20+
$ERROR = function $ERROR(message) {
21+
throw new Test262Error(message);
22+
};
23+
24+
function testFailed(message) {
25+
$ERROR(message);
26+
}

0 commit comments

Comments
 (0)