Merge pull request #4247 from deepak1556/common_exports_patch
common: export hideInternalModules
This commit is contained in:
commit
e9d00b1fc0
3 changed files with 20 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
// Do not expose the internal modules to `require`.
|
// Do not expose the internal modules to `require`.
|
||||||
exports.hideInternalModules = function() {
|
const hideInternalModules = function() {
|
||||||
var globalPaths = require('module').globalPaths;
|
var globalPaths = require('module').globalPaths;
|
||||||
if (globalPaths.length === 3) {
|
if (globalPaths.length === 3) {
|
||||||
|
|
||||||
|
@ -11,6 +11,10 @@ exports.hideInternalModules = function() {
|
||||||
// Attaches properties to |exports|.
|
// Attaches properties to |exports|.
|
||||||
exports.defineProperties = function(exports) {
|
exports.defineProperties = function(exports) {
|
||||||
return Object.defineProperties(exports, {
|
return Object.defineProperties(exports, {
|
||||||
|
hideInternalModules: {
|
||||||
|
enumerable: true,
|
||||||
|
value: hideInternalModules
|
||||||
|
},
|
||||||
|
|
||||||
// Common modules, please sort with alphabet order.
|
// Common modules, please sort with alphabet order.
|
||||||
clipboard: {
|
clipboard: {
|
||||||
|
|
|
@ -16,9 +16,6 @@ PRODUCT_NAME = atom_gyp()['product_name%']
|
||||||
def main():
|
def main():
|
||||||
os.chdir(SOURCE_ROOT)
|
os.chdir(SOURCE_ROOT)
|
||||||
|
|
||||||
# Disable old APIs
|
|
||||||
os.environ['ELECTRON_HIDE_INTERNAL_MODULES'] = 'true'
|
|
||||||
|
|
||||||
config = 'D'
|
config = 'D'
|
||||||
if len(sys.argv) == 2 and sys.argv[1] == '-R':
|
if len(sys.argv) == 2 and sys.argv[1] == '-R':
|
||||||
config = 'R'
|
config = 'R'
|
||||||
|
|
|
@ -10,6 +10,21 @@ remote = require('electron').remote;
|
||||||
|
|
||||||
ref = remote.require('electron'), app = ref.app, BrowserWindow = ref.BrowserWindow;
|
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 module', function() {
|
||||||
describe('app.getVersion()', function() {
|
describe('app.getVersion()', function() {
|
||||||
return it('returns the version field of package.json', function() {
|
return it('returns the version field of package.json', function() {
|
||||||
|
|
Loading…
Reference in a new issue