2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2022-08-20 11:31:33 -04:00
|
|
|
|
|
|
|
// deno-lint-ignore-file
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
const primordials = globalThis.__bootstrap.primordials;
|
|
|
|
const {
|
|
|
|
ArrayPrototypeFilter,
|
|
|
|
Proxy,
|
|
|
|
ReflectDefineProperty,
|
2023-02-08 19:11:12 -05:00
|
|
|
ReflectDeleteProperty,
|
|
|
|
ReflectGet,
|
2023-02-07 14:22:46 -05:00
|
|
|
ReflectGetOwnPropertyDescriptor,
|
2023-02-08 19:11:12 -05:00
|
|
|
ReflectHas,
|
2023-02-07 14:22:46 -05:00
|
|
|
ReflectOwnKeys,
|
2023-02-08 19:11:12 -05:00
|
|
|
ReflectSet,
|
2023-02-07 14:22:46 -05:00
|
|
|
Set,
|
|
|
|
SetPrototypeHas,
|
|
|
|
} = primordials;
|
2022-08-20 11:31:33 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
const nodeGlobals = {};
|
|
|
|
const nodeGlobalThis = new Proxy(globalThis, {
|
2023-02-08 19:11:12 -05:00
|
|
|
get(target, prop) {
|
|
|
|
if (ReflectHas(nodeGlobals, prop)) {
|
|
|
|
return ReflectGet(nodeGlobals, prop);
|
2023-02-07 14:22:46 -05:00
|
|
|
} else {
|
2023-02-08 19:11:12 -05:00
|
|
|
return ReflectGet(target, prop);
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
|
|
|
},
|
2023-02-08 19:11:12 -05:00
|
|
|
set(target, prop, value) {
|
|
|
|
if (ReflectHas(nodeGlobals, prop)) {
|
|
|
|
return ReflectSet(nodeGlobals, prop, value);
|
2023-02-07 14:22:46 -05:00
|
|
|
} else {
|
2023-02-08 19:11:12 -05:00
|
|
|
return ReflectSet(target, prop, value);
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
|
|
|
},
|
2023-02-08 19:11:12 -05:00
|
|
|
has(target, prop) {
|
|
|
|
return ReflectHas(nodeGlobals, prop) || ReflectHas(target, prop);
|
2023-02-07 14:22:46 -05:00
|
|
|
},
|
2023-02-08 19:11:12 -05:00
|
|
|
deleteProperty(target, prop) {
|
|
|
|
const nodeDeleted = ReflectDeleteProperty(nodeGlobals, prop);
|
|
|
|
const targetDeleted = ReflectDeleteProperty(target, prop);
|
|
|
|
return nodeDeleted || targetDeleted;
|
|
|
|
},
|
|
|
|
ownKeys(target) {
|
|
|
|
const targetKeys = ReflectOwnKeys(target);
|
2023-02-07 14:22:46 -05:00
|
|
|
const nodeGlobalsKeys = ReflectOwnKeys(nodeGlobals);
|
|
|
|
const nodeGlobalsKeySet = new Set(nodeGlobalsKeys);
|
|
|
|
return [
|
|
|
|
...ArrayPrototypeFilter(
|
2023-02-08 19:11:12 -05:00
|
|
|
targetKeys,
|
2023-02-07 14:22:46 -05:00
|
|
|
(k) => !SetPrototypeHas(nodeGlobalsKeySet, k),
|
|
|
|
),
|
|
|
|
...nodeGlobalsKeys,
|
|
|
|
];
|
|
|
|
},
|
2023-02-08 19:11:12 -05:00
|
|
|
defineProperty(target, prop, desc) {
|
|
|
|
if (ReflectHas(nodeGlobals, prop)) {
|
2023-02-07 14:22:46 -05:00
|
|
|
return ReflectDefineProperty(nodeGlobals, prop, desc);
|
|
|
|
} else {
|
2023-02-08 19:11:12 -05:00
|
|
|
return ReflectDefineProperty(target, prop, desc);
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
|
|
|
},
|
2023-02-08 19:11:12 -05:00
|
|
|
getOwnPropertyDescriptor(target, prop) {
|
|
|
|
if (ReflectHas(nodeGlobals, prop)) {
|
2023-02-07 14:22:46 -05:00
|
|
|
return ReflectGetOwnPropertyDescriptor(nodeGlobals, prop);
|
|
|
|
} else {
|
2023-02-08 19:11:12 -05:00
|
|
|
return ReflectGetOwnPropertyDescriptor(target, prop);
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2022-09-08 16:01:48 -04:00
|
|
|
|
2023-03-20 14:05:13 -04:00
|
|
|
export { nodeGlobals, nodeGlobalThis };
|