GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — buffer: Added Buffer#includes() to keep parity with TypedArray. by umamialex · Pull Request #3567 · nodejs/node

Conversation

@umamialex

@umamialex umamialex commented Oct 28, 2015

Copy link
Copy Markdown
Contributor

Simply adds Buffer.prototype.includes by wrapping an indexOf and
performing a strict equals check to -1.

The includes method takes the search value, byteOffset, and
encoding as arguments.

The test is a modified version of the indexOf test.

Addresses #3552.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Fishrock123 Fishrock123 added the buffer Issues and PRs related to the buffer subsystem. label Oct 28, 2015
@Fishrock123

Fishrock123 commented Oct 28, 2015

Copy link
Copy Markdown
Contributor

cc @trevnorris

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123 Fishrock123 added the semver-minor PRs that contain new features and should be released in the next minor version. label Oct 28, 2015
evanlucas
evanlucas reviewed Oct 28, 2015
View reviewed changes
Comment thread test/parallel/test-buffer-includes.js Outdated

@evanlucas evanlucas Oct 28, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const instead of var please

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Fishrock123 Fishrock123 mentioned this pull request Oct 28, 2015
buffer: Add Buffer#includes() #3568
Closed
@umamialex

umamialex commented Oct 28, 2015

Copy link
Copy Markdown
Contributor Author

Switched var to const where possible.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Oct 28, 2015

Copy link
Copy Markdown
Member

Isn't this a little premature? TypedArray#includes() is still behind a flag in the V8 we ship, isn't it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris

trevnorris commented Oct 28, 2015

Copy link
Copy Markdown
Contributor

@bnoordhuis v8's implementation of this and other methods like fill(), indexOf(), etc. are all restrictive and/or slow, and we've already replaced them with our own implementation. So figured it would be fine to implement this now using our faster implementation since the change was relatively minimal.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris

trevnorris commented Oct 28, 2015

Copy link
Copy Markdown
Contributor

@suitupalex Excellent job on all the tests. LGTM if CI is happy.

CI: https://ci.nodejs.org/job/node-test-pull-request/640/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@evanlucas

evanlucas commented Oct 28, 2015

Copy link
Copy Markdown
Contributor

Mind adding docs for it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@umamialex
buffer: Added Buffer#includes() to keep parity with TypedArray.
25ffa3b
Simply adds Buffer.prototype.includes by wrapping an indexOf and
performing a strict equals check to -1.

The includes method takes the search value, byteOffset, and
encoding as arguments.

The test is a modified version of the indexOf test.

Addresses #3552.
@umamialex

umamialex commented Oct 28, 2015

Copy link
Copy Markdown
Contributor Author

@trevnorris thanks! Glad to be able to contribute.

@evanlucas absolutely. Just reupped with documentation.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@evanlucas

evanlucas commented Oct 28, 2015

Copy link
Copy Markdown
Contributor

CI looks good. Those failures look unrelated. It looks like the PPC machines are having some trouble though? /cc @nodejs/build

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@evanlucas

evanlucas commented Oct 28, 2015

Copy link
Copy Markdown
Contributor

LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rvagg

rvagg commented Oct 28, 2015

Copy link
Copy Markdown
Member

Even though we're bypassing V8 on this I'd be in favour of waiting till TypedArray#includes() has landed stable upstream. There's a chance we could be overlooking something and it would be good to be able to test our implementation alongside theirs so we get maximum coverage of the requirements. The fact that they still have it in staging suggests (to me, without any actual knowledge of why) that it's non-trivial.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rvagg

rvagg commented Oct 28, 2015

Copy link
Copy Markdown
Member

^ the main reason for waiting would be to ensure that we don't ship something we have to break in a later version because we've overlooked something.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris

trevnorris commented Oct 29, 2015

Copy link
Copy Markdown
Contributor

@rvagg I'm curious what you could mean? Our implementations all break ECMA standards (b/c honestly they suck in this case), so I'm not sure what we should be worried about.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@domenic

domenic commented Oct 30, 2015

Copy link
Copy Markdown
Contributor

includes was specifically designed not to suck so I'd at least like to see some benchmarks before creating an overriden version...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris

trevnorris commented Oct 30, 2015

Copy link
Copy Markdown
Contributor

@domenic but you can still only pass a number, right? Buffer#includes() should allow multi character strings or Buffers to be passed in like similar existing APIs in core. In this case it's not only about performance.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@domenic

domenic commented Oct 30, 2015

Copy link
Copy Markdown
Contributor

Why? That isn't what "includes" means in ES.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@targos

targos commented Oct 30, 2015

Copy link
Copy Markdown
Member

It would be similar to String#includes:

new Buffer('abcd').includes('bc') <=> 'abcd'.includes('bc')

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123

Fishrock123 commented Oct 30, 2015

Copy link
Copy Markdown
Contributor

@domenic Keep in mind this isn't TypedArray.includes -- this is for buffer, which acts more like a string in some cases.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123

Fishrock123 commented Nov 3, 2015

Copy link
Copy Markdown
Contributor

Is anything blocking this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris

trevnorris commented Nov 3, 2015

Copy link
Copy Markdown
Contributor

Nothing from me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123

Fishrock123 commented Nov 5, 2015

Copy link
Copy Markdown
Contributor

LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Nov 5, 2015

Copy link
Copy Markdown
Member

Perhaps the approach to take on this is to get it landed in master but hold off just a bit before landing it in v5.x? The change itself LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123 Fishrock123 mentioned this pull request Dec 9, 2015
Add Buffer#includes() #3552
Closed
@trevnorris

trevnorris commented Dec 9, 2015

Copy link
Copy Markdown
Contributor

@Fishrock123 Follow up, can this be merged?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123

Fishrock123 commented Dec 10, 2015

Copy link
Copy Markdown
Contributor

@trevnorris is the agreement to ship in master but not land it in a stable until TypedArray adds it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris

trevnorris commented Dec 10, 2015

Copy link
Copy Markdown
Contributor

@Fishrock123 Not sure. Since this disregards the Typed Array spec I was under the impression that it wouldn't matter. Let's land this on master and discuss back porting after.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

trevnorris pushed a commit that referenced this pull request Dec 10, 2015
@umamialex @trevnorris
buffer: add includes() for parity with TypedArray
67e1819
Add Buffer#includes() by wrapping an indexOf and performing a strict
equals check to -1.

The includes method takes the search value, byteOffset, and encoding as
arguments.

The test is a modified version of the indexOf test.

Fixes: #3552
PR-URL: #3567
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@trevnorris

trevnorris commented Dec 10, 2015

Copy link
Copy Markdown
Contributor

Thanks much! Landed in 67e1819.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris trevnorris closed this Dec 10, 2015
@Fishrock123 Fishrock123 mentioned this pull request Dec 15, 2015
v5.3.0 Release Proposal (Stable) #4281
Closed
cjihrig pushed a commit that referenced this pull request Dec 16, 2015
@umamialex @cjihrig
buffer: add includes() for parity with TypedArray
9ab669f
Add Buffer#includes() by wrapping an indexOf and performing a strict
equals check to -1.

The includes method takes the search value, byteOffset, and encoding as
arguments.

The test is a modified version of the indexOf test.

Fixes: #3552
PR-URL: #3567
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
cjihrig added a commit that referenced this pull request Dec 16, 2015
@cjihrig
2015-12-16, Version 5.3.0 (Stable)
b21110f
Notable changes:

* buffer:
  - Buffer.prototype.includes() has been added to keep parity
    with TypedArrays. (Alexander Martin) #3567.
* domains:
  - Fix handling of uncaught exceptions.
    (Julien Gilli) #3654.
* https:
  - Added support for disabling session caching.
    (Fedor Indutny) #4252.
* repl:
  - Allow third party modules to be imported using
    require(). This corrects a regression from 5.2.0.
    (Ben Noordhuis) #4215.
* deps:
  - Upgrade libuv to 1.8.0.
    (Saúl Ibarra Corretgé) #4276.

PR-URL: #4281
cjihrig added a commit that referenced this pull request Dec 16, 2015
@cjihrig
2015-12-16, Version 5.3.0 (Stable)
e5774c9
Notable changes:

* buffer:
  - Buffer.prototype.includes() has been added to keep parity
    with TypedArrays. (Alexander Martin) #3567.
* domains:
  - Fix handling of uncaught exceptions.
    (Julien Gilli) #3654.
* https:
  - Added support for disabling session caching.
    (Fedor Indutny) #4252.
* repl:
  - Allow third party modules to be imported using
    require(). This corrects a regression from 5.2.0.
    (Ben Noordhuis) #4215.
* deps:
  - Upgrade libuv to 1.8.0.
    (Saúl Ibarra Corretgé) #4276.

PR-URL: #4281

Conflicts:
	src/node_version.h
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
@umamialex Michael Scovetta
buffer: add includes() for parity with TypedArray
ff8a634
Add Buffer#includes() by wrapping an indexOf and performing a strict
equals check to -1.

The includes method takes the search value, byteOffset, and encoding as
arguments.

The test is a modified version of the indexOf test.

Fixes: nodejs#3552
PR-URL: nodejs#3567
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
@cjihrig Michael Scovetta
2015-12-16, Version 5.3.0 (Stable)
c74c53a
Notable changes:

* buffer:
  - Buffer.prototype.includes() has been added to keep parity
    with TypedArrays. (Alexander Martin) nodejs#3567.
* domains:
  - Fix handling of uncaught exceptions.
    (Julien Gilli) nodejs#3654.
* https:
  - Added support for disabling session caching.
    (Fedor Indutny) nodejs#4252.
* repl:
  - Allow third party modules to be imported using
    require(). This corrects a regression from 5.2.0.
    (Ben Noordhuis) nodejs#4215.
* deps:
  - Upgrade libuv to 1.8.0.
    (Saúl Ibarra Corretgé) nodejs#4276.

PR-URL: nodejs#4281

Conflicts:
	src/node_version.h
@aqrln aqrln mentioned this pull request Mar 25, 2017
test: fix broken tests in test-buffer-includes #12040
Closed
2 tasks done
aqrln added a commit to aqrln/node that referenced this pull request Mar 26, 2017
@aqrln
test: fix broken tests in test-buffer-includes
b9977cf
Some of the tests for `buffer.includes()` functionality introduced in
nodejs#3567 have been broken in a way that
caused them to always pass regardless of the result of the tested
method.

This behavior was caused by two reasons:

 * These tests were written as though `buffer.includes()` was supposed
   to return the same value that `buffer.indexOf()` does, i.e., used
   indices or -1 as expected return values instead of true and false.
 * `assert()` was used as the assertion function to do that instead of
   `assert.strictEqual()`.

Thus `assert()` was called with a non-zero number as the first argument
effectively causing these tests to pass.

This commit changes the tests to use `assert.ok()` and removes redundant
indices.

Refs: nodejs#3567
jasnell pushed a commit that referenced this pull request Mar 27, 2017
@aqrln @jasnell
test: fix broken tests in test-buffer-includes
52b666e
Some of the tests for `buffer.includes()` functionality introduced in
#3567 have been broken in a way that
caused them to always pass regardless of the result of the tested
method.

This behavior was caused by two reasons:

 * These tests were written as though `buffer.includes()` was supposed
   to return the same value that `buffer.indexOf()` does, i.e., used
   indices or -1 as expected return values instead of true and false.
 * `assert()` was used as the assertion function to do that instead of
   `assert.strictEqual()`.

Thus `assert()` was called with a non-zero number as the first argument
effectively causing these tests to pass.

This commit changes the tests to use `assert.ok()` and removes redundant
indices.

PR-URL: #12040
Ref: #3567
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Mar 28, 2017
@aqrln @MylesBorins
test: fix broken tests in test-buffer-includes
948b99d
Some of the tests for `buffer.includes()` functionality introduced in
#3567 have been broken in a way that
caused them to always pass regardless of the result of the tested
method.

This behavior was caused by two reasons:

 * These tests were written as though `buffer.includes()` was supposed
   to return the same value that `buffer.indexOf()` does, i.e., used
   indices or -1 as expected return values instead of true and false.
 * `assert()` was used as the assertion function to do that instead of
   `assert.strictEqual()`.

Thus `assert()` was called with a non-zero number as the first argument
effectively causing these tests to pass.

This commit changes the tests to use `assert.ok()` and removes redundant
indices.

PR-URL: #12040
Ref: #3567
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Apr 18, 2017
@aqrln @MylesBorins
test: fix broken tests in test-buffer-includes
edfa343
Some of the tests for `buffer.includes()` functionality introduced in
#3567 have been broken in a way that
caused them to always pass regardless of the result of the tested
method.

This behavior was caused by two reasons:

 * These tests were written as though `buffer.includes()` was supposed
   to return the same value that `buffer.indexOf()` does, i.e., used
   indices or -1 as expected return values instead of true and false.
 * `assert()` was used as the assertion function to do that instead of
   `assert.strictEqual()`.

Thus `assert()` was called with a non-zero number as the first argument
effectively causing these tests to pass.

This commit changes the tests to use `assert.ok()` and removes redundant
indices.

PR-URL: #12040
Ref: #3567
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Apr 19, 2017
@aqrln @MylesBorins
test: fix broken tests in test-buffer-includes
e2279e2
Some of the tests for `buffer.includes()` functionality introduced in
#3567 have been broken in a way that
caused them to always pass regardless of the result of the tested
method.

This behavior was caused by two reasons:

 * These tests were written as though `buffer.includes()` was supposed
   to return the same value that `buffer.indexOf()` does, i.e., used
   indices or -1 as expected return values instead of true and false.
 * `assert()` was used as the assertion function to do that instead of
   `assert.strictEqual()`.

Thus `assert()` was called with a non-zero number as the first argument
effectively causing these tests to pass.

This commit changes the tests to use `assert.ok()` and removes redundant
indices.

PR-URL: #12040
Ref: #3567
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: James M Snell <[email protected]>
andrew749 pushed a commit to michielbaird/node that referenced this pull request Jul 19, 2017
@aqrln @andrew749
test: fix broken tests in test-buffer-includes
a004b3d
Some of the tests for `buffer.includes()` functionality introduced in
nodejs/node#3567 have been broken in a way that
caused them to always pass regardless of the result of the tested
method.

This behavior was caused by two reasons:

 * These tests were written as though `buffer.includes()` was supposed
   to return the same value that `buffer.indexOf()` does, i.e., used
   indices or -1 as expected return values instead of true and false.
 * `assert()` was used as the assertion function to do that instead of
   `assert.strictEqual()`.

Thus `assert()` was called with a non-zero number as the first argument
effectively causing these tests to pass.

This commit changes the tests to use `assert.ok()` and removes redundant
indices.

PR-URL: nodejs/node#12040
Ref: nodejs/node#3567
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

buffer Issues and PRs related to the buffer subsystem. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

9 participants

@umamialex @Fishrock123 @bnoordhuis @trevnorris @evanlucas @rvagg @domenic @targos @jasnell
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.