Skip to content

Commit

Permalink
fast path on core.isProxy() check
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronO committed Oct 1, 2021
1 parent 9c701e4 commit 1ca8daf
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions ext/webidl/00_webidl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"use strict";

((window) => {
const core = window.Deno.core;
const {
ArrayBuffer,
ArrayBufferIsView,
Expand Down Expand Up @@ -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;
};
Expand Down

0 comments on commit 1ca8daf

Please sign in to comment.