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 — Undo `instanceof Buffer` changes by feross · Pull Request #155 · feross/buffer

Conversation

@feross

@feross feross commented Feb 9, 2017

Copy link
Copy Markdown
Owner

It turns out that it's not possible to use instanceof Buffer safely, like I thought.

It's not possible to use instanceof Buffer reliably in a browserify context because there could be multiple different copies of the 'buffer' package in use.

This previous method (checking buf._isBuffer) works even for Buffer instances that were created from another copy of the buffer package.

NOTE: It's possible to have two different "instances" of the 'buffer' package, even if the 'buffer' package appears only once in the bundled code. This can happen if you require 'buffer' in different ways, for example:

require('buffer') vs. require('buffer/') vs. using the implicit Buffer global.

You can confirm this by browserifying this code:

console.log(require('buffer').Buffer === require('buffer/').Buffer) // will be false

So, for this reason, instanceof won't work.

Fixes: #154

Sorry, something went wrong.

Uh oh!

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

All reactions
@feross
Undo instanceof Buffer changes
6bd6029
It turns out that it's not possible to use `instanceof Buffer` safely,
like I thought.

It's not possible to use `instanceof Buffer` reliably in a browserify
context because there could be multiple different copies of the
'buffer' package in use.

This previous method (checking `buf._isBuffer`) works even for Buffer
instances that were created from another copy of the `buffer` package.

NOTE: It's possible to have two different "instances" of the 'buffer'
package, even if the 'buffer' package appears only once in the bundled
code. This can happen if you require 'buffer' in different ways, for
example:

`require('buffer')` vs. `require('buffer/')` vs. using the implicit
`Buffer` global.

You can confirm this by browserifying this code:

```js
console.log(require('buffer').Buffer === require('buffer/').Buffer) //
will be false
```

So, for this reason, `instanceof` won't work.
@feross
feross requested a review from dcousens February 9, 2017 22:03
@feross
feross merged commit 0d2666d into master Feb 9, 2017
@feross
feross deleted the instanceof branch February 9, 2017 22:06
@feross

feross commented Feb 9, 2017

Copy link
Copy Markdown
Owner Author

Released as 5.0.5.

All reactions

Sorry, something went wrong.

Uh oh!

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

dcousens
dcousens reviewed Feb 9, 2017
View reviewed changes
Comment thread index.js
// reliably in a browserify context because there could be multiple different
// copies of the 'buffer' package in use. This method works even for Buffer
// instances that were created from another copy of the `buffer` package.
// See: https://github.com/feross/buffer/issues/154

@dcousens dcousens Feb 9, 2017

Copy link
Copy Markdown
Collaborator

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.

Perfect

Sorry, something went wrong.

Uh oh!

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

All reactions
@dcousens

dcousens commented Feb 9, 2017 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Collaborator

LGTM, nice work @feross.
I did think of this as being an issue when I saw the instanceof, but didn't think anyone would realistically run into the issue since very few people explicitly require('buffer').
I guess I was wrong.

All reactions

Sorry, something went wrong.

Uh oh!

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

@feross

feross commented Feb 9, 2017

Copy link
Copy Markdown
Owner Author

Live and learn!

All reactions

Sorry, something went wrong.

Uh oh!

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

@dcousens dcousens mentioned this pull request Jul 31, 2017
iOS browserify bitcoinjs/bitcoinjs-lib#830
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dcousens dcousens dcousens left review comments

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

2 participants

@feross @dcousens
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.