1+ 'use strict' ;
2+
3+ // compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js
4+ // original notice:
5+
6+ /*!
7+ * The buffer module from node.js, for the browser.
8+ *
9+ * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
10+ * @license MIT
11+ */
12+ function compare ( a , b ) {
13+ if ( a === b ) {
14+ return 0 ;
15+ }
16+
17+ var x = a . length ;
18+ var y = b . length ;
19+
20+ for ( var i = 0 , len = Math . min ( x , y ) ; i < len ; ++ i ) {
21+ if ( a [ i ] !== b [ i ] ) {
22+ x = a [ i ] ;
23+ y = b [ i ] ;
24+ break ;
25+ }
26+ }
27+
28+ if ( x < y ) {
29+ return - 1 ;
30+ }
31+ if ( y < x ) {
32+ return 1 ;
33+ }
34+ return 0 ;
35+ }
36+ function isBuffer ( b ) {
37+ if ( global . Buffer && typeof global . Buffer . isBuffer === 'function' ) {
38+ return global . Buffer . isBuffer ( b ) ;
39+ }
40+ return ! ! ( b != null && b . _isBuffer ) ;
41+ }
42+
43+ // based on node assert, original notice:
44+
145// http://wiki.commonjs.org/wiki/Unit_Testing/1.0
246//
347// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
2266// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2367// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2468
25- 'use strict' ;
26-
27- // UTILITY
28- function compare ( bufa , bufb ) {
29- var cmpLen = Math . min ( bufa , bufb ) ;
30- if ( cmpLen <= 0 ) {
31- return 0 ;
32- }
33- var i = - 1 ;
34- var a , b ;
35- while ( ++ i < cmpLen ) {
36- a = bufa [ i ] ;
37- b = bufb [ i ] ;
38- if ( a < b ) {
39- return - 1 ;
40- } else if ( a > b ) {
41- return 1 ;
42- }
43- }
44- return 0 ;
45- }
4669var util = require ( 'util/' ) ;
47- var Buffer = require ( 'buffer' ) . Buffer ;
48- var BufferShim = require ( 'buffer-shims' ) ;
4970var hasOwn = Object . prototype . hasOwnProperty ;
5071var pSlice = Array . prototype . slice ;
5172var functionsHaveNames = ( function ( ) {
@@ -55,6 +76,9 @@ function pToString (obj) {
5576 return Object . prototype . toString . call ( obj ) ;
5677}
5778function isView ( arrbuf ) {
79+ if ( isBuffer ( arrbuf ) ) {
80+ return false ;
81+ }
5882 if ( typeof global . ArrayBuffer !== 'function' ) {
5983 return false ;
6084 }
@@ -110,25 +134,25 @@ assert.AssertionError = function AssertionError(options) {
110134 }
111135 var stackStartFunction = options . stackStartFunction || fail ;
112136 if ( Error . captureStackTrace ) {
113- Error . captureStackTrace ( this , stackStartFunction ) ;
114- } else {
115- // non v8 browsers so we can have a stacktrace
116- var err = new Error ( ) ;
117- if ( err . stack ) {
118- var out = err . stack ;
119-
120- // try to strip useless frames
121- var fn_name = getName ( stackStartFunction ) ;
122- var idx = out . indexOf ( '\n' + fn_name ) ;
123- if ( idx >= 0 ) {
124- // once we have located the function frame
125- // we need to strip out everything before it (and its line)
126- var next_line = out . indexOf ( '\n' , idx + 1 ) ;
127- out = out . substring ( next_line + 1 ) ;
128- }
129-
130- this . stack = out ;
131- }
137+ Error . captureStackTrace ( this , stackStartFunction ) ;
138+ } else {
139+ // non v8 browsers so we can have a stacktrace
140+ var err = new Error ( ) ;
141+ if ( err . stack ) {
142+ var out = err . stack ;
143+
144+ // try to strip useless frames
145+ var fn_name = getName ( stackStartFunction ) ;
146+ var idx = out . indexOf ( '\n' + fn_name ) ;
147+ if ( idx >= 0 ) {
148+ // once we have located the function frame
149+ // we need to strip out everything before it (and its line)
150+ var next_line = out . indexOf ( '\n' , idx + 1 ) ;
151+ out = out . substring ( next_line + 1 ) ;
152+ }
153+
154+ this . stack = out ;
155+ }
132156 }
133157} ;
134158
@@ -228,7 +252,7 @@ function _deepEqual(actual, expected, strict, memos) {
228252 // 7.1. All identical values are equivalent, as determined by ===.
229253 if ( actual === expected ) {
230254 return true ;
231- } else if ( Buffer . isBuffer ( actual ) && Buffer . isBuffer ( expected ) ) {
255+ } else if ( isBuffer ( actual ) && isBuffer ( expected ) ) {
232256 return compare ( actual , expected ) === 0 ;
233257
234258 // 7.2. If the expected value is a Date object, the actual value is
@@ -262,15 +286,17 @@ function _deepEqual(actual, expected, strict, memos) {
262286 pToString ( actual ) === pToString ( expected ) &&
263287 ! ( actual instanceof Float32Array ||
264288 actual instanceof Float64Array ) ) {
265- return compare ( BufferShim . from ( actual . buffer ) ,
266- BufferShim . from ( expected . buffer ) ) === 0 ;
289+ return compare ( new Uint8Array ( actual . buffer ) ,
290+ new Uint8Array ( expected . buffer ) ) === 0 ;
267291
268292 // 7.5 For all other Object pairs, including Array objects, equivalence is
269293 // determined by having the same number of owned properties (as verified
270294 // with Object.prototype.hasOwnProperty.call), the same set of keys
271295 // (although not necessarily the same order), equivalent values for every
272296 // corresponding key, and an identical 'prototype' property. Note: this
273297 // accounts for both named and indexed properties on Arrays.
298+ } else if ( isBuffer ( actual ) !== isBuffer ( expected ) ) {
299+ return false ;
274300 } else {
275301 memos = memos || { actual : [ ] , expected : [ ] } ;
276302
0 commit comments