Skip to content

Commit a0d4b69

Browse files
joyeecheungtargos
authored andcommittedNov 10, 2023
bootstrap: lazy-load Performance.prototype.timeOrigin
PR-URL: #46425 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 5f852cc commit a0d4b69

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed
 

‎lib/internal/perf/performance.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,24 @@ ObjectDefineProperties(Performance.prototype, {
206206
enumerable: false,
207207
value: timerify,
208208
},
209-
// This would be updated during pre-execution in case
210-
// the process is launched from a snapshot.
211-
// TODO(joyeecheung): we may want to warn about access to
212-
// this during snapshot building.
213209
timeOrigin: {
214210
__proto__: null,
215211
configurable: true,
216212
enumerable: true,
217-
value: getTimeOriginTimestamp(),
213+
get() {
214+
const value = getTimeOriginTimestamp();
215+
ObjectDefineProperty(Performance.prototype, 'timeOrigin', {
216+
__proto__: null,
217+
value,
218+
});
219+
return value;
220+
},
221+
set(value) {
222+
ObjectDefineProperty(Performance.prototype, 'timeOrigin', {
223+
__proto__: null,
224+
value,
225+
});
226+
},
218227
},
219228
toJSON: {
220229
__proto__: null,
@@ -224,15 +233,6 @@ ObjectDefineProperties(Performance.prototype, {
224233
},
225234
});
226235

227-
function refreshTimeOrigin() {
228-
ObjectDefineProperty(Performance.prototype, 'timeOrigin', {
229-
__proto__: null,
230-
configurable: true,
231-
enumerable: true,
232-
value: getTimeOriginTimestamp(),
233-
});
234-
}
235-
236236
const performance = new InternalPerformance();
237237

238238
function dispatchBufferFull(type) {
@@ -246,5 +246,4 @@ setDispatchBufferFull(dispatchBufferFull);
246246
module.exports = {
247247
Performance,
248248
performance,
249-
refreshTimeOrigin,
250249
};

‎lib/internal/process/pre_execution.js

-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ function setupTraceCategoryState() {
383383
}
384384

385385
function setupPerfHooks() {
386-
require('internal/perf/performance').refreshTimeOrigin();
387386
require('internal/perf/utils').refreshTimeOrigin();
388387
}
389388

0 commit comments

Comments
 (0)
Please sign in to comment.