Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
lib,test: stop using process.jsEngine
Browse files Browse the repository at this point in the history
Replace calls to process.jsEngine with property checks of the
`process.versions` object.

This doesn't address all of them, but makes a bit of progress.

PR-URL: #501
Reviewed-By: Seth Brenith <[email protected]>
Reviewed-By: Jimmy Thomson <[email protected]>
Reviewed-By: Jack Horton <[email protected]>
  • Loading branch information
kfarnung committed Mar 21, 2018
1 parent d2ac2ee commit 3036f13
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function innerOk(fn, argLen, value, message) {
if (argLen === 0) {
generatedMessage = true;
message = 'No value argument passed to `assert.ok()`';
} else if (message == null && process.jsEngine !== 'chakracore') {
} else if (message == null && !('chakracore' in process.versions)) {
// Use the call as error message if possible.
// This does not work with e.g. the repl.
const err = new Error();
Expand Down Expand Up @@ -245,7 +245,7 @@ function innerOk(fn, argLen, value, message) {
expected: true,
message,
operator: '==',
stackStartFn: process.jsEngine === 'chakracore' ? ok : fn
stackStartFn: 'chakracore' in process.versions ? ok : fn
});
err.generatedMessage = generatedMessage;
throw err;
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// do this good and early, since it handles errors.
setupProcessFatal();

if (process.jsEngine === 'chakracore') {
if ('chakracore' in process.versions) {
// This file contains the V8-specific "%<function>" syntax for accessing
// private functions. This is not supported on ChakraCore and causes a
// parser failure. Inject a cache entry to prevent the file from being
Expand Down
4 changes: 2 additions & 2 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1482,13 +1482,13 @@ function isRecoverableError(e, code) {
return true;
}

if (process.jsEngine === 'v8') {
if ('v8' in process.versions) {
if (message === 'missing ) after argument list') {
const frames = e.stack.split(/\r?\n/);
const pos = frames.findIndex((f) => f.match(/^\s*\^+$/));
return pos > 0 && frames[pos - 1].length === frames[pos].length;
}
} else if (process.jsEngine.match(/^chakra/)) {
} else if ('chakracore' in process.versions) {
if (/^(Expected|Unterminated)/.test(message) &&
!/ in regular expression$/.test(message)) {
return true;
Expand Down
12 changes: 9 additions & 3 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Object.defineProperty(exports, 'PORT', {


exports.isWindows = process.platform === 'win32';
exports.isChakraEngine = process.jsEngine === 'chakracore';
exports.isChakraEngine = 'chakracore' in process.versions;
exports.isWOW64 = exports.isWindows &&
(process.env.PROCESSOR_ARCHITEW6432 !== undefined);
exports.isAIX = process.platform === 'aix';
Expand Down Expand Up @@ -618,8 +618,14 @@ exports.engineSpecificMessage = function(messageObject) {
assert.ok(!areAllValuesStringEqual(messageObject),
'Unnecessary usage of \'engineSpecificMessage\'');

const jsEngine = process.jsEngine || 'v8'; //default is 'v8'
return messageObject[jsEngine];
for (const version of Object.getOwnPropertyNames(process.versions)) {
const message = messageObject[version];
if (message !== undefined) {
return message;
}
}

return undefined;
};

exports.busyLoop = function busyLoop(time) {
Expand Down

0 comments on commit 3036f13

Please sign in to comment.