+11
-7
@@ -54,7 +54,14 @@ "use strict"; | ||
| function _createXHR(options) { | ||
| var callback = options.callback | ||
| if(typeof callback === "undefined"){ | ||
| if(typeof options.callback === "undefined"){ | ||
| throw new Error("callback argument missing") | ||
| } | ||
| var called = false | ||
| var callback = function cbOnce(err, response, body){ | ||
| if(!called){ | ||
| called = true | ||
| options.callback(err, response, body) | ||
| } | ||
| } | ||
| function readystatechange() { | ||
@@ -100,4 +107,3 @@ if (xhr.readyState === 4) { | ||
| evt.statusCode = 0 | ||
| callback(evt, failureResponse) | ||
| callback = noop | ||
| return callback(evt, failureResponse) | ||
| } | ||
@@ -134,5 +140,3 @@ | ||
| } | ||
| callback(err, response, response.body) | ||
| callback = noop | ||
| return callback(err, response, response.body) | ||
| } | ||
@@ -139,0 +143,0 @@ |
+1
-1
| { | ||
| "name": "xhr", | ||
| "version": "2.2.1", | ||
| "version": "2.2.2", | ||
| "description": "small xhr abstraction", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
+16
-0
@@ -55,2 +55,18 @@ var window = require("global/window") | ||
| test("[func] Calls the callback once even if error is thrown issue #127", function(assert) { | ||
| var count = 0; | ||
| setTimeout(function(){ | ||
| assert.equal(count, 1, "expected one call") | ||
| assert.end() | ||
| },100) | ||
| try{ | ||
| xhr({ | ||
| uri: "instanterror://foo" | ||
| }, function(err, resp, body) { | ||
| count++; | ||
| throw Error("dummy error") | ||
| }) | ||
| } catch(e){} | ||
| }) | ||
| test("[func] Times out to an error ", function(assert) { | ||
@@ -57,0 +73,0 @@ xhr({ |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
26077
2.14%473
4.19%