mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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:
@@ -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();
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user