perf_hooks: use spec-compliant structuredClone

Serialize PerformanceMark's `detail` correctly.

Fixes: https://github.com/nodejs/node/issues/40840

PR-URL: https://github.com/nodejs/node/pull/40904
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Michaël Zasso
2021-11-29 13:45:46 +01:00
committed by GitHub
parent 1e8b296c58
commit 42c0b2ae65
3 changed files with 6 additions and 18 deletions

View File

@@ -26,7 +26,8 @@ const {
},
} = require('internal/errors');
const { structuredClone, lazyDOMException } = require('internal/util');
const { structuredClone } = require('internal/structured_clone');
const { lazyDOMException } = require('internal/util');
const markTimings = new SafeMap();

View File

@@ -477,21 +477,6 @@ const lazyDOMException = hideStackFrames((message, name) => {
return new _DOMException(message, name);
});
function structuredClone(value) {
const {
DefaultSerializer,
DefaultDeserializer,
} = require('v8');
const ser = new DefaultSerializer();
ser._getDataCloneError = hideStackFrames((message) =>
lazyDOMException(message, 'DataCloneError'));
ser.writeValue(value);
const serialized = ser.releaseBuffer();
const des = new DefaultDeserializer(serialized);
return des.readValue();
}
module.exports = {
assertCrypto,
cachedResult,
@@ -515,7 +500,6 @@ module.exports = {
promisify,
sleep,
spliceOne,
structuredClone,
toUSVString,
removeColors,

View File

@@ -44,12 +44,15 @@ assert.throws(() => mark(Symbol('a')), {
assert.strictEqual(m.entryType, 'mark');
assert.strictEqual(m.detail, null);
});
[1, 'any', {}, []].forEach((detail) => {
[1, 'any', {}, [], /a/].forEach((detail) => {
const m = mark('a', { detail });
assert.strictEqual(m.name, 'a');
assert.strictEqual(m.entryType, 'mark');
// Value of detail is structured cloned.
assert.deepStrictEqual(m.detail, detail);
if (typeof detail === 'object') {
assert.notStrictEqual(m.detail, detail);
}
});
clearMarks();