简体   繁体   English

Node.js 中的原始元素是什么?

[英]What are primordials in Node.js?

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 .我刚刚开始阅读 Node.js 源代码,我注意到很多东西是使用了一个叫做primordias的对象。 But I can't seem find where its definition is.但我似乎无法找到它的定义在哪里。

Eg: /node/lib/events.js例如:/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?有人可以解释什么是原始物以及它在哪里声明吗?

Some brief research revealed this github issue leading to this node source file with some enlightening comments about the purpose of primordials :一些简短的研究揭示了这个 github 问题导致了这个节点源文件,其中有一些关于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.因此,正如问题中所提到的, primordials对象旨在保证节点内置模块可以访问真正的未篡改的全局变量,而不是可能已被用户修改的全局变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM