From 20b4d24ae9db95dfb8073090ca0ff572868ea5a0 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Thu, 16 May 2024 15:52:13 -0400 Subject: [PATCH] fixup! feat(scripts): Add esbench --- scripts/esbench.mjs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/esbench.mjs b/scripts/esbench.mjs index eb1ea8838d..234bba2ed8 100755 --- a/scripts/esbench.mjs +++ b/scripts/esbench.mjs @@ -190,13 +190,16 @@ const spawnKit = async ([cmd, ...args], { input, ...options } = {}) => { }; const toSource = (value, space) => + // Rely on JSON.stringify, but replace `"__proto__"` property names + // with computed equivalent `["__proto__"]` and make all objects + // null-prototype (ensuring that absent fields are undefined). JSON.stringify(value, undefined, space) - // Escape "{" in strings, replace "__proto__" with a computed property, - // and make all objects null-prototype (ensuring that absent fields are - // undefined). + // Escape "{" in strings to avoid confusing later replacements. .replaceAll(/"(\\.|[^\\"])*"/gs, s => s.replaceAll('{', '\\x7B')) .replaceAll('"__proto__":', '["__proto__"]:') - .replaceAll('{', '{__proto__: null,'); + .replaceAll('{', '{__proto__: null,') + // Restore "{". + .replaceAll(/\\x7B|\\./gs, s => (s === '\\x7B' ? '{' : s)); const { makeSimpleError, raiseError } = (() => { const simpleErrors = new WeakSet();