mirror of
https://github.com/nodejs/node.git
synced 2024-11-29 23:16:30 +01:00
c8a389e19f
This follows the EPS an allows the node CLI to have ESM as an entry point. `node ./example.mjs`. A newer V8 is needed for `import()` so that is not included. `import.meta` is still in specification stage so that also is not included. PR-URL: https://github.com/nodejs/node/pull/14369 Author: Bradley Farias <bradley.meck@gmail.com> Author: Guy Bedford <guybedford@gmail.com> Author: Jan Krems <jan.krems@groupon.com> Author: Timothy Gu <timothygu99@gmail.com> Author: Michaël Zasso <targos@protonmail.com> Author: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
27 lines
798 B
JavaScript
27 lines
798 B
JavaScript
'use strict';
|
|
|
|
const copyProps = (unsafe, safe) => {
|
|
for (const key of [...Object.getOwnPropertyNames(unsafe),
|
|
...Object.getOwnPropertySymbols(unsafe)
|
|
]) {
|
|
if (!Object.getOwnPropertyDescriptor(safe, key)) {
|
|
Object.defineProperty(
|
|
safe,
|
|
key,
|
|
Object.getOwnPropertyDescriptor(unsafe, key));
|
|
}
|
|
}
|
|
};
|
|
const makeSafe = (unsafe, safe) => {
|
|
copyProps(unsafe.prototype, safe.prototype);
|
|
copyProps(unsafe, safe);
|
|
Object.setPrototypeOf(safe.prototype, null);
|
|
Object.freeze(safe.prototype);
|
|
Object.freeze(safe);
|
|
return safe;
|
|
};
|
|
|
|
exports.SafeMap = makeSafe(Map, class SafeMap extends Map {});
|
|
exports.SafeSet = makeSafe(Set, class SafeSet extends Set {});
|
|
exports.SafePromise = makeSafe(Promise, class SafePromise extends Promise {});
|