Skip to content

Commit

Permalink
lib: remove unnecessary ObjectGetValueSafe
Browse files Browse the repository at this point in the history
PR-URL: #46335
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
legendecas authored and ruyadorno committed Jan 31, 2023
1 parent bf62da5 commit b966ef9
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions lib/internal/source_map/source_map_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,12 @@ const {
ArrayPrototypeMap,
JSONParse,
ObjectKeys,
ObjectGetOwnPropertyDescriptor,
ObjectPrototypeHasOwnProperty,
RegExpPrototypeExec,
RegExpPrototypeSymbolSplit,
SafeMap,
StringPrototypeSplit,
} = primordials;

function ObjectGetValueSafe(obj, key) {
const desc = ObjectGetOwnPropertyDescriptor(obj, key);
if (desc === undefined) {
return undefined;
}
return ObjectPrototypeHasOwnProperty(desc, 'value') ? desc.value : undefined;
}

// See https://sourcemaps.info/spec.html for SourceMap V3 specification.
const { Buffer } = require('buffer');
let debug = require('internal/util/debuglog').debuglog('source_map', (fn) => {
Expand Down Expand Up @@ -301,11 +291,11 @@ function sourceMapCacheToObject() {

function appendCJSCache(obj) {
for (const value of getCjsSourceMapCache()) {
obj[ObjectGetValueSafe(value, 'filename')] = {
obj[value.filename] = {
__proto__: null,
lineLengths: ObjectGetValueSafe(value, 'lineLengths'),
data: ObjectGetValueSafe(value, 'data'),
url: ObjectGetValueSafe(value, 'url')
lineLengths: value.lineLengths,
data: value.data,
url: value.url,
};
}
}
Expand All @@ -320,8 +310,8 @@ function findSourceMap(sourceURL) {
let entry = esmSourceMapCache.get(sourceURL) ?? generatedSourceMapCache.get(sourceURL);
if (entry === undefined) {
for (const value of getCjsSourceMapCache()) {
const filename = ObjectGetValueSafe(value, 'filename');
const cachedSourceURL = ObjectGetValueSafe(value, 'sourceURL');
const filename = value.filename;
const cachedSourceURL = value.sourceURL;
if (sourceURL === filename || sourceURL === cachedSourceURL) {
entry = value;
}
Expand All @@ -330,9 +320,9 @@ function findSourceMap(sourceURL) {
if (entry === undefined) {
return undefined;
}
let sourceMap = ObjectGetValueSafe(entry, 'sourceMap');
let sourceMap = entry.sourceMap;
if (sourceMap === undefined) {
sourceMap = new SourceMap(ObjectGetValueSafe(entry, 'data'));
sourceMap = new SourceMap(entry.data);
entry.sourceMap = sourceMap;
}
return sourceMap;
Expand Down

0 comments on commit b966ef9

Please sign in to comment.