]> khamidou — GitHub mirrors - electron.git/commitdiff
common: export hideInternalModules
authorRobo <hop2deep@gmail.com>
Wed, 27 Jan 2016 08:44:10 +0000 (14:14 +0530)
committerRobo <hop2deep@gmail.com>
Wed, 27 Jan 2016 13:14:47 +0000 (18:44 +0530)
atom/common/api/lib/exports/electron.js
script/test.py
spec/api-app-spec.js

index 5b93d286da615c335922ccbf35455e1516ef3307..6811e73a10b6a8f93431106909ed1a1800d1dbe7 100644 (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: {
index 7f75d3113d69c1a200e642543bac21892970a76e..28aeac9dc1ff012301f271fd7831223c13598b86 100755 (executable)
@@ -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'
index dafaf44a2d15f5be45681ef846fde42fb391213e..0019ec59d5f067a5797b6732099720c8b8dd4353 100644 (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() {