summaryrefslogtreecommitdiff
path: root/cli/rt/01_web_util.js
diff options
context:
space:
mode:
authorAnonymous <65428781+00ff0000red@users.noreply.github.com>2020-11-21 08:29:18 -0800
committerGitHub <noreply@github.com>2020-11-21 17:29:18 +0100
commit27dd78601669a92d0200ad197adcf0919fdc9e46 (patch)
treed58ad7dadc8ea39d3ececb64c64a57026320c92b /cli/rt/01_web_util.js
parent692322cc2818a7ee573aecff98f2e0f08972b389 (diff)
fix: "cloneValue" should return a Set when given a Set (#7972)
Diffstat (limited to 'cli/rt/01_web_util.js')
-rw-r--r--cli/rt/01_web_util.js10
1 files changed, 7 insertions, 3 deletions
diff --git a/cli/rt/01_web_util.js b/cli/rt/01_web_util.js
index c843ac086..3076993ff 100644
--- a/cli/rt/01_web_util.js
+++ b/cli/rt/01_web_util.js
@@ -88,22 +88,26 @@
if (value instanceof Map) {
const clonedMap = new Map();
objectCloneMemo.set(value, clonedMap);
- value.forEach((v, k) => clonedMap.set(k, cloneValue(v)));
+ value.forEach((v, k) => {
+ clonedMap.set(cloneValue(k), cloneValue(v));
+ });
return clonedMap;
}
if (value instanceof Set) {
- const clonedSet = new Map();
+ // assumes that cloneValue still takes only one argument
+ const clonedSet = new Set([...value].map(cloneValue));
objectCloneMemo.set(value, clonedSet);
- value.forEach((v, k) => clonedSet.set(k, cloneValue(v)));
return clonedSet;
}
+ // default for objects
const clonedObj = {};
objectCloneMemo.set(value, clonedObj);
const sourceKeys = Object.getOwnPropertyNames(value);
for (const key of sourceKeys) {
clonedObj[key] = cloneValue(value[key]);
}
+ Reflect.setPrototypeOf(clonedObj, Reflect.getPrototypeOf(value));
return clonedObj;
}
case "symbol":