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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const {
swap64: _swap64,
kMaxLength,
kStringMaxLength
} = process.binding('buffer');
} = internalBinding('buffer');
const { isAnyArrayBuffer } = internalBinding('types');
const {
customInspectSymbol,
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@
'url',
'spawn_sync',
'js_stream',
'zlib']);
'zlib',
'buffer']);
process.binding = function binding(name) {
return internalBindingWhitelist.has(name) ?
internalBinding(name) :
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/buffer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const binding = process.binding('buffer');
const binding = internalBinding('buffer');
const {
ERR_BUFFER_OUT_OF_BOUNDS,
ERR_INVALID_ARG_TYPE,
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const {

const {
encodeUtf8String
} = process.binding('buffer');
} = internalBinding('buffer');

var Buffer;
function lazyBuffer() {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {
UV_EAI_NODATA,
UV_EAI_NONAME
} = internalBinding('uv');
const { kMaxLength } = process.binding('buffer');
const { kMaxLength } = internalBinding('buffer');
const { defineProperty } = Object;

// Lazily loaded
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { compare } = process.binding('buffer');
const { compare } = internalBinding('buffer');
const { isArrayBufferView } = require('internal/util/types');
const {
isAnyArrayBuffer,
Expand Down
2 changes: 1 addition & 1 deletion lib/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {
Serializer: _Serializer,
Deserializer: _Deserializer
} = internalBinding('serdes');
const { copy } = process.binding('buffer');
const { copy } = internalBinding('buffer');
const { objectToString } = require('internal/util');
const { FastBuffer } = require('internal/buffer');

Expand Down
2 changes: 1 addition & 1 deletion src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1104,4 +1104,4 @@ void Initialize(Local<Object> target,
} // namespace Buffer
} // namespace node

NODE_BUILTIN_MODULE_CONTEXT_AWARE(buffer, node::Buffer::Initialize)
NODE_MODULE_CONTEXT_AWARE_INTERNAL(buffer, node::Buffer::Initialize)
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
// Flags: --expose-internals

const common = require('../../common');
const { internalBinding } = require('internal/test/binding');
const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem)
common.skip(skipMessage);
Expand All @@ -10,7 +12,7 @@ const assert = require('assert');

// v8 fails silently if string length > v8::String::kMaxLength
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
const kStringMaxLength = internalBinding('buffer').kStringMaxLength;

let buf;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
// Flags: --expose-internals

const common = require('../../common');
const { internalBinding } = require('internal/test/binding');
const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem)
common.skip(skipMessage);
Expand All @@ -9,7 +11,7 @@ const binding = require(`./build/${common.buildType}/binding`);

// v8 fails silently if string length > v8::String::kMaxLength
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
const kStringMaxLength = internalBinding('buffer').kStringMaxLength;

let buf;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
// Flags: --expose-internals

const common = require('../../common');
const { internalBinding } = require('internal/test/binding');
const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem)
common.skip(skipMessage);
Expand All @@ -9,7 +11,7 @@ const binding = require(`./build/${common.buildType}/binding`);

// v8 fails silently if string length > v8::String::kMaxLength
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
const kStringMaxLength = internalBinding('buffer').kStringMaxLength;

let buf;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Flags: --expose-gc
// Flags: --expose-gc --expose-internals
'use strict';

const common = require('../../common');
const { internalBinding } = require('internal/test/binding');
const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem)
common.skip(skipMessage);
Expand All @@ -11,7 +12,7 @@ const assert = require('assert');

// v8 fails silently if string length > v8::String::kMaxLength
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
const kStringMaxLength = internalBinding('buffer').kStringMaxLength;

let buf;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
// Flags: --expose-internals

const common = require('../../common');
const { internalBinding } = require('internal/test/binding');
const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem)
common.skip(skipMessage);
Expand All @@ -9,7 +11,7 @@ const binding = require(`./build/${common.buildType}/binding`);

// v8 fails silently if string length > v8::String::kMaxLength
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
const kStringMaxLength = internalBinding('buffer').kStringMaxLength;

let buf;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
// Flags: --expose-internals

const common = require('../../common');
const { internalBinding } = require('internal/test/binding');
const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem)
common.skip(skipMessage);
Expand All @@ -10,7 +12,7 @@ const assert = require('assert');

// v8 fails silently if string length > v8::String::kMaxLength
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
const kStringMaxLength = internalBinding('buffer').kStringMaxLength;

let buf;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
// Flags: --expose-internals

const common = require('../../common');
const { internalBinding } = require('internal/test/binding');
const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem)
common.skip(skipMessage);
Expand All @@ -10,7 +12,7 @@ const assert = require('assert');

// v8 fails silently if string length > v8::String::kMaxLength
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
const kStringMaxLength = internalBinding('buffer').kStringMaxLength;

let buf;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
// Flags: --expose-internals

const common = require('../../common');
const { internalBinding } = require('internal/test/binding');
const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem)
common.skip(skipMessage);
Expand All @@ -9,7 +11,7 @@ const binding = require(`./build/${common.buildType}/binding`);

// v8 fails silently if string length > v8::String::kMaxLength
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
const kStringMaxLength = internalBinding('buffer').kStringMaxLength;

let buf;
try {
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-buffer-fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const common = require('../common');
const assert = require('assert');
const { codes: { ERR_OUT_OF_RANGE } } = require('internal/errors');
const { internalBinding } = require('internal/test/binding');
const SIZE = 28;

const buf1 = Buffer.allocUnsafe(SIZE);
Expand Down Expand Up @@ -327,7 +328,7 @@ Buffer.alloc(8, '');
// Testing process.binding. Make sure "start" is properly checked for -1 wrap
// around.
assert.strictEqual(
process.binding('buffer').fill(Buffer.alloc(1), 1, -1, 0, 1), -2);
internalBinding('buffer').fill(Buffer.alloc(1), 1, -1, 0, 1), -2);

// Make sure "end" is properly checked, even if it's magically mangled using
// Symbol.toPrimitive.
Expand Down Expand Up @@ -365,7 +366,7 @@ assert.strictEqual(
// Testing process.binding. Make sure "end" is properly checked for -1 wrap
// around.
assert.strictEqual(
process.binding('buffer').fill(Buffer.alloc(1), 1, 1, -2, 1), -2);
internalBinding('buffer').fill(Buffer.alloc(1), 1, 1, -2, 1), -2);

// Test that bypassing 'length' won't cause an abort.
common.expectsError(() => {
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-internal-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const {
hijackStdout,
restoreStdout,
} = require('../common/hijackstdio');

const { internalBinding } = require('internal/test/binding');
const assert = require('assert');
const errors = require('internal/errors');

Expand Down Expand Up @@ -183,7 +185,7 @@ assert.strictEqual(
'Invalid asyncId value: undefined');

{
const { kMaxLength } = process.binding('buffer');
const { kMaxLength } = internalBinding('buffer');
const error = new errors.codes.ERR_BUFFER_TOO_LARGE();
assert.strictEqual(
error.message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ assert(process.binding('contextify'));
assert(process.binding('url'));
assert(process.binding('spawn_sync'));
assert(process.binding('js_stream'));
assert(process.binding('buffer'));
4 changes: 3 additions & 1 deletion test/parallel/test-process-binding.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
// Flags: --expose-internals
require('../common');
const assert = require('assert');
const { internalBinding } = require('internal/test/binding');

assert.throws(
function() {
Expand All @@ -9,4 +11,4 @@ assert.throws(
/No such module: test/
);

process.binding('buffer');
internalBinding('buffer');
4 changes: 3 additions & 1 deletion test/sequential/test-fs-readfile-tostring-fail.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
// Flags: --expose-internals

const common = require('../common');
const { internalBinding } = require('internal/test/binding');

if (!common.enoughTestMem)
common.skip('intensive toString tests due to memory confinements');
Expand All @@ -9,7 +11,7 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');
const cp = require('child_process');
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
const kStringMaxLength = internalBinding('buffer').kStringMaxLength;
if (common.isAIX && (Number(cp.execSync('ulimit -f')) * 512) < kStringMaxLength)
common.skip('intensive toString tests due to file size confinements');

Expand Down