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

Commit 3036f13

Browse files
committed
lib,test: stop using process.jsEngine
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 <sethb@microsoft.com> Reviewed-By: Jimmy Thomson <jithomso@microsoft.com> Reviewed-By: Jack Horton <Jack.Horton@microsoft.com>
1 parent d2ac2ee commit 3036f13

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

lib/assert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function innerOk(fn, argLen, value, message) {
217217
if (argLen === 0) {
218218
generatedMessage = true;
219219
message = 'No value argument passed to `assert.ok()`';
220-
} else if (message == null && process.jsEngine !== 'chakracore') {
220+
} else if (message == null && !('chakracore' in process.versions)) {
221221
// Use the call as error message if possible.
222222
// This does not work with e.g. the repl.
223223
const err = new Error();
@@ -245,7 +245,7 @@ function innerOk(fn, argLen, value, message) {
245245
expected: true,
246246
message,
247247
operator: '==',
248-
stackStartFn: process.jsEngine === 'chakracore' ? ok : fn
248+
stackStartFn: 'chakracore' in process.versions ? ok : fn
249249
});
250250
err.generatedMessage = generatedMessage;
251251
throw err;

lib/internal/bootstrap/node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// do this good and early, since it handles errors.
3030
setupProcessFatal();
3131

32-
if (process.jsEngine === 'chakracore') {
32+
if ('chakracore' in process.versions) {
3333
// This file contains the V8-specific "%<function>" syntax for accessing
3434
// private functions. This is not supported on ChakraCore and causes a
3535
// parser failure. Inject a cache entry to prevent the file from being

lib/repl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,13 +1482,13 @@ function isRecoverableError(e, code) {
14821482
return true;
14831483
}
14841484

1485-
if (process.jsEngine === 'v8') {
1485+
if ('v8' in process.versions) {
14861486
if (message === 'missing ) after argument list') {
14871487
const frames = e.stack.split(/\r?\n/);
14881488
const pos = frames.findIndex((f) => f.match(/^\s*\^+$/));
14891489
return pos > 0 && frames[pos - 1].length === frames[pos].length;
14901490
}
1491-
} else if (process.jsEngine.match(/^chakra/)) {
1491+
} else if ('chakracore' in process.versions) {
14921492
if (/^(Expected|Unterminated)/.test(message) &&
14931493
!/ in regular expression$/.test(message)) {
14941494
return true;

test/common/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Object.defineProperty(exports, 'PORT', {
4747

4848

4949
exports.isWindows = process.platform === 'win32';
50-
exports.isChakraEngine = process.jsEngine === 'chakracore';
50+
exports.isChakraEngine = 'chakracore' in process.versions;
5151
exports.isWOW64 = exports.isWindows &&
5252
(process.env.PROCESSOR_ARCHITEW6432 !== undefined);
5353
exports.isAIX = process.platform === 'aix';
@@ -618,8 +618,14 @@ exports.engineSpecificMessage = function(messageObject) {
618618
assert.ok(!areAllValuesStringEqual(messageObject),
619619
'Unnecessary usage of \'engineSpecificMessage\'');
620620

621-
const jsEngine = process.jsEngine || 'v8'; //default is 'v8'
622-
return messageObject[jsEngine];
621+
for (const version of Object.getOwnPropertyNames(process.versions)) {
622+
const message = messageObject[version];
623+
if (message !== undefined) {
624+
return message;
625+
}
626+
}
627+
628+
return undefined;
623629
};
624630

625631
exports.busyLoop = function busyLoop(time) {

0 commit comments

Comments
 (0)