incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject js commit: Revert "Make circular require()'s and exception."
Date Fri, 31 Aug 2012 20:23:04 GMT
Updated Branches:
  refs/heads/master 1a7a0b81f -> 2aa46aa0e
Updated Tags:  refs/tags/2.1.0rc2 1a7a0b81f -> 2aa46aa0e


Revert "Make circular require()'s and exception."

This reverts commit 775c526a34c8de969e8ae82026584950874689d7.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/2aa46aa0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/2aa46aa0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/2aa46aa0

Branch: refs/heads/master
Commit: 2aa46aa0eef2ba641cf91793735152d7fb5b6998
Parents: 1a7a0b8
Author: Fil Maj <maj.fil@gmail.com>
Authored: Fri Aug 31 13:21:26 2012 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Fri Aug 31 13:21:26 2012 -0700

----------------------------------------------------------------------
 lib/scripts/require.js |   21 ++-------------------
 test/test.require.js   |   32 --------------------------------
 2 files changed, 2 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/2aa46aa0/lib/scripts/require.js
----------------------------------------------------------------------
diff --git a/lib/scripts/require.js b/lib/scripts/require.js
index 9736dad..5ae09e2 100644
--- a/lib/scripts/require.js
+++ b/lib/scripts/require.js
@@ -3,10 +3,6 @@ var require,
 
 (function () {
     var modules = {};
-    // Stack of moduleIds currently being built.
-    var requireStack = [];
-    // Map of module ID -> index into requireStack of modules currently being built.
-    var inProgressModules = {};
 
     function build(module) {
         var factory = module.factory;
@@ -19,21 +15,8 @@ var require,
     require = function (id) {
         if (!modules[id]) {
             throw "module " + id + " not found";
-        } else if (id in inProgressModules) {
-            var cycle = requireStack.slice(inProgressModules[id]).join('->') + '->'
+ id;
-            throw "Cycle in require graph: " + cycle;
         }
-        if (modules[id].factory) {
-            try {
-                inProgressModules[id] = requireStack.length;
-                requireStack.push(id);
-                return build(modules[id]);
-            } finally {
-                delete inProgressModules[id];
-                requireStack.pop();
-            }
-        }
-        return modules[id].exports;
+        return modules[id].factory ? build(modules[id]) : modules[id].exports;
     };
 
     define = function (id, factory) {
@@ -57,4 +40,4 @@ var require,
 if (typeof module === "object" && typeof require === "function") {
     module.exports.require = require;
     module.exports.define = define;
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/2aa46aa0/test/test.require.js
----------------------------------------------------------------------
diff --git a/test/test.require.js b/test/test.require.js
index 566ae05..b79dec4 100644
--- a/test/test.require.js
+++ b/test/test.require.js
@@ -35,38 +35,6 @@ describe("require + define", function () {
             }).toThrow("module your mom not found");
         });
 
-        it("throws an exception when modules depend on each other", function () {
-            define("ModuleA", function(require, exports, module) {
-                require("ModuleB");
-            });
-            define("ModuleB", function(require, exports, module) {
-                require("ModuleA");
-            });
-            expect(function () {
-                require("ModuleA");
-            }).toThrow("Cycle in require graph: ModuleA->ModuleB->ModuleA");
-            define.remove("ModuleA");
-            define.remove("ModuleB");
-        });
-
-        it("throws an exception when a cycle of requires occurs", function () {
-            define("ModuleA", function(require, exports, module) {
-                require("ModuleB");
-            });
-            define("ModuleB", function(require, exports, module) {
-                require("ModuleC");
-            });
-            define("ModuleC", function(require, exports, module) {
-                require("ModuleA");
-            });
-            expect(function () {
-                require("ModuleA");
-            }).toThrow("Cycle in require graph: ModuleA->ModuleB->ModuleC->ModuleA");
-            define.remove("ModuleA");
-            define.remove("ModuleB");
-            define.remove("ModuleC");
-        });
-
         it("calls the factory method when requiring", function () {
             var factory = jasmine.createSpy();
             define("dino", factory);


Mime
View raw message