From 2c6e5c3fc4a7255eb29f7ae618d2826dd9a7d5e5 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Mon, 25 Apr 2022 07:09:18 -0700 Subject: [PATCH] some of buffer --- Makefile | 13 +- .../export-default-module-hot.hmr.js | 36 +- .../snapshots/export-default-module-hot.js | 21 +- src/base64/README.md | 8 + src/base64/base64.zig | 53 + src/base64/bun-base64.bc | Bin 0 -> 4096 bytes src/base64/bun-base64.c | 46 + src/base64/bun-base64.h | 7 + src/base64/chromiumbase64.bc | Bin 0 -> 15120 bytes src/base64/chromiumbase64.c | 415 ++++++ src/base64/chromiumbase64.h | 165 +++ src/base64/fastavxbase64.bc | Bin 0 -> 1856 bytes src/base64/fastavxbase64.c | 186 +++ src/base64/fastavxbase64.h | 41 + src/base64/neonbase64 | Bin 0 -> 17648 bytes src/base64/neonbase64.bc | Bin 0 -> 31120 bytes src/base64/neonbase64.cc | 120 ++ src/global.zig | 1 + src/javascript/jsc/bindings/Buffer.cpp | 52 + src/javascript/jsc/bindings/Buffer.h | 42 + .../jsc/bindings/BufferEncodingType.h | 20 + src/javascript/jsc/bindings/JSBuffer.cpp | 1218 +++++++++++++++++ src/javascript/jsc/bindings/JSBuffer.h | 109 ++ .../jsc/bindings/JSBufferEncodingType.cpp | 164 +++ .../jsc/bindings/JSBufferEncodingType.h | 13 + .../JSDOMConvertBufferSource+JSBuffer.h | 31 + .../jsc/bindings/ZigGlobalObject.cpp | 17 + src/javascript/jsc/bindings/bindings.zig | 13 + src/javascript/jsc/bindings/headers-cpp.h | 2 +- .../jsc/bindings/headers-handwritten.h | 12 + src/javascript/jsc/bindings/headers.h | 2 +- .../bindings/webcore/DOMClientIsoSubspaces.h | 4 + .../jsc/bindings/webcore/DOMConstructors.h | 7 +- .../jsc/bindings/webcore/DOMIsoSubspaces.h | 4 + .../jsc/bindings/webcore/JSDOMConvert.h | 2 + .../jsc/bindings/webcore/JSDOMConvertUnion.h | 1 + src/javascript/jsc/bindings/wtf-bindings.cpp | 6 + src/javascript/jsc/bindings/wtf-bindings.h | 6 + src/javascript/jsc/node/types.zig | 7 + src/javascript/jsc/webcore/base64.zig | 445 ++++++ src/javascript/jsc/webcore/encoding.zig | 281 +++- src/runtime.version | 2 +- src/string_immutable.zig | 160 ++- 43 files changed, 3645 insertions(+), 87 deletions(-) create mode 100644 src/base64/README.md create mode 100644 src/base64/base64.zig create mode 100644 src/base64/bun-base64.bc create mode 100644 src/base64/bun-base64.c create mode 100644 src/base64/bun-base64.h create mode 100644 src/base64/chromiumbase64.bc create mode 100644 src/base64/chromiumbase64.c create mode 100644 src/base64/chromiumbase64.h create mode 100644 src/base64/fastavxbase64.bc create mode 100644 src/base64/fastavxbase64.c create mode 100644 src/base64/fastavxbase64.h create mode 100644 src/base64/neonbase64 create mode 100644 src/base64/neonbase64.bc create mode 100644 src/base64/neonbase64.cc create mode 100644 src/javascript/jsc/bindings/Buffer.cpp create mode 100644 src/javascript/jsc/bindings/Buffer.h create mode 100644 src/javascript/jsc/bindings/BufferEncodingType.h create mode 100644 src/javascript/jsc/bindings/JSBuffer.cpp create mode 100644 src/javascript/jsc/bindings/JSBuffer.h create mode 100644 src/javascript/jsc/bindings/JSBufferEncodingType.cpp create mode 100644 src/javascript/jsc/bindings/JSBufferEncodingType.h create mode 100644 src/javascript/jsc/bindings/JSDOMConvertBufferSource+JSBuffer.h create mode 100644 src/javascript/jsc/bindings/wtf-bindings.cpp create mode 100644 src/javascript/jsc/bindings/wtf-bindings.h create mode 100644 src/javascript/jsc/webcore/base64.zig 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 0000000000000000000000000000000000000000..6a004c8dcc921c1d43e77f6f3a33ef495bb93a7e GIT binary patch literal 4096 zcmZu!4R90372fmNI$`9KFiw#1NjYIi6oReu4@SmvDp@WuiPFkITBjwk&X$ZEY)O{n zUy|lz3C>JSMlf!0X6THRG6`v!j!2l)X_!{F9O8OJ#-U8cLkY2iAr3=`3#7v&Ow+d# z=4Z-|c5mO?w{Q1-``+8t`S^;Z2udE*8972fLa8yw&#wnY7Vw&6-0G*F|69u|KOApd zS}#}#;AvzC^^gcH&Cs9>pdW@x1q%0@CNeim6s461h>&bemNZ|T`P(Kz@zac&150Z{ ziqbs2RQXJHY0W^LXIxWQn=1|~Ob0UT6VhXOta;M_`wybDCZt@eT^lZWIktU2J3aw= z_p%7(!nbslbP3zE32B~KJ*?2IfhPYk+3v$(TaA4?yV~AA^F|@sU6~Q;kLR%&=JKbI zZ>$70s9uTCU*KDCtMDeal?bDK9MvloyR>43Aa>VL-4W3n zrsAseqpGulYEr`_3HGc;buOAS9c4bzFw@bTD^ccTKz-h%K0Bj69bo1O71ASVcaK;R z0aa9wAo@L`&l&8JQhi2BP|roxlLUJypdRCy&!RaqCiVG%dXi`6XH|32objkSIm%3e zHk5)kyP6`px6Bd11s?Qnh5X3$-MyO{3s>x{1Sq+W))ng|0CsAfTnv;w&V*&ML z6KGQl>!qT1n5t+9c7(+aTX4OS>Ybo^B4Ri6S+P4p^@PQ476eG2AXZ4JUMICHPNqqH zjPyCFE|BEJJ{#4=Q9T1>6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ma|8;2gQS$ zAdhZhW8Q(gKm*^U*44kz%v#j^-)h41oAlL4OD=rO3Po|*{P zXOBzvg8(FiMVCu^r@PY+UW@*8xKMTrNl9nkDnuIdGEGvL{SdO%lLpY>M%mED_k5Z2 zrHww%=2a}qV6)>RwP^R_vWQ-aY};1}84pRO7%Ae4ml>nkbFg;dmBGKV)$7S{{foBpou_{yTfnc;iGql zLj>34L9A4AYRmU96ubrC0mP(5_Y*HE-90I zR1O}UISytb?AgE0#Q$c}g=Z1k1l>hU)zD92Dyhv{2K{?5T@2$zJcDcV*51K0l80>M zzp=l&V|x|IicYQ>d&I(9KQbY7A$L}OggbJ{h=h*43)FMUZEg+#H|1>#W&G zmt;)c0Yv)_w(U5!Ep`X5SMLrV!NVyy)5CZ0+ULc1B~o~Oh=tO4E$g?1*98?xW!~%8 zC=?qVH1Rp0jwnfE5l>;EDM`NzmnsP9U_dJc(^I8`P4i1>#i|hcB1>!Bnc_RZg*HGh zmmG>=--Psl8lYnTwLrx@Oyh#T`2Ql9m?|$q3t@-4pkhD9IODQ7j{8_1mwu@DKOQbv z4$S(ISdGvS^q1e};c?8D0{?C3W4iG6*rNOgK(ByW4i*0=U6jXbVgR0oN-y%)K?lkU zu(>Muf{lO2_T1wO>G=Bp``{jtw7Wd`F2Gk)vAt literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..42178e5b85502feb8f154152b7371c97d361f855 GIT binary patch literal 15120 zcmeHudt6l4weUW34l@TBW)2T!(3#-sT!&f0sewbxqvwe~v0)j(o20!V<*#7czj0TdVlSC>IW1k{zwxztCt z{Y&LDe?40ky~$ZZK%GvG&>{sw(Gne!06rT&GFQrBVSrjEW%Rj6h*tUh2s%kiJy-5b zSR*Mo5?yeL(I@24s`XL&&F#gueqBmooVSA!jz}y6^qBLl-ik~n-4|OL-GTse5TEo?QE*m?R+tXPcR~5X9^-C z5>$mZXx`=24d%8nNn1J_J5DTz!h1zfrTAs)10=zwA!<2EP3)Q3MOk9HTg^726r znxL7I^ceJ1c~u*MoPe^7Qxi9j@nplAp#XQG+r9*s>icGB0+gmq#pg)1lRpb}sQKovkWz)pZ&05t%$0CfQM05*UI06Rb@Yl_wuuX|*D$%e0OG;Z3wW$UA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2E+1&qb%8TNg%SPYq% zUZ9%ZS|>w{d1tWthUrs(GM*_ujYTp&B8M607i!>&*&zh=?O@g7V0MM^YzcUf--R!u zAL%<_g^E|`W9vR4(8{E(AuYZ_yR%?MD_U3BypScaW;`?VBz|4~LwpjC#{KodllUY3 z5iAV0^FzmSLD=N1uRbVlFr9GNi`#7cHDbqu6b)gDIe5&)TpUb{sm#)RoQmCFg=3DH zD=AWxIR{tcwPz+JN-^1FlETXAoZkXEbS?lLZYuDWRM|GQC1qucTasr(d*S^psYmu1 zjNsrPn00@rIP^l7=n%)X)MVe%*L%-~cgJbwNGbUbpn5EngYeEckVTPRM@eC2N zC+9tl=lx|o@4598u&9>fSuS_T4_%jjV*y8M$ZI`8O1 zJ;VcMvOG=P|Lkop8RAdQ&ww3j_=Qu+a7+015bTw4Vkt4hjbW_Kl-3XHv9rz;nF6CA zUK759UgVJU3Hhc-$M{fegl6{G3mjSwtx6r|e;1b1HaBsB`Tl%k2aC#4yX=rANv z%g$JH#1zU-=5qgcx?*rvBp?{$pKQyeAuD2%2^(sXKIcP_LRo~fA}wMHIeu?D1!fl=B_xOwBq$iO3;7?9Rzje0a`pVz- z%)aSPI!YvU1e5&2obKS9eI`a)-qY~C$G2ThT{CpRdPO}TsC$IDy}`MG;Ps`05-P+e zNHv#Tni2Tni%aVaCEq5JKXE1d3Kn#R7WfMmwz|_hLJPayi+c(d^@bLWN*4D^?5P(P z4;3sK4lQA$4+%7?2dhWiKj|Kvf$S_+?0gy tYuSv7vZ;!x1ff-YQTwIpa8G3qc2#EO%B=b_3s+{zDzm^tHa6=4_`iwj3a$VE literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..f7ee9825d7648cb9957570b0de93f3e38ae7c997 GIT binary patch literal 1856 zcmZt{VN4rk^ebgth3?vIxKX**yA_mdcD)vK)V2w5I6LjK&P~N+X1%u8QAgY3t}885 z(^AZ_NKA($HgP5p_ecHHMSfti7~pW$r7pOrSt21IY@)%1=rkHl^j*(aCl8a1`Z)= ze^Wt2H3Km`sD0&9-oH0=l57eLbu?%SW~4^DihN#57S)gT=J*Vj@=HQ*E~%0FQ&M_H zY9CP_%)l?Vo%P|-1$=N5kLK}Y2R7)(5(_oo>MoaYt zFYZMkDb$CX^+J7*dVV?rX-$}4CNj8Mjl_Gbun7Ex`}W4@K*i2afu>sQpP#f z6sFHRujHHyjAKgex{`AZtDWV|`lKH_*NYwOg%V*0GZNH|_hZQxEcweea66EZPC?xo zB%vUs3)zS6Y~pv8@thT+%x8_)*qSf%jHARj3Kcpnw~sSW za_6{gg+qTIa(=FM7G>?n5sB}S1U{GORW2yeASEUw!}a63J4p9~4`0jUs~x%(65oI< z$QI+`tZA;(bb}%mv!=ymVr|9voyrt$IM!Zd9=(`zmVHfsCE}L`Qdp{R%zHPlQz~G3 z!E}u!)+yuCtnp=)NeP%TZn8BeUdgqWWoMCbLqUF@bFDGX5fJ6kk7^-PX#nEUV1q4~ zP{^KK)#Dp8_$?p)BW<3&(P>&+*>iKnxC8-s49;TCJ(X)5mfJ@eM_G1F&pJvnR&o4?** ziMg!t=E|N8%6OYH&QnIX!FB5XF!`4A3gezuJH~U4a?cgGeMoi?;`B%ZJTzdMMCfJc zF~Q^^nGvnw9>MM*&Dqfl7e4Er(6@wKHhb4=dFt(TI$d?NA#rx5ZEWnwvv0J8Suw#T zQvp`w9%(xev_36zf@pn#6$CD1W#S>u8aNxXibBx3W#WlPxq!e8kikAScA89rbtE1m zZLJ6B12(HS5)fD+ZSCfgTwk2$1aJ|Jvaygi65~$9<9(v_c=wZ{^#~h0dc4PGKOlzA z{QJ3kfEB{zGh0r(xxm@eJIs(?C5f=WMmY-~kHiw30QEI% zRP>O(+N{X}(}H9h($_Q3se;>KAg+Evpg>y0AI7aQ#13(zkzOo?Mb9=c6j zo!q|OsjL=gtF4*X-L~q-zwyDS>DH8i(|zN^?-nyzEZtJs1Stu+Seb(!{-WGIrE*@% zxyR+IGq6;M#T8xPEUn$O>@qO)&u9sUDwJWF;pB6hB@-<-Hz21^&ww8%Q6S0Cj*CKn4D` v+mimF&%;@Y9h?jEgCo4Vs$%&xHKrrt +#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 0000000000000000000000000000000000000000..74153ebe4f8569012bfd67d6b958deb286f2f3f6 GIT binary patch literal 17648 zcmch83tUrIy6@UaNCJcq9zu{L>>z4JLmbSrH)mlk-2^Jv)M4;C0Bw$d{ zh7PUR+BR5P>9jqi)@jjkrb$4G4CA1+J=F0yL8+y^)=Mp?<5=6?Z>^nJdS-g=z30xk z`H`^q+H0-<_x-=e`qs|Q6<2gHf>$KGFJ>Y1BfK&)T~`)BLjbhpi_{7CZ~T4nli!`l z3(jS7C}>lP5Gs%$6wFZ~4xC59TVR>iqU-0a;!BbjJwr8!rUwXP6ukZUjC46C;TXrj+j$@vY^*{azN&91J^Ep%T$ z%)6IHXaW3Bj&BO2^H(6{oP;*1ayop(%oH_tI1KrPo9TpND+;|XbQun!c6djMD4|E& zD|BfYW%IQ(;o)h*9HY?V9LjIfN%-6LggITJKYb%fS&2fX(HGR5@HXR7)vx!22@O(< zW6)%j7VUAqWIuX9eX8l`sz6n1$E>3bXOB6GuO|KA`Egc&a_>Z^tKnBE%Ujidi@cEY zo84a@`u^crs#*;1+RaiyeXXFbgj?Aus8ZX_Fkzd$ zdI)-sBYI3J8y%4iSQM8GGH<(rF)@N#kf+2})5K+99*4b3C8#gqR;lbJr@h``H@684 zA)a>GbxX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Uri7;YOAi zM4s2zU?7WA(-6Co4IRbK^_TVop9G(QJf7Py@{V$B-e1AjvRmu_D!=Kv_vOdb$axV zI%lZ7F)&0)s8pWLsEk3&=vk zZC&t;qB0~(l7SpJ?}XK3U;?v(OqZ&aiW z@&0VhmoUsmy@(@83*M(g)?(cp{j)oahu^DwQQB-du0HUMwk4%S7lSNnNn<6wH|7X6 zwZk&?O)B<;CH6E0KbwT#G|Mkqw-Pth3+D zkTRCP>aYwau;jy>c+~JX6^5+8VHRGZ#To69HCJbB$)B;CGuM+bx6e9vz%%z8XWoU3 zd7oJ4UGmJk!b!ZEk$Byj_@yWDCMW4uM$)&|q&uFZA2=x)nJFu5DfjoJJj7kFI&;B# z+k#C!3$}1m^D|S6ZK>OOQp>pu&6x{pkIvl1nQ6|LS#oqn8D~a*#*7U|r*Dp*zBYe) z&ea5cenR%q1Z{jm*3r1TBXJYPxZ5L&ab?_CyW)mYF=|x6&$hir`Ea}Zf=+&pk`K6L zeHNKVC)-WQ>fO;bmS~eQy1G58Y$U4C7*#Sd#h{GZ&^~3ea>`ocl$?=By)JTvCGw6d z^am7qOB?zvgMTdgrAs_&5RbV+t|0LRE&PZ&WWXglheG-okw+_9svbLi;14H)-H<*OX3^Qn2@5l=>#UjE~_x0dIJo70KX@U;gX(*bhX(82FtFdEtKWK*x_L0U-sn z<0mX}o5a^HoQqHrw8L*^5FDbIN$snkT?yy#5GJDi?J&7rwQ literal 0 HcmV?d00001 diff --git a/src/base64/neonbase64.bc b/src/base64/neonbase64.bc new file mode 100644 index 0000000000000000000000000000000000000000..91c10bf4fd52e529cda6c0148a9d7bcec191fd6e GIT binary patch literal 31120 zcmb__4O~-I|MG2_!i8k)q)oqjpp!h>P5w1thbQ*?s1PBJxisx^Ld+qxaHlifgfyNsgX zOC^kJ93j&#q+)KJ&?1SM2#4^=LG^pBYHiLs*@WC$MbPI$yZS+@75>8V<^D1uPgy^O zQA&h!w~eydgBI_!CM=>xj+gbw{X$w=%cM2iMhVptv${v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zyEws{mopA7%}A8YaJbN~PV literal 0 HcmV?d00001 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::call(*lexicalGlobalObject, *callFrame, "writeIntBE"); +} +JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeIntLE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeIntLE"); +} +JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeUInt16BE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeUInt16BE"); +} +JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeUInt16LE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeUInt16LE"); +} +JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeUInt32BE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeUInt32BE"); +} +JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeUInt32LE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeUInt32LE"); +} +JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeUInt8, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeUInt8"); +} +JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeUIntBE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeUIntBE"); +} +JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeUIntLE, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::call(*lexicalGlobalObject, *callFrame, "writeUIntLE"); +} + +/* Hash table for prototype */ + +static const HashTableValue JSBufferPrototypeTableValues[] + = { + { "compare", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_compare), (intptr_t)(5) } }, + { "copy", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_copy), (intptr_t)(4) } }, + { "equals", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_equals), (intptr_t)(1) } }, + { "fill", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_fill), (intptr_t)(4) } }, + { "includes", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_includes), (intptr_t)(3) } }, + { "indexOf", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_indexOf), (intptr_t)(3) } }, + { "lastIndexOf", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_lastIndexOf), (intptr_t)(3) } }, + { "readBigInt64BE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readBigInt64BE), (intptr_t)(2) } }, + { "readBigInt64LE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readBigInt64LE), (intptr_t)(2) } }, + { "readBigUInt64BE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readBigUInt64BE), (intptr_t)(2) } }, + { "readBigUInt64LE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readBigUInt64LE), (intptr_t)(2) } }, + { "readDoubleBE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readDoubleBE), (intptr_t)(2) } }, + { "readDoubleLE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readDoubleLE), (intptr_t)(2) } }, + { "readFloatBE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readFloatBE), (intptr_t)(2) } }, + { "readFloatLE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readFloatLE), (intptr_t)(2) } }, + { "readInt16BE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readInt16BE), (intptr_t)(2) } }, + { "readInt16LE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readInt16LE), (intptr_t)(2) } }, + { "readInt32BE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readInt32BE), (intptr_t)(2) } }, + { "readInt32LE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readInt32LE), (intptr_t)(2) } }, + { "readInt8", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readInt8), (intptr_t)(2) } }, + { "readIntBE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readIntBE), (intptr_t)(2) } }, + { "readIntLE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readIntLE), (intptr_t)(2) } }, + { "readUInt16BE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readUInt16BE), (intptr_t)(2) } }, + { "readUInt16LE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readUInt16LE), (intptr_t)(2) } }, + { "readUInt32BE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readUInt32BE), (intptr_t)(2) } }, + { "readUInt32LE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readUInt32LE), (intptr_t)(2) } }, + { "readUInt8", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readUInt8), (intptr_t)(2) } }, + { "readUIntBE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readUIntBE), (intptr_t)(2) } }, + { "readUIntLE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_readUIntLE), (intptr_t)(2) } }, + { "swap16", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_swap16), (intptr_t)(0) } }, + { "swap32", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_swap32), (intptr_t)(0) } }, + { "swap64", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_swap64), (intptr_t)(0) } }, + { "toString", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_toString), (intptr_t)(4) } }, + { "write", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_write), (intptr_t)(4) } }, + { "writeBigInt64BE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeBigInt64BE), (intptr_t)(2) } }, + { "writeBigInt64LE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeBigInt64LE), (intptr_t)(2) } }, + { "writeBigUInt64BE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeBigUInt64BE), (intptr_t)(2) } }, + { "writeBigUInt64LE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeBigUInt64LE), (intptr_t)(2) } }, + { "writeDoubleBE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeDoubleBE), (intptr_t)(2) } }, + { "writeDoubleLE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeDoubleLE), (intptr_t)(2) } }, + { "writeFloatBE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeFloatBE), (intptr_t)(2) } }, + { "writeFloatLE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeFloatLE), (intptr_t)(2) } }, + { "writeInt16BE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeInt16BE), (intptr_t)(2) } }, + { "writeInt16LE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeInt16LE), (intptr_t)(2) } }, + { "writeInt32BE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeInt32BE), (intptr_t)(2) } }, + { "writeInt32LE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeInt32LE), (intptr_t)(2) } }, + { "writeInt8", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeInt8), (intptr_t)(2) } }, + { "writeIntBE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeIntBE), (intptr_t)(2) } }, + { "writeIntLE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeIntLE), (intptr_t)(2) } }, + { "writeUInt16BE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeUInt16BE), (intptr_t)(2) } }, + { "writeUInt16LE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeUInt16LE), (intptr_t)(2) } }, + { "writeUInt32BE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeUInt32BE), (intptr_t)(2) } }, + { "writeUInt32LE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeUInt32LE), (intptr_t)(2) } }, + { "writeUInt8", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeUInt8), (intptr_t)(2) } }, + { "writeUIntBE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeUIntBE), (intptr_t)(2) } }, + { "writeUIntLE", static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast(jsBufferPrototypeFunction_writeUIntLE), (intptr_t)(2) } }, + }; + +void JSBufferPrototype::finishCreation(VM& vm, JSC::JSGlobalObject* globalThis) +{ + Base::finishCreation(vm); + reifyStaticProperties(vm, JSBuffer::info(), JSBufferPrototypeTableValues, *this); + JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); + this->setPrototypeDirect(vm, globalThis->m_typedArrayUint8.prototype(globalThis)); +} + +const ClassInfo JSBufferPrototype::s_info = { "Buffer"_s, nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(JSBufferPrototype) }; + +JSObject* JSBuffer::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) +{ + return JSBufferPrototype::create(vm, &globalObject, JSBufferPrototype::createStructure(vm, &globalObject, globalObject.m_typedArrayUint8.prototype(&globalObject))); +} + +JSObject* JSBuffer::prototype(VM& vm, JSDOMGlobalObject& globalObject) +{ + return getDOMPrototype(vm, globalObject); +} + +JSValue JSBuffer::getConstructor(VM& vm, const JSGlobalObject* globalObject) +{ + return getDOMConstructor(vm, *jsCast(globalObject)); +} + +void JSBuffer::destroy(JSC::JSCell* cell) +{ + JSBuffer* thisObject = static_cast(cell); + thisObject->JSBuffer::~JSBuffer(); +} + +JSBuffer::JSBuffer(Structure* structure, JSDOMGlobalObject& globalObject, Ref&& impl) + : JSDOMWrapper(structure, globalObject, WTFMove(impl)) +{ +} + +void JSBuffer::finishCreation(VM& vm) +{ + Base::finishCreation(vm); + ASSERT(inherits(vm, info())); + + // static_assert(!std::is_base_of::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject."); +} + +JSC::GCClient::IsoSubspace* JSBuffer::subspaceForImpl(JSC::VM& vm) +{ + return WebCore::subspaceForImpl( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForBuffer.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForBuffer = WTFMove(space); }, + [](auto& spaces) { return spaces.m_subspaceForBuffer.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForBuffer = WTFMove(space); }); +} + +// template +// void JSBuffer::visitChildrenImpl(JSCell* cell, Visitor& visitor) +// { +// auto* thisObject = jsCast(cell); +// ASSERT_GC_OBJECT_INHERITS(thisObject, info()); +// Base::visitChildren(thisObject, visitor); +// } + +// DEFINE_VISIT_CHILDREN(JSBuffer); + +// template +// void JSBuffer::visitOutputConstraints(JSCell* cell, Visitor& visitor) +// { +// auto* thisObject = jsCast(cell); +// ASSERT_GC_OBJECT_INHERITS(thisObject, info()); +// Base::visitOutputConstraints(thisObject, visitor); +// } + +// template void JSBuffer::visitOutputConstraints(JSCell*, AbstractSlotVisitor&); +// template void JSBuffer::visitOutputConstraints(JSCell*, SlotVisitor&); +// void JSBuffer::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer) +// { +// auto* thisObject = jsCast(cell); +// analyzer.setWrappedObjectForCell(cell, &thisObject->wrapped()); +// // if (thisObject->scriptExecutionContext()) +// // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); +// Base::analyzeHeap(cell, analyzer); +// } + +JSBufferOwner::~JSBufferOwner() +{ +} + +bool JSBufferOwner::isReachableFromOpaqueRoots(JSC::Handle handle, void*, AbstractSlotVisitor& visitor, const char** reason) +{ + UNUSED_PARAM(handle); + UNUSED_PARAM(visitor); + UNUSED_PARAM(reason); + return false; +} + +void JSBufferOwner::finalize(JSC::Handle handle, void* context) +{ + auto* jsBuffer = static_cast(handle.slot()->asCell()); + auto& world = *static_cast(context); + uncacheWrapper(world, &jsBuffer->wrapped(), jsBuffer); +} + +JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject* globalObject, Ref&& impl) +{ + + return createWrapper(globalObject, WTFMove(impl)); +} + +JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, Buffer& impl) +{ + return wrap(lexicalGlobalObject, globalObject, impl); +} + +Buffer* JSBuffer::toWrapped(JSC::VM& vm, JSC::JSValue value) +{ + if (auto* wrapper = jsDynamicCast(vm, value)) + return &wrapper->wrapped(); + return nullptr; +} + +} // namespace WebCore \ No newline at end of file diff --git a/src/javascript/jsc/bindings/JSBuffer.h b/src/javascript/jsc/bindings/JSBuffer.h new file mode 100644 index 0000000000..52c48e9450 --- /dev/null +++ b/src/javascript/jsc/bindings/JSBuffer.h @@ -0,0 +1,109 @@ +/* + This file is part of the WebKit open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#pragma once + +#include "root.h" + +#include "JSDOMWrapper.h" +#include "wtf/NeverDestroyed.h" + +#include "BufferEncodingType.h" +#include "Buffer.h" + +extern "C" bool JSBuffer__isBuffer(JSC::JSGlobalObject*, JSC::EncodedJSValue); + +namespace WebCore { + +class WEBCORE_EXPORT JSBuffer final : public JSDOMWrapper { +public: + using Base = JSDOMWrapper; + + static constexpr JSC::TypedArrayType TypedArrayStorageType = JSC::JSUint8Array::Adaptor::typeValue; + static JSBuffer* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject, Ref&& impl) + { + JSBuffer* ptr = new (NotNull, JSC::allocateCell(globalObject->vm())) JSBuffer(structure, *globalObject, WTFMove(impl)); + ptr->finishCreation(globalObject->vm()); + return ptr; + } + + static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&); + static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&); + static Buffer* toWrapped(JSC::VM&, JSC::JSValue); + static void destroy(JSC::JSCell*); + + using Adaptor = JSC::JSUint8Array::Adaptor; + + DECLARE_INFO; + + 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(), JSC::NonArray); + } + + static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*); + mutable JSC::WriteBarrier m_searchParams; + template static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return subspaceForImpl(vm); + } + static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm); + // DECLARE_VISIT_CHILDREN; + // template void visitAdditionalChildren(Visitor&); + // template static void visitOutputConstraints(JSCell*, Visitor&); + // static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&); + +protected: + JSBuffer(JSC::Structure*, JSDOMGlobalObject&, Ref&&); + + void finishCreation(JSC::VM&); +}; + +class JSBufferOwner final : public JSC::WeakHandleOwner { +public: + ~JSBufferOwner() final; + bool isReachableFromOpaqueRoots(JSC::Handle, void* context, JSC::AbstractSlotVisitor&, const char**) final; + void finalize(JSC::Handle, void* context) final; +}; + +inline JSC::WeakHandleOwner* wrapperOwner(DOMWrapperWorld&, Buffer*) +{ + static NeverDestroyed owner; + return &owner.get(); +} + +inline void* wrapperKey(Buffer* wrappableObject) +{ + return wrappableObject; +} + +WEBCORE_EXPORT JSC::JSValue toJS(JSC::JSGlobalObject*, JSDOMGlobalObject*, Buffer&); +inline JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, Buffer* impl) { return impl ? toJS(lexicalGlobalObject, globalObject, *impl) : JSC::jsNull(); } +JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject*, Ref&&); +inline JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, RefPtr&& impl) { return impl ? toJSNewlyCreated(lexicalGlobalObject, globalObject, impl.releaseNonNull()) : JSC::jsNull(); } + +template<> struct JSDOMWrapperConverterTraits { + using WrapperClass = JSBuffer; + using ToWrappedReturnType = Buffer*; +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/JSBufferEncodingType.cpp b/src/javascript/jsc/bindings/JSBufferEncodingType.cpp new file mode 100644 index 0000000000..5d972a419f --- /dev/null +++ b/src/javascript/jsc/bindings/JSBufferEncodingType.cpp @@ -0,0 +1,164 @@ +/* + This file is part of the WebKit open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#pragma once + +#include "config.h" +#include "JSBufferEncodingType.h" + +#include +#include +#include + +namespace WebCore { +using namespace JSC; + +String convertEnumerationToString(BufferEncodingType enumerationValue) +{ + static const NeverDestroyed values[] = { + MAKE_STATIC_STRING_IMPL("utf8"), + MAKE_STATIC_STRING_IMPL("ucs2"), + MAKE_STATIC_STRING_IMPL("utf16le"), + MAKE_STATIC_STRING_IMPL("latin1"), + MAKE_STATIC_STRING_IMPL("ascii"), + MAKE_STATIC_STRING_IMPL("base64"), + MAKE_STATIC_STRING_IMPL("base64url"), + MAKE_STATIC_STRING_IMPL("hex"), + MAKE_STATIC_STRING_IMPL("buffer"), + }; + ASSERT(static_cast(enumerationValue) < WTF_ARRAY_LENGTH(values)); + return values[static_cast(enumerationValue)]; +} + +template<> JSString* convertEnumerationToJS(JSGlobalObject& lexicalGlobalObject, BufferEncodingType enumerationValue) +{ + return jsStringWithCache(lexicalGlobalObject.vm(), convertEnumerationToString(enumerationValue)); +} + +// this function is mostly copied from node +template<> std::optional parseEnumeration(JSGlobalObject& lexicalGlobalObject, JSValue value) +{ + JSC::JSString* str = value.toStringOrNull(&lexicalGlobalObject); + if (!str) + return std::nullopt; + + auto encoding = str->value(&lexicalGlobalObject); + if (encoding.length() < 3) + return std::nullopt; + + switch (encoding[0]) { + case 'u': + case 'U': + // utf8, utf16le + if (encoding[1] == 't' && encoding[2] == 'f') { + // Skip `-` + const size_t skip = encoding[3] == '-' ? 4 : 3; + if (encoding[skip] == '8' && encoding[skip + 1] == '\0') + return BufferEncodingType::utf8; + if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(skip, 5), "16le")) + return BufferEncodingType::ucs2; + // ucs2 + } else if (encoding[1] == 'c' && encoding[2] == 's') { + const size_t skip = encoding[3] == '-' ? 4 : 3; + if (encoding[skip] == '2' && encoding[skip + 1] == '\0') + return BufferEncodingType::ucs2; + } + if (WTF::equalIgnoringASCIICase(encoding, "utf8")) + return BufferEncodingType::utf8; + if (WTF::equalIgnoringASCIICase(encoding, "utf-8")) + return BufferEncodingType::utf8; + if (WTF::equalIgnoringASCIICase(encoding, "ucs2")) + return BufferEncodingType::ucs2; + if (WTF::equalIgnoringASCIICase(encoding, "ucs-2")) + return BufferEncodingType::ucs2; + if (WTF::equalIgnoringASCIICase(encoding, "utf16le")) + return BufferEncodingType::ucs2; + if (WTF::equalIgnoringASCIICase(encoding, "utf-16le")) + return BufferEncodingType::ucs2; + break; + + case 'l': + case 'L': + // latin1 + if (encoding[1] == 'a') { + if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 4), "tin1")) + return BufferEncodingType::latin1; + } + if (WTF::equalIgnoringASCIICase(encoding, "latin1")) + return BufferEncodingType::latin1; + break; + + case 'b': + case 'B': + // binary is a deprecated alias of latin1 + if (encoding[1] == 'i') { + if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 5), "nary")) + return BufferEncodingType::latin1; + // buffer + } else if (encoding[1] == 'u') { + if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 5), "ffer")) + return BufferEncodingType::buffer; + // base64 + } else if (encoding[1] == 'a') { + if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 5), "se64")) + return BufferEncodingType::base64; + if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 8), "se64url")) + return BufferEncodingType::base64url; + } + if (WTF::equalIgnoringASCIICase(encoding, "binary")) + return BufferEncodingType::latin1; // BINARY is a deprecated alias of LATIN1. + if (WTF::equalIgnoringASCIICase(encoding, "buffer")) + return BufferEncodingType::buffer; + if (WTF::equalIgnoringASCIICase(encoding, "base64")) + return BufferEncodingType::base64; + if (WTF::equalIgnoringASCIICase(encoding, "base64url")) + return BufferEncodingType::base64url; + break; + + case 'a': + case 'A': + // ascii + if (encoding[1] == 's') { + if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 3), "cii")) + return BufferEncodingType::ascii; + } + if (WTF::equalIgnoringASCIICase(encoding, "ascii")) + return BufferEncodingType::ascii; + break; + + case 'h': + case 'H': + // hex + if (encoding[1] == 'e') + if (encoding[2] == 'x' && encoding[3] == '\0') + return BufferEncodingType::hex; + if (WTF::equalIgnoringASCIICase(encoding, "hex")) + return BufferEncodingType::hex; + break; + } + + return std::nullopt; +} +template<> const char* expectedEnumerationValues() +{ + return "\"utf8\", \"ucs2\", \"utf16le\", \"latin1\", \"ascii\", \"base64\", \"base64url\", \"hex\", \"buffer\""; +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/JSBufferEncodingType.h b/src/javascript/jsc/bindings/JSBufferEncodingType.h new file mode 100644 index 0000000000..ee78800624 --- /dev/null +++ b/src/javascript/jsc/bindings/JSBufferEncodingType.h @@ -0,0 +1,13 @@ +#include "root.h" +#include "BufferEncodingType.h" +#include "JSDOMConvertEnumeration.h" + +namespace WebCore { + +String convertEnumerationToString(BufferEncodingType); +template<> JSC::JSString* convertEnumerationToJS(JSC::JSGlobalObject&, BufferEncodingType); + +template<> std::optional parseEnumeration(JSC::JSGlobalObject&, JSC::JSValue); +template<> const char* expectedEnumerationValues(); + +} // namespace WebCore \ No newline at end of file diff --git a/src/javascript/jsc/bindings/JSDOMConvertBufferSource+JSBuffer.h b/src/javascript/jsc/bindings/JSDOMConvertBufferSource+JSBuffer.h new file mode 100644 index 0000000000..76d05e1b11 --- /dev/null +++ b/src/javascript/jsc/bindings/JSDOMConvertBufferSource+JSBuffer.h @@ -0,0 +1,31 @@ +#pragma once + +#include "BufferSource.h" +#include "IDLTypes.h" +#include "JSDOMConvertBase.h" +#include "JSDOMWrapperCache.h" +#include "JSBuffer.h" + +namespace WebCore { + +struct IDLJSBuffer : IDLTypedArray { +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } + + template + static JSC::JSValue convertNewlyCreated(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, U&& value) + { + return convert(lexicalGlobalObject, globalObject, std::forward(value)); + } +}; + +} \ No newline at end of file diff --git a/src/javascript/jsc/bindings/ZigGlobalObject.cpp b/src/javascript/jsc/bindings/ZigGlobalObject.cpp index a2e4fc42a0..8e522ab858 100644 --- a/src/javascript/jsc/bindings/ZigGlobalObject.cpp +++ b/src/javascript/jsc/bindings/ZigGlobalObject.cpp @@ -88,6 +88,8 @@ #include "JavaScriptCore/RemoteInspectorServer.h" +#include "JSBuffer.h" + using JSGlobalObject = JSC::JSGlobalObject; using Exception = JSC::Exception; using JSValue = JSC::JSValue; @@ -99,6 +101,7 @@ using SourceOrigin = JSC::SourceOrigin; using JSObject = JSC::JSObject; using JSNonFinalObject = JSC::JSNonFinalObject; namespace JSCastingHelpers = JSC::JSCastingHelpers; +using JSBuffer = WebCore::JSBuffer; static bool has_loaded_jsc = false; @@ -325,6 +328,17 @@ void GlobalObject::setConsole(void* console) #pragma mark - Globals +JSC_DECLARE_CUSTOM_GETTER(JSBuffer_getter); + +JSC_DEFINE_CUSTOM_GETTER(JSBuffer_getter, + (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, + JSC::PropertyName)) +{ + Zig::GlobalObject* thisObject = JSC::jsCast(lexicalGlobalObject); + return JSC::JSValue::encode( + WebCore::JSBuffer::getConstructor(JSC::getVM(lexicalGlobalObject), thisObject)); +} + JSC_DECLARE_CUSTOM_GETTER(JSDOMURL_getter); JSC_DEFINE_CUSTOM_GETTER(JSDOMURL_getter, @@ -874,6 +888,9 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "ErrorEvent"_s), JSC::CustomGetterSetter::create(vm, JSErrorEvent_getter, nullptr), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); + putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "Buffer"_s), JSC::CustomGetterSetter::create(vm, JSBuffer_getter, nullptr), + JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); + extraStaticGlobals.releaseBuffer(); this->setRemoteDebuggingEnabled(true); diff --git a/src/javascript/jsc/bindings/bindings.zig b/src/javascript/jsc/bindings/bindings.zig index 3cec43447d..f09d56e3e8 100644 --- a/src/javascript/jsc/bindings/bindings.zig +++ b/src/javascript/jsc/bindings/bindings.zig @@ -3461,6 +3461,19 @@ pub const StringView = extern struct { }; }; +pub const WTF = struct { + extern fn WTF__copyLCharsFromUCharSource(dest: [*]u8, source: *const anyopaque, len: usize) void; + + /// This uses SSE2 instructions and/or ARM NEON to copy 16-bit characters efficiently + /// See wtf/Text/ASCIIFastPath.h for details + pub fn copyLCharsFromUCharSource(destination: [*]u8, comptime Source: type, source: Source) void { + if (comptime JSC.is_bindgen) unreachable; + + // This is any alignment + WTF__copyLCharsFromUCharSource(destination, source.ptr, source.len); + } +}; + pub const Callback = struct { // zig: Value, }; diff --git a/src/javascript/jsc/bindings/headers-cpp.h b/src/javascript/jsc/bindings/headers-cpp.h index bd05427570..a0393e4547 100644 --- a/src/javascript/jsc/bindings/headers-cpp.h +++ b/src/javascript/jsc/bindings/headers-cpp.h @@ -1,4 +1,4 @@ -//-- AUTOGENERATED FILE -- 1650708320 +//-- AUTOGENERATED FILE -- 1650803913 // clang-format off #pragma once diff --git a/src/javascript/jsc/bindings/headers-handwritten.h b/src/javascript/jsc/bindings/headers-handwritten.h index a190d694af..d955e3138c 100644 --- a/src/javascript/jsc/bindings/headers-handwritten.h +++ b/src/javascript/jsc/bindings/headers-handwritten.h @@ -205,4 +205,16 @@ extern "C" const char* Bun__versions_zig; extern "C" void ZigString__free_global(const unsigned char* ptr, size_t len); +extern "C" int64_t Bun__encoding__writeLatin1AsHex(const unsigned char* ptr, size_t len, unsigned char* to, size_t other_len); +extern "C" int64_t Bun__encoding__writeUTF16AsHex(const UChar* ptr, size_t len, unsigned char* to, size_t other_len); +extern "C" int64_t Bun__encoding__writeLatin1AsURLSafeBase64(const unsigned char* ptr, size_t len, unsigned char* to, size_t other_len); +extern "C" int64_t Bun__encoding__writeUTF16AsURLSafeBase64(const UChar* ptr, size_t len, unsigned char* to, size_t other_len); +extern "C" int64_t Bun__encoding__writeLatin1AsBase64(const unsigned char* ptr, size_t len, unsigned char* to, size_t other_len); +extern "C" int64_t Bun__encoding__writeUTF16AsBase64(const UChar* ptr, size_t len, unsigned char* to, size_t other_len); +extern "C" int64_t Bun__encoding__writeLatin1AsUTF16(const unsigned char* ptr, size_t len, unsigned char* to, size_t other_len); +extern "C" int64_t Bun__encoding__writeUTF16AsUTF16(const UChar* ptr, size_t len, unsigned char* to, size_t other_len); +extern "C" int64_t Bun__encoding__writeLatin1AsUTF8(const unsigned char* ptr, size_t len, unsigned char* to, size_t other_len); +extern "C" int64_t Bun__encoding__writeUTF16AsUTF8(const UChar* ptr, size_t len, unsigned char* to, size_t other_len); +extern "C" int64_t Bun__encoding__writeLatin1AsASCII(const unsigned char* ptr, size_t len, unsigned char* to, size_t other_len); +extern "C" int64_t Bun__encoding__writeUTF16AsASCII(const UChar* ptr, size_t len, unsigned char* to, size_t other_len); #endif diff --git a/src/javascript/jsc/bindings/headers.h b/src/javascript/jsc/bindings/headers.h index f45e6fee9f..aad13bc5bc 100644 --- a/src/javascript/jsc/bindings/headers.h +++ b/src/javascript/jsc/bindings/headers.h @@ -1,5 +1,5 @@ // clang-format: off -//-- AUTOGENERATED FILE -- 1650708320 +//-- AUTOGENERATED FILE -- 1650803913 #pragma once #include diff --git a/src/javascript/jsc/bindings/webcore/DOMClientIsoSubspaces.h b/src/javascript/jsc/bindings/webcore/DOMClientIsoSubspaces.h index ad1b6a32bb..b3f4e6e030 100644 --- a/src/javascript/jsc/bindings/webcore/DOMClientIsoSubspaces.h +++ b/src/javascript/jsc/bindings/webcore/DOMClientIsoSubspaces.h @@ -15,6 +15,10 @@ class DOMClientIsoSubspaces { public: DOMClientIsoSubspaces() = default; + /* --- bun --- */ + std::unique_ptr m_clientSubspaceForBuffer; + /* --- bun --- */ + std::unique_ptr m_clientSubspaceForGlobalObject; std::unique_ptr m_clientSubspaceForDOMException; diff --git a/src/javascript/jsc/bindings/webcore/DOMConstructors.h b/src/javascript/jsc/bindings/webcore/DOMConstructors.h index c58be6584e..b6bc299b7c 100644 --- a/src/javascript/jsc/bindings/webcore/DOMConstructors.h +++ b/src/javascript/jsc/bindings/webcore/DOMConstructors.h @@ -843,9 +843,14 @@ enum class DOMConstructorID : uint16_t { XPathNSResolver, XPathResult, XSLTProcessor, + + // Bun extras + Buffer }; -static constexpr unsigned numberOfDOMConstructors = 836; +static constexpr unsigned bunExtraConstructors = 1; + +static constexpr unsigned numberOfDOMConstructors = 836 + bunExtraConstructors; class DOMConstructors { WTF_MAKE_NONCOPYABLE(DOMConstructors); diff --git a/src/javascript/jsc/bindings/webcore/DOMIsoSubspaces.h b/src/javascript/jsc/bindings/webcore/DOMIsoSubspaces.h index 75d91c0a20..8a32c3520e 100644 --- a/src/javascript/jsc/bindings/webcore/DOMIsoSubspaces.h +++ b/src/javascript/jsc/bindings/webcore/DOMIsoSubspaces.h @@ -15,6 +15,10 @@ class DOMIsoSubspaces { public: DOMIsoSubspaces() = default; + /*-- BUN --*/ + std::unique_ptr m_subspaceForBuffer; + /*-- BUN --*/ + // std::unique_ptr m_subspaceForTouch; // std::unique_ptr m_subspaceForTouchEvent; // std::unique_ptr m_subspaceForTouchList; diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvert.h b/src/javascript/jsc/bindings/webcore/JSDOMConvert.h index 91cd5602c0..f5c32823d1 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConvert.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvert.h @@ -45,3 +45,5 @@ #include "JSDOMConvertStrings.h" #include "JSDOMConvertUnion.h" #include "JSDOMConvertWebGL.h" + +#include "JSDOMConvertBufferSource+JSBuffer.h" \ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertUnion.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertUnion.h index db192f7f99..75ce6f86ab 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConvertUnion.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertUnion.h @@ -29,6 +29,7 @@ #include "JSDOMBinding.h" #include "JSDOMConvertBase.h" #include "JSDOMConvertBufferSource.h" +#include "JSDOMConvertBufferSource+JSBuffer.h" #include "JSDOMConvertInterface.h" #include "JSDOMConvertNull.h" #include "JavaScriptCore/IteratorOperations.h" diff --git a/src/javascript/jsc/bindings/wtf-bindings.cpp b/src/javascript/jsc/bindings/wtf-bindings.cpp new file mode 100644 index 0000000000..5dae859307 --- /dev/null +++ b/src/javascript/jsc/bindings/wtf-bindings.cpp @@ -0,0 +1,6 @@ +#include "wtf-bindings.h" + +extern "C" void WTF__copyLCharsFromUCharSource(LChar* destination, const UChar* source, size_t length) +{ + WTF::copyLCharsFromUCharSource(destination, source, length); +} \ No newline at end of file diff --git a/src/javascript/jsc/bindings/wtf-bindings.h b/src/javascript/jsc/bindings/wtf-bindings.h new file mode 100644 index 0000000000..3f71ff0c29 --- /dev/null +++ b/src/javascript/jsc/bindings/wtf-bindings.h @@ -0,0 +1,6 @@ +#pragma once + +#include "root.h" +#include "wtf/text/ASCIIFastPath.h" + +extern "C" void WTF__copyLCharsFromUCharSource(LChar* destination, const UChar* source, size_t length); \ No newline at end of file diff --git a/src/javascript/jsc/node/types.zig b/src/javascript/jsc/node/types.zig index 36978f7d49..8ba9a59010 100644 --- a/src/javascript/jsc/node/types.zig +++ b/src/javascript/jsc/node/types.zig @@ -187,6 +187,13 @@ pub const Encoding = enum(u8) { /// Refer to the buffer's encoding buffer, + pub fn isBinaryToText(this: Encoding) bool { + return switch (this) { + .hex, .base64, .base64url => true, + else => false, + }; + } + const Eight = strings.ExactSizeMatcher(8); /// Caller must verify the value is a string pub fn fromStringValue(value: JSC.JSValue, global: *JSC.JSGlobalObject) ?Encoding { diff --git a/src/javascript/jsc/webcore/base64.zig b/src/javascript/jsc/webcore/base64.zig new file mode 100644 index 0000000000..50c1ac68d1 --- /dev/null +++ b/src/javascript/jsc/webcore/base64.zig @@ -0,0 +1,445 @@ +// this is ripped from zig's stdlib +const std = @import("std"); +const assert = std.debug.assert; +const testing = std.testing; +const mem = std.mem; + +pub const Error = error{ + InvalidCharacter, + InvalidPadding, + NoSpaceLeft, +}; + +/// Base64 codecs +pub const Codecs = struct { + alphabet_chars: [64]u8, + pad_char: ?u8, + decoderWithIgnore: fn (ignore: []const u8) Base64DecoderWithIgnore, + Encoder: Base64Encoder, + Decoder: Base64Decoder, +}; + +pub const standard_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".*; +fn standardBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore { + return Base64DecoderWithIgnore.init(standard_alphabet_chars, '=', ignore); +} + +/// Standard Base64 codecs, with padding +pub const standard = Codecs{ + .alphabet_chars = standard_alphabet_chars, + .pad_char = '=', + .decoderWithIgnore = standardBase64DecoderWithIgnore, + .Encoder = Base64Encoder.init(standard_alphabet_chars, '='), + .Decoder = Base64Decoder.init(standard_alphabet_chars, '='), +}; + +/// Standard Base64 codecs, without padding +pub const standard_no_pad = Codecs{ + .alphabet_chars = standard_alphabet_chars, + .pad_char = null, + .decoderWithIgnore = standardBase64DecoderWithIgnore, + .Encoder = Base64Encoder.init(standard_alphabet_chars, null), + .Decoder = Base64Decoder.init(standard_alphabet_chars, null), +}; + +pub const url_safe_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".*; +fn urlSafeBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore { + return Base64DecoderWithIgnore.init(url_safe_alphabet_chars, null, ignore); +} + +/// URL-safe Base64 codecs, with padding +pub const url_safe = Codecs{ + .alphabet_chars = url_safe_alphabet_chars, + .pad_char = '=', + .decoderWithIgnore = urlSafeBase64DecoderWithIgnore, + .Encoder = Base64Encoder.init(url_safe_alphabet_chars, '='), + .Decoder = Base64Decoder.init(url_safe_alphabet_chars, '='), +}; + +/// URL-safe Base64 codecs, without padding +pub const url_safe_no_pad = Codecs{ + .alphabet_chars = url_safe_alphabet_chars, + .pad_char = null, + .decoderWithIgnore = urlSafeBase64DecoderWithIgnore, + .Encoder = Base64Encoder.init(url_safe_alphabet_chars, null), + .Decoder = Base64Decoder.init(url_safe_alphabet_chars, null), +}; + +pub const standard_pad_char = @compileError("deprecated; use standard.pad_char"); +pub const standard_encoder = @compileError("deprecated; use standard.Encoder"); +pub const standard_decoder = @compileError("deprecated; use standard.Decoder"); + +pub const Base64Encoder = struct { + alphabet_chars: [64]u8, + pad_char: ?u8, + + /// A bunch of assertions, then simply pass the data right through. + pub fn init(alphabet_chars: [64]u8, pad_char: ?u8) Base64Encoder { + assert(alphabet_chars.len == 64); + var char_in_alphabet = [_]bool{false} ** 256; + for (alphabet_chars) |c| { + assert(!char_in_alphabet[c]); + assert(pad_char == null or c != pad_char.?); + char_in_alphabet[c] = true; + } + return Base64Encoder{ + .alphabet_chars = alphabet_chars, + .pad_char = pad_char, + }; + } + + /// Compute the encoded length + pub fn calcSize(encoder: *const Base64Encoder, source_len: usize) usize { + if (encoder.pad_char != null) { + return @divTrunc(source_len + 2, 3) * 4; + } else { + const leftover = source_len % 3; + return @divTrunc(source_len, 3) * 4 + @divTrunc(leftover * 4 + 2, 3); + } + } + + /// dest.len must at least be what you get from ::calcSize. + pub fn encode(encoder: *const Base64Encoder, dest: []u8, source: []const u8) []const u8 { + const out_len = encoder.calcSize(source.len); + assert(dest.len >= out_len); + + var acc: u12 = 0; + var acc_len: u4 = 0; + var out_idx: usize = 0; + for (source) |v| { + acc = (acc << 8) + v; + acc_len += 8; + while (acc_len >= 6) { + acc_len -= 6; + dest[out_idx] = encoder.alphabet_chars[@truncate(u6, (acc >> acc_len))]; + out_idx += 1; + } + } + if (acc_len > 0) { + dest[out_idx] = encoder.alphabet_chars[@truncate(u6, (acc << 6 - acc_len))]; + out_idx += 1; + } + if (encoder.pad_char) |pad_char| { + for (dest[out_idx..]) |*pad| { + pad.* = pad_char; + } + } + return dest[0..out_len]; + } +}; + +pub const Base64Decoder = struct { + const invalid_char: u8 = 0xff; + + /// e.g. 'A' => 0. + /// `invalid_char` for any value not in the 64 alphabet chars. + char_to_index: [256]u8, + pad_char: ?u8, + + pub fn init(alphabet_chars: [64]u8, pad_char: ?u8) Base64Decoder { + var result = Base64Decoder{ + .char_to_index = [_]u8{invalid_char} ** 256, + .pad_char = pad_char, + }; + + var char_in_alphabet = [_]bool{false} ** 256; + for (alphabet_chars) |c, i| { + assert(!char_in_alphabet[c]); + assert(pad_char == null or c != pad_char.?); + + result.char_to_index[c] = @intCast(u8, i); + char_in_alphabet[c] = true; + } + return result; + } + + /// Return the maximum possible decoded size for a given input length - The actual length may be less if the input includes padding. + /// `InvalidPadding` is returned if the input length is not valid. + pub fn calcSizeUpperBound(decoder: *const Base64Decoder, source_len: usize) Error!usize { + var result = source_len / 4 * 3; + const leftover = source_len % 4; + if (decoder.pad_char != null) { + if (leftover % 4 != 0) return error.InvalidPadding; + } else { + if (leftover % 4 == 1) return error.InvalidPadding; + result += leftover * 3 / 4; + } + return result; + } + + /// Return the exact decoded size for a slice. + /// `InvalidPadding` is returned if the input length is not valid. + pub fn calcSizeForSlice(decoder: *const Base64Decoder, source: []const u8) Error!usize { + const source_len = source.len; + var result = try decoder.calcSizeUpperBound(source_len); + if (decoder.pad_char) |pad_char| { + if (source_len >= 1 and source[source_len - 1] == pad_char) result -= 1; + if (source_len >= 2 and source[source_len - 2] == pad_char) result -= 1; + } + return result; + } + + /// dest.len must be what you get from ::calcSize. + /// invalid characters result in error.InvalidCharacter. + /// invalid padding results in error.InvalidPadding. + pub fn decode(decoder: *const Base64Decoder, dest: []u8, source: []const u8) Error!void { + if (decoder.pad_char != null and source.len % 4 != 0) return error.InvalidPadding; + var acc: u12 = 0; + var acc_len: u4 = 0; + var dest_idx: usize = 0; + var leftover_idx: ?usize = null; + for (source) |c, src_idx| { + const d = decoder.char_to_index[c]; + if (d == invalid_char) { + if (decoder.pad_char == null or c != decoder.pad_char.?) return error.InvalidCharacter; + leftover_idx = src_idx; + break; + } + acc = (acc << 6) + d; + acc_len += 6; + if (acc_len >= 8) { + acc_len -= 8; + dest[dest_idx] = @truncate(u8, acc >> acc_len); + dest_idx += 1; + } + } + if (acc_len > 4 or (acc & (@as(u12, 1) << acc_len) - 1) != 0) { + return error.InvalidPadding; + } + if (leftover_idx == null) return; + var leftover = source[leftover_idx.?..]; + if (decoder.pad_char) |pad_char| { + const padding_len = acc_len / 2; + var padding_chars: usize = 0; + for (leftover) |c| { + if (c != pad_char) { + return if (c == Base64Decoder.invalid_char) error.InvalidCharacter else error.InvalidPadding; + } + padding_chars += 1; + } + if (padding_chars != padding_len) return error.InvalidPadding; + } + } +}; + +pub const Base64DecoderWithIgnore = struct { + decoder: Base64Decoder, + char_is_ignored: [256]bool, + + pub fn init(alphabet_chars: [64]u8, pad_char: ?u8, ignore_chars: []const u8) Base64DecoderWithIgnore { + var result = Base64DecoderWithIgnore{ + .decoder = Base64Decoder.init(alphabet_chars, pad_char), + .char_is_ignored = [_]bool{false} ** 256, + }; + for (ignore_chars) |c| { + assert(result.decoder.char_to_index[c] == Base64Decoder.invalid_char); + assert(!result.char_is_ignored[c]); + assert(result.decoder.pad_char != c); + result.char_is_ignored[c] = true; + } + return result; + } + + /// Return the maximum possible decoded size for a given input length - The actual length may be less if the input includes padding + /// `InvalidPadding` is returned if the input length is not valid. + pub fn calcSizeUpperBound(decoder_with_ignore: *const Base64DecoderWithIgnore, source_len: usize) Error!usize { + var result = source_len / 4 * 3; + if (decoder_with_ignore.decoder.pad_char == null) { + const leftover = source_len % 4; + result += leftover * 3 / 4; + } + return result; + } + + /// Invalid characters that are not ignored result in error.InvalidCharacter. + /// Invalid padding results in error.InvalidPadding. + /// Decoding more data than can fit in dest results in error.NoSpaceLeft. See also ::calcSizeUpperBound. + /// Returns the number of bytes written to dest. + pub fn decode(decoder_with_ignore: *const Base64DecoderWithIgnore, dest: []u8, source: []const u8) Error!usize { + const decoder = &decoder_with_ignore.decoder; + var acc: u12 = 0; + var acc_len: u4 = 0; + var dest_idx: usize = 0; + var leftover_idx: ?usize = null; + for (source) |c, src_idx| { + if (decoder_with_ignore.char_is_ignored[c]) continue; + const d = decoder.char_to_index[c]; + if (d == Base64Decoder.invalid_char) { + if (decoder.pad_char == null or c != decoder.pad_char.?) return error.InvalidCharacter; + leftover_idx = src_idx; + break; + } + acc = (acc << 6) + d; + acc_len += 6; + if (acc_len >= 8) { + if (dest_idx == dest.len) return error.NoSpaceLeft; + acc_len -= 8; + dest[dest_idx] = @truncate(u8, acc >> acc_len); + dest_idx += 1; + } + } + if (acc_len > 4 or (acc & (@as(u12, 1) << acc_len) - 1) != 0) { + return error.InvalidPadding; + } + const padding_len = acc_len / 2; + if (leftover_idx == null) { + if (decoder.pad_char != null and padding_len != 0) return error.InvalidPadding; + return dest_idx; + } + var leftover = source[leftover_idx.?..]; + if (decoder.pad_char) |pad_char| { + var padding_chars: usize = 0; + for (leftover) |c| { + if (decoder_with_ignore.char_is_ignored[c]) continue; + if (c != pad_char) { + return if (c == Base64Decoder.invalid_char) error.InvalidCharacter else error.InvalidPadding; + } + padding_chars += 1; + } + if (padding_chars != padding_len) return error.InvalidPadding; + } + return dest_idx; + } +}; + +test "base64" { + @setEvalBranchQuota(8000); + try testBase64(); + comptime try testAllApis(standard, "comptime", "Y29tcHRpbWU="); +} + +test "base64 url_safe_no_pad" { + @setEvalBranchQuota(8000); + try testBase64UrlSafeNoPad(); + comptime try testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU"); +} + +fn testBase64() !void { + const codecs = standard; + + try testAllApis(codecs, "", ""); + try testAllApis(codecs, "f", "Zg=="); + try testAllApis(codecs, "fo", "Zm8="); + try testAllApis(codecs, "foo", "Zm9v"); + try testAllApis(codecs, "foob", "Zm9vYg=="); + try testAllApis(codecs, "fooba", "Zm9vYmE="); + try testAllApis(codecs, "foobar", "Zm9vYmFy"); + + try testDecodeIgnoreSpace(codecs, "", " "); + try testDecodeIgnoreSpace(codecs, "f", "Z g= ="); + try testDecodeIgnoreSpace(codecs, "fo", " Zm8="); + try testDecodeIgnoreSpace(codecs, "foo", "Zm9v "); + try testDecodeIgnoreSpace(codecs, "foob", "Zm9vYg = = "); + try testDecodeIgnoreSpace(codecs, "fooba", "Zm9v YmE="); + try testDecodeIgnoreSpace(codecs, "foobar", " Z m 9 v Y m F y "); + + // test getting some api errors + try testError(codecs, "A", error.InvalidPadding); + try testError(codecs, "AA", error.InvalidPadding); + try testError(codecs, "AAA", error.InvalidPadding); + try testError(codecs, "A..A", error.InvalidCharacter); + try testError(codecs, "AA=A", error.InvalidPadding); + try testError(codecs, "AA/=", error.InvalidPadding); + try testError(codecs, "A/==", error.InvalidPadding); + try testError(codecs, "A===", error.InvalidPadding); + try testError(codecs, "====", error.InvalidPadding); + + try testNoSpaceLeftError(codecs, "AA=="); + try testNoSpaceLeftError(codecs, "AAA="); + try testNoSpaceLeftError(codecs, "AAAA"); + try testNoSpaceLeftError(codecs, "AAAAAA=="); +} + +fn testBase64UrlSafeNoPad() !void { + const codecs = url_safe_no_pad; + + try testAllApis(codecs, "", ""); + try testAllApis(codecs, "f", "Zg"); + try testAllApis(codecs, "fo", "Zm8"); + try testAllApis(codecs, "foo", "Zm9v"); + try testAllApis(codecs, "foob", "Zm9vYg"); + try testAllApis(codecs, "fooba", "Zm9vYmE"); + try testAllApis(codecs, "foobar", "Zm9vYmFy"); + + try testDecodeIgnoreSpace(codecs, "", " "); + try testDecodeIgnoreSpace(codecs, "f", "Z g "); + try testDecodeIgnoreSpace(codecs, "fo", " Zm8"); + try testDecodeIgnoreSpace(codecs, "foo", "Zm9v "); + try testDecodeIgnoreSpace(codecs, "foob", "Zm9vYg "); + try testDecodeIgnoreSpace(codecs, "fooba", "Zm9v YmE"); + try testDecodeIgnoreSpace(codecs, "foobar", " Z m 9 v Y m F y "); + + // test getting some api errors + try testError(codecs, "A", error.InvalidPadding); + try testError(codecs, "AAA=", error.InvalidCharacter); + try testError(codecs, "A..A", error.InvalidCharacter); + try testError(codecs, "AA=A", error.InvalidCharacter); + try testError(codecs, "AA/=", error.InvalidCharacter); + try testError(codecs, "A/==", error.InvalidCharacter); + try testError(codecs, "A===", error.InvalidCharacter); + try testError(codecs, "====", error.InvalidCharacter); + + try testNoSpaceLeftError(codecs, "AA"); + try testNoSpaceLeftError(codecs, "AAA"); + try testNoSpaceLeftError(codecs, "AAAA"); + try testNoSpaceLeftError(codecs, "AAAAAA"); +} + +fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: []const u8) !void { + // Base64Encoder + { + var buffer: [0x100]u8 = undefined; + const encoded = codecs.Encoder.encode(&buffer, expected_decoded); + try testing.expectEqualSlices(u8, expected_encoded, encoded); + } + + // Base64Decoder + { + var buffer: [0x100]u8 = undefined; + var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)]; + try codecs.Decoder.decode(decoded, expected_encoded); + try testing.expectEqualSlices(u8, expected_decoded, decoded); + } + + // Base64DecoderWithIgnore + { + const decoder_ignore_nothing = codecs.decoderWithIgnore(""); + var buffer: [0x100]u8 = undefined; + var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)]; + var written = try decoder_ignore_nothing.decode(decoded, expected_encoded); + try testing.expect(written <= decoded.len); + try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]); + } +} + +fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded: []const u8) !void { + const decoder_ignore_space = codecs.decoderWithIgnore(" "); + var buffer: [0x100]u8 = undefined; + var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)]; + var written = try decoder_ignore_space.decode(decoded, encoded); + try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]); +} + +fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void { + const decoder_ignore_space = codecs.decoderWithIgnore(" "); + var buffer: [0x100]u8 = undefined; + if (codecs.Decoder.calcSizeForSlice(encoded)) |decoded_size| { + var decoded = buffer[0..decoded_size]; + if (codecs.Decoder.decode(decoded, encoded)) |_| { + return error.ExpectedError; + } else |err| if (err != expected_err) return err; + } else |err| if (err != expected_err) return err; + + if (decoder_ignore_space.decode(buffer[0..], encoded)) |_| { + return error.ExpectedError; + } else |err| if (err != expected_err) return err; +} + +fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void { + const decoder_ignore_space = codecs.decoderWithIgnore(" "); + var buffer: [0x100]u8 = undefined; + var decoded = buffer[0 .. (try codecs.Decoder.calcSizeForSlice(encoded)) - 1]; + if (decoder_ignore_space.decode(decoded, encoded)) |_| { + return error.ExpectedError; + } else |err| if (err != error.NoSpaceLeft) return err; +} diff --git a/src/javascript/jsc/webcore/encoding.zig b/src/javascript/jsc/webcore/encoding.zig index cc90f3c9b1..78d3f2877c 100644 --- a/src/javascript/jsc/webcore/encoding.zig +++ b/src/javascript/jsc/webcore/encoding.zig @@ -12,7 +12,7 @@ const js = JSC.C; const Method = @import("../../../http/method.zig").Method; const ObjectPool = @import("../../../pool.zig").ObjectPool; - +const bun = @import("../../../global.zig"); const Output = @import("../../../global.zig").Output; const MutableString = @import("../../../global.zig").MutableString; const strings = @import("../../../global.zig").strings; @@ -457,23 +457,16 @@ pub const TextDecoder = struct { } var buffer = std.ArrayListAlignedUnmanaged(u16, @alignOf(@TypeOf(slice.ptr))){}; - buffer.ensureTotalCapacity(default_allocator, slice.len) catch unreachable; + // copy the allocator to reduce the number of threadlocal accesses + const allocator = VirtualMachine.vm.allocator; + buffer.ensureTotalCapacity(allocator, slice.len) catch unreachable; buffer.items.len = i; - defer buffer.deinit( - default_allocator, - ); - if (comptime Slice == []u16) { - @memcpy( - std.mem.sliceAsBytes(buffer.items).ptr, - std.mem.sliceAsBytes(slice).ptr, - std.mem.sliceAsBytes(slice[0..i]).len, - ); - } else { - for (slice[0..i]) |ch, j| { - buffer.items[j] = ch; - } - } + @memcpy( + std.mem.sliceAsBytes(buffer.items).ptr, + std.mem.sliceAsBytes(slice).ptr, + std.mem.sliceAsBytes(slice[0..i]).len, + ); const first_high_surrogate = 0xD800; const last_high_surrogate = 0xDBFF; @@ -484,20 +477,24 @@ pub const TextDecoder = struct { while (remainder.len > 0) { switch (remainder[0]) { 0...127 => { - var count: usize = 1; - while (remainder.len > count and remainder[count] <= 127) : (count += 1) {} - buffer.ensureUnusedCapacity(default_allocator, count) catch unreachable; + const count: usize = if (strings.firstNonASCII16CheckMin(Slice, remainder, false)) |index| index + 1 else remainder.len; + + buffer.ensureUnusedCapacity(allocator, count) catch unreachable; + const prev = buffer.items.len; buffer.items.len += count; - for (remainder[0..count]) |char, j| { - buffer.items[prev + j] = char; - } + // Since this string is freshly allocated, we know it's not going to overlap + @memcpy( + std.mem.sliceAsBytes(buffer.items[prev..]).ptr, + std.mem.sliceAsBytes(remainder).ptr, + std.mem.sliceAsBytes(remainder[0..count]).len, + ); remainder = remainder[count..]; }, first_high_surrogate...last_high_surrogate => |first| { if (remainder.len > 1) { if (remainder[1] >= first_low_surrogate and remainder[1] <= last_low_surrogate) { - buffer.ensureUnusedCapacity(default_allocator, 2) catch unreachable; + buffer.ensureUnusedCapacity(allocator, 2) catch unreachable; buffer.items.ptr[buffer.items.len] = first; buffer.items.ptr[buffer.items.len + 1] = remainder[1]; buffer.items.len += 2; @@ -505,7 +502,7 @@ pub const TextDecoder = struct { continue; } } - buffer.ensureUnusedCapacity(default_allocator, 1) catch unreachable; + buffer.ensureUnusedCapacity(allocator, 1) catch unreachable; buffer.items.ptr[buffer.items.len] = strings.unicode_replacement; buffer.items.len += 1; remainder = remainder[1..]; @@ -514,7 +511,7 @@ pub const TextDecoder = struct { // Is this an unpaired low surrogate or four-digit hex escape? else => { - buffer.ensureUnusedCapacity(default_allocator, 1) catch unreachable; + buffer.ensureUnusedCapacity(allocator, 1) catch unreachable; buffer.items.ptr[buffer.items.len] = strings.unicode_replacement; buffer.items.len += 1; remainder = remainder[1..]; @@ -522,9 +519,11 @@ pub const TextDecoder = struct { } } + var full = buffer.toOwnedSlice(allocator); + var out = ZigString.init(""); - out.ptr = @ptrCast([*]u8, buffer.items.ptr); - out.len = buffer.items.len; + out.ptr = @ptrCast([*]u8, full.ptr); + out.len = full.len; out.markUTF16(); return out.toValueGC(ctx.ptr()).asObjectRef(); } @@ -651,4 +650,232 @@ pub const TextDecoder = struct { } }; +pub const Encoder = struct { + export fn Bun__encoding__writeLatin1AsHex(input: [*]const u8, len: usize, to: [*]u8, to_len: usize) i64 { + return writeU8(input, len, to, to_len, .hex); + } + export fn Bun__encoding__writeLatin1AsASCII(input: [*]const u8, len: usize, to: [*]u8, to_len: usize) i64 { + return writeU8(input, len, to, to_len, .ascii); + } + export fn Bun__encoding__writeLatin1AsURLSafeBase64(input: [*]const u8, len: usize, to: [*]u8, to_len: usize) i64 { + return writeU8(input, len, to, to_len, .base64url); + } + export fn Bun__encoding__writeLatin1AsUTF16(input: [*]const u8, len: usize, to: [*]u8, to_len: usize) i64 { + return writeU8(input, len, to, to_len, .utf16le); + } + export fn Bun__encoding__writeLatin1AsUTF8(input: [*]const u8, len: usize, to: [*]u8, to_len: usize) i64 { + return writeU8(input, len, to, to_len, JSC.Node.Encoding.utf8); + } + export fn Bun__encoding__writeLatin1AsBase64(input: [*]const u8, len: usize, to: [*]u8, to_len: usize) i64 { + return writeU8(input, len, to, to_len, .base64); + } + export fn Bun__encoding__writeUTF16AsBase64(input: [*]const u16, len: usize, to: [*]u8, to_len: usize) i64 { + return writeU16(input, len, to, to_len, .base64); + } + export fn Bun__encoding__writeUTF16AsHex(input: [*]const u16, len: usize, to: [*]u8, to_len: usize) i64 { + return writeU16(input, len, to, to_len, .hex); + } + export fn Bun__encoding__writeUTF16AsURLSafeBase64(input: [*]const u16, len: usize, to: [*]u8, to_len: usize) i64 { + return writeU16(input, len, to, to_len, .base64url); + } + export fn Bun__encoding__writeUTF16AsUTF16(input: [*]const u16, len: usize, to: [*]u8, to_len: usize) i64 { + return writeU16(input, len, to, to_len, JSC.Node.Encoding.utf16le); + } + export fn Bun__encoding__writeUTF16AsUTF8(input: [*]const u16, len: usize, to: [*]u8, to_len: usize) i64 { + return writeU16(input, len, to, to_len, .utf8); + } + export fn Bun__encoding__writeUTF16AsASCII(input: [*]const u8, len: usize, to: [*]u8, to_len: usize) i64 { + return writeU8(input, len, to, to_len, .ascii); + } + + // pub fn writeUTF16AsUTF8(utf16: [*]const u16, len: usize, to: [*]u8, to_len: usize) callconv(.C) i32 { + // return @intCast(i32, strings.copyUTF16IntoUTF8(to[0..to_len], []const u16, utf16[0..len]).written); + // } + + // pub fn toString(input: [*]const u8, len: usize, zig_str: *ZigString, comptime encoding: JSC.Node.Encoding) callconv(.C) i64 {} + + pub fn writeU8(input: [*]const u8, len: usize, to: [*]u8, to_len: usize, comptime encoding: JSC.Node.Encoding) i64 { + if (len == 0 or to_len == 0) + return 0; + + // TODO: increase temporary buffer size for larger amounts of data + // defer { + // if (comptime encoding.isBinaryToText()) {} + // } + + // if (comptime encoding.isBinaryToText()) {} + + switch (comptime encoding) { + JSC.Node.Encoding.ascii => { + const written = @truncate(u32, @minimum(len, to_len)); + @memcpy(to, input, written); + return @intCast(i32, written); + }, + .utf8 => { + // need to encode + return @intCast(i32, strings.copyLatin1IntoUTF8(to[0..to_len], []const u8, input[0..len]).written); + }, + // encode latin1 into UTF16 + JSC.Node.Encoding.ucs2, JSC.Node.Encoding.utf16le => { + if (to_len < 2) + return 0; + + if (std.mem.isAligned(@ptrToInt(to), @alignOf([*]u16))) { + var buf = input[0..len]; + var output = @ptrCast([*]u16, @alignCast(@alignOf(u16), to))[0 .. to_len / 2]; + return strings.copyLatin1IntoUTF16([]u16, output, []const u8, buf).written; + } else { + var buf = input[0..len]; + var output = @ptrCast([*]align(1) u16, to)[0 .. to_len / 2]; + return strings.copyLatin1IntoUTF16([]align(1) u16, output, []const u8, buf).written; + } + }, + + JSC.Node.Encoding.hex => { + return @intCast(i64, strings.decodeHexToBytes(to[0..to_len], u8, input[0..len])); + }, + + JSC.Node.Encoding.base64url => { + var slice = strings.trim(input[0..len], "\r\n\t " ++ [_]u8{std.ascii.control_code.VT}); + if (slice.len == 0) + return 0; + + if (strings.eqlComptime(slice[slice.len - 2 ..][0..2], "==")) { + slice = slice[0 .. slice.len - 2]; + } else if (slice[slice.len - 1] == '=') { + slice = slice[0 .. slice.len - 1]; + } + + const wrote = bun.base64.urlsafe.decode(to[0..to_len], slice) catch |err| brk: { + if (err == error.NoSpaceLeft) { + break :brk to_len; + } + + return -1; + }; + return @intCast(i64, wrote); + }, + + JSC.Node.Encoding.base64 => { + var slice = strings.trim(input[0..len], "\r\n\t " ++ [_]u8{std.ascii.control_code.VT}); + var outlen = bun.base64.decodeLen(slice); + + return @intCast(i64, bun.base64.decode(to[0..outlen], slice).written); + }, + else => return 0, + } + } + + pub fn writeU16(input: [*]const u16, len: usize, to: [*]u8, to_len: usize, comptime encoding: JSC.Node.Encoding) i64 { + + // TODO: increase temporary buffer size for larger amounts of data + // defer { + // if (comptime encoding.isBinaryToText()) {} + // } + + // if (comptime encoding.isBinaryToText()) {} + + switch (comptime encoding) { + .utf8 => { + return @intCast(i32, strings.copyUTF16IntoUTF8(to[0..to_len], []const u16, input[0..len]).written); + }, + // string is already encoded, just need to copy the data + JSC.Node.Encoding.ucs2, JSC.Node.Encoding.ascii, JSC.Node.Encoding.utf16le => { + strings.copyU16IntoU8(to[0..to_len], []const u16, input[0..len]); + + return @intCast(i64, @minimum(len, to_len)); + }, + + JSC.Node.Encoding.hex => { + return @intCast(i64, strings.decodeHexToBytes(to[0..to_len], u16, input[0..len])); + }, + + JSC.Node.Encoding.base64, JSC.Node.Encoding.base64url => { + if (to_len < 2 or len == 0) + return 0; + + // very very slow case! + // shouldn't really happen though + var transcoded = strings.toUTF8Alloc(bun.default_allocator, input[0..len]) catch return 0; + defer bun.default_allocator.free(transcoded); + return writeU8(transcoded.ptr, transcoded.len, to, to_len, encoding); + }, + else => return 0, + } + } + // pub fn writeU8(input: [*]const u8, len: usize, to: [*]u8, to_len: usize, comptime encoding: JSC.Node.Encoding) callconv(.C) i32 {} + + // pub fn toUTF8FromU16(comptime Slice: type, slice: Slice, out_ptr: *[*]u8) i32 { + // var out = strings.toUTF8AllocWithType( + // default_allocator, + // Slice, + // slice, + // ) catch { + // return -1; + // }; + // out_ptr.* = out.ptr; + // return @intCast(isize, out.len); + // } + + // pub fn toUTF8FromLatin1(comptime Slice: type, slice: Slice, out_ptr: *[*]u8) i32 { + // var latin1 = strings.allocateLatin1IntoUTF8(default_allocator, Slice, slice) catch return -1; + // out_ptr.* = latin1.ptr; + // return @intCast(isize, latin1.len); + // } + + // pub fn toUTF16FromLatin1(comptime Slice: type, slice: Slice, out_ptr: *[*]u8) i32 { + // var latin1 = strings.toUTF(default_allocator, Slice, slice) catch return -1; + // out_ptr.* = latin1.ptr; + // return @intCast(isize, latin1.len); + // } + + // pub fn toUTF16FromU8(slice: []const u8, out_ptr: *[*]u16) i32 { + // if (strings.toUTF16Alloc(default_allocator, slice, true)) |result_| { + // if (result_) |result| { + // out_ptr.* = result.ptr; + // return @intCast(isize, result.len); + // } + // } else |err| { + // switch (err) { + // error.InvalidByteSequence => { + // return -2; + // }, + // error.OutOfMemory => { + // return -1; + // }, + // else => { + // return -3; + // }, + // } + // } + + // var out = default_allocator.alloc(u16, slice.len) catch return -1; + // strings.copyU8IntoU16(out, slice); + // out_ptr.* = out.ptr; + // return @intCast(isize, out.len); + // } + comptime { + if (!JSC.is_bindgen) { + _ = Bun__encoding__writeLatin1AsHex; + _ = Bun__encoding__writeLatin1AsURLSafeBase64; + _ = Bun__encoding__writeLatin1AsUTF16; + _ = Bun__encoding__writeLatin1AsUTF8; + _ = Bun__encoding__writeLatin1AsBase64; + _ = Bun__encoding__writeUTF16AsBase64; + _ = Bun__encoding__writeUTF16AsHex; + _ = Bun__encoding__writeUTF16AsURLSafeBase64; + _ = Bun__encoding__writeUTF16AsUTF16; + _ = Bun__encoding__writeUTF16AsUTF8; + _ = Bun__encoding__writeLatin1AsASCII; + _ = Bun__encoding__writeUTF16AsASCII; + } + } +}; + +comptime { + if (!JSC.is_bindgen) { + std.testing.refAllDecls(Encoder); + } +} + test "Vec" {} diff --git a/src/runtime.version b/src/runtime.version index 648229454c..16f1dd4853 100644 --- a/src/runtime.version +++ b/src/runtime.version @@ -1 +1 @@ -4c25d48a40ae51d8 \ No newline at end of file +44f6d21c5e1451d0 \ No newline at end of file diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 95bd8ee4d8..9ebf0d330e 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -719,10 +719,18 @@ pub fn copyU8IntoU16WithAlignment(comptime alignment: u21, output_: []align(alig if (comptime Environment.allow_assert) { std.debug.assert(input.len <= output.len); } - while (input.len >= word) { - appendUTF8MachineWordToUTF16MachineWordUnaligned(alignment, output[0..word], input[0..word]); - output = output[word..]; - input = input[word..]; + + // un-aligned data access is slow + // so we attempt to align the data + while (!std.mem.isAligned(@ptrToInt(output.ptr), @alignOf(u16)) and input.len >= word) { + output[0] = input[0]; + output = output[1..]; + input = input[1..]; + } + + if (std.mem.isAligned(@ptrToInt(output.ptr), @alignOf(u16)) and input.len > 0) { + copyU8IntoU16(@alignCast(@alignOf(u16), output.ptr)[0..output.len], input); + return; } for (input) |c, i| { @@ -758,28 +766,33 @@ pub fn copyU8IntoU16WithAlignment(comptime alignment: u21, output_: []align(alig // } pub inline fn copyU16IntoU8(output_: []u8, comptime InputType: type, input_: InputType) void { - var output = output_; - var input = input_; if (comptime Environment.allow_assert) { - std.debug.assert(input.len <= output.len); + std.debug.assert(input_.len <= output_.len); } - // on X64, this is 4 - // on WASM, this is 2 - const machine_word_length = comptime @sizeOf(usize) / @sizeOf(u16); + if (comptime !JSC.is_bindgen) { + JSC.WTF.copyLCharsFromUCharSource(output_.ptr, InputType, input_); + } else { + var output = output_; + var input = input_; - while (input.len >= machine_word_length) { - comptime var machine_word_i: usize = 0; - inline while (machine_word_i < machine_word_length) : (machine_word_i += 1) { - output[machine_word_i] = @intCast(u8, input[machine_word_i]); + // on X64, this is 4 + // on WASM, this is 2 + const machine_word_length = comptime @sizeOf(usize) / @sizeOf(u16); + + while (input.len >= machine_word_length) { + comptime var machine_word_i: usize = 0; + inline while (machine_word_i < machine_word_length) : (machine_word_i += 1) { + output[machine_word_i] = @intCast(u8, input[machine_word_i]); + } + + output = output[machine_word_length..]; + input = input[machine_word_length..]; } - output = output[machine_word_length..]; - input = input[machine_word_length..]; - } - - for (input) |c, i| { - output[i] = @intCast(u8, c); + for (input) |c, i| { + output[i] = @intCast(u8, c); + } } } @@ -972,7 +985,7 @@ pub fn allocateLatin1IntoUTF8(allocator: std.mem.Allocator, comptime Type: type, if (first < 16) { latin1 = latin1[(comptime count * ascii_vector_size)..]; list.items.len += (comptime count * ascii_vector_size); - try list.appendSlice(latin1[0..first]); + list.appendSliceAssumeCapacity(latin1[0..first]); latin1 = latin1[first..]; break_outer = true; break :outer; @@ -1152,6 +1165,29 @@ pub fn copyLatin1IntoUTF8(buf_: []u8, comptime Type: type, latin1_: Type) Encode }; } +const JSC = @import("javascript_core"); + +pub fn copyLatin1IntoUTF16(comptime Buffer: type, buf_: Buffer, comptime Type: type, latin1_: Type) EncodeIntoResult { + var buf = buf_; + var latin1 = latin1_; + while (buf.len > 0 and latin1.len > 0) { + var to_write = strings.firstNonASCII(latin1) orelse @truncate(u32, latin1.len); + strings.copyU8IntoU16WithAlignment(std.meta.alignment(Buffer), buf, latin1[0..to_write]); + latin1 = latin1[to_write..]; + buf = buf[to_write..]; + if (latin1.len > 0 and buf.len >= 2) { + buf[0..2].* = latin1ToCodepointBytesAssumeNotASCII16(latin1[0]); + latin1 = latin1[1..]; + buf = buf[2..]; + } + } + + return .{ + .read = @truncate(u32, buf_.len - buf.len), + .written = @truncate(u32, latin1_.len - latin1.len), + }; +} + test "copyLatin1IntoUTF8" { var input: string = "hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!"; var output = std.mem.zeroes([500]u8); @@ -1172,13 +1208,21 @@ pub fn latin1ToCodepointAssumeNotASCII(char: u8, comptime CodePointType: type) C ); } -pub fn latin1ToCodepointBytesAssumeNotASCII(char: u32) [2]u8 { - return [2]u8{ - @truncate(u8, 0xc0 | char >> 6), - @truncate(u8, 0x80 | (char & 0x3f)), +pub fn latin1ToCodepointBytesAssumeNotASCIIWIthCharType(comptime Char: type, char: u32) [2]Char { + return [2]Char{ + @as(Char, @truncate(u8, 0xc0 | char >> 6)), + @as(Char, @truncate(u8, 0x80 | (char & 0x3f))), }; } +pub fn latin1ToCodepointBytesAssumeNotASCII(char: u32) [2]u8 { + return latin1ToCodepointBytesAssumeNotASCIIWIthCharType(u8, char); +} + +pub fn latin1ToCodepointBytesAssumeNotASCII16(char: u32) [2]u16 { + return latin1ToCodepointBytesAssumeNotASCIIWIthCharType(u16, char); +} + pub fn copyUTF16IntoUTF8(buf: []u8, comptime Type: type, utf16: Type) EncodeIntoResult { var remaining = buf; var utf16_remaining = utf16; @@ -1661,11 +1705,72 @@ pub fn indexOfNotChar(slice: []const u8, char: u8) ?u32 { return null; } +const hex_table: [255]u8 = brk: { + var values: [255]u8 = [_]u8{0} ** 255; + values['0'] = 0; + values['1'] = 1; + values['2'] = 2; + values['3'] = 3; + values['4'] = 4; + values['5'] = 5; + values['6'] = 6; + values['7'] = 7; + values['8'] = 8; + values['9'] = 9; + values['A'] = 10; + values['B'] = 11; + values['C'] = 12; + values['D'] = 13; + values['E'] = 14; + values['F'] = 15; + values['a'] = 10; + values['b'] = 11; + values['c'] = 12; + values['d'] = 13; + values['e'] = 14; + values['f'] = 15; + + break :brk values; +}; + +pub fn decodeHexToBytes(destination: []u8, comptime Char: type, source: []const Char) usize { + var remain = destination; + var input = source; + + while (input.len > 1 and remain.len > 0) { + const int = input[0..2].*; + const a = hex_table[@truncate(u8, int[0])]; + const b = hex_table[@truncate(u8, int[1])]; + if (a == 255 or b == 255) { + break; + } + remain[0] = a << 4 | b; + remain = remain[1..]; + input = input[2..]; + } + + return destination.len - remain.len; +} + +test "decodeHexToBytes" { + var buffer = std.mem.zeroes([1024]u8); + for (buffer) |_, i| { + buffer[i] = @truncate(u8, i % 256); + } + var written: [2048]u8 = undefined; + var hex = std.fmt.bufPrint(&written, "{}", .{std.fmt.fmtSliceHexLower(&buffer)}) catch unreachable; + var good: [4096]u8 = undefined; + var ours_buf: [4096]u8 = undefined; + var match = try std.fmt.hexToBytes(good[0..1024], hex); + var ours = decodeHexToBytes(&ours_buf, hex); + try std.testing.expectEqualSlices(u8, match, ours_buf[0..ours]); + try std.testing.expectEqualSlices(u8, &buffer, ours_buf[0..ours]); +} + pub fn trimLeadingChar(slice: []const u8, char: u8) []const u8 { if (indexOfNotChar(slice, char)) |i| { return slice[i..]; } - return ""; } @@ -2028,9 +2133,10 @@ pub fn containsNonBmpCodePoint(text: string) bool { } // this is std.mem.trim except it doesn't forcibly change the slice to be const -pub fn trim(slice: anytype, values_to_strip: []const u8) @TypeOf(slice) { +pub fn trim(slice: anytype, comptime values_to_strip: []const u8) @TypeOf(slice) { var begin: usize = 0; var end: usize = slice.len; + while (begin < end and std.mem.indexOfScalar(u8, values_to_strip, slice[begin]) != null) : (begin += 1) {} while (end > begin and std.mem.indexOfScalar(u8, values_to_strip, slice[end - 1]) != null) : (end -= 1) {} return slice[begin..end];