From 1ca8daf1db91624542fa5ca40bc201ac43c0f24b Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Fri, 1 Oct 2021 11:54:47 +0200 Subject: [PATCH] fast path on core.isProxy() check --- ext/webidl/00_webidl.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js index 927fb34fd08ecc..a2eaed1e2d7be7 100644 --- a/ext/webidl/00_webidl.js +++ b/ext/webidl/00_webidl.js @@ -9,6 +9,7 @@ "use strict"; ((window) => { + const core = window.Deno.core; const { ArrayBuffer, ArrayBufferIsView, @@ -846,14 +847,29 @@ ); } const result = {}; - for (const key in V) { - if (!ObjectPrototypeHasOwnProperty(V, key)) { - continue; + const isProxy = core.isProxy(V); + if (isProxy) { + const keys = ReflectOwnKeys(V); + for (const key of keys) { + const desc = ObjectGetOwnPropertyDescriptor(V, key); + if (desc !== undefined && desc.enumerable === true) { + const typedKey = keyConverter(key, opts); + const value = V[key]; + const typedValue = valueConverter(value, opts); + result[typedKey] = typedValue; + } + } + } else { + // Fast path for common case (not a Proxy) + for (const key in V) { + if (!ObjectPrototypeHasOwnProperty(V, key)) { + continue; + } + const typedKey = keyConverter(key, opts); + const value = V[key]; + const typedValue = valueConverter(value, opts); + result[typedKey] = typedValue; } - const typedKey = keyConverter(key, opts); - const value = V[key]; - const typedValue = valueConverter(value, opts); - result[typedKey] = typedValue; } return result; };