Skip to content
Permalink
Browse files

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

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>
  • Loading branch information
starkwang authored and jasnell committed Aug 17, 2018
1 parent e806167 commit 5d95542212d20db007ef518d8e5874985dc687f6
@@ -36,7 +36,7 @@ const {
swap64: _swap64,
kMaxLength,
kStringMaxLength
} = process.binding('buffer');
} = internalBinding('buffer');
const { isAnyArrayBuffer } = internalBinding('types');
const {
customInspectSymbol,
@@ -413,7 +413,8 @@
'url',
'spawn_sync',
'js_stream',
'zlib']);
'zlib',
'buffer']);
process.binding = function binding(name) {
return internalBindingWhitelist.has(name) ?
internalBinding(name) :
@@ -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,
@@ -29,7 +29,7 @@ const {

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

var Buffer;
function lazyBuffer() {
@@ -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
@@ -1,6 +1,6 @@
'use strict';

const { compare } = process.binding('buffer');
const { compare } = internalBinding('buffer');
const { isArrayBufferView } = require('internal/util/types');
const {
isAnyArrayBuffer,
@@ -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');

@@ -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)
@@ -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);
@@ -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 {
@@ -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);
@@ -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 {
@@ -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);
@@ -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 {
@@ -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);
@@ -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 {
@@ -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);
@@ -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 {
@@ -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);
@@ -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 {
@@ -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);
@@ -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 {
@@ -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);
@@ -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 {
@@ -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);
@@ -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.
@@ -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(() => {
@@ -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');

@@ -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,
@@ -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'));
@@ -1,6 +1,8 @@
'use strict';
// Flags: --expose-internals
require('../common');
const assert = require('assert');
const { internalBinding } = require('internal/test/binding');

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

process.binding('buffer');
internalBinding('buffer');
@@ -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');
@@ -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');

0 comments on commit 5d95542

Please sign in to comment.
You can’t perform that action at this time.