Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2022-02-17 18:15:40 +0300
committerJoyee Cheung <joyeec9h3@gmail.com>2022-03-23 15:07:56 +0300
commitc37fdacb348fa8f735f0c01fdfb0eefe6152dd34 (patch)
treea88081563b8b9f82b9921d947518ad9d40d687ee /lib
parentea0668a27e2d89dd7924d577b6bcf3f87ed3d986 (diff)
lib: use class fields in observe.js
https://bugs.chromium.org/p/v8/issues/detail?id=10704 is already fixed, so switch back to class fields instead of using symbol properties. PR-URL: https://github.com/nodejs/node/pull/42361 Refs: https://github.com/nodejs/node/commit/b1c3909bd766327a569c2e4279a4670454f3f9db Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Mestery <mestery@protonmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/perf/observe.js75
1 files changed, 36 insertions, 39 deletions
diff --git a/lib/internal/perf/observe.js b/lib/internal/perf/observe.js
index 2f9506ed28e..ca9e68a9625 100644
--- a/lib/internal/perf/observe.js
+++ b/lib/internal/perf/observe.js
@@ -61,13 +61,9 @@ const {
const { inspect } = require('util');
-const kBuffer = Symbol('kBuffer');
-const kCallback = Symbol('kCallback');
const kDispatch = Symbol('kDispatch');
-const kEntryTypes = Symbol('kEntryTypes');
const kMaybeBuffer = Symbol('kMaybeBuffer');
const kDeprecatedFields = Symbol('kDeprecatedFields');
-const kType = Symbol('kType');
const kDeprecationMessage =
'Custom PerformanceEntry accessors are deprecated. ' +
@@ -151,20 +147,22 @@ function maybeIncrementObserverCount(type) {
}
class PerformanceObserverEntryList {
+ #buffer = [];
+
constructor(entries) {
- this[kBuffer] = ArrayPrototypeSort(entries, (first, second) => {
+ this.#buffer = ArrayPrototypeSort(entries, (first, second) => {
return first.startTime - second.startTime;
});
}
getEntries() {
- return ArrayPrototypeSlice(this[kBuffer]);
+ return ArrayPrototypeSlice(this.#buffer);
}
getEntriesByType(type) {
type = `${type}`;
return ArrayPrototypeFilter(
- this[kBuffer],
+ this.#buffer,
(entry) => entry.entryType === type);
}
@@ -172,11 +170,11 @@ class PerformanceObserverEntryList {
name = `${name}`;
if (type != null /** not nullish */) {
return ArrayPrototypeFilter(
- this[kBuffer],
+ this.#buffer,
(entry) => entry.name === name && entry.entryType === type);
}
return ArrayPrototypeFilter(
- this[kBuffer],
+ this.#buffer,
(entry) => entry.name === name);
}
@@ -188,20 +186,19 @@ class PerformanceObserverEntryList {
depth: options.depth == null ? null : options.depth - 1
};
- return `PerformanceObserverEntryList ${inspect(this[kBuffer], opts)}`;
+ return `PerformanceObserverEntryList ${inspect(this.#buffer, opts)}`;
}
}
class PerformanceObserver {
+ #buffer = [];
+ #entryTypes = new SafeSet();
+ #type;
+ #callback;
+
constructor(callback) {
- // TODO(joyeecheung): V8 snapshot does not support instance member
- // initializers for now:
- // https://bugs.chromium.org/p/v8/issues/detail?id=10704
- this[kBuffer] = [];
- this[kEntryTypes] = new SafeSet();
- this[kType] = undefined;
validateFunction(callback, 'callback');
- this[kCallback] = callback;
+ this.#callback = callback;
}
observe(options = {}) {
@@ -219,10 +216,10 @@ class PerformanceObserver {
'options.entryTypes can not set with ' +
'options.type together');
- switch (this[kType]) {
+ switch (this.#type) {
case undefined:
- if (entryTypes !== undefined) this[kType] = kTypeMultiple;
- if (type !== undefined) this[kType] = kTypeSingle;
+ if (entryTypes !== undefined) this.#type = kTypeMultiple;
+ if (type !== undefined) this.#type = kTypeSingle;
break;
case kTypeSingle:
if (entryTypes !== undefined)
@@ -238,53 +235,53 @@ class PerformanceObserver {
break;
}
- if (this[kType] === kTypeMultiple) {
+ if (this.#type === kTypeMultiple) {
if (!ArrayIsArray(entryTypes)) {
throw new ERR_INVALID_ARG_TYPE(
'options.entryTypes',
'string[]',
entryTypes);
}
- maybeDecrementObserverCounts(this[kEntryTypes]);
- this[kEntryTypes].clear();
+ maybeDecrementObserverCounts(this.#entryTypes);
+ this.#entryTypes.clear();
for (let n = 0; n < entryTypes.length; n++) {
if (ArrayPrototypeIncludes(kSupportedEntryTypes, entryTypes[n])) {
- this[kEntryTypes].add(entryTypes[n]);
+ this.#entryTypes.add(entryTypes[n]);
maybeIncrementObserverCount(entryTypes[n]);
}
}
} else {
if (!ArrayPrototypeIncludes(kSupportedEntryTypes, type))
return;
- this[kEntryTypes].add(type);
+ this.#entryTypes.add(type);
maybeIncrementObserverCount(type);
if (buffered) {
const entries = filterBufferMapByNameAndType(undefined, type);
- ArrayPrototypePushApply(this[kBuffer], entries);
+ ArrayPrototypePushApply(this.#buffer, entries);
kPending.add(this);
if (kPending.size)
queuePending();
}
}
- if (this[kEntryTypes].size)
+ if (this.#entryTypes.size)
kObservers.add(this);
else
this.disconnect();
}
disconnect() {
- maybeDecrementObserverCounts(this[kEntryTypes]);
+ maybeDecrementObserverCounts(this.#entryTypes);
kObservers.delete(this);
kPending.delete(this);
- this[kBuffer] = [];
- this[kEntryTypes].clear();
- this[kType] = undefined;
+ this.#buffer = [];
+ this.#entryTypes.clear();
+ this.#type = undefined;
}
takeRecords() {
- const list = this[kBuffer];
- this[kBuffer] = [];
+ const list = this.#buffer;
+ this.#buffer = [];
return list;
}
@@ -293,17 +290,17 @@ class PerformanceObserver {
}
[kMaybeBuffer](entry) {
- if (!this[kEntryTypes].has(entry.entryType))
+ if (!this.#entryTypes.has(entry.entryType))
return;
- ArrayPrototypePush(this[kBuffer], entry);
+ ArrayPrototypePush(this.#buffer, entry);
kPending.add(this);
if (kPending.size)
queuePending();
}
[kDispatch]() {
- this[kCallback](new PerformanceObserverEntryList(this.takeRecords()),
- this);
+ this.#callback(new PerformanceObserverEntryList(this.takeRecords()),
+ this);
}
[kInspect](depth, options) {
@@ -317,8 +314,8 @@ class PerformanceObserver {
return `PerformanceObserver ${inspect({
connected: kObservers.has(this),
pending: kPending.has(this),
- entryTypes: ArrayFrom(this[kEntryTypes]),
- buffer: this[kBuffer],
+ entryTypes: ArrayFrom(this.#entryTypes),
+ buffer: this.#buffer,
}, opts)}`;
}
}