I've just started to read Node.js source code, and something that I notice quite a lot is the use of an object called primordials. But I can't seem find where its definition is.
E.g: /node/lib/events.js
const {
Array,
Boolean,
Error,
MathMin,
NumberIsNaN,
ObjectCreate,
ObjectDefineProperty,
ObjectGetPrototypeOf,
ObjectSetPrototypeOf,
ObjectKeys,
Promise,
PromiseReject,
PromiseResolve,
ReflectApply,
ReflectOwnKeys,
Symbol,
SymbolFor,
SymbolAsyncIterator
} = primordials;
Can someone explain what primordials are and where it is declared?
Deno is a JavaScript and TypeScript runtime similar to Node. js, built on Rust and the V8 JavaScript engine. It was created by Ryan Dahl, the original inventor of Node. js, to counter mistakes he made when he originally designed and released Node.
Some brief research revealed this github issue leading to this node source file with some enlightening comments about the purpose of primordials
:
// This file subclasses and stores the JS builtins that come from the VM
// so that Node.js's builtin modules do not need to later look these up from
// the global proxy, which can be mutated by users.
So, as mentioned in the issue, the primordials
object is meant to be a way to guarantee that node builtin modules can access the true untampered globals instead of ones which may have been modified by users.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With