Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buffer: move process.binding('buffer') to internalBinding #22370

Closed
wants to merge 1 commit into from

Conversation

starkwang
Copy link
Contributor

@starkwang starkwang commented Aug 17, 2018

Refs: #22160

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Aug 17, 2018
@starkwang starkwang added the wip Issues and PRs that are still a work in progress. label Aug 17, 2018
@starkwang
Copy link
Contributor Author

starkwang commented Aug 17, 2018

// Load from file system because internal buffer is already loaded and we're
// testing code that runs on first load only.
// Do not move this require() to top of file. It is important that
// `require('internal/buffer').setupBufferJS` be monkey-patched before this
// runs.
const monkeyPatchedBuffer = require('../../lib/buffer');

The tests is failed now because the monkeyPatchedBuffer is loaded from file system and internal/bootstrap/loaders cannot be required in that way.

out/Release/node --expose-internals /Users/apple/Desktop/node/test/parallel/test-buffer-bindingobj-no-zerofill.js
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module 'internal/bootstrap/loaders'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/Users/apple/Desktop/node/lib/buffer.js:24:29)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

How can we solve it?

@jasnell
Copy link
Member

jasnell commented Aug 17, 2018

This is going to be a tricky one because the way that test is written, there is no other way to test that particular bit. One question is: do we actually need to test that particular case?

@BridgeAR
Copy link
Member

I am +1 on removing that part from the test.

@jdalton
Copy link
Member

jdalton commented Aug 18, 2018

@starkwang I believe this should be added to the allow list at here.

@starkwang starkwang force-pushed the buffer-internal-binding branch from e9c556d to b0984ae Compare August 18, 2018 14:22
@Trott
Copy link
Member

Trott commented Aug 18, 2018

This is going to be a tricky one because the way that test is written, there is no other way to test that particular bit. One question is: do we actually need to test that particular case?

Ideally, that entire test file should be replaced by an addon test. See conversation at 27e84ddd4e1#r19182129 and #11706.

The test was written to cover the || [0] part of this code from lib/buffer.js:

// |zeroFill| can be undefined when running inside an isolate where we
// do not own the ArrayBuffer allocator.  Zero fill is always on in that case.
const zeroFill = bindingObj.zeroFill || [0];

If you can come up with an addon test that makes sure that code is run in the appropriate condition, then this rather inelegant way to test that bit of code can be removed.

@Trott
Copy link
Member

Trott commented Aug 18, 2018

Moreover, that assertion was added by @bengl in 8172f45. It seems to me like it is inessential and can be removed, but he may believe otherwise?

@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Aug 23, 2018
@BridgeAR
Copy link
Member

BridgeAR commented Sep 5, 2018

This needs a rebase.

@starkwang starkwang force-pushed the buffer-internal-binding branch 2 times, most recently from 2c1292c to 3870dcd Compare September 10, 2018 02:05
@starkwang
Copy link
Contributor Author

I've removed the tricky test-buffer-bindingobj-no-zerofill.js. We can follow up it in #22547.

@starkwang
Copy link
Contributor Author

@starkwang starkwang removed the wip Issues and PRs that are still a work in progress. label Sep 11, 2018
@starkwang starkwang force-pushed the buffer-internal-binding branch from bf7a154 to 2eda676 Compare October 11, 2018 02:55
@starkwang
Copy link
Contributor Author

@starkwang
Copy link
Contributor Author

@nodejs/buffer PTAL

@starkwang starkwang force-pushed the buffer-internal-binding branch from 2eda676 to 5e88675 Compare October 15, 2018 02:42
@starkwang
Copy link
Contributor Author

@starkwang
Copy link
Contributor Author

This change is semver-major so it needs another member in TSC to approve.

@nodejs/tsc PTAL.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@starkwang
Copy link
Contributor Author

Landed in ac23e65

@starkwang starkwang closed this Oct 15, 2018
starkwang added a commit that referenced this pull request Oct 15, 2018
PR-URL: #22370
Refs: #22160
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
jasnell pushed a commit that referenced this pull request Oct 17, 2018
PR-URL: #22370
Refs: #22160
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants