[Pkg-javascript-commits] [node-sha.js] 144/237: Fall back to normal array if no typed arrays

Bastien Roucariès rouca at moszumanska.debian.org
Fri May 5 09:03:48 UTC 2017


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

rouca pushed a commit to branch master
in repository node-sha.js.

commit 8ca8dfc025e5b2de4a126235b2f3eb4a1046b2d6
Author: Parsha Pourkhomami <parshap+git at gmail.com>
Date:   Mon Sep 15 17:13:21 2014 -0700

    Fall back to normal array if no typed arrays
    
    Fixes tests in IE9.
---
 package.json  |  4 +++-
 sha1.js       |  3 ++-
 test/write.js | 15 ++++++++-------
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/package.json b/package.json
index c18eeda..0a1d395 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,9 @@
     "url": "git://github.com/dominictarr/sha.js.git"
   },
   "dependencies": {
-    "buffer": "~2.3.2"
+    "buffer": "~2.3.2",
+    "global": "^4.2.1",
+    "typedarray": "0.0.6"
   },
   "devDependencies": {
     "tape": "~2.3.2"
diff --git a/sha1.js b/sha1.js
index 2b5a09c..3516edb 100644
--- a/sha1.js
+++ b/sha1.js
@@ -9,6 +9,7 @@
 module.exports = function (Buffer, Hash) {
 
   var inherits = require('util').inherits
+  var global = require('global')
 
   inherits(Sha1, Hash)
 
@@ -21,7 +22,7 @@ module.exports = function (Buffer, Hash) {
   var BE = false
   var LE = true
 
-  var W = new Int32Array(80)
+  var W = new (global.Int32Array || Array)(80)
 
   var POOL = []
 
diff --git a/test/write.js b/test/write.js
index 4f8146a..9ac8bd3 100644
--- a/test/write.js
+++ b/test/write.js
@@ -2,9 +2,10 @@ var tape = require('tape')
 var write = require('../util').write
 var hexpp = require('../hexpp')
 var u = require('../util')
+var TA = require('typedarray')
 
 function toBuffer (string) {
-  var a = new Uint8Array(string.length)
+  var a = new TA.Uint8Array(string.length)
   for(var i = 0; i < string.length; i++)
     a[i] = string.charCodeAt(i)
   return a
@@ -13,13 +14,13 @@ function toBuffer (string) {
 var zero = '0'.charCodeAt(0)
 var A    = 'a'.charCodeAt(0)
 
-var HELLOTHERE = new Uint8Array([
+var HELLOTHERE = new TA.Uint8Array([
     104, 101, 108, 108,
     111, 32, 116, 104,
     101, 114, 101, 46
   ])
 
-var FOOBARBAZ = new Uint8Array([
+var FOOBARBAZ = new TA.Uint8Array([
     102, 111, 111,
     98, 97, 114,
     98, 97, 112
@@ -39,7 +40,7 @@ var BAZx = BAZ.toString('hex')
 
 tape('hello there, ascii', function (t) {
   var expected = HELLOTHERE
-  var actual = new Uint8Array(12)
+  var actual = new TA.Uint8Array(12)
 
   write(actual, 'hello there.', 'ascii', 0, 0, 12)
 
@@ -52,7 +53,7 @@ tape('hello there, ascii', function (t) {
 })
 
 tape('foobarbaz, ascii', function (t) {
-  var actual = new Uint8Array(9)
+  var actual = new TA.Uint8Array(9)
   var expected = FOOBARBAZ
   write(actual, 'foo', 'ascii', 0, 0, 3)
   write(actual, 'bar', 'ascii', 3, 0, 3)
@@ -71,7 +72,7 @@ function equal(t, a,b) {
 }
 
 tape('foobarbaz, ascii', function (t) {
-  var actual = new Uint8Array(9)
+  var actual = new TA.Uint8Array(9)
   var expected = FOOBARBAZ
   write(actual, FOO, null, 0, 0, 3)
   write(actual, BAR, null, 3, 0, 3)
@@ -81,7 +82,7 @@ tape('foobarbaz, ascii', function (t) {
 })
 
 tape('foobarbaz, hex', function (t) {
-  var actual = new Uint8Array(9)
+  var actual = new TA.Uint8Array(9)
   var expected = FOOBARBAZ
   write(actual, FOOx, 'hex', 0, 0, 3)
   write(actual, BARx, 'hex', 3, 0, 3)

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



More information about the Pkg-javascript-commits mailing list