| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3621889 commit 8172f45
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,7 +35,6 @@ const { | |||
| 35 | 35 | readDoubleLE: _readDoubleLE, | |
| 36 | 36 | readFloatBE: _readFloatBE, | |
| 37 | 37 | readFloatLE: _readFloatLE, | |
| 38 | - setupBufferJS, | ||
| 39 | 38 | swap16: _swap16, | |
| 40 | 39 | swap32: _swap32, | |
| 41 | 40 | swap64: _swap64, | |
@@ -63,6 +62,8 @@ const errors = require('internal/errors'); | |||
| 63 | 62 | ||
| 64 | 63 | const internalBuffer = require('internal/buffer'); | |
| 65 | 64 | ||
| 65 | + const { setupBufferJS } = internalBuffer; | ||
| 66 | + | ||
| 66 | 67 | const bindingObj = {}; | |
| 67 | 68 | ||
| 68 | 69 | class FastBuffer extends Uint8Array { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -292,6 +292,10 @@ | |||
| 292 | 292 | } | |
| 293 | 293 | }); | |
| 294 | 294 | ||
| 295 | + // This, as side effect, removes `setupBufferJS` from the buffer binding, | ||
| 296 | + // and exposes it on `internal/buffer`. | ||
| 297 | + NativeModule.require('internal/buffer'); | ||
| 298 | + | ||
| 295 | 299 | global.Buffer = NativeModule.require('buffer').Buffer; | |
| 296 | 300 | process.domain = null; | |
| 297 | 301 | process._exiting = false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,13 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - // This is needed still for FastBuffer | ||
| 4 | - module.exports = {}; | ||
| 3 | + const binding = process.binding('buffer'); | ||
| 4 | + const { setupBufferJS } = binding; | ||
| 5 | + | ||
| 6 | + // Remove from the binding so that function is only available as exported here. | ||
| 7 | + // (That is, for internal use only.) | ||
| 8 | + delete binding.setupBufferJS; | ||
| 9 | + | ||
| 10 | + // FastBuffer wil be inserted here by lib/buffer.js | ||
| 11 | + module.exports = { | ||
| 12 | + setupBufferJS | ||
| 13 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,33 +11,26 @@ const assert = require('assert'); | |||
| 11 | 11 | const buffer = require('buffer'); | |
| 12 | 12 | ||
| 13 | 13 | // Monkey-patch setupBufferJS() to have an undefined zeroFill. | |
| 14 | - const process = require('process'); | ||
| 15 | - const originalBinding = process.binding; | ||
| 14 | + const internalBuffer = require('internal/buffer'); | ||
| 16 | 15 | ||
| 17 | - const binding = originalBinding('buffer'); | ||
| 18 | - const originalSetup = binding.setupBufferJS; | ||
| 16 | + const originalSetup = internalBuffer.setupBufferJS; | ||
| 19 | 17 | ||
| 20 | - binding.setupBufferJS = (proto, obj) => { | ||
| 18 | + internalBuffer.setupBufferJS = (proto, obj) => { | ||
| 21 | 19 | originalSetup(proto, obj); | |
| 22 | 20 | assert.strictEqual(obj.zeroFill[0], 1); | |
| 23 | 21 | delete obj.zeroFill; | |
| 24 | 22 | }; | |
| 25 | 23 | ||
| 26 | 24 | const bindingObj = {}; | |
| 27 | 25 | ||
| 28 | - binding.setupBufferJS(Buffer.prototype, bindingObj); | ||
| 26 | + internalBuffer.setupBufferJS(Buffer.prototype, bindingObj); | ||
| 29 | 27 | assert.strictEqual(bindingObj.zeroFill, undefined); | |
| 30 | 28 | ||
| 31 | - process.binding = (bindee) => { | ||
| 32 | - if (bindee === 'buffer') | ||
| 33 | - return binding; | ||
| 34 | - return originalBinding(bindee); | ||
| 35 | - }; | ||
| 36 | - | ||
| 37 | 29 | // Load from file system because internal buffer is already loaded and we're | |
| 38 | 30 | // testing code that runs on first load only. | |
| 39 | 31 | // Do not move this require() to top of file. It is important that | |
| 40 | - // `process.binding('buffer').setupBufferJS` be monkey-patched before this runs. | ||
| 32 | + // `require('internal/buffer').setupBufferJS` be monkey-patched before this | ||
| 33 | + // runs. | ||
| 41 | 34 | const monkeyPatchedBuffer = require('../../lib/buffer'); | |
| 42 | 35 | ||
| 43 | 36 | // On unpatched buffer, allocUnsafe() should not zero fill memory. It's always | |
@@ -51,3 +44,6 @@ while (uninitialized.every((val) => val === 0)) | |||
| 51 | 44 | // zero-fill in that case. | |
| 52 | 45 | const zeroFilled = monkeyPatchedBuffer.Buffer.allocUnsafe(1024); | |
| 53 | 46 | assert(zeroFilled.every((val) => val === 0)); | |
| 47 | + | ||
| 48 | + // setupBufferJS shouldn't still be exposed on the binding | ||
| 49 | + assert(!('setupBufferJs' in process.binding('buffer'))); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments