perf_hooks: make PerformanceObserver an AsyncResource
PR-URL: https://github.com/nodejs/node/pull/18789 Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
9e509b622b
commit
009e41826f
@ -36,6 +36,7 @@ const {
|
|||||||
NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END
|
NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END
|
||||||
} = constants;
|
} = constants;
|
||||||
|
|
||||||
|
const { AsyncResource } = require('async_hooks');
|
||||||
const L = require('internal/linkedlist');
|
const L = require('internal/linkedlist');
|
||||||
const kInspect = require('internal/util').customInspectSymbol;
|
const kInspect = require('internal/util').customInspectSymbol;
|
||||||
const { inherits } = require('util');
|
const { inherits } = require('util');
|
||||||
@ -317,12 +318,13 @@ class PerformanceObserverEntryList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PerformanceObserver {
|
class PerformanceObserver extends AsyncResource {
|
||||||
constructor(callback) {
|
constructor(callback) {
|
||||||
if (typeof callback !== 'function') {
|
if (typeof callback !== 'function') {
|
||||||
const errors = lazyErrors();
|
const errors = lazyErrors();
|
||||||
throw new errors.TypeError('ERR_INVALID_CALLBACK');
|
throw new errors.TypeError('ERR_INVALID_CALLBACK');
|
||||||
}
|
}
|
||||||
|
super('PerformanceObserver');
|
||||||
Object.defineProperties(this, {
|
Object.defineProperties(this, {
|
||||||
[kTypes]: {
|
[kTypes]: {
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
@ -568,7 +570,7 @@ function getObserversList(type) {
|
|||||||
|
|
||||||
function doNotify() {
|
function doNotify() {
|
||||||
this[kQueued] = false;
|
this[kQueued] = false;
|
||||||
this[kCallback](this[kBuffer], this);
|
this.runInAsyncScope(this[kCallback], this, this[kBuffer], this);
|
||||||
this[kBuffer][kEntries] = [];
|
this[kBuffer][kEntries] = [];
|
||||||
L.init(this[kBuffer][kEntries]);
|
L.init(this[kBuffer][kEntries]);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user