electron(atom-shell)Module.require的源码在哪里?

Where is the source code for electron (atom-shell) Module.require?

我正在使用模仿 nodejs require自定义要求 函数,它工作正常。

但是,在 electron 中,我得到

SecurityError: An attempt was made to break through the security policy of the user agent.

在自定义要求的代码中调用 window.addEventListener 时。

如果我能阅读 electron 的 'require' 函数的源代码,我大概就能理解为什么我的版本失败了。

您要查找的内容应该在 GitHub 上。

https://github.com/atom/atom 要么... https://github.com/atom/electron 要么... https://github.com/atom/node

根据您的更新,您正在寻找的代码(关于共享全局上下文)实际上在这里:https://github.com/atom/node/blob/atom-iojs/lib/module.js#L399

因为 Electron 不包含 Node.js 的最新版本,我认为值得一提。

toString检查后,除了Module._contextload为真时的编译外,其他来源与nodejs相同。这部分好像优化掉了。

我的代码现在可以通过使用编译 sharing the global context 正常工作,因此表现得像来自同一来源(在 chromium 中预防 XSS)。这与电子中的 require 功能相同。