[Pkg-javascript-commits] [node-stream-browserify] 24/44: expand the instance checks to use the constructor and skip the ArrayBuffer test if Uint8Array isn't defined
Bastien Roucariès
rouca at moszumanska.debian.org
Sun Aug 13 14:18:43 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-browserify.
commit 3921bf7d3bc15e20579e00ff0b7535af662ec884
Author: James Halliday <mail at substack.net>
Date: Fri Dec 20 00:49:41 2013 -0800
expand the instance checks to use the constructor and skip the ArrayBuffer test if Uint8Array isn't defined
---
test/array_buffer.js | 22 ++++++++++++----------
writable.js | 10 +++++++---
2 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/test/array_buffer.js b/test/array_buffer.js
index fc9bca8..f81d583 100644
--- a/test/array_buffer.js
+++ b/test/array_buffer.js
@@ -25,16 +25,18 @@ TestWritable.prototype._write = function(chunk, encoding, cb) {
var typedArray = new xUint8Array(1);
typedArray[0] = 88;
-test('.writable writing ArrayBuffer', function(t) {
- var writable = new TestWritable();
-
- writable.write(typedArray.buffer);
- writable.end();
-
- t.equal(writable._written.length, 1);
- t.equal(writable._written[0].toString(), 'X')
- t.end()
-});
+if (typeof Uint8array !== 'undefined') {
+ test('.writable writing ArrayBuffer', function(t) {
+ var writable = new TestWritable();
+
+ writable.write(typedArray.buffer);
+ writable.end();
+
+ t.equal(writable._written.length, 1);
+ t.equal(writable._written[0].toString(), 'X')
+ t.end()
+ });
+}
test('.writable writing Uint8array', function(t) {
var writable = new TestWritable();
diff --git a/writable.js b/writable.js
index e75ac3c..dd631e8 100644
--- a/writable.js
+++ b/writable.js
@@ -28,11 +28,15 @@ Writable.WritableState = WritableState;
var isUint8Array = typeof Uint8Array !== 'undefined'
? function (x) { return x instanceof Uint8Array }
- : function () { return false }
+ : function (x) {
+ return x && x.constructor && x.constructor.name === 'Uint8Array'
+ }
;
var isArrayBuffer = typeof ArrayBuffer !== 'undefined'
? function (x) { return x instanceof ArrayBuffer }
- : function () { return false }
+ : function () {
+ return x && x.constructor && x.constructor.name === 'ArrayBuffer'
+ }
;
var inherits = require('inherits');
@@ -178,7 +182,7 @@ Writable.prototype.write = function(chunk, encoding, cb) {
if (isUint8Array(chunk))
chunk = new Buffer(chunk);
- if (isArrayBuffer(chunk))
+ if (isArrayBuffer(chunk) && typeof Uint8Array !== 'undefined')
chunk = new Buffer(new Uint8Array(chunk));
if (Buffer.isBuffer(chunk))
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stream-browserify.git
More information about the Pkg-javascript-commits
mailing list