[Pkg-javascript-commits] [node-q] 01/04: Imported Upstream version 1.4.1

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Sun May 17 10:45:29 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository node-q.

commit 4fa29182940e0486db4854d5fc57b53d2397095a
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Sun May 17 12:31:21 2015 +0200

    Imported Upstream version 1.4.1
---
 .gitignore     |  4 +---
 CHANGES.md     | 12 +++++++++++-
 package.json   |  2 +-
 q.js           | 22 ++++++++++++++++++++--
 spec/q-spec.js | 30 ++++++++++++++++++++++++++++++
 5 files changed, 63 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore
index 4c44b4e..4aca249 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,9 +5,7 @@ README.html
 .tmp
 q.min.js
 
-.coverage_data/
-.coverage_debug/
-cover_html/
+coverage/
 
 # IntelliJ IDEA project files
 .idea
diff --git a/CHANGES.md b/CHANGES.md
index 1fa4a01..cd351fd 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,4 +1,14 @@
-<!-- vim:ts=4:sts=4:sw=4:et:tw=70 -->
+
+## 1.4.1
+
+ - Address an issue that prevented Q from being used as a `<script>` for
+   Firefox add-ons. Q can now be used in any environment that provides `window`
+   or `self` globals, favoring `window` since add-ons have an an immutable
+   `self` that is distinct from `window`.
+
+## 1.4.0
+
+ - Add `noConflict` support for use in `<script>` (@jahnjw).
 
 ## 1.3.0
 
diff --git a/package.json b/package.json
index a5a8201..acfd182 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "q",
-  "version": "1.3.0",
+  "version": "1.4.1",
   "description": "A library for promises (CommonJS/Promises/A,B,D)",
   "homepage": "https://github.com/kriskowal/q",
   "author": "Kris Kowal <kris at cixar.com> (https://github.com/kriskowal)",
diff --git a/q.js b/q.js
index f80156a..cf5339e 100644
--- a/q.js
+++ b/q.js
@@ -55,8 +55,22 @@
         }
 
     // <script>
-    } else if (typeof self !== "undefined") {
-        self.Q = definition();
+    } else if (typeof window !== "undefined" || typeof self !== "undefined") {
+        // Prefer window over self for add-on scripts. Use self for
+        // non-windowed contexts.
+        var global = typeof window !== "undefined" ? window : self;
+
+        // Get the `window` object, save the previous Q global
+        // and initialize Q as a global.
+        var previousQ = global.Q;
+        global.Q = definition();
+
+        // Add a noConflict function so Q can be removed from the
+        // global namespace.
+        global.Q.noConflict = function () {
+            global.Q = previousQ;
+            return this;
+        };
 
     } else {
         throw new Error("This environment was not anticipated by Q. Please file a bug.");
@@ -2022,6 +2036,10 @@ Promise.prototype.nodeify = function (nodeback) {
     }
 };
 
+Q.noConflict = function() {
+    throw new Error("Q.noConflict only works when Q is used as a global");
+};
+
 // All code before this point will be filtered from stack traces.
 var qEndingLine = captureLine();
 
diff --git a/spec/q-spec.js b/spec/q-spec.js
index f1d726e..ce47ef1 100644
--- a/spec/q-spec.js
+++ b/spec/q-spec.js
@@ -2491,6 +2491,36 @@ describe("node support", function () {
 
 });
 
+describe("browser support", function () {
+    var _Q;
+
+    beforeEach(function() {
+        _Q = Q;
+    });
+
+    afterEach(function() {
+        Q = _Q;
+    });
+
+    it("sets the global Q object to its original value", function() {
+        if (typeof window !== 'undefined') {
+            // If window is not undefined, the tests are running in the browser
+            // assert that Q.noConflict returns window.Q to it's initial value
+            // In this context the original value of Q is undefined
+            Q.noConflict();
+            expect(Q).toEqual(undefined);
+        }
+    });
+
+    it("throws an error if Q.noConflict is called in node", function () {
+        if (typeof window === 'undefined') {
+            // If window is undefined the tests are being run in node, and
+            // Q.noConflict should throw an error
+            expect(Q.noConflict).toThrow();
+        }
+    });
+});
+
 describe("isPromise", function () {
     it("returns true if passed a promise", function () {
         expect(Q.isPromise(Q(10))).toBe(true);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-q.git



More information about the Pkg-javascript-commits mailing list