diff options
author | Anna Henningsen <anna@addaleax.net> | 2016-12-10 22:28:37 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2016-12-21 07:48:14 +0100 |
commit | beca3244e2792bc4257f480b138c1b603de3781c (patch) | |
tree | f298c9f0deef44b2003f4bc4da1098fef0347d76 /test/parallel/test-buffer-indexof.js | |
parent | 6cb33c0764f307e33d29655cd1bac2916656352a (diff) | |
download | android-node-v8-beca3244e2792bc4257f480b138c1b603de3781c.tar.gz android-node-v8-beca3244e2792bc4257f480b138c1b603de3781c.tar.bz2 android-node-v8-beca3244e2792bc4257f480b138c1b603de3781c.zip |
buffer: allow Uint8Array input to methods
Allow all methods on `buffer` and `Buffer` to take `Uint8Array`
arguments where it makes sense. On the native side, there is
effectively no difference, and as a bonus the `isUint8Array`
check is faster than `instanceof Buffer`.
PR-URL: https://github.com/nodejs/node/pull/10236
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Diffstat (limited to 'test/parallel/test-buffer-indexof.js')
-rw-r--r-- | test/parallel/test-buffer-indexof.js | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/test/parallel/test-buffer-indexof.js b/test/parallel/test-buffer-indexof.js index 746a272316..6aab628fe9 100644 --- a/test/parallel/test-buffer-indexof.js +++ b/test/parallel/test-buffer-indexof.js @@ -524,3 +524,11 @@ assert.equal(0, reallyLong.lastIndexOf(pattern)); assert.strictEqual(buf.indexOf(0xff), -1); assert.strictEqual(buf.indexOf(0xffff), -1); } + +// Test that Uint8Array arguments are okay. +{ + const needle = new Uint8Array([ 0x66, 0x6f, 0x6f ]); + const haystack = Buffer.from('a foo b foo'); + assert.strictEqual(haystack.indexOf(needle), 2); + assert.strictEqual(haystack.lastIndexOf(needle), haystack.length - 3); +} |