Merge pull request #4247 from deepak1556/common_exports_patch

common: export hideInternalModules
This commit is contained in:
Cheng Zhao 2016-01-27 23:20:59 +08:00
commit e9d00b1fc0
3 changed files with 20 additions and 4 deletions

View file

@ -1,5 +1,5 @@
// Do not expose the internal modules to `require`.
exports.hideInternalModules = function() {
const hideInternalModules = function() {
var globalPaths = require('module').globalPaths;
if (globalPaths.length === 3) {
@ -11,6 +11,10 @@ exports.hideInternalModules = function() {
// Attaches properties to |exports|.
exports.defineProperties = function(exports) {
return Object.defineProperties(exports, {
hideInternalModules: {
enumerable: true,
value: hideInternalModules
},
// Common modules, please sort with alphabet order.
clipboard: {

View file

@ -16,9 +16,6 @@ PRODUCT_NAME = atom_gyp()['product_name%']
def main():
os.chdir(SOURCE_ROOT)
# Disable old APIs
os.environ['ELECTRON_HIDE_INTERNAL_MODULES'] = 'true'
config = 'D'
if len(sys.argv) == 2 and sys.argv[1] == '-R':
config = 'R'

View file

@ -10,6 +10,21 @@ remote = require('electron').remote;
ref = remote.require('electron'), app = ref.app, BrowserWindow = ref.BrowserWindow;
describe('electron module', function() {
it ('can prevent exposing internal modules to require', function(done) {
const electron = require('electron');
const clipboard = require('clipboard');
assert.equal(typeof clipboard, 'object');
electron.hideInternalModules();
try {
require('clipboard');
} catch(err) {
assert.equal(err.message, 'Cannot find module \'clipboard\'');
done();
}
});
});
describe('app module', function() {
describe('app.getVersion()', function() {
return it('returns the version field of package.json', function() {