Skip to content

Commit

Permalink
lib: replace Symbol.toPrimitive to SymbolToPrimitive primordials
Browse files Browse the repository at this point in the history
PR-URL: #30905
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
Sebastien-Ahkrin authored and targos committed Jan 14, 2020
1 parent d1702f5 commit 7c3ac42
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
5 changes: 3 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const {
ObjectDefineProperty,
ObjectSetPrototypeOf,
Symbol,
SymbolToPrimitive,
} = primordials;

const {
Expand Down Expand Up @@ -297,8 +298,8 @@ Buffer.from = function from(value, encodingOrOffset, length) {
if (b)
return b;

if (typeof value[Symbol.toPrimitive] === 'function') {
return Buffer.from(value[Symbol.toPrimitive]('string'),
if (typeof value[SymbolToPrimitive] === 'function') {
return Buffer.from(value[SymbolToPrimitive]('string'),
encodingOrOffset,
length);
}
Expand Down
24 changes: 12 additions & 12 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

const {
ObjectDefineProperties,
Symbol,
SymbolToPrimitive,
} = primordials;

const { safeGetenv } = internalBinding('credentials');
Expand Down Expand Up @@ -73,13 +73,13 @@ const getInterfaceAddresses = getCheckedFunction(_getInterfaceAddresses);
const getOSRelease = getCheckedFunction(_getOSRelease);
const getOSType = getCheckedFunction(_getOSType);

getFreeMem[Symbol.toPrimitive] = () => getFreeMem();
getHostname[Symbol.toPrimitive] = () => getHostname();
getHomeDirectory[Symbol.toPrimitive] = () => getHomeDirectory();
getOSRelease[Symbol.toPrimitive] = () => getOSRelease();
getOSType[Symbol.toPrimitive] = () => getOSType();
getTotalMem[Symbol.toPrimitive] = () => getTotalMem();
getUptime[Symbol.toPrimitive] = () => getUptime();
getFreeMem[SymbolToPrimitive] = () => getFreeMem();
getHostname[SymbolToPrimitive] = () => getHostname();
getHomeDirectory[SymbolToPrimitive] = () => getHomeDirectory();
getOSRelease[SymbolToPrimitive] = () => getOSRelease();
getOSType[SymbolToPrimitive] = () => getOSType();
getTotalMem[SymbolToPrimitive] = () => getTotalMem();
getUptime[SymbolToPrimitive] = () => getUptime();

const kEndianness = isBigEndian ? 'BE' : 'LE';

Expand Down Expand Up @@ -117,12 +117,12 @@ function cpus() {
function arch() {
return process.arch;
}
arch[Symbol.toPrimitive] = () => process.arch;
arch[SymbolToPrimitive] = () => process.arch;

function platform() {
return process.platform;
}
platform[Symbol.toPrimitive] = () => process.platform;
platform[SymbolToPrimitive] = () => process.platform;

function tmpdir() {
var path;
Expand All @@ -143,12 +143,12 @@ function tmpdir() {

return path;
}
tmpdir[Symbol.toPrimitive] = () => tmpdir();
tmpdir[SymbolToPrimitive] = () => tmpdir();

function endianness() {
return kEndianness;
}
endianness[Symbol.toPrimitive] = () => kEndianness;
endianness[SymbolToPrimitive] = () => kEndianness;

// Returns the number of ones in the binary representation of the decimal
// number.
Expand Down

0 comments on commit 7c3ac42

Please sign in to comment.