Skip to content

Commit a6bcc5d

Browse files
committed
common: export hideInternalModules
1 parent 2c7717d commit a6bcc5d

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

atom/common/api/lib/exports/electron.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Do not expose the internal modules to `require`.
2-
exports.hideInternalModules = function() {
2+
const hideInternalModules = function() {
33
var globalPaths = require('module').globalPaths;
44
if (globalPaths.length === 3) {
55

@@ -11,6 +11,10 @@ exports.hideInternalModules = function() {
1111
// Attaches properties to |exports|.
1212
exports.defineProperties = function(exports) {
1313
return Object.defineProperties(exports, {
14+
hideInternalModules: {
15+
enumerable: true,
16+
value: hideInternalModules
17+
},
1418

1519
// Common modules, please sort with alphabet order.
1620
clipboard: {

script/test.py

-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
def main():
1717
os.chdir(SOURCE_ROOT)
1818

19-
# Disable old APIs
20-
os.environ['ELECTRON_HIDE_INTERNAL_MODULES'] = 'true'
21-
2219
config = 'D'
2320
if len(sys.argv) == 2 and sys.argv[1] == '-R':
2421
config = 'R'

spec/api-app-spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ remote = require('electron').remote;
1010

1111
ref = remote.require('electron'), app = ref.app, BrowserWindow = ref.BrowserWindow;
1212

13+
describe('electron module', function() {
14+
it ('can prevent exposing internal modules to require', function(done) {
15+
const electron = require('electron');
16+
const clipboard = require('clipboard');
17+
assert.equal(typeof clipboard, 'object');
18+
electron.hideInternalModules();
19+
try {
20+
require('clipboard');
21+
} catch(err) {
22+
assert.equal(err.message, 'Cannot find module \'clipboard\'');
23+
done();
24+
}
25+
});
26+
});
27+
1328
describe('app module', function() {
1429
describe('app.getVersion()', function() {
1530
return it('returns the version field of package.json', function() {

0 commit comments

Comments
 (0)