diff --git a/lib/internal/perf/performance.js b/lib/internal/perf/performance.js index 130613c5635fa4..6b619c3ecc13f7 100644 --- a/lib/internal/perf/performance.js +++ b/lib/internal/perf/performance.js @@ -206,15 +206,24 @@ ObjectDefineProperties(Performance.prototype, { enumerable: false, value: timerify, }, - // This would be updated during pre-execution in case - // the process is launched from a snapshot. - // TODO(joyeecheung): we may want to warn about access to - // this during snapshot building. timeOrigin: { __proto__: null, configurable: true, enumerable: true, - value: getTimeOriginTimestamp(), + get() { + const value = getTimeOriginTimestamp(); + ObjectDefineProperty(Performance.prototype, 'timeOrigin', { + __proto__: null, + value, + }); + return value; + }, + set(value) { + ObjectDefineProperty(Performance.prototype, 'timeOrigin', { + __proto__: null, + value, + }); + }, }, toJSON: { __proto__: null, @@ -224,15 +233,6 @@ ObjectDefineProperties(Performance.prototype, { }, }); -function refreshTimeOrigin() { - ObjectDefineProperty(Performance.prototype, 'timeOrigin', { - __proto__: null, - configurable: true, - enumerable: true, - value: getTimeOriginTimestamp(), - }); -} - const performance = new InternalPerformance(); function dispatchBufferFull(type) { @@ -246,5 +246,4 @@ setDispatchBufferFull(dispatchBufferFull); module.exports = { Performance, performance, - refreshTimeOrigin, }; diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js index b4a24bbffb6c43..776be4414900da 100644 --- a/lib/internal/process/pre_execution.js +++ b/lib/internal/process/pre_execution.js @@ -383,7 +383,6 @@ function setupTraceCategoryState() { } function setupPerfHooks() { - require('internal/perf/performance').refreshTimeOrigin(); require('internal/perf/utils').refreshTimeOrigin(); }