Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf_hooks: use spec-compliant structuredClone #40904

Merged
merged 1 commit into from Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/perf/usertiming.js
Expand Up @@ -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();

Expand Down
16 changes: 0 additions & 16 deletions lib/internal/util.js
Expand Up @@ -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,
Expand All @@ -515,7 +500,6 @@ module.exports = {
promisify,
sleep,
spliceOne,
structuredClone,
toUSVString,
removeColors,

Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-perf-hooks-usertiming.js
Expand Up @@ -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();
Expand Down