[Pkg-javascript-commits] [node-stream-http] 36/208: Clean up polyfill

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 13 13:39:25 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 f0b2220359ad39c663bd97bdb0053b8de9e93ea7
Author: John Hiesey <john at hiesey.com>
Date:   Tue Jul 7 21:36:10 2015 -0700

    Clean up polyfill
---
 test/browser/auth.js           |  2 +-
 test/browser/headers.js        | 13 ++++++--
 test/server/static/polyfill.js | 67 +-----------------------------------------
 3 files changed, 13 insertions(+), 69 deletions(-)

diff --git a/test/browser/auth.js b/test/browser/auth.js
index 01144da..5c73115 100644
--- a/test/browser/auth.js
+++ b/test/browser/auth.js
@@ -3,7 +3,7 @@ var test = require('tape')
 
 var http = require('../..')
 
-test('Authentication', function (t) {
+test('authentication', function (t) {
 	http.get({
 		path: '/auth',
 		auth: 'TestUser:trustno1'
diff --git a/test/browser/headers.js b/test/browser/headers.js
index c902d44..33b632b 100644
--- a/test/browser/headers.js
+++ b/test/browser/headers.js
@@ -5,6 +5,15 @@ var test = require('tape')
 
 var http = require('../..')
 
+function indexOf (arr, item) {
+	var len = arr.length
+	for (var i = 0; i < len; i++) {
+		if (arr[i] === item)
+			return i
+	}
+	return -1
+}
+
 test('headers', function (t) {
 	http.get({
 		path: '/testHeaders?Response-Header=bar&Response-Header-2=BAR2',
@@ -19,10 +28,10 @@ test('headers', function (t) {
 			if (lowerKey.indexOf('test-') === 0)
 				rawHeaders.push(lowerKey, res.rawHeaders[i + 1])
 		}
-		var header1Pos = rawHeaders.indexOf('test-response-header')
+		var header1Pos = indexOf(rawHeaders, 'test-response-header')
 		t.ok(header1Pos >= 0, 'raw response header 1 present')
 		t.equal(rawHeaders[header1Pos + 1], 'bar', 'raw response header value 1')
-		var header2Pos = rawHeaders.indexOf('test-response-header-2')
+		var header2Pos = indexOf(rawHeaders, 'test-response-header-2')
 		t.ok(header2Pos >= 0, 'raw response header 2 present')
 		t.equal(rawHeaders[header2Pos + 1], 'BAR2', 'raw response header value 2')
 		t.equal(rawHeaders.length, 4, 'correct number of raw headers')
diff --git a/test/server/static/polyfill.js b/test/server/static/polyfill.js
index 12e50e4..da6fbe0 100644
--- a/test/server/static/polyfill.js
+++ b/test/server/static/polyfill.js
@@ -1,3 +1,4 @@
+// TODO: send a PR to url to remove .trim() so this isn't necessary
 if (!String.prototype.trim) {
   (function() {
     // Make sure we trim BOM and NBSP
@@ -7,69 +8,3 @@ if (!String.prototype.trim) {
     };
   })();
 }
-
-// Production steps of ECMA-262, Edition 5, 15.4.4.14
-// Reference: http://es5.github.io/#x15.4.4.14
-if (!Array.prototype.indexOf) {
-  Array.prototype.indexOf = function(searchElement, fromIndex) {
-
-    var k;
-
-    // 1. Let O be the result of calling ToObject passing
-    //    the this value as the argument.
-    if (this == null) {
-      throw new TypeError('"this" is null or not defined');
-    }
-
-    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 len is 0, return -1.
-    if (len === 0) {
-      return -1;
-    }
-
-    // 5. If argument fromIndex was passed let n be
-    //    ToInteger(fromIndex); else let n be 0.
-    var n = +fromIndex || 0;
-
-    if (Math.abs(n) === Infinity) {
-      n = 0;
-    }
-
-    // 6. If n >= len, return -1.
-    if (n >= len) {
-      return -1;
-    }
-
-    // 7. If n >= 0, then Let k be n.
-    // 8. Else, n<0, Let k be len - abs(n).
-    //    If k is less than 0, then let k be 0.
-    k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
-
-    // 9. Repeat, while k < len
-    while (k < len) {
-      // 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
-      //    i.  Let elementK be the result of calling the Get
-      //        internal method of O with the argument ToString(k).
-      //   ii.  Let same be the result of applying the
-      //        Strict Equality Comparison Algorithm to
-      //        searchElement and elementK.
-      //  iii.  If same is true, return k.
-      if (k in O && O[k] === searchElement) {
-        return k;
-      }
-      k++;
-    }
-    return -1;
-  };
-}

-- 
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