-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
106 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (C) 2014, Microsoft Corporation. All rights reserved. | ||
// This code is governed by the BSD License found in the LICENSE file. | ||
|
||
module.exports = NodeRunner; | ||
|
||
var vm = require('vm'); | ||
var Runner = require('../runner'); | ||
|
||
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 = { | ||
$ERROR: function(err) { | ||
error = err; | ||
}, | ||
$DONE: function(err) { | ||
if(err) context.$ERROR(err); | ||
result.doneCalled = true; | ||
}, | ||
$LOG: function(log) { | ||
result.log.push(log); | ||
} | ||
} | ||
try { | ||
vm.runInNewContext(contents, context); | ||
} catch(e) { | ||
error = e; | ||
} | ||
|
||
process.nextTick(function () { | ||
if(error) { | ||
if(typeof error === 'object') { | ||
// custom thrown errors won't have a name property. | ||
result.errorName = error.name || "Test262Error"; | ||
result.errorMessage = error.message; | ||
result.errorStack = error.stack | ||
} else { | ||
result.errorName = error; | ||
} | ||
} | ||
|
||
this.validateResult(test, result); | ||
cb(); | ||
}.bind(this)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,28 @@ | ||
// Copyright (C) 2014, Microsoft Corporation. All rights reserved. | ||
// This code is governed by the BSD License found in the LICENSE file. | ||
var Runner = require('../runner'); | ||
var ConsoleRunner = require('./console'); | ||
var cp = require('child_process'); | ||
|
||
module.exports = NodeRunner; | ||
|
||
var vm = require('vm'); | ||
var Runner = require('../runner'); | ||
|
||
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: []}; | ||
function NodeRunner(args) { | ||
args.consoleCommand = 'dummy'; | ||
var runner = this; | ||
ConsoleRunner.apply(this, arguments); | ||
this.deps = []; // all env deps provided by nodehost.js | ||
|
||
var context = { | ||
$ERROR: function(err) { | ||
error = err; | ||
}, | ||
$DONE: function(err) { | ||
if(err) context.$ERROR(err); | ||
result.doneCalled = true; | ||
}, | ||
$LOG: function(log) { | ||
result.log.push(log); | ||
} | ||
} | ||
try { | ||
vm.runInNewContext(contents, context); | ||
} catch(e) { | ||
error = e; | ||
} | ||
|
||
process.nextTick(function () { | ||
if(error) { | ||
if(typeof error === 'object') { | ||
// custom thrown errors won't have a name property. | ||
result.errorName = error.name || "Test262Error"; | ||
result.errorMessage = error.message; | ||
result.errorStack = error.stack | ||
} else { | ||
result.errorName = error; | ||
} | ||
} | ||
this._instance = cp.fork(__dirname + '/nodehost.js') | ||
this._instance.on('message', function(result) { | ||
runner.validateResult(runner._test, result) | ||
runner._testDone(); | ||
}) | ||
} | ||
NodeRunner.prototype = Object.create(ConsoleRunner.prototype); | ||
NodeRunner.prototype.execute = function(test, cb) { | ||
this._test = test; | ||
this._testDone = cb; | ||
this._instance.send(test.contents); | ||
} | ||
|
||
this.validateResult(test, result); | ||
cb(); | ||
}.bind(this)); | ||
NodeRunner.prototype.end = function() { | ||
this._instance.disconnect(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var vm = require('vm'); | ||
|
||
process.on('message', function(test) { | ||
var result = { log: [] } | ||
var error; | ||
var context = { | ||
$ERROR: function(err) { | ||
error = err; | ||
}, | ||
$DONE: function(err) { | ||
if(err) context.$ERROR(err); | ||
if(error) { | ||
if(typeof error === 'object') { | ||
// custom thrown errors won't have a name property. | ||
result.errorName = error.name || "Test262Error"; | ||
result.errorMessage = error.message; | ||
result.errorStack = error.stack | ||
} else { | ||
result.errorName = error; | ||
} | ||
} | ||
result.doneCalled = true; | ||
process.send(result); | ||
}, | ||
$LOG: function(log) { | ||
result.log.push(log); | ||
} | ||
} | ||
|
||
try { | ||
vm.runInNewContext(test, context); | ||
} catch(e) { | ||
context.$DONE(e); | ||
} | ||
}) |