aboutsummaryrefslogtreecommitdiff
path: root/src/javascript/jsc/bindings/builtins/js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-29 07:49:48 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-29 07:49:48 -0700
commitd49ba5028949f726e68b31093921c2187759ab4b (patch)
tree91fdcf74bc342c872ee7047fe1bd6ca9d3a0fe93 /src/javascript/jsc/bindings/builtins/js
parent22f74756b4cf173749b2f72fdae438f8def24bd2 (diff)
downloadbun-d49ba5028949f726e68b31093921c2187759ab4b.tar.gz
bun-d49ba5028949f726e68b31093921c2187759ab4b.tar.zst
bun-d49ba5028949f726e68b31093921c2187759ab4b.zip
[bun.js] Implement unsafe.{`arrayBufferToPtr`, `arrayBufferFromPtr`, `bufferFromPtr`}
Diffstat (limited to 'src/javascript/jsc/bindings/builtins/js')
-rw-r--r--src/javascript/jsc/bindings/builtins/js/JSBufferPrototype.js90
1 files changed, 40 insertions, 50 deletions
diff --git a/src/javascript/jsc/bindings/builtins/js/JSBufferPrototype.js b/src/javascript/jsc/bindings/builtins/js/JSBufferPrototype.js
index b7563580d..ea1234b8e 100644
--- a/src/javascript/jsc/bindings/builtins/js/JSBufferPrototype.js
+++ b/src/javascript/jsc/bindings/builtins/js/JSBufferPrototype.js
@@ -26,185 +26,181 @@
// ^ that comment is required or the builtins generator will have a fit.
//
//
-
-
-
-
// The fastest way as of April 2022 is to use DataView.
// DataView has intrinsics that cause inlining
function setBigUint64(offset, value, le) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setBigUint64(offset, value, le);
+ return this.dataView.setBigUint64(offset, value, le);
}
function readInt8(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getInt8(offset);
+ return this.dataView.getInt8(offset);
}
function readUInt8(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getUint8(offset);
+ return this.dataView.getUint8(offset);
}
function readInt16LE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getInt16(offset, true);
+ return this.dataView.getInt16(offset, true);
}
function readInt16BE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getInt16(offset);
+ return this.dataView.getInt16(offset);
}
function readUInt16LE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getUint16(offset, true);
+ return this.dataView.getUint16(offset, true);
}
function readUInt16BE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getUint16(offset);
+ return this.dataView.getUint16(offset);
}
function readInt32LE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getInt32(offset, true);
+ return this.dataView.getInt32(offset, true);
}
function readInt32BE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getInt32(offset);
+ return this.dataView.getInt32(offset);
}
function readUInt32LE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getUint32(offset, true);
+ return this.dataView.getUint32(offset, true);
}
function readUInt32BE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getUint32(offset);
+ return this.dataView.getUint32(offset);
}
function readFloatLE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getFloat32(offset, true);
+ return this.dataView.getFloat32(offset, true);
}
function readFloatBE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getFloat32(offset);
+ return this.dataView.getFloat32(offset);
}
function readDoubleLE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getFloat64(offset, true);
+ return this.dataView.getFloat64(offset, true);
}
function readDoubleBE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getFloat64(offset);
+ return this.dataView.getFloat64(offset);
}
function readBigInt64LE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getBigInt64(offset, true);
+ return this.dataView.getBigInt64(offset, true);
}
function readBigInt64BE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getBigInt64(offset);
+ return this.dataView.getBigInt64(offset);
}
function readBigUInt64LE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getBigUint64(offset, true);
+ return this.dataView.getBigUint64(offset, true);
}
function readBigUInt64BE(offset) {
"use strict";
- return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getBigUint64(offset);
+ return this.dataView.getBigUint64(offset);
}
function writeInt8(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setInt8(offset, value);
+ this.dataView.setInt8(offset, value);
return offset + 1;
}
function writeUInt8(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setUint8(offset, value);
+ this.dataView.setUint8(offset, value);
return offset + 1;
}
function writeInt16LE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setInt16(offset, value, true);
+ this.dataView.setInt16(offset, value, true);
return offset + 2;
}
function writeInt16BE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setInt16(offset, value);
+ this.dataView.setInt16(offset, value);
return offset + 2;
}
function writeUInt16LE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setUint16(offset, value, true);
+ this.dataView.setUint16(offset, value, true);
return offset + 2;
}
function writeUInt16BE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setUint16(offset, value);
+ this.dataView.setUint16(offset, value);
return offset + 2;
}
function writeInt32LE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setInt32(offset, value, true);
+ this.dataView.setInt32(offset, value, true);
return offset + 4;
}
function writeInt32BE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setInt32(offset, value);
+ this.dataView.setInt32(offset, value);
return offset + 4;
}
function writeUInt32LE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setUint32(offset, value, true);
+ this.dataView.setUint32(offset, value, true);
return offset + 4;
}
function writeUInt32BE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setUint32(offset, value);
+ this.dataView.setUint32(offset, value);
return offset + 4;
}
function writeFloatLE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setFloat32(offset, value, true);
+ this.dataView.setFloat32(offset, value, true);
return offset + 4;
}
function writeFloatBE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setFloat32(offset, value);
+ this.dataView.setFloat32(offset, value);
return offset + 4;
}
function writeDoubleLE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setFloat64(offset, value, true);
+ this.dataView.setFloat64(offset, value, true);
return offset + 8;
}
function writeDoubleBE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setFloat64(offset, value);
+ this.dataView.setFloat64(offset, value);
return offset + 8;
}
function writeBigInt64LE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setBigInt64(offset, value, true);
+ this.dataView.setBigInt64(offset, value, true);
return offset + 8;
}
function writeBigInt64BE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setBigInt64(offset, value);
+ this.dataView.setBigInt64(offset, value);
return offset + 8;
}
function writeBigUInt64LE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setBigUint64(offset, value, true);
+ this.dataView.setBigUint64(offset, value, true);
return offset + 8;
}
function writeBigUInt64BE(value, offset) {
"use strict";
- (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setBigUint64(offset, value);
+ this.dataView.setBigUint64(offset, value);
return offset + 8;
}
@@ -219,8 +215,6 @@ function slice(start, end) {
return new Buffer(this.buffer, this.byteOffset + (start || 0), (end || this.byteLength) - (start || 0));
}
-
-
function utf8Write(text, offset, length) {
"use strict";
return this.write(text, offset, length, "utf8");
@@ -282,15 +276,11 @@ function base64urlSlice(offset, length) {
"use strict";
return this.toString(offset, length, "base64url");
}
-function hexSlice(offset, length) {
+
+function subarray(start, end) {
"use strict";
- var array = new @Uint8Array(this.buffer, this.byteOffset + (start || 0), (end || this.byteLength) - (start || 0));
- @setPrototypeDirect.@call(
- array,
- Buffer.prototype
- );
- return array;
+ return new Buffer(this.buffer, this.byteOffset + (start || 0), (end || this.byteLength) - (start || 0));
}
function toJSON() {