summaryrefslogtreecommitdiff
path: root/lib/buffer.js
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-12-31 16:11:01 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-01-10 16:59:24 +0800
commit97f59b95675b80a8d8df1d0e9c179c06c0c86a7b (patch)
treef895a5b2b53b7098f779daf769188a4ba6f4331c /lib/buffer.js
parentfa5af0d50846083fcd0bb9de6006bb57424a17cf (diff)
downloadandroid-node-v8-97f59b95675b80a8d8df1d0e9c179c06c0c86a7b.tar.gz
android-node-v8-97f59b95675b80a8d8df1d0e9c179c06c0c86a7b.tar.bz2
android-node-v8-97f59b95675b80a8d8df1d0e9c179c06c0c86a7b.zip
buffer: move initialization of buffer prototype into node.js
Instead of exposing it in `lib/internal/buffer.js` after deleting it from the binding and then do the initialization in `lib/buffer.js`, which results in an implicit dependency on the order in which these modules are loaded. PR-URL: https://github.com/nodejs/node/pull/25292 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/buffer.js')
-rw-r--r--lib/buffer.js40
1 files changed, 32 insertions, 8 deletions
diff --git a/lib/buffer.js b/lib/buffer.js
index 0b76583266..b9baae7fef 100644
--- a/lib/buffer.js
+++ b/lib/buffer.js
@@ -35,7 +35,22 @@ const {
swap32: _swap32,
swap64: _swap64,
kMaxLength,
- kStringMaxLength
+ kStringMaxLength,
+ zeroFill: bindingZeroFill,
+
+ // Additional Buffer methods
+ asciiSlice,
+ base64Slice,
+ latin1Slice,
+ hexSlice,
+ ucs2Slice,
+ utf8Slice,
+ asciiWrite,
+ base64Write,
+ latin1Write,
+ hexWrite,
+ ucs2Write,
+ utf8Write
} = internalBinding('buffer');
const {
getOwnNonIndexProperties,
@@ -74,10 +89,6 @@ const { validateString } = require('internal/validators');
const internalBuffer = require('internal/buffer');
-const { setupBufferJS } = internalBuffer;
-
-const bindingObj = {};
-
class FastBuffer extends Uint8Array {}
FastBuffer.prototype.constructor = Buffer;
internalBuffer.FastBuffer = FastBuffer;
@@ -88,6 +99,19 @@ for (const [name, method] of Object.entries(internalBuffer.readWrites)) {
Buffer.prototype[name] = method;
}
+Buffer.prototype.asciiSlice = asciiSlice;
+Buffer.prototype.base64Slice = base64Slice;
+Buffer.prototype.latin1Slice = latin1Slice;
+Buffer.prototype.hexSlice = hexSlice;
+Buffer.prototype.ucs2Slice = ucs2Slice;
+Buffer.prototype.utf8Slice = utf8Slice;
+Buffer.prototype.asciiWrite = asciiWrite;
+Buffer.prototype.base64Write = base64Write;
+Buffer.prototype.latin1Write = latin1Write;
+Buffer.prototype.hexWrite = hexWrite;
+Buffer.prototype.ucs2Write = ucs2Write;
+Buffer.prototype.utf8Write = utf8Write;
+
const constants = Object.defineProperties({}, {
MAX_LENGTH: {
value: kMaxLength,
@@ -104,11 +128,11 @@ const constants = Object.defineProperties({}, {
Buffer.poolSize = 8 * 1024;
let poolSize, poolOffset, allocPool;
-setupBufferJS(Buffer.prototype, bindingObj);
-
+// A toggle used to access the zero fill setting of the array buffer allocator
+// in C++.
// |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];
+const zeroFill = bindingZeroFill || [0];
function createUnsafeBuffer(size) {
return new FastBuffer(createUnsafeArrayBuffer(size));