mirror of
https://github.com/denoland/deno
synced 2024-11-05 18:45:24 +00:00
fix: "cloneValue" should return a Set when given a Set (#7972)
This commit is contained in:
parent
692322cc28
commit
27dd786016
2 changed files with 12 additions and 6 deletions
|
@ -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":
|
||||
|
|
|
@ -81,13 +81,14 @@
|
|||
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();
|
||||
const clonedSet = new Set([...value].map(cloneValue));
|
||||
objectCloneMemo.set(value, clonedSet);
|
||||
value.forEach((v, k) => clonedSet.set(k, cloneValue(v)));
|
||||
return clonedSet;
|
||||
}
|
||||
|
||||
|
@ -97,6 +98,7 @@
|
|||
for (const key of sourceKeys) {
|
||||
clonedObj[key] = cloneValue(value[key]);
|
||||
}
|
||||
Reflect.setPrototypeOf(clonedObj, Reflect.getPrototypeOf(value));
|
||||
return clonedObj;
|
||||
}
|
||||
case "symbol":
|
||||
|
|
Loading…
Reference in a new issue