aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-22 13:53:00 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-22 13:53:24 -0700
commite869fc092f45d03aa0398613b316814a5219b762 (patch)
tree7d0129bf7b1fc11f15a6e2f9615e97bdee020107
parent2a6a5cf6d96cf4f24e193aaa5e8ed7fd0b37e034 (diff)
downloadbun-e869fc092f45d03aa0398613b316814a5219b762.tar.gz
bun-e869fc092f45d03aa0398613b316814a5219b762.tar.zst
bun-e869fc092f45d03aa0398613b316814a5219b762.zip
[node:buffer] Add missing `inspect` functionbun-v0.6.3
cc @paperdave
-rw-r--r--src/bun.js/bindings/JSBuffer.cpp1
-rw-r--r--src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.cpp13
-rw-r--r--src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.h9
-rw-r--r--src/bun.js/builtins/js/JSBufferPrototype.js7
-rw-r--r--test/js/node/buffer.test.js5
5 files changed, 35 insertions, 0 deletions
diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp
index 9d66fa1db..5c41ba0b1 100644
--- a/src/bun.js/bindings/JSBuffer.cpp
+++ b/src/bun.js/bindings/JSBuffer.cpp
@@ -1817,6 +1817,7 @@ static const HashTableValue JSBufferPrototypeTableValues[]
{ "hexWrite"_s, static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, jsBufferPrototypeHexWriteCodeGenerator, 1 } },
{ "includes"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsBufferPrototypeFunction_includes, 3 } },
{ "indexOf"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsBufferPrototypeFunction_indexOf, 3 } },
+ { "inspect"_s, static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, jsBufferPrototypeInspectCodeGenerator, 2 } },
{ "lastIndexOf"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsBufferPrototypeFunction_lastIndexOf, 3 } },
{ "latin1Slice"_s, static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, jsBufferPrototypeLatin1SliceCodeGenerator, 2 } },
{ "latin1Write"_s, static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, jsBufferPrototypeLatin1WriteCodeGenerator, 1 } },
diff --git a/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.cpp b/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.cpp
index 8bd695758..19ce8a395 100644
--- a/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.cpp
+++ b/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.cpp
@@ -282,6 +282,19 @@ const char* const s_jsBufferPrototypeReadUIntLECode =
"})\n" \
;
+const JSC::ConstructAbility s_jsBufferPrototypeInspectCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeInspectCodeConstructorKind = JSC::ConstructorKind::None;
+const JSC::ImplementationVisibility s_jsBufferPrototypeInspectCodeImplementationVisibility = JSC::ImplementationVisibility::Public;
+const int s_jsBufferPrototypeInspectCodeLength = 81;
+static const JSC::Intrinsic s_jsBufferPrototypeInspectCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeInspectCode =
+ "(function (recurseTimes, ctx) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return @Bun.inspect(this);\n" \
+ "})\n" \
+;
+
const JSC::ConstructAbility s_jsBufferPrototypeReadUIntBECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_jsBufferPrototypeReadUIntBECodeConstructorKind = JSC::ConstructorKind::None;
const JSC::ImplementationVisibility s_jsBufferPrototypeReadUIntBECodeImplementationVisibility = JSC::ImplementationVisibility::Public;
diff --git a/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.h b/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.h
index 38544b9b5..47e720468 100644
--- a/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.h
+++ b/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.h
@@ -117,6 +117,11 @@ extern const int s_jsBufferPrototypeReadUIntLECodeLength;
extern const JSC::ConstructAbility s_jsBufferPrototypeReadUIntLECodeConstructAbility;
extern const JSC::ConstructorKind s_jsBufferPrototypeReadUIntLECodeConstructorKind;
extern const JSC::ImplementationVisibility s_jsBufferPrototypeReadUIntLECodeImplementationVisibility;
+extern const char* const s_jsBufferPrototypeInspectCode;
+extern const int s_jsBufferPrototypeInspectCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeInspectCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeInspectCodeConstructorKind;
+extern const JSC::ImplementationVisibility s_jsBufferPrototypeInspectCodeImplementationVisibility;
extern const char* const s_jsBufferPrototypeReadUIntBECode;
extern const int s_jsBufferPrototypeReadUIntBECodeLength;
extern const JSC::ConstructAbility s_jsBufferPrototypeReadUIntBECodeConstructAbility;
@@ -388,6 +393,7 @@ extern const JSC::ImplementationVisibility s_jsBufferPrototypeOffsetCodeImplemen
macro(readIntLE, jsBufferPrototypeReadIntLE, 2) \
macro(readIntBE, jsBufferPrototypeReadIntBE, 2) \
macro(readUIntLE, jsBufferPrototypeReadUIntLE, 2) \
+ macro(inspect, jsBufferPrototypeInspect, 2) \
macro(readUIntBE, jsBufferPrototypeReadUIntBE, 2) \
macro(readFloatLE, jsBufferPrototypeReadFloatLE, 1) \
macro(readFloatBE, jsBufferPrototypeReadFloatBE, 1) \
@@ -454,6 +460,7 @@ extern const JSC::ImplementationVisibility s_jsBufferPrototypeOffsetCodeImplemen
#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READINTLE 1
#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READINTBE 1
#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READUINTLE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_INSPECT 1
#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READUINTBE 1
#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READFLOATLE 1
#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READFLOATBE 1
@@ -521,6 +528,7 @@ extern const JSC::ImplementationVisibility s_jsBufferPrototypeOffsetCodeImplemen
macro(jsBufferPrototypeReadIntLECode, readIntLE, ASCIILiteral(), s_jsBufferPrototypeReadIntLECodeLength) \
macro(jsBufferPrototypeReadIntBECode, readIntBE, ASCIILiteral(), s_jsBufferPrototypeReadIntBECodeLength) \
macro(jsBufferPrototypeReadUIntLECode, readUIntLE, ASCIILiteral(), s_jsBufferPrototypeReadUIntLECodeLength) \
+ macro(jsBufferPrototypeInspectCode, inspect, ASCIILiteral(), s_jsBufferPrototypeInspectCodeLength) \
macro(jsBufferPrototypeReadUIntBECode, readUIntBE, ASCIILiteral(), s_jsBufferPrototypeReadUIntBECodeLength) \
macro(jsBufferPrototypeReadFloatLECode, readFloatLE, ASCIILiteral(), s_jsBufferPrototypeReadFloatLECodeLength) \
macro(jsBufferPrototypeReadFloatBECode, readFloatBE, ASCIILiteral(), s_jsBufferPrototypeReadFloatBECodeLength) \
@@ -582,6 +590,7 @@ extern const JSC::ImplementationVisibility s_jsBufferPrototypeOffsetCodeImplemen
macro(base64urlWrite) \
macro(hexSlice) \
macro(hexWrite) \
+ macro(inspect) \
macro(latin1Slice) \
macro(latin1Write) \
macro(offset) \
diff --git a/src/bun.js/builtins/js/JSBufferPrototype.js b/src/bun.js/builtins/js/JSBufferPrototype.js
index ec22806e2..1ae6fb0d6 100644
--- a/src/bun.js/builtins/js/JSBufferPrototype.js
+++ b/src/bun.js/builtins/js/JSBufferPrototype.js
@@ -155,6 +155,13 @@ function readUIntLE(offset, byteLength) {
}
@throwRangeError("byteLength must be >= 1 and <= 6");
}
+
+function inspect(recurseTimes, ctx) {
+ "use strict";
+
+ return @Bun.inspect(this);
+}
+
function readUIntBE(offset, byteLength) {
"use strict";
const view = this.@dataView ||= new DataView(this.buffer, this.byteOffset, this.byteLength);
diff --git a/test/js/node/buffer.test.js b/test/js/node/buffer.test.js
index f0295b08f..697774e0a 100644
--- a/test/js/node/buffer.test.js
+++ b/test/js/node/buffer.test.js
@@ -2387,3 +2387,8 @@ it("repro #2063", () => {
expect(buf[83]).toBe(49);
expect(buf[84]).toBe(125);
});
+
+it("inspect() should exist", () => {
+ expect(Buffer.prototype.inspect).toBeInstanceOf(Function);
+ expect(new Buffer("123").inspect()).toBe(Bun.inspect(new Buffer("123")));
+});