From b966ef9a42ad46094e4c3500cd6733d3b8b40b1c Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Mon, 30 Jan 2023 18:54:58 +0800 Subject: [PATCH] lib: remove unnecessary ObjectGetValueSafe PR-URL: https://github.com/nodejs/node/pull/46335 Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Antoine du Hamel Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- lib/internal/source_map/source_map_cache.js | 26 +++++++-------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/lib/internal/source_map/source_map_cache.js b/lib/internal/source_map/source_map_cache.js index ea8834d6a930b8..a520af68eb7efa 100644 --- a/lib/internal/source_map/source_map_cache.js +++ b/lib/internal/source_map/source_map_cache.js @@ -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) => { @@ -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, }; } } @@ -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; } @@ -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;