Skip to content

Commit

Permalink
bootstrap: lazy-load Performance.prototype.timeOrigin
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
joyeecheung authored and targos committed Nov 10, 2023
1 parent 5f852cc commit a0d4b69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
29 changes: 14 additions & 15 deletions lib/internal/perf/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -246,5 +246,4 @@ setDispatchBufferFull(dispatchBufferFull);
module.exports = {
Performance,
performance,
refreshTimeOrigin,
};
1 change: 0 additions & 1 deletion lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ function setupTraceCategoryState() {
}

function setupPerfHooks() {
require('internal/perf/performance').refreshTimeOrigin();
require('internal/perf/utils').refreshTimeOrigin();
}

Expand Down

0 comments on commit a0d4b69

Please sign in to comment.