[Pkg-javascript-commits] [node-stream-http] 14/208: Use only features supported in ie8

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 13 13:39:23 UTC 2017


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

rouca pushed a commit to branch master
in repository node-stream-http.

commit ca29b49a8af7a41d0612ad98474258b4df5b5cfd
Author: John Hiesey <john at hiesey.com>
Date:   Thu Jul 2 16:11:33 2015 -0700

    Use only features supported in ie8
---
 lib/request.js                 |   8 ++--
 lib/response.js                |   3 +-
 package.json                   |   2 +
 test/server/static/polyfill.js | 101 -----------------------------------------
 4 files changed, 9 insertions(+), 105 deletions(-)

diff --git a/lib/request.js b/lib/request.js
index 71c6632..fcdac1c 100644
--- a/lib/request.js
+++ b/lib/request.js
@@ -1,5 +1,7 @@
 // var Base64 = require('Base64')
 var capability = require('./capability')
+var foreach = require('foreach')
+var keys = require('object-keys')
 var response = require('./response')
 var stream = require('stream')
 var util = require('util')
@@ -39,7 +41,7 @@ var ClientRequest = module.exports = function (opts) {
 	self._opts = opts
 	self._body = []
 	self._fullHeaders = {}
-	Object.keys(opts.headers).forEach(function (name) {
+	foreach(keys(opts.headers), function (name) {
 		self.setHeader(name, opts.headers[name])
 	})
 
@@ -111,7 +113,7 @@ ClientRequest.prototype._onFinish = function () {
 	}
 
 	if (self._mode === 'fetch') {
-		var headers = Object.keys(fullHeaders).map(function (name) {
+		var headers = keys(fullHeaders).map(function (name) {
 			return [name, fullHeaders[name]]
 		})
 
@@ -139,7 +141,7 @@ ClientRequest.prototype._onFinish = function () {
 		if (self._mode === 'text' && 'overrideMimeType' in xhr)
 			xhr.overrideMimeType('text/plain; charset=x-user-defined')
 
-		Object.keys(fullHeaders, function (name) {
+		keys(fullHeaders, function (name) {
 			xhr.setRequestHeader(name, headers[name])
 		})
 
diff --git a/lib/response.js b/lib/response.js
index d4d3552..02011dd 100644
--- a/lib/response.js
+++ b/lib/response.js
@@ -1,3 +1,4 @@
+var foreach = require('foreach')
 var stream = require('stream')
 var util = require('util')
 
@@ -53,7 +54,7 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode) {
 		self.statusCode = xhr.status
 		self.statusMessage = xhr.statusText
 		var headers = xhr.getAllResponseHeaders().split(/\r?\n/)
-		headers.forEach(function (header) {
+		foreach(headers, function (header) {
 			var matches = header.match(/^([^:]+):\s*(.*)/)
 			if (matches) {
 				var key = matches[1].toLowerCase()
diff --git a/package.json b/package.json
index 2372da9..12b6fda 100644
--- a/package.json
+++ b/package.json
@@ -15,6 +15,8 @@
   "author": "John Hiesey",
   "license": "MIT",
   "dependencies": {
+    "foreach": "^2.0.5",
+    "object-keys": "^1.0.4"
   },
   "devDependencies": {
     "brfs": "^1.4.0",
diff --git a/test/server/static/polyfill.js b/test/server/static/polyfill.js
index a02b56a..f6a1a9d 100644
--- a/test/server/static/polyfill.js
+++ b/test/server/static/polyfill.js
@@ -1,104 +1,3 @@
-// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
-if (!Object.keys) {
-  Object.keys = (function() {
-    'use strict';
-    var hasOwnProperty = Object.prototype.hasOwnProperty,
-        hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'),
-        dontEnums = [
-          'toString',
-          'toLocaleString',
-          'valueOf',
-          'hasOwnProperty',
-          'isPrototypeOf',
-          'propertyIsEnumerable',
-          'constructor'
-        ],
-        dontEnumsLength = dontEnums.length;
-
-    return function(obj) {
-      if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
-        throw new TypeError('Object.keys called on non-object');
-      }
-
-      var result = [], prop, i;
-
-      for (prop in obj) {
-        if (hasOwnProperty.call(obj, prop)) {
-          result.push(prop);
-        }
-      }
-
-      if (hasDontEnumBug) {
-        for (i = 0; i < dontEnumsLength; i++) {
-          if (hasOwnProperty.call(obj, dontEnums[i])) {
-            result.push(dontEnums[i]);
-          }
-        }
-      }
-      return result;
-    };
-  }());
-}
-
-// Production steps of ECMA-262, Edition 5, 15.4.4.18
-// Reference: http://es5.github.io/#x15.4.4.18
-if (!Array.prototype.forEach) {
-
-  Array.prototype.forEach = function(callback, thisArg) {
-
-    var T, k;
-
-    if (this == null) {
-      throw new TypeError(' this is null or not defined');
-    }
-
-    // 1. Let O be the result of calling ToObject passing the |this| value as the argument.
-    var O = Object(this);
-
-    // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
-    // 3. Let len be ToUint32(lenValue).
-    var len = O.length >>> 0;
-
-    // 4. If IsCallable(callback) is false, throw a TypeError exception.
-    // See: http://es5.github.com/#x9.11
-    if (typeof callback !== "function") {
-      throw new TypeError(callback + ' is not a function');
-    }
-
-    // 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
-    if (arguments.length > 1) {
-      T = thisArg;
-    }
-
-    // 6. Let k be 0
-    k = 0;
-
-    // 7. Repeat, while k < len
-    while (k < len) {
-
-      var kValue;
-
-      // a. Let Pk be ToString(k).
-      //   This is implicit for LHS operands of the in operator
-      // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
-      //   This step can be combined with c
-      // c. If kPresent is true, then
-      if (k in O) {
-
-        // i. Let kValue be the result of calling the Get internal method of O with argument Pk.
-        kValue = O[k];
-
-        // ii. Call the Call internal method of callback with T as the this value and
-        // argument list containing kValue, k, and O.
-        callback.call(T, kValue, k, O);
-      }
-      // d. Increase k by 1.
-      k++;
-    }
-    // 8. return undefined
-  };
-}
-
 if (!String.prototype.trim) {
   (function() {
     // Make sure we trim BOM and NBSP

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



More information about the Pkg-javascript-commits mailing list