mirror of https://github.com/nodejs/node.git
use reflect functions
This commit is contained in:
parent
27b66cc891
commit
f038f19056
|
@ -48,6 +48,9 @@ const {
|
|||
ObjectSetPrototypeOf,
|
||||
Proxy,
|
||||
ReflectApply,
|
||||
ReflectDeleteProperty,
|
||||
ReflectGet,
|
||||
ReflectHas,
|
||||
ReflectSet,
|
||||
RegExpPrototypeExec,
|
||||
SafeMap,
|
||||
|
@ -321,35 +324,24 @@ let patched = false;
|
|||
/* Make Module._cache case-insensitive on Windows */
|
||||
if (isWindows) {
|
||||
/* Create a proxy handler to intercept some operations */
|
||||
const toLowerCaseIfString = (prop) => (typeof prop === 'string' ? StringPrototypeToLowerCase(prop) : prop);
|
||||
const cacheHandler = {
|
||||
__proto__: null,
|
||||
get(target, prop) {
|
||||
if (typeof prop === 'string') {
|
||||
return target[StringPrototypeToLowerCase(prop)];
|
||||
}
|
||||
return target[prop];
|
||||
|
||||
get(target, prop, receiver) {
|
||||
return ReflectGet(target, toLowerCaseIfString(prop), receiver);
|
||||
},
|
||||
set(target, prop, value) {
|
||||
if (typeof prop === 'string') {
|
||||
target[StringPrototypeToLowerCase(prop)] = value;
|
||||
} else {
|
||||
target[prop] = value;
|
||||
}
|
||||
return true;
|
||||
|
||||
set(target, prop, value, receiver) {
|
||||
return ReflectSet(target, toLowerCaseIfString(prop), value, receiver);
|
||||
},
|
||||
|
||||
deleteProperty(target, prop) {
|
||||
if (typeof prop === 'string') {
|
||||
delete target[StringPrototypeToLowerCase(prop)];
|
||||
} else {
|
||||
delete target[prop];
|
||||
}
|
||||
return true;
|
||||
return ReflectDeleteProperty(target, toLowerCaseIfString(prop));
|
||||
},
|
||||
|
||||
has(target, prop) {
|
||||
if (typeof prop === 'string') {
|
||||
return StringPrototypeToLowerCase(prop) in target;
|
||||
}
|
||||
return prop in target;
|
||||
return ReflectHas(target, toLowerCaseIfString(prop));
|
||||
},
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue