Skip to content

Commit 009e418

Browse files
committed
perf_hooks: make PerformanceObserver an AsyncResource
PR-URL: nodejs#18789 Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 9e509b6 commit 009e418

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/perf_hooks.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const {
3636
NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END
3737
} = constants;
3838

39+
const { AsyncResource } = require('async_hooks');
3940
const L = require('internal/linkedlist');
4041
const kInspect = require('internal/util').customInspectSymbol;
4142
const { inherits } = require('util');
@@ -317,12 +318,13 @@ class PerformanceObserverEntryList {
317318
}
318319
}
319320

320-
class PerformanceObserver {
321+
class PerformanceObserver extends AsyncResource {
321322
constructor(callback) {
322323
if (typeof callback !== 'function') {
323324
const errors = lazyErrors();
324325
throw new errors.TypeError('ERR_INVALID_CALLBACK');
325326
}
327+
super('PerformanceObserver');
326328
Object.defineProperties(this, {
327329
[kTypes]: {
328330
enumerable: false,
@@ -568,7 +570,7 @@ function getObserversList(type) {
568570

569571
function doNotify() {
570572
this[kQueued] = false;
571-
this[kCallback](this[kBuffer], this);
573+
this.runInAsyncScope(this[kCallback], this, this[kBuffer], this);
572574
this[kBuffer][kEntries] = [];
573575
L.init(this[kBuffer][kEntries]);
574576
}

0 commit comments

Comments
 (0)