diff --git a/Makefile b/Makefile
index 07ab522d34..faa8ab9324 100644
--- a/Makefile
+++ b/Makefile
@@ -298,6 +298,7 @@ ARCHIVE_FILES_WITHOUT_LIBCRYPTO = $(MIMALLOC_FILE_PATH) \
-lz \
-larchive \
-lssl \
+ -lbase64
ARCHIVE_FILES = $(ARCHIVE_FILES_WITHOUT_LIBCRYPTO) -lcrypto
@@ -345,8 +346,14 @@ CLANG_VERSION = $(shell $(CC) --version | awk '/version/ {for(i=1; i<=NF; i++){i
bun:
+base64:
+ cd src/base64 && \
+ rm -rf src/base64/*.{o,ll,bc} && \
+ $(CC) $(CFLAGS) $(OPTIMIZATION_LEVEL) -g -fPIC -c *.c -I$(SRC_DIR)/base64 -emit-llvm && \
+ $(CXX) $(CXXFLAGS) $(CFLAGS) -c neonbase64.cc -g -fPIC -emit-llvm && \
+ $(AR) rcvs $(BUN_DEPS_OUT_DIR)/libbase64.a ./*.bc
-vendor-without-check: api analytics node-fallbacks runtime_js fallback_decoder bun_error mimalloc picohttp zlib boringssl libarchive libbacktrace lolhtml usockets uws
+vendor-without-check: api analytics node-fallbacks runtime_js fallback_decoder bun_error mimalloc picohttp zlib boringssl libarchive libbacktrace lolhtml usockets uws base64
prepare-types:
BUN_VERSION=$(PACKAGE_JSON_VERSION) $(BUN_RELEASE_BIN) types/bun/bundle.ts packages/bun-types
@@ -632,7 +639,7 @@ jsc-bindings-headers:
touch src/javascript/jsc/bindings/headers.zig
mkdir -p src/javascript/jsc/bindings-obj/
$(ZIG) build headers-obj
- $(CXX) $(PLATFORM_LINKER_FLAGS) $(JSC_FILES) ${ICU_FLAGS} $(BUN_LLD_FLAGS_WITHOUT_JSC) -g $(DEBUG_BIN)/headers.o -W -o /tmp/build-jsc-headers -lc -Wl,--unresolved-symbols=ignore-all;
+ $(CXX) $(PLATFORM_LINKER_FLAGS) $(JSC_FILES) ${ICU_FLAGS} $(BUN_LLD_FLAGS_WITHOUT_JSC) -g $(DEBUG_BIN)/headers.o -W -o /tmp/build-jsc-headers -lc;
/tmp/build-jsc-headers
$(ZIG) translate-c src/javascript/jsc/bindings/headers.h > src/javascript/jsc/bindings/headers.zig
$(ZIG) run misctools/headers-cleaner.zig -lc
@@ -854,6 +861,8 @@ test-dev: test-dev-with-hmr
jsc-copy-headers:
cp $(WEBKIT_DIR)/Source/JavaScriptCore/heap/WeakHandleOwner.h $(WEBKIT_RELEASE_DIR)/JavaScriptCore/PrivateHeaders/JavaScriptCore/WeakHandleOwner.h
+ cp $(WEBKIT_DIR)/Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.h $(WEBKIT_RELEASE_DIR)/JavaScriptCore/PrivateHeaders/JavaScriptCore/JSTypedArrayViewPrototype.h
+ cp $(WEBKIT_DIR)/Source/JavaScriptCore/runtime/JSTypedArrayPrototypes.h $(WEBKIT_RELEASE_DIR)/JavaScriptCore/PrivateHeaders/JavaScriptCore/JSTypedArrayPrototypes.h
find $(WEBKIT_RELEASE_DIR)/JavaScriptCore/Headers/JavaScriptCore/ -name "*.h" -exec cp {} $(WEBKIT_RELEASE_DIR)/JavaScriptCore/PrivateHeaders/JavaScriptCore/ \;
# This is a workaround for a JSC bug that impacts aarch64
diff --git a/integration/snapshots/export-default-module-hot.hmr.js b/integration/snapshots/export-default-module-hot.hmr.js
index e0d02d271c..39d1c30952 100644
--- a/integration/snapshots/export-default-module-hot.hmr.js
+++ b/integration/snapshots/export-default-module-hot.hmr.js
@@ -1,19 +1,35 @@
import {
-__cJS2eSM
+__HMRClient as Bun
} from "http://localhost:8080/bun:wrap";
-import {
-__exportDefault
-} from "http://localhost:8080/bun:wrap";
-export default __cJS2eSM(function(module, exports) {
- __exportDefault(module.exports, module.id);
+Bun.activate(false);
+import {
+__FastRefreshModule as FastHMR
+} from "http://localhost:8080/bun:wrap";
+import {
+__FastRefreshRuntime as FastRefresh
+} from "http://localhost:8080/bun:wrap";
+var hmr = new FastHMR(2909748314, "export-default-module-hot.js", FastRefresh), exports = hmr.exports;
+
+(hmr._load = function() {
+ var export_default_module_hot_default = typeof module !== "undefined" && module.id;
function test() {
testDone(import.meta.url);
}
- Object.defineProperty(module.exports,"test",{get: () => test, enumerable: true, configurable: true});
-}, "export-default-module-hot.js");
-
-
+ hmr.exportAll({
+ default: () => export_default_module_hot_default,
+ test: () => test
+ });
+})();
+var $$hmr_default = hmr.exports.default, $$hmr_test = hmr.exports.test;
+hmr._update = function(exports) {
+ $$hmr_default = exports.default;
+ $$hmr_test = exports.test;
+};
+export {
+ $$hmr_default as default,
+ $$hmr_test as test
+};
//# sourceMappingURL=http://localhost:8080/export-default-module-hot.js.map
diff --git a/integration/snapshots/export-default-module-hot.js b/integration/snapshots/export-default-module-hot.js
index e0d02d271c..a9de546d54 100644
--- a/integration/snapshots/export-default-module-hot.js
+++ b/integration/snapshots/export-default-module-hot.js
@@ -1,19 +1,6 @@
-import {
-__cJS2eSM
-} from "http://localhost:8080/bun:wrap";
-import {
-__exportDefault
-} from "http://localhost:8080/bun:wrap";
-export default __cJS2eSM(function(module, exports) {
- __exportDefault(module.exports, module.id);
-
- function test() {
- testDone(import.meta.url);
- }
- Object.defineProperty(module.exports,"test",{get: () => test, enumerable: true, configurable: true});
-}, "export-default-module-hot.js");
-
-
-
+export default typeof module !== "undefined" && module.id;
+export function test() {
+ testDone(import.meta.url);
+}
//# sourceMappingURL=http://localhost:8080/export-default-module-hot.js.map
diff --git a/src/base64/README.md b/src/base64/README.md
new file mode 100644
index 0000000000..82bfb8ba25
--- /dev/null
+++ b/src/base64/README.md
@@ -0,0 +1,8 @@
+# Base64
+
+This uses https://github.com/lemire/fastbase64
+
+Changes:
+
+- chromiumbase64 doesn't add a null byte
+- chromiumbase64 handles some whitespace characters more loosely
diff --git a/src/base64/base64.zig b/src/base64/base64.zig
new file mode 100644
index 0000000000..fa4fc9dc9e
--- /dev/null
+++ b/src/base64/base64.zig
@@ -0,0 +1,53 @@
+const std = @import("std");
+
+extern fn bun_base64_encode(dest: [*]u8, src: [*]const u8, len: usize) usize;
+extern fn bun_base64_decode(dest: [*]u8, src: [*]const u8, len: usize, out_len: *usize) usize;
+
+pub const DecodeResult = struct {
+ written: usize,
+ fail: bool = false,
+};
+
+pub fn decode(destination: []u8, source: []const u8) DecodeResult {
+ var out: usize = 0;
+ const ret = bun_base64_decode(destination.ptr, source.ptr, source.len, &out);
+ if (ret == std.math.maxInt(usize) - 1) {
+ return .{
+ .written = out,
+ .fail = true,
+ };
+ }
+
+ // std.debug.assert(out == ret);
+
+ return .{
+ .written = out,
+ .fail = false,
+ };
+}
+
+pub fn encode(destination: []u8, source: []const u8) usize {
+ return bun_base64_encode(destination.ptr, source.ptr, source.len);
+}
+
+/// Given a source string of length len, this returns the amount of
+/// memory the destination string should have.
+///
+/// remember, this is integer math
+/// 3 bytes turn into 4 chars
+/// ceiling[len / 3] * 4
+///
+///
+pub fn decodeLen(source: []const u8) usize {
+ return (source.len / 4 * 3 + 2);
+}
+
+pub fn encodeLen(source: []const u8) usize {
+ return (source.len + 2) / 3 * 4;
+}
+
+pub const urlsafe = std.base64.Base64DecoderWithIgnore.init(
+ std.base64.url_safe_alphabet_chars,
+ null,
+ "= \t\r\n" ++ [_]u8{ std.ascii.control_code.VT, std.ascii.control_code.FF },
+);
diff --git a/src/base64/bun-base64.bc b/src/base64/bun-base64.bc
new file mode 100644
index 0000000000..6a004c8dcc
Binary files /dev/null and b/src/base64/bun-base64.bc differ
diff --git a/src/base64/bun-base64.c b/src/base64/bun-base64.c
new file mode 100644
index 0000000000..e11f88da59
--- /dev/null
+++ b/src/base64/bun-base64.c
@@ -0,0 +1,46 @@
+
+#include "bun-base64.h"
+
+#if defined(__GNUC__) && defined(__ARM_NEON__)
+
+int neon_base64_decode(char *out, const char *src, size_t srclen,
+ size_t *outlen);
+
+#elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
+
+#include "fastavxbase64.h"
+
+#endif
+
+#if defined(__GNUC__) && defined(__ARM_NEON__)
+size_t bun_base64_decode(char *dest, const char *src, size_t len,
+ size_t *outlen) {
+ // neon base64 is decode only
+ return neon_base64_decode(dest, src, len, outlen);
+}
+size_t bun_base64_encode(char *dest, const char *src, size_t len) {
+ return chromium_base64_encode(dest, src, len);
+}
+
+#elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
+
+size_t bun_base64_decode(char *dest, const char *src, size_t len,
+ size_t *outlen) {
+ return fast_avx2_base64_decode(dest, src, len, outlen);
+}
+size_t bun_base64_encode(char *dest, const char *src, size_t len) {
+
+ return fast_avx2_base64_encode(dest, src, len);
+}
+
+#else
+
+size_t bun_base64_decode(char *dest, const char *src, size_t len,
+ size_t *outlen) {
+ return chromium_base64_decode(dest, src, len, outlen);
+}
+size_t bun_base64_encode(char *dest, const char *src, size_t len) {
+ return chromium_base64_encode(dest, src, len);
+}
+
+#endif
\ No newline at end of file
diff --git a/src/base64/bun-base64.h b/src/base64/bun-base64.h
new file mode 100644
index 0000000000..82b15d73ab
--- /dev/null
+++ b/src/base64/bun-base64.h
@@ -0,0 +1,7 @@
+
+#include "chromiumbase64.h"
+#include "fastavxbase64.h"
+
+size_t bun_base64_decode(char *dest, const char *src, size_t len,
+ size_t *outlen);
+size_t bun_base64_encode(char *dest, const char *str, size_t len);
\ No newline at end of file
diff --git a/src/base64/chromiumbase64.bc b/src/base64/chromiumbase64.bc
new file mode 100644
index 0000000000..42178e5b85
Binary files /dev/null and b/src/base64/chromiumbase64.bc differ
diff --git a/src/base64/chromiumbase64.c b/src/base64/chromiumbase64.c
new file mode 100644
index 0000000000..8fabd57d21
--- /dev/null
+++ b/src/base64/chromiumbase64.c
@@ -0,0 +1,415 @@
+#include "chromiumbase64.h"
+
+// from node:
+static const int8_t unbase64_table[256] = {
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, -2, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60,
+ 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1,
+ 63, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
+ 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1};
+
+#define CHAR62 '+'
+#define CHAR63 '/'
+#define CHARPAD '='
+static const char e0[256] = {
+ 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'D', 'D', 'D',
+ 'D', 'E', 'E', 'E', 'E', 'F', 'F', 'F', 'F', 'G', 'G', 'G', 'G', 'H', 'H',
+ 'H', 'H', 'I', 'I', 'I', 'I', 'J', 'J', 'J', 'J', 'K', 'K', 'K', 'K', 'L',
+ 'L', 'L', 'L', 'M', 'M', 'M', 'M', 'N', 'N', 'N', 'N', 'O', 'O', 'O', 'O',
+ 'P', 'P', 'P', 'P', 'Q', 'Q', 'Q', 'Q', 'R', 'R', 'R', 'R', 'S', 'S', 'S',
+ 'S', 'T', 'T', 'T', 'T', 'U', 'U', 'U', 'U', 'V', 'V', 'V', 'V', 'W', 'W',
+ 'W', 'W', 'X', 'X', 'X', 'X', 'Y', 'Y', 'Y', 'Y', 'Z', 'Z', 'Z', 'Z', 'a',
+ 'a', 'a', 'a', 'b', 'b', 'b', 'b', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'd',
+ 'e', 'e', 'e', 'e', 'f', 'f', 'f', 'f', 'g', 'g', 'g', 'g', 'h', 'h', 'h',
+ 'h', 'i', 'i', 'i', 'i', 'j', 'j', 'j', 'j', 'k', 'k', 'k', 'k', 'l', 'l',
+ 'l', 'l', 'm', 'm', 'm', 'm', 'n', 'n', 'n', 'n', 'o', 'o', 'o', 'o', 'p',
+ 'p', 'p', 'p', 'q', 'q', 'q', 'q', 'r', 'r', 'r', 'r', 's', 's', 's', 's',
+ 't', 't', 't', 't', 'u', 'u', 'u', 'u', 'v', 'v', 'v', 'v', 'w', 'w', 'w',
+ 'w', 'x', 'x', 'x', 'x', 'y', 'y', 'y', 'y', 'z', 'z', 'z', 'z', '0', '0',
+ '0', '0', '1', '1', '1', '1', '2', '2', '2', '2', '3', '3', '3', '3', '4',
+ '4', '4', '4', '5', '5', '5', '5', '6', '6', '6', '6', '7', '7', '7', '7',
+ '8', '8', '8', '8', '9', '9', '9', '9', '+', '+', '+', '+', '/', '/', '/',
+ '/'};
+
+static const char e1[256] = {
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
+ 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
+ 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', '+', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
+ 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
+ '4', '5', '6', '7', '8', '9', '+', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
+ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
+ 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
+ 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', 'A', 'B', 'C',
+ 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
+ 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
+ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+ 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+',
+ '/'};
+
+static const char e2[256] = {
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
+ 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
+ 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', '+', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
+ 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
+ '4', '5', '6', '7', '8', '9', '+', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
+ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
+ 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
+ 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', 'A', 'B', 'C',
+ 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
+ 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
+ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+ 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+',
+ '/'};
+
+/* SPECIAL DECODE TABLES FOR LITTLE ENDIAN (INTEL) CPUS */
+
+static const uint32_t d0[256] = {
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x000000f8, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x000000fc,
+ 0x000000d0, 0x000000d4, 0x000000d8, 0x000000dc, 0x000000e0, 0x000000e4,
+ 0x000000e8, 0x000000ec, 0x000000f0, 0x000000f4, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000,
+ 0x00000004, 0x00000008, 0x0000000c, 0x00000010, 0x00000014, 0x00000018,
+ 0x0000001c, 0x00000020, 0x00000024, 0x00000028, 0x0000002c, 0x00000030,
+ 0x00000034, 0x00000038, 0x0000003c, 0x00000040, 0x00000044, 0x00000048,
+ 0x0000004c, 0x00000050, 0x00000054, 0x00000058, 0x0000005c, 0x00000060,
+ 0x00000064, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x00000068, 0x0000006c, 0x00000070, 0x00000074, 0x00000078,
+ 0x0000007c, 0x00000080, 0x00000084, 0x00000088, 0x0000008c, 0x00000090,
+ 0x00000094, 0x00000098, 0x0000009c, 0x000000a0, 0x000000a4, 0x000000a8,
+ 0x000000ac, 0x000000b0, 0x000000b4, 0x000000b8, 0x000000bc, 0x000000c0,
+ 0x000000c4, 0x000000c8, 0x000000cc, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff};
+
+static const uint32_t d1[256] = {
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x0000e003, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x0000f003,
+ 0x00004003, 0x00005003, 0x00006003, 0x00007003, 0x00008003, 0x00009003,
+ 0x0000a003, 0x0000b003, 0x0000c003, 0x0000d003, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000,
+ 0x00001000, 0x00002000, 0x00003000, 0x00004000, 0x00005000, 0x00006000,
+ 0x00007000, 0x00008000, 0x00009000, 0x0000a000, 0x0000b000, 0x0000c000,
+ 0x0000d000, 0x0000e000, 0x0000f000, 0x00000001, 0x00001001, 0x00002001,
+ 0x00003001, 0x00004001, 0x00005001, 0x00006001, 0x00007001, 0x00008001,
+ 0x00009001, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x0000a001, 0x0000b001, 0x0000c001, 0x0000d001, 0x0000e001,
+ 0x0000f001, 0x00000002, 0x00001002, 0x00002002, 0x00003002, 0x00004002,
+ 0x00005002, 0x00006002, 0x00007002, 0x00008002, 0x00009002, 0x0000a002,
+ 0x0000b002, 0x0000c002, 0x0000d002, 0x0000e002, 0x0000f002, 0x00000003,
+ 0x00001003, 0x00002003, 0x00003003, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff};
+
+static const uint32_t d2[256] = {
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x00800f00, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00c00f00,
+ 0x00000d00, 0x00400d00, 0x00800d00, 0x00c00d00, 0x00000e00, 0x00400e00,
+ 0x00800e00, 0x00c00e00, 0x00000f00, 0x00400f00, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000,
+ 0x00400000, 0x00800000, 0x00c00000, 0x00000100, 0x00400100, 0x00800100,
+ 0x00c00100, 0x00000200, 0x00400200, 0x00800200, 0x00c00200, 0x00000300,
+ 0x00400300, 0x00800300, 0x00c00300, 0x00000400, 0x00400400, 0x00800400,
+ 0x00c00400, 0x00000500, 0x00400500, 0x00800500, 0x00c00500, 0x00000600,
+ 0x00400600, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x00800600, 0x00c00600, 0x00000700, 0x00400700, 0x00800700,
+ 0x00c00700, 0x00000800, 0x00400800, 0x00800800, 0x00c00800, 0x00000900,
+ 0x00400900, 0x00800900, 0x00c00900, 0x00000a00, 0x00400a00, 0x00800a00,
+ 0x00c00a00, 0x00000b00, 0x00400b00, 0x00800b00, 0x00c00b00, 0x00000c00,
+ 0x00400c00, 0x00800c00, 0x00c00c00, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff};
+
+static const uint32_t d3[256] = {
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x003e0000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x003f0000,
+ 0x00340000, 0x00350000, 0x00360000, 0x00370000, 0x00380000, 0x00390000,
+ 0x003a0000, 0x003b0000, 0x003c0000, 0x003d0000, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000,
+ 0x00010000, 0x00020000, 0x00030000, 0x00040000, 0x00050000, 0x00060000,
+ 0x00070000, 0x00080000, 0x00090000, 0x000a0000, 0x000b0000, 0x000c0000,
+ 0x000d0000, 0x000e0000, 0x000f0000, 0x00100000, 0x00110000, 0x00120000,
+ 0x00130000, 0x00140000, 0x00150000, 0x00160000, 0x00170000, 0x00180000,
+ 0x00190000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x001a0000, 0x001b0000, 0x001c0000, 0x001d0000, 0x001e0000,
+ 0x001f0000, 0x00200000, 0x00210000, 0x00220000, 0x00230000, 0x00240000,
+ 0x00250000, 0x00260000, 0x00270000, 0x00280000, 0x00290000, 0x002a0000,
+ 0x002b0000, 0x002c0000, 0x002d0000, 0x002e0000, 0x002f0000, 0x00300000,
+ 0x00310000, 0x00320000, 0x00330000, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
+ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff};
+
+#define BADCHAR 0x01FFFFFF
+
+/**
+ * you can control if we use padding by commenting out this
+ * next line. However, I highly recommend you use padding and not
+ * using it should only be for compatability with a 3rd party.
+ * Also, 'no padding' is not tested!
+ */
+// #define DOPAD 1
+
+/*
+ * if we aren't doing padding
+ * set the pad character to NULL
+ */
+#ifndef DOPAD
+#undef CHARPAD
+#define CHARPAD '\0'
+#endif
+
+size_t chromium_base64_encode(char *dest, const char *str, size_t len) {
+ size_t i = 0;
+ uint8_t *p = (uint8_t *)dest;
+
+ /* unsigned here is important! */
+ uint8_t t1, t2, t3;
+
+ if (len > 2) {
+ for (; i < len - 2; i += 3) {
+ t1 = str[i];
+ t2 = str[i + 1];
+ t3 = str[i + 2];
+ *p++ = e0[t1];
+ *p++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
+ *p++ = e1[((t2 & 0x0F) << 2) | ((t3 >> 6) & 0x03)];
+ *p++ = e2[t3];
+ }
+ }
+
+ switch (len - i) {
+ case 0:
+ break;
+ case 1:
+ t1 = str[i];
+ *p++ = e0[t1];
+ *p++ = e1[(t1 & 0x03) << 4];
+ // *p++ = CHARPAD;
+ // *p++ = CHARPAD;
+ break;
+ default: /* case 2 */
+ t1 = str[i];
+ t2 = str[i + 1];
+ *p++ = e0[t1];
+ *p++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
+ *p++ = e2[(t2 & 0x0F) << 2];
+ // *p++ = CHARPAD;
+ }
+
+ // Commented out because it already returns the length
+ // *p = '\0';
+ return p - (uint8_t *)dest;
+}
+
+size_t chromium_base64_decode(char *dest, const char *src, size_t len,
+ size_t *out_len) {
+ if (len == 0) {
+ *out_len = 0;
+ return 0;
+ }
+
+#ifdef DOPAD
+ /*
+ * if padding is used, then the message must be at least
+ * 4 chars and be a multiple of 4
+ */
+ if (len < 4 || (len % 4 != 0)) {
+ *out_len = 0;
+ return MODP_B64_ERROR; /* error */
+ }
+ /* there can be at most 2 pad chars at the end */
+ if (src[len - 1] == CHARPAD) {
+ len--;
+ if (src[len - 1] == CHARPAD) {
+ len--;
+ }
+ }
+#endif
+
+ size_t i;
+ int leftover = len % 4;
+ size_t chunks = (leftover == 0) ? len / 4 - 1 : len / 4;
+
+ uint8_t *p = (uint8_t *)dest;
+ uint32_t x = 0;
+ const uint8_t *y = (uint8_t *)src;
+ for (i = 0; i < chunks;) {
+ x = d0[y[0]] | d1[y[1]] | d2[y[2]] | d3[y[3]];
+ if (x >= BADCHAR) {
+ // skip whitespace
+ // this is change bun added
+ if (y[0] < 64) {
+ y++;
+ continue;
+ }
+
+ *out_len = p - (uint8_t *)dest;
+ return MODP_B64_ERROR;
+ }
+
+ *p++ = ((uint8_t *)(&x))[0];
+ *p++ = ((uint8_t *)(&x))[1];
+ *p++ = ((uint8_t *)(&x))[2];
+ y += 4;
+ ++i;
+ }
+
+ switch (leftover) {
+ case 0:
+ x = d0[y[0]] | d1[y[1]] | d2[y[2]] | d3[y[3]];
+
+ if (x >= BADCHAR) {
+ *out_len = p - (uint8_t *)dest + 1;
+ return MODP_B64_ERROR;
+ }
+
+ *p++ = ((uint8_t *)(&x))[0];
+ *p++ = ((uint8_t *)(&x))[1];
+ *p = ((uint8_t *)(&x))[2];
+ return (chunks + 1) * 3;
+ break;
+ case 1: /* with padding this is an impossible case */
+ x = d0[y[0]];
+ *p = *((uint8_t *)(&x)); // i.e. first char/byte in int
+ break;
+ case 2: // * case 2, 1 output byte */
+ x = d0[y[0]] | d1[y[1]];
+ *p = *((uint8_t *)(&x)); // i.e. first char
+ break;
+ default: /* case 3, 2 output bytes */
+ x = d0[y[0]] | d1[y[1]] | d2[y[2]]; /* 0x3c */
+ *p++ = ((uint8_t *)(&x))[0];
+ *p = ((uint8_t *)(&x))[1];
+ break;
+ }
+
+ *out_len = 3 * chunks + (6 * leftover) / 8;
+
+ if (x >= BADCHAR)
+ return MODP_B64_ERROR;
+
+ return 3 * chunks + (6 * leftover) / 8;
+}
\ No newline at end of file
diff --git a/src/base64/chromiumbase64.h b/src/base64/chromiumbase64.h
new file mode 100644
index 0000000000..96b201c7bc
--- /dev/null
+++ b/src/base64/chromiumbase64.h
@@ -0,0 +1,165 @@
+/***************
+ * Taken more or less as-is from the chromium project
+ ****************/
+
+/**
+ * \file
+ *
+ * High performance base64 encoder / decoder
+ * Version 1.3 -- 17-Mar-2006
+ *
+ * Copyright © 2005, 2006, Nick Galbreath -- nickg [at] modp [dot] com
+ * All rights reserved.
+ *
+ * http://modp.com/release/base64
+ *
+ * Released under bsd license. See modp_b64.c for details.
+ *
+ *
+ * The default implementation is the standard b64 encoding with padding.
+ * It's easy to change this to use "URL safe" characters and to remove
+ * padding. See the modp_b64.c source code for details.
+ *
+ */
+
+#ifndef MODP_B64
+#define MODP_B64
+
+#include
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MODP_B64_ERROR ((size_t)-1)
+/**
+ * Encode a raw binary string into base 64.
+ * src contains the bytes
+ * len contains the number of bytes in the src
+ * dest should be allocated by the caller to contain
+ * at least chromium_base64_encode_len(len) bytes (see below)
+ * This will contain the null-terminated b64 encoded result
+ * returns length of the destination string plus the ending null byte
+ * i.e. the result will be equal to strlen(dest) + 1
+ *
+ * Example
+ *
+ * \code
+ * char* src = ...;
+ * int srclen = ...; //the length of number of bytes in src
+ * char* dest = (char*) malloc(chromium_base64_encode_len(srclen));
+ * int len = chromium_base64_encode(dest, src, sourcelen);
+ * if (len == MODP_B64_ERROR) {
+ * printf("Error\n");
+ * } else {
+ * printf("b64 = %s\n", dest);
+ * }
+ * \endcode
+ *
+ */
+size_t chromium_base64_encode(char *dest, const char *str, size_t len);
+
+/**
+ * Decode a base64 encoded string
+ *
+ *
+ * src should contain exactly len bytes of b64 characters.
+ * if src contains -any- non-base characters (such as white
+ * space, MODP_B64_ERROR is returned.
+ *
+ * dest should be allocated by the caller to contain at least
+ * len * 3 / 4 bytes.
+ *
+ * Returns the length (strlen) of the output, or MODP_B64_ERROR if unable to
+ * decode
+ *
+ * \code
+ * char* src = ...;
+ * int srclen = ...; // or if you don't know use strlen(src)
+ * char* dest = (char*) malloc(chromium_base64_decode_len(srclen));
+ * int len = chromium_base64_decode(dest, src, sourcelen);
+ * if (len == MODP_B64_ERROR) { error }
+ * \endcode
+ */
+size_t chromium_base64_decode(char *dest, const char *src, size_t len,
+ size_t *out_len);
+
+/**
+ * Given a source string of length len, this returns the amount of
+ * memory the destination string should have.
+ *
+ * remember, this is integer math
+ * 3 bytes turn into 4 chars
+ * ceiling[len / 3] * 4 + 1
+ *
+ * +1 is for any extra null.
+ */
+#define chromium_base64_encode_len(A) ((A + 2) / 3 * 4 + 1)
+
+/**
+ * Given a base64 string of length len,
+ * this returns the amount of memory required for output string
+ * It maybe be more than the actual number of bytes written.
+ * NOTE: remember this is integer math
+ * this allocates a bit more memory than traditional versions of b64
+ * decode 4 chars turn into 3 bytes
+ * floor[len * 3/4] + 2
+ */
+#define chromium_base64_decode_len(A) (A / 4 * 3 + 2)
+
+/**
+ * Will return the strlen of the output from encoding.
+ * This may be less than the required number of bytes allocated.
+ *
+ * This allows you to 'deserialized' a struct
+ * \code
+ * char* b64encoded = "...";
+ * int len = strlen(b64encoded);
+ *
+ * struct datastuff foo;
+ * if (chromium_base64_encode_strlen(sizeof(struct datastuff)) != len) {
+ * // wrong size
+ * return false;
+ * } else {
+ * // safe to do;
+ * if (chromium_base64_encode((char*) &foo, b64encoded, len) ==
+ * MODP_B64_ERROR) {
+ * // bad characters
+ * return false;
+ * }
+ * }
+ * // foo is filled out now
+ * \endcode
+ */
+#define chromium_base64_encode_strlen(A) ((A + 2) / 3 * 4)
+
+#ifdef __cplusplus
+}
+
+#include
+
+/**
+ * base 64 decode a string (self-modifing)
+ * On failure, the string is empty.
+ *
+ * This function is for C++ only (duh)
+ *
+ * \param[in,out] s the string to be decoded
+ * \return a reference to the input string
+ */
+inline std::string &chromium_base64_encode(std::string &s) {
+ std::string x(chromium_base64_encode_len(s.size()), '\0');
+ size_t d = chromium_base64_encode(const_cast(x.data()), s.data(),
+ (int)s.size());
+ if (d == MODP_B64_ERROR) {
+ x.clear();
+ } else {
+ x.erase(d, std::string::npos);
+ }
+ s.swap(x);
+ return s;
+}
+
+#endif /* __cplusplus */
+#endif
\ No newline at end of file
diff --git a/src/base64/fastavxbase64.bc b/src/base64/fastavxbase64.bc
new file mode 100644
index 0000000000..f7ee9825d7
Binary files /dev/null and b/src/base64/fastavxbase64.bc differ
diff --git a/src/base64/fastavxbase64.c b/src/base64/fastavxbase64.c
new file mode 100644
index 0000000000..47be824b42
--- /dev/null
+++ b/src/base64/fastavxbase64.c
@@ -0,0 +1,186 @@
+#if defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
+#include "fastavxbase64.h"
+
+#include
+#include
+
+/**
+ * This code borrows from Wojciech Mula's library at
+ * https://github.com/WojciechMula/base64simd (published under BSD)
+ * as well as code from Alfred Klomp's library https://github.com/aklomp/base64
+ * (published under BSD)
+ *
+ */
+
+/**
+ * Note : Hardware such as Knights Landing might do poorly with this AVX2 code
+ * since it relies on shuffles. Alternatives might be faster.
+ */
+
+static inline __m256i enc_reshuffle(const __m256i input) {
+
+ // translation from SSE into AVX2 of procedure
+ // https://github.com/WojciechMula/base64simd/blob/master/encode/unpack_bigendian.cpp
+ const __m256i in = _mm256_shuffle_epi8(
+ input,
+ _mm256_set_epi8(10, 11, 9, 10, 7, 8, 6, 7, 4, 5, 3, 4, 1, 2, 0, 1,
+
+ 14, 15, 13, 14, 11, 12, 10, 11, 8, 9, 7, 8, 5, 6, 4, 5));
+
+ const __m256i t0 = _mm256_and_si256(in, _mm256_set1_epi32(0x0fc0fc00));
+ const __m256i t1 = _mm256_mulhi_epu16(t0, _mm256_set1_epi32(0x04000040));
+
+ const __m256i t2 = _mm256_and_si256(in, _mm256_set1_epi32(0x003f03f0));
+ const __m256i t3 = _mm256_mullo_epi16(t2, _mm256_set1_epi32(0x01000010));
+
+ return _mm256_or_si256(t1, t3);
+}
+
+static inline __m256i enc_translate(const __m256i in) {
+ const __m256i lut = _mm256_setr_epi8(
+ 65, 71, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -19, -16, 0, 0, 65, 71,
+ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -19, -16, 0, 0);
+ __m256i indices = _mm256_subs_epu8(in, _mm256_set1_epi8(51));
+ __m256i mask = _mm256_cmpgt_epi8((in), _mm256_set1_epi8(25));
+ indices = _mm256_sub_epi8(indices, mask);
+ __m256i out = _mm256_add_epi8(in, _mm256_shuffle_epi8(lut, indices));
+ return out;
+}
+
+static inline __m256i dec_reshuffle(__m256i in) {
+
+ // inlined procedure pack_madd from
+ // https://github.com/WojciechMula/base64simd/blob/master/decode/pack.avx2.cpp
+ // The only difference is that elements are reversed,
+ // only the multiplication constants were changed.
+
+ const __m256i merge_ab_and_bc = _mm256_maddubs_epi16(
+ in,
+ _mm256_set1_epi32(0x01400140)); //_mm256_maddubs_epi16 is likely expensive
+ __m256i out =
+ _mm256_madd_epi16(merge_ab_and_bc, _mm256_set1_epi32(0x00011000));
+ // end of inlined
+
+ // Pack bytes together within 32-bit words, discarding words 3 and 7:
+ out = _mm256_shuffle_epi8(out, _mm256_setr_epi8(2, 1, 0, 6, 5, 4, 10, 9, 8,
+ 14, 13, 12, -1, -1, -1, -1, 2,
+ 1, 0, 6, 5, 4, 10, 9, 8, 14,
+ 13, 12, -1, -1, -1, -1));
+ // the call to _mm256_permutevar8x32_epi32 could be replaced by a call to
+ // _mm256_storeu2_m128i but it is doubtful that it would help
+ return _mm256_permutevar8x32_epi32(
+ out, _mm256_setr_epi32(0, 1, 2, 4, 5, 6, -1, -1));
+}
+
+size_t fast_avx2_base64_encode(char *dest, const char *str, size_t len) {
+ const char *const dest_orig = dest;
+ if (len >= 32 - 4) {
+ // first load is masked
+ __m256i inputvector = _mm256_maskload_epi32(
+ (int const *)(str - 4),
+ _mm256_set_epi32(0x80000000, 0x80000000, 0x80000000, 0x80000000,
+
+ 0x80000000, 0x80000000, 0x80000000,
+ 0x00000000 // we do not load the first 4 bytes
+ ));
+ //////////
+ // Intel docs: Faults occur only due to mask-bit required memory accesses
+ // that caused the faults. Faults will not occur due to referencing any
+ // memory location if the corresponding mask bit for
+ // that memory location is 0. For example, no faults will be detected if the
+ // mask bits are all zero.
+ ////////////
+ while (true) {
+ inputvector = enc_reshuffle(inputvector);
+ inputvector = enc_translate(inputvector);
+ _mm256_storeu_si256((__m256i *)dest, inputvector);
+ str += 24;
+ dest += 32;
+ len -= 24;
+ if (len >= 32) {
+ inputvector =
+ _mm256_loadu_si256((__m256i *)(str - 4)); // no need for a mask here
+ // we could do a mask load as long as len >= 24
+ } else {
+ break;
+ }
+ }
+ }
+ size_t scalarret = chromium_base64_encode(dest, str, len);
+ if (scalarret == MODP_B64_ERROR)
+ return MODP_B64_ERROR;
+ return (dest - dest_orig) + scalarret;
+}
+
+size_t fast_avx2_base64_decode(char *out, const char *src, size_t srclen,
+ size_t *outlen) {
+ char *out_orig = out;
+ while (srclen >= 45) {
+
+ // The input consists of six character sets in the Base64 alphabet,
+ // which we need to map back to the 6-bit values they represent.
+ // There are three ranges, two singles, and then there's the rest.
+ //
+ // # From To Add Characters
+ // 1 [43] [62] +19 +
+ // 2 [47] [63] +16 /
+ // 3 [48..57] [52..61] +4 0..9
+ // 4 [65..90] [0..25] -65 A..Z
+ // 5 [97..122] [26..51] -71 a..z
+ // (6) Everything else => invalid input
+
+ __m256i str = _mm256_loadu_si256((__m256i *)src);
+
+ // code by @aqrit from
+ // https://github.com/WojciechMula/base64simd/issues/3#issuecomment-271137490
+ // transated into AVX2
+ const __m256i lut_lo = _mm256_setr_epi8(
+ 0x15, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x13, 0x1A,
+ 0x1B, 0x1B, 0x1B, 0x1A, 0x15, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
+ 0x11, 0x11, 0x13, 0x1A, 0x1B, 0x1B, 0x1B, 0x1A);
+ const __m256i lut_hi = _mm256_setr_epi8(
+ 0x10, 0x10, 0x01, 0x02, 0x04, 0x08, 0x04, 0x08, 0x10, 0x10, 0x10, 0x10,
+ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x01, 0x02, 0x04, 0x08, 0x04, 0x08,
+ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10);
+ const __m256i lut_roll = _mm256_setr_epi8(
+ 0, 16, 19, 4, -65, -65, -71, -71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 19, 4,
+ -65, -65, -71, -71, 0, 0, 0, 0, 0, 0, 0, 0);
+
+ const __m256i mask_2F = _mm256_set1_epi8(0x2f);
+
+ // lookup
+ __m256i hi_nibbles = _mm256_srli_epi32(str, 4);
+ __m256i lo_nibbles = _mm256_and_si256(str, mask_2F);
+
+ const __m256i lo = _mm256_shuffle_epi8(lut_lo, lo_nibbles);
+ const __m256i eq_2F = _mm256_cmpeq_epi8(str, mask_2F);
+
+ hi_nibbles = _mm256_and_si256(hi_nibbles, mask_2F);
+ const __m256i hi = _mm256_shuffle_epi8(lut_hi, hi_nibbles);
+ const __m256i roll =
+ _mm256_shuffle_epi8(lut_roll, _mm256_add_epi8(eq_2F, hi_nibbles));
+
+ if (!_mm256_testz_si256(lo, hi)) {
+ break;
+ }
+
+ str = _mm256_add_epi8(str, roll);
+ // end of copied function
+
+ srclen -= 32;
+ src += 32;
+
+ // end of inlined function
+
+ // Reshuffle the input to packed 12-byte output format:
+ str = dec_reshuffle(str);
+ _mm256_storeu_si256((__m256i *)out, str);
+ out += 24;
+ }
+ size_t scalarret = chromium_base64_decode(out, src, srclen, outlen);
+ *outlen += (out - out_orig);
+ if (scalarret == MODP_B64_ERROR)
+ return MODP_B64_ERROR;
+ return (out - out_orig) + scalarret;
+}
+#endif
\ No newline at end of file
diff --git a/src/base64/fastavxbase64.h b/src/base64/fastavxbase64.h
new file mode 100644
index 0000000000..d1064a5d16
--- /dev/null
+++ b/src/base64/fastavxbase64.h
@@ -0,0 +1,41 @@
+#if defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
+
+#ifndef EXPAVX_B64
+#define EXPAVX_B64
+
+/**
+ * Assumes recent x64 hardware with AVX2 instructions.
+ */
+
+#include "chromiumbase64.h"
+#include
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * This code extends Nick Galbreath's high performance base 64decoder (used in
+ * Chromium), the API is the same effectively, see chromium64.h.
+ */
+
+/*
+ * AVX2 accelerated version of Galbreath's chromium_base64_decode function
+ * Usage remains the same, see chromium.h.
+ */
+size_t fast_avx2_base64_decode(char *out, const char *src, size_t srclen,
+ size_t *outlen);
+
+/*
+ * AVX2 accelerated version of Galbreath's chromium_base64_encode function
+ * Usage remains the same, see chromium.h.
+ */
+size_t fast_avx2_base64_encode(char *dest, const char *str, size_t len);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
+#endif
\ No newline at end of file
diff --git a/src/base64/neonbase64 b/src/base64/neonbase64
new file mode 100644
index 0000000000..74153ebe4f
Binary files /dev/null and b/src/base64/neonbase64 differ
diff --git a/src/base64/neonbase64.bc b/src/base64/neonbase64.bc
new file mode 100644
index 0000000000..91c10bf4fd
Binary files /dev/null and b/src/base64/neonbase64.bc differ
diff --git a/src/base64/neonbase64.cc b/src/base64/neonbase64.cc
new file mode 100644
index 0000000000..a1249d21bc
--- /dev/null
+++ b/src/base64/neonbase64.cc
@@ -0,0 +1,120 @@
+// clang-format off
+#if defined (__GNUC__) && defined(__ARM_NEON__)
+
+#include
+#include
+#include "chromiumbase64.h"
+#define MODP_B64_ERROR ((size_t)-1)
+
+#include
+
+
+extern "C" int neon_base64_decode(char *out, const char *src, size_t srclen, size_t *outlen);
+
+
+// The input consists of six character sets in the Base64 alphabet,
+// which we need to map back to the 6-bit values they represent.
+// There are three ranges, two singles, and then there's the rest.
+//
+// # From To Add Characters
+// 1 [43] [62] +19 +
+// 2 [47] [63] +16 /
+// 3 [48..57] [52..61] +4 0..9
+// 4 [65..90] [0..25] -65 A..Z
+// 5 [97..122] [26..51] -71 a..z
+// (6) Everything else => invalid input
+
+int neon_base64_decode(char *out, const char *src, size_t srclen, size_t *outlen) {
+ char *out_orig = out;
+ const uint8x16_t lut_lo = {0x15, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
+ 0x11, 0x11, 0x13, 0x1A, 0x1B, 0x1B, 0x1B, 0x1A};
+ const uint8x16_t lut_hi = {0x10, 0x10, 0x01, 0x02, 0x04, 0x08, 0x04, 0x08,
+ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10};
+ const uint8x16_t lut_roll = {0, 16, 19, 4, 191, 191, 185, 185,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ const uint8x16_t zero8 = vdupq_n_u8(0);
+ const uint16x8_t zero16 = vdupq_n_u16(0);
+ const uint8x16_t k2f = vdupq_n_u8(0x2f);
+ const uint8x16_t kf = vdupq_n_u8(0xf);
+ const uint8x8_t cst = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
+ const uint16x4_t cst1 = {0x1000, 0x1000, 0x1000, 0x1000};
+
+ const uint8x8_t shuf0 = {2, 1, 0, 6, 5, 4, 2 + 8, 1 + 8};
+ const uint8x8_t shuf1 = {0 + 8, 6 + 8, 5 + 8, 4 + 8,
+ 2 + 16, 1 + 16, 0 + 16, 6 + 16};
+ const uint8x8_t shuf2 = {5 + 16, 4 + 16, 2 + 24, 1 + 24,
+ 0 + 24, 6 + 24, 5 + 24, 4 + 24};
+
+ uint8x8x4_t pack;
+ uint8x8_t res[3];
+ uint8x16_t str[2];
+
+ while (srclen >= 8 * 4) {
+ __builtin_memcpy(str, src, 8 * 4);
+
+ uint8x16_t in0 = str[0];
+ uint8x16_t in1 = str[1];
+ uint8x16_t lo_nibbles0 = vandq_u8(in0, kf);
+ uint8x16_t lo_nibbles1 = vandq_u8(in1, kf);
+ uint8x16_t hi_nibbles0 = vshrq_n_u8(in0, 4);
+ uint8x16_t hi_nibbles1 = vshrq_n_u8(in1, 4);
+
+ uint8x16_t lo0 = vqtbl1q_u8(lut_lo, lo_nibbles0);
+ uint8x16_t lo1 = vqtbl1q_u8(lut_lo, lo_nibbles1);
+ uint8x16_t hi0 = vqtbl1q_u8(lut_hi, hi_nibbles0);
+ uint8x16_t hi1 = vqtbl1q_u8(lut_hi, hi_nibbles1);
+ uint8x16_t test0 = vtstq_u8(lo0, hi0);
+ uint8x16_t test1 = vtstq_u8(lo1, hi1);
+ uint8x16_t orr0 = vorrq_u8(test0, test1);
+ uint8x8_t orr1 = vorr_u8(vget_low_u8(orr0), vget_high_u8(orr0));
+ if ((uint64_t)orr1)
+ break;
+
+ uint8x16_t eq_2F0 = vceqq_u8(in0, k2f);
+ uint8x16_t eq_2F1 = vceqq_u8(in1, k2f);
+ uint8x16_t add0 = vaddq_u8(eq_2F0, hi_nibbles0);
+ uint8x16_t add1 = vaddq_u8(eq_2F1, hi_nibbles1);
+ uint8x16_t roll0 = vqtbl1q_u8(lut_roll, add0);
+ uint8x16_t roll1 = vqtbl1q_u8(lut_roll, add1);
+ uint8x16_t rolled0 = vaddq_u8(in0, roll0);
+ uint8x16_t rolled1 = vaddq_u8(in1, roll1);
+
+ // Step 1: swap and merge adjacent 6-bit fields.
+ uint8x16x2_t unzip8 = vuzpq_u8(rolled0, rolled1);
+ uint8x16x2_t zip8 = vzipq_u8(unzip8.val[1], zero8);
+ uint16x8_t mul0 = vmlal_u8(vreinterpretq_u16_u8(zip8.val[0]),
+ vget_low_u8(unzip8.val[0]), cst);
+ uint16x8_t mul1 = vmlal_u8(vreinterpretq_u16_u8(zip8.val[1]),
+ vget_high_u8(unzip8.val[0]), cst);
+
+ // Step 2: swap and merge 12-bit words into a 24-bit word.
+ uint16x8x2_t unzip16 = vuzpq_u16(mul0, mul1);
+ uint16x8x2_t zip16 = vzipq_u16(unzip16.val[1], zero16);
+ uint32x4_t merge0 = vmlal_u16(vreinterpretq_u32_u16(zip16.val[0]),
+ vget_low_u16(unzip16.val[0]), cst1);
+ uint32x4_t merge1 = vmlal_u16(vreinterpretq_u32_u16(zip16.val[1]),
+ vget_high_u16(unzip16.val[0]), cst1);
+ pack.val[0] = vget_low_u8(vreinterpretq_u8_u32(merge0));
+ pack.val[1] = vget_high_u8(vreinterpretq_u8_u32(merge0));
+ pack.val[2] = vget_low_u8(vreinterpretq_u8_u32(merge1));
+ pack.val[3] = vget_high_u8(vreinterpretq_u8_u32(merge1));
+
+ res[0] = vtbl4_u8(pack, shuf0);
+ res[1] = vtbl4_u8(pack, shuf1);
+ res[2] = vtbl4_u8(pack, shuf2);
+ __builtin_memcpy(out, res, 6 * 4);
+
+ out += 6 * 4;
+ srclen -= 8 * 4;
+ src += 8 * 4;
+ }
+
+// std::cout << "Chromium? " << (out - out_orig) << std::endl;
+ size_t scalarret = chromium_base64_decode(out, src, srclen, outlen);
+ *outlen += (out - out_orig);
+ if (scalarret == MODP_B64_ERROR)
+ return (int)MODP_B64_ERROR;
+ return (out - out_orig) + scalarret;
+}
+
+#endif
\ No newline at end of file
diff --git a/src/global.zig b/src/global.zig
index 1e16db2162..5bec684b03 100644
--- a/src/global.zig
+++ b/src/global.zig
@@ -14,6 +14,7 @@ pub const FeatureFlags = @import("feature_flags.zig");
const root = @import("root");
pub const meta = @import("./meta.zig");
pub const ComptimeStringMap = @import("./comptime_string_map.zig").ComptimeStringMap;
+pub const base64 = @import("./base64/base64.zig");
pub const fmt = struct {
pub usingnamespace std.fmt;
diff --git a/src/javascript/jsc/bindings/Buffer.cpp b/src/javascript/jsc/bindings/Buffer.cpp
new file mode 100644
index 0000000000..e20807b504
--- /dev/null
+++ b/src/javascript/jsc/bindings/Buffer.cpp
@@ -0,0 +1,52 @@
+// ----- THIS IS NOT WEBCORE ----
+// It reuses the namespace.
+// ----- THIS IS NOT WEBCORE ----
+
+// Node.js buffer
+
+#include "root.h"
+
+#include "Buffer.h"
+#include "JavaScriptCore/JSArrayBufferViewInlines.h"
+
+namespace WebCore {
+
+Ref Buffer::create(JSC::JSGlobalObject* globalObject, RefPtr&& arrayBuffer, size_t byteOffset, size_t length)
+{
+ return adoptRef(*new Buffer(globalObject, WTFMove(arrayBuffer), byteOffset, length));
+}
+Ref Buffer::create(JSC::JSGlobalObject* globalObject, RefPtr&& arrayBuffer)
+{
+ return create(globalObject, WTFMove(arrayBuffer), 0, arrayBuffer->byteLength());
+}
+
+int32_t static write(WTF::StringView view, size_t offset, size_t length, BufferEncodingType encodingType)
+{
+}
+
+Buffer::~Buffer()
+{
+ m_arrayBuffer->deref();
+}
+
+Ref Buffer::createEmpty(JSC::JSGlobalObject* globalObject)
+{
+ return adoptRef(*new Buffer(globalObject, nullptr, 0, 0));
+}
+Ref Buffer::create(JSC::JSGlobalObject* globalObject, UChar* ptr, size_t len, BufferEncodingType encoding)
+{
+}
+Ref Buffer::create(JSC::JSGlobalObject* globalObject, LChar* ptr, size_t len, BufferEncodingType encoding)
+{
+}
+
+Ref Buffer::create(JSC::JSGlobalObject* globalObject, WTF::StringView& str, BufferEncodingType encoding)
+{
+ if (str.is8Bit()) {
+ }
+}
+Ref Buffer::create(JSC::JSGlobalObject* globalObject, WTF::String& str, BufferEncodingType encoding)
+{
+}
+
+}
\ No newline at end of file
diff --git a/src/javascript/jsc/bindings/Buffer.h b/src/javascript/jsc/bindings/Buffer.h
new file mode 100644
index 0000000000..ac57e4d258
--- /dev/null
+++ b/src/javascript/jsc/bindings/Buffer.h
@@ -0,0 +1,42 @@
+#pragma once
+// ----- THIS IS NOT WEBCORE ----
+// It reuses the namespace.
+// ----- THIS IS NOT WEBCORE ----
+
+// Node.js buffer
+
+#include "root.h"
+
+#include "BufferEncodingType.h"
+#include "JavaScriptCore/GenericTypedArrayView.h"
+
+namespace WebCore {
+
+class Buffer final : public RefCounted {
+public:
+ using Adaptor = JSC::JSUint8Array::Adaptor;
+ ~Buffer();
+
+ static int32_t write(WTF::StringView view, size_t offset, size_t length, BufferEncodingType encodingType);
+
+ static Ref create(JSC::JSGlobalObject* globalObject, RefPtr&&, size_t byteOffset, size_t length);
+ static Ref create(JSC::JSGlobalObject* globalObject, RefPtr&&);
+
+ static Ref createEmpty(JSC::JSGlobalObject* globalObject);
+ static Ref create(JSC::JSGlobalObject* globalObject, UChar* ptr, size_t len, BufferEncodingType encoding);
+ static Ref create(JSC::JSGlobalObject* globalObject, LChar* ptr, size_t len, BufferEncodingType encoding);
+
+ static Ref create(JSC::JSGlobalObject* globalObject, WTF::StringView&, BufferEncodingType encoding);
+ static Ref create(JSC::JSGlobalObject* globalObject, WTF::String&, BufferEncodingType encoding);
+
+ Buffer(JSC::JSGlobalObject* globalObject, RefPtr&& arrayBuffer, size_t byteOffset,
+ size_t length)
+ : m_arrayBuffer(WTFMove(arrayBuffer))
+
+ {
+ }
+
+ RefPtr m_arrayBuffer;
+};
+
+}
\ No newline at end of file
diff --git a/src/javascript/jsc/bindings/BufferEncodingType.h b/src/javascript/jsc/bindings/BufferEncodingType.h
new file mode 100644
index 0000000000..0d50587126
--- /dev/null
+++ b/src/javascript/jsc/bindings/BufferEncodingType.h
@@ -0,0 +1,20 @@
+#pragma once
+
+namespace WebCore {
+
+enum class BufferEncodingType {
+ utf8 = 0,
+ ucs2 = 1,
+ utf16le = 2,
+ latin1 = 3,
+ ascii = 4,
+ base64 = 5,
+ base64url = 6,
+ hex = 7,
+
+ /// Refer to the buffer's encoding
+ buffer = 8,
+
+};
+
+}
\ No newline at end of file
diff --git a/src/javascript/jsc/bindings/JSBuffer.cpp b/src/javascript/jsc/bindings/JSBuffer.cpp
new file mode 100644
index 0000000000..f45fd2a9af
--- /dev/null
+++ b/src/javascript/jsc/bindings/JSBuffer.cpp
@@ -0,0 +1,1218 @@
+#include "root.h"
+#include "JSBuffer.h"
+
+#include "ActiveDOMObject.h"
+#include "ExtendedDOMClientIsoSubspaces.h"
+#include "ExtendedDOMIsoSubspaces.h"
+#include "IDLTypes.h"
+// #include "JSBlob.h"
+#include "JSDOMAttribute.h"
+#include "JSDOMBinding.h"
+#include "JSDOMConstructor.h"
+#include "JSDOMConvertBase.h"
+#include "JSDOMConvertInterface.h"
+#include "JSDOMConvertStrings.h"
+#include "JSDOMExceptionHandling.h"
+#include "JSDOMGlobalObject.h"
+#include "JSDOMGlobalObjectInlines.h"
+#include "JSDOMOperation.h"
+#include "JSDOMWrapperCache.h"
+#include "ScriptExecutionContext.h"
+#include "WebCoreJSClientData.h"
+#include "JavaScriptCore/FunctionPrototype.h"
+#include "JavaScriptCore/HeapAnalyzer.h"
+
+#include "JavaScriptCore/JSDestructibleObjectHeapCellType.h"
+#include "JavaScriptCore/SlotVisitorMacros.h"
+#include "JavaScriptCore/SubspaceInlines.h"
+#include "wtf/GetPtr.h"
+#include "wtf/PointerPreparations.h"
+#include "wtf/URL.h"
+
+#include "JSBufferEncodingType.h"
+
+#if ENABLE(MEDIA_SOURCE)
+#include "BufferMediaSource.h"
+#include "JSMediaSource.h"
+#endif
+
+// #include "JavaScriptCore/JSTypedArrayViewPrototype.h"
+#include "JavaScriptCore/JSArrayBufferViewInlines.h"
+
+static JSC_DECLARE_HOST_FUNCTION(jsBufferConstructorFunction_alloc);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferConstructorFunction_allocUnsafe);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferConstructorFunction_allocUnsafeSlow);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferConstructorFunction_byteLength);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferConstructorFunction_compare);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferConstructorFunction_concat);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferConstructorFunction_from);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferConstructorFunction_isBuffer);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferConstructorFunction_isEncoding);
+
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_compare);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_copy);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_equals);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_fill);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_includes);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_indexOf);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_lastIndexOf);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readBigInt64BE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readBigInt64LE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readBigUInt64BE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readBigUInt64LE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readDoubleBE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readDoubleLE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readFloatBE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readFloatLE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readInt16BE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readInt16LE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readInt32BE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readInt32LE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readInt8);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readIntBE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readIntLE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readUInt16BE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readUInt16LE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readUInt32BE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readUInt32LE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readUInt8);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readUIntBE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_readUIntLE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_swap16);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_swap32);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_swap64);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_toString);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_write);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeBigInt64BE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeBigInt64LE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeBigUInt64BE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeBigUInt64LE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeDoubleBE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeDoubleLE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeFloatBE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeFloatLE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeInt16BE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeInt16LE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeInt32BE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeInt32LE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeInt8);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeIntBE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeIntLE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeUInt16BE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeUInt16LE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeUInt32BE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeUInt32LE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeUInt8);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeUIntBE);
+static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_writeUIntLE);
+
+namespace WebCore {
+using namespace JSC;
+
+template<> class IDLOperation {
+public:
+ using ClassParameter = JSC::JSUint8Array*;
+ using Operation = JSC::EncodedJSValue(JSC::JSGlobalObject*, JSC::CallFrame*, ClassParameter);
+
+ template
+ static JSC::EncodedJSValue call(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, const char* operationName)
+ {
+ auto& vm = JSC::getVM(&lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+ auto thisValue = callFrame.thisValue().toThis(&lexicalGlobalObject, JSC::ECMAMode::strict());
+ if (thisValue.isUndefinedOrNull()) {
+ throwTypeError(&lexicalGlobalObject, throwScope, "Cannot convert undefined or null to object");
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ auto thisObject = JSC::jsCast(thisValue);
+ if (UNLIKELY(!thisObject))
+ return throwThisTypeError(lexicalGlobalObject, throwScope, "Buffer", operationName);
+
+ RELEASE_AND_RETURN(throwScope, (operation(&lexicalGlobalObject, &callFrame, thisObject)));
+ }
+};
+
+class JSBufferPrototype : public JSC::JSNonFinalObject {
+public:
+ using Base = JSC::JSNonFinalObject;
+ static constexpr JSC::TypedArrayType TypedArrayStorageType = JSC::JSUint8Array::Adaptor::typeValue;
+ static JSBufferPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
+ {
+ JSBufferPrototype* ptr = new (NotNull, JSC::allocateCell(vm)) JSBufferPrototype(vm, globalObject, structure);
+ ptr->finishCreation(vm, globalObject);
+ return ptr;
+ }
+
+ DECLARE_INFO;
+ template
+ static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ return &vm.plainObjectSpace();
+ }
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+
+private:
+ JSBufferPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
+ : Base(vm, structure)
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
+};
+STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSBufferPrototype, JSBufferPrototype::Base);
+
+static inline JSC::EncodedJSValue jsBufferConstructorFunction_allocBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSValue::encode(jsUndefined());
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_alloc, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "alloc");
+}
+static inline JSC::EncodedJSValue jsBufferConstructorFunction_allocUnsafeBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSValue::encode(jsUndefined());
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_allocUnsafe, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "allocUnsafe");
+}
+static inline JSC::EncodedJSValue jsBufferConstructorFunction_allocUnsafeSlowBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSValue::encode(jsUndefined());
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_allocUnsafeSlow, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "allocUnsafeSlow");
+}
+static inline JSC::EncodedJSValue jsBufferConstructorFunction_byteLengthBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSValue::encode(jsUndefined());
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_byteLength, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "byteLength");
+}
+static inline JSC::EncodedJSValue jsBufferConstructorFunction_compareBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSValue::encode(jsUndefined());
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_compare, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "compare");
+}
+static inline JSC::EncodedJSValue jsBufferConstructorFunction_concatBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSValue::encode(jsUndefined());
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_concat, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "concat");
+}
+static inline JSC::EncodedJSValue jsBufferConstructorFunction_fromBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSValue::encode(jsUndefined());
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_from, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "from");
+}
+static inline JSC::EncodedJSValue jsBufferConstructorFunction_isBufferBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSValue::encode(jsUndefined());
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_isBuffer, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "isBuffer");
+}
+static inline JSC::EncodedJSValue jsBufferConstructorFunction_isEncodingBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSValue::encode(jsUndefined());
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_isEncoding, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "isEncoding");
+}
+
+using JSBufferConstructor = JSDOMConstructor;
+
+/* Hash table for constructor */
+static const HashTableValue JSBufferConstructorTableValues[] = {
+ { "alloc", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferConstructorFunction_alloc), (intptr_t)(3) } },
+ { "allocUnsafe", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferConstructorFunction_allocUnsafe), (intptr_t)(1) } },
+ { "allocUnsafeSlow", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferConstructorFunction_allocUnsafeSlow), (intptr_t)(1) } },
+ { "byteLength", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferConstructorFunction_byteLength), (intptr_t)(2) } },
+ { "compare", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferConstructorFunction_compare), (intptr_t)(2) } },
+ { "concat", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferConstructorFunction_concat), (intptr_t)(2) } },
+ { "from", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferConstructorFunction_from), (intptr_t)(3) } },
+ { "isBuffer", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferConstructorFunction_isBuffer), (intptr_t)(1) } },
+ { "isEncoding", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferConstructorFunction_isEncoding), (intptr_t)(1) } },
+};
+
+// new Buffer()
+static inline EncodedJSValue constructBufferEmpty(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
+{
+ VM& vm = lexicalGlobalObject->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto* castedThis = jsCast(callFrame->jsCallee());
+ ASSERT(castedThis);
+ auto object = Buffer::createEmpty(lexicalGlobalObject);
+ auto jsValue = toJSNewlyCreated>(*lexicalGlobalObject, *castedThis->globalObject(), throwScope, WTFMove(object));
+ if constexpr (IsExceptionOr)
+ RETURN_IF_EXCEPTION(throwScope, {});
+ setSubclassStructureIfNeeded(lexicalGlobalObject, callFrame, asObject(jsValue));
+ RETURN_IF_EXCEPTION(throwScope, {});
+ return JSValue::encode(jsValue);
+}
+
+// new Buffer(array)
+static inline EncodedJSValue constructBufferFromArray(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
+{
+ VM& vm = lexicalGlobalObject->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto* castedThis = jsCast(callFrame->jsCallee());
+ ASSERT(castedThis);
+ EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0);
+}
+
+// new Buffer(arrayBuffer[, byteOffset[, length]])
+static inline EncodedJSValue constructBufferFromArrayBuffer(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
+{
+ VM& vm = lexicalGlobalObject->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto* castedThis = jsCast(callFrame->jsCallee());
+ ASSERT(castedThis);
+ EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0);
+}
+
+// new Buffer(buffer)
+static inline EncodedJSValue constructBufferFromBuffer(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
+{
+ VM& vm = lexicalGlobalObject->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto* castedThis = jsCast(callFrame->jsCallee());
+ ASSERT(castedThis);
+ EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0);
+}
+
+// new Buffer(size)
+static inline EncodedJSValue constructBufferFromLength(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
+{
+ VM& vm = lexicalGlobalObject->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto* castedThis = jsCast(callFrame->jsCallee());
+ ASSERT(castedThis);
+ auto length = callFrame->uncheckedArgument(0).toInt32(lexicalGlobalObject);
+ if (length < 0) {
+ throwRangeError(lexicalGlobalObject, throwScope, "Invalid array length");
+ return JSValue::encode(jsUndefined());
+ }
+
+ auto arrayBuffer = JSC::ArrayBuffer::tryCreate(length, 1);
+ if (!arrayBuffer) {
+ throwOutOfMemoryError(lexicalGlobalObject, throwScope);
+ return JSValue::encode(jsUndefined());
+ }
+
+ auto uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, lexicalGlobalObject->typedArrayStructure(JSC::TypeUint8), WTFMove(arrayBuffer), 0, length);
+ uint8Array->setPrototypeDirect(vm, JSBuffer::prototype(vm, *jsCast(lexicalGlobalObject)));
+
+ return JSC::JSValue::encode(uint8Array);
+}
+
+// new Buffer(string[, encoding])
+static inline EncodedJSValue constructBufferFromStringAndEncoding(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
+{
+ VM& vm = lexicalGlobalObject->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto* castedThis = jsCast(callFrame->jsCallee());
+ ASSERT(castedThis);
+ EnsureStillAliveScope string = callFrame->uncheckedArgument(0);
+
+ JSC::JSValue optionalEncodingValue = jsUndefined();
+ if (callFrame->argumentCount() > 1) {
+ optionalEncodingValue = callFrame->uncheckedArgument(1);
+ }
+}
+
+template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSBufferConstructor::construct(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
+{
+ VM& vm = lexicalGlobalObject->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ UNUSED_PARAM(throwScope);
+ size_t argsCount = std::min(3, callFrame->argumentCount());
+ if (argsCount == 0) {
+ RELEASE_AND_RETURN(throwScope, (constructBufferEmpty(lexicalGlobalObject, callFrame)));
+ }
+ JSValue distinguishingArg = callFrame->uncheckedArgument(0);
+ if (distinguishingArg.isNumber()) {
+ RELEASE_AND_RETURN(throwScope, (constructBufferFromLength(lexicalGlobalObject, callFrame)));
+ }
+ // if (argsCount == 2) {
+
+ // if (distinguishingArg.isUndefined())
+ // RELEASE_AND_RETURN(throwScope, (constructJSBuffer1(lexicalGlobalObject, callFrame)));
+ // if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(vm))
+ // RELEASE_AND_RETURN(throwScope, (constructJSBuffer2(lexicalGlobalObject, callFrame)));
+ // RELEASE_AND_RETURN(throwScope, (constructJSBuffer1(lexicalGlobalObject, callFrame)));
+ // }
+ return argsCount < 1 ? throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)) : throwVMTypeError(lexicalGlobalObject, throwScope);
+}
+JSC_ANNOTATE_HOST_FUNCTION(JSBufferConstructorConstruct, JSBufferConstructor::construct);
+
+template<> const ClassInfo JSBufferConstructor::s_info = { "Buffer"_s, nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(JSBufferConstructor) };
+
+template<> JSValue JSBufferConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
+{
+ UNUSED_PARAM(vm);
+ return globalObject.functionPrototype();
+}
+
+template<> void JSBufferConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
+{
+ putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
+ JSString* nameString = jsNontrivialString(vm, "Buffer"_s);
+ m_originalName.set(vm, this, nameString);
+ putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
+ putDirect(vm, vm.propertyNames->prototype, JSBuffer::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete);
+ reifyStaticProperties(vm, JSBuffer::info(), JSBufferConstructorTableValues, *this);
+}
+
+bool JSBuffer__isBuffer(JSC::JSGlobalObject* global, JSC::EncodedJSValue value)
+{
+ VM& vm = global->vm();
+ auto* jsBuffer = jsDynamicCast(vm, JSValue::decode(value));
+ return !!jsBuffer;
+}
+
+const ClassInfo JSBuffer::s_info = { "Buffer"_s, JSC::getUint8ArrayClassInfo(), nullptr, nullptr, CREATE_METHOD_TABLE(JSBuffer) };
+
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_compareBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_copyBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_equalsBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_includesBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ UNUSED_PARAM(throwScope);
+ UNUSED_PARAM(callFrame);
+
+ return JSC::JSValue::encode(JSC::JSValue(reinterpret_cast(castedThis->vector())[0]));
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_indexOfBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_lastIndexOfBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readBigInt64BEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readBigInt64LEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readBigUInt64BEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readBigUInt64LEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readDoubleBEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readDoubleLEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readFloatBEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readFloatLEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readInt16BEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readInt16LEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readInt32BEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readInt32LEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readInt8Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readIntBEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readIntLEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readUInt16BEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readUInt16LEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readUInt32BEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readUInt32LEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readUInt8Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readUIntBEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_readUIntLEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_swap16Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_swap32Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_swap64Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_toStringBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ uint32_t offset = 0;
+ uint32_t length = castedThis->length();
+ WebCore::BufferEncodingType encoding = WebCore::BufferEncodingType::utf8;
+
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ if (UNLIKELY(callFrame->argumentCount() == 0)) {
+ throwTypeError(lexicalGlobalObject, scope, "Not enough arguments");
+ return JSC::JSValue::encode(jsUndefined());
+ }
+
+ EnsureStillAliveScope arg0 = callFrame->argument(0);
+ auto* str = arg0.value().toStringOrNull(lexicalGlobalObject);
+ if (!str) {
+ throwTypeError(lexicalGlobalObject, scope, "write() expects a string");
+ return JSC::JSValue::encode(jsUndefined());
+ }
+
+ EnsureStillAliveScope arg1 = callFrame->argument(1);
+
+ if (str->length() == 0)
+ return JSC::JSValue::encode(JSC::jsNumber(0));
+
+ if (callFrame->argumentCount() > 1) {
+ if (arg1.value().isAnyInt()) {
+ int32_t ioffset = arg1.value().toInt32(lexicalGlobalObject);
+ if (ioffset < 0) {
+ throwTypeError(lexicalGlobalObject, scope, "Offset must be a positive integer");
+ return JSC::JSValue::encode(jsUndefined());
+ }
+ offset = static_cast(ioffset);
+ } else if (arg1.value().isString()) {
+ std::optional encoded = parseEnumeration(*lexicalGlobalObject, arg1.value());
+ if (!encoded) {
+ throwTypeError(lexicalGlobalObject, scope, "Invalid encoding");
+ return JSC::JSValue::encode(jsUndefined());
+ }
+
+ encoding = encoded.value();
+ }
+ }
+
+ if (callFrame->argumentCount() > 2) {
+ length = static_cast(callFrame->argument(2).toInt32(lexicalGlobalObject));
+ }
+
+ length -= std::min(offset, length);
+
+ if (UNLIKELY(length < offset)) {
+ RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::jsNumber(0)));
+ }
+
+ if (callFrame->argumentCount() > 2) {
+ std::optional encoded = parseEnumeration(*lexicalGlobalObject, callFrame->argument(3));
+ if (!encoded) {
+ throwTypeError(lexicalGlobalObject, scope, "Invalid encoding");
+ return JSC::JSValue::encode(jsUndefined());
+ }
+
+ encoding = encoded.value();
+ }
+
+ auto view = str->tryGetValue(lexicalGlobalObject);
+ int64_t written = 0;
+
+ switch (encoding) {
+ case WebCore::BufferEncodingType::utf8: {
+ if (view.is8Bit()) {
+ written = Bun__encoding__writeLatin1AsUTF8(view.characters8(), view.length(), castedThis->typedVector() + offset, length);
+ } else {
+ written = Bun__encoding__writeUTF16AsUTF8(view.characters16(), view.length(), castedThis->typedVector() + offset, length);
+ }
+ break;
+ }
+
+ case WebCore::BufferEncodingType::latin1:
+ case WebCore::BufferEncodingType::ascii: {
+ if (view.is8Bit()) {
+ written = Bun__encoding__writeLatin1AsASCII(view.characters8(), view.length(), castedThis->typedVector() + offset, length);
+ } else {
+ written = Bun__encoding__writeUTF16AsASCII(view.characters16(), view.length(), castedThis->typedVector() + offset, length);
+ }
+ break;
+ }
+ case WebCore::BufferEncodingType::ucs2:
+ case WebCore::BufferEncodingType::utf16le: {
+ if (view.is8Bit()) {
+ written = Bun__encoding__writeLatin1AsUTF16(view.characters8(), view.length(), castedThis->typedVector() + offset, length);
+ } else {
+ written = Bun__encoding__writeUTF16AsUTF16(view.characters16(), view.length(), castedThis->typedVector() + offset, length);
+ }
+ break;
+ }
+
+ case WebCore::BufferEncodingType::base64: {
+ if (view.is8Bit()) {
+ written = Bun__encoding__writeLatin1AsBase64(view.characters8(), view.length(), castedThis->typedVector() + offset, length);
+ } else {
+ written = Bun__encoding__writeUTF16AsBase64(view.characters16(), view.length(), castedThis->typedVector() + offset, length);
+ }
+ break;
+ }
+
+ case WebCore::BufferEncodingType::base64url: {
+ if (view.is8Bit()) {
+ written = Bun__encoding__writeLatin1AsURLSafeBase64(view.characters8(), view.length(), castedThis->typedVector() + offset, length);
+ } else {
+ written = Bun__encoding__writeUTF16AsURLSafeBase64(view.characters16(), view.length(), castedThis->typedVector() + offset, length);
+ }
+ break;
+ }
+
+ case WebCore::BufferEncodingType::hex: {
+ if (view.is8Bit()) {
+ written = Bun__encoding__writeLatin1AsHex(view.characters8(), view.length(), castedThis->typedVector() + offset, length);
+ } else {
+ written = Bun__encoding__writeUTF16AsHex(view.characters16(), view.length(), castedThis->typedVector() + offset, length);
+ }
+ break;
+ }
+ }
+
+ RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::jsNumber(written)));
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeBigInt64BEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeBigInt64LEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeBigUInt64BEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeBigUInt64LEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeDoubleBEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeDoubleLEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeFloatBEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeFloatLEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeInt16BEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeInt16LEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeInt32BEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeInt32LEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeInt8Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeIntBEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeIntLEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeUInt16BEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeUInt16LEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeUInt32BEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeUInt32LEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeUInt8Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeUIntBEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeUIntLEBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis)
+{
+ auto& vm = JSC::getVM(lexicalGlobalObject);
+ return JSC::JSValue::encode(jsUndefined());
+}
+
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_compare, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "compare");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_copy, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "copy");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_equals, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "equals");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_fill, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "fill");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_includes, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "includes");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_indexOf, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "indexOf");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_lastIndexOf, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "lastIndexOf");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readBigInt64BE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readBigInt64BE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readBigInt64LE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readBigInt64LE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readBigUInt64BE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readBigUInt64BE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readBigUInt64LE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readBigUInt64LE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readDoubleBE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readDoubleBE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readDoubleLE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readDoubleLE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readFloatBE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readFloatBE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readFloatLE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readFloatLE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readInt16BE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readInt16BE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readInt16LE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readInt16LE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readInt32BE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readInt32BE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readInt32LE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readInt32LE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readInt8, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readInt8");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readIntBE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readIntBE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readIntLE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readIntLE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readUInt16BE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readUInt16BE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readUInt16LE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readUInt16LE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readUInt32BE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readUInt32BE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readUInt32LE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readUInt32LE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readUInt8, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readUInt8");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readUIntBE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readUIntBE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_readUIntLE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "readUIntLE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_swap16, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "swap16");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_swap32, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "swap32");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_swap64, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "swap64");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_toString, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "toString");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_write, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "write");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeBigInt64BE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeBigInt64BE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeBigInt64LE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeBigInt64LE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeBigUInt64BE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeBigUInt64BE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeBigUInt64LE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeBigUInt64LE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeDoubleBE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeDoubleBE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeDoubleLE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeDoubleLE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeFloatBE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeFloatBE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeFloatLE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeFloatLE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeInt16BE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeInt16BE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeInt16LE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeInt16LE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeInt32BE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeInt32BE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeInt32LE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeInt32LE");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeInt8, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeInt8");
+}
+JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeIntBE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ return IDLOperation