[gjs/wip/require: 5/7] bootstrap: Add some prep code to only import native modules once



commit af3215111ede392dc7aeb7662326884c85f3baa7
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Jun 17 16:08:54 2015 -0700

    bootstrap: Add some prep code to only import native modules once
    
    Some native modules, like byteArray, can't be loaded more than once, so
    we need to store each loaded module somewhere. Until now, we have been
    doing this using the old imports system, but now that we're about to rip
    it out, let's add a quick Object that stores each module.

 modules/bootstrap.js |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/modules/bootstrap.js b/modules/bootstrap.js
index cfca99b..3f1ee3d 100644
--- a/modules/bootstrap.js
+++ b/modules/bootstrap.js
@@ -1,14 +1,21 @@
-(function(exports, importNativeModule) {
+(function(exports, _importNativeModule) {
     "use strict";
 
-    const Importer = importNativeModule('_importer');
-
     let _exports = {};
 
     // This is where "unknown namespace" classes live, where we don't
     // have info for them. One common example is GLocalFile.
     _exports['gi/__gjsPrivateNS'] = {};
 
+    function importNativeModule(moduleID) {
+        if (!_exports[moduleID])
+            _exports[moduleID] = _importNativeModule(moduleID);
+
+        return _exports[moduleID];
+    }
+
+    const Importer = importNativeModule('_importer');
+
     function loadNativeModule(moduleID) {
         // _exports[moduleID] = importNativeModule(moduleID);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]