aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/builtins/ts/JSBufferConstructor.ts
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-06-01 21:16:47 -0400
committerGravatar GitHub <noreply@github.com> 2023-06-01 18:16:47 -0700
commit4df1d37ddc54242c339765f22fb90ba2e9e3a99a (patch)
treed63ede76463e7ecba78a4d4b31e5e8158193552f /src/bun.js/builtins/ts/JSBufferConstructor.ts
parent03ffd1c732aaaa30b5481f197221ce96da559e63 (diff)
downloadbun-4df1d37ddc54242c339765f22fb90ba2e9e3a99a.tar.gz
bun-4df1d37ddc54242c339765f22fb90ba2e9e3a99a.tar.zst
bun-4df1d37ddc54242c339765f22fb90ba2e9e3a99a.zip
Bundle and minify `.exports.js` files. (#3036)
* move all exports.js into src/js * finalize the sort of this * and it works * add test.ts to gitignore * okay * convert some to ts just to show * finish up * fixup makefile * minify syntax in dev * finish rebase * dont minify all modules * merge * finish rebase merge * flaky test that hangs
Diffstat (limited to 'src/bun.js/builtins/ts/JSBufferConstructor.ts')
-rw-r--r--src/bun.js/builtins/ts/JSBufferConstructor.ts67
1 files changed, 0 insertions, 67 deletions
diff --git a/src/bun.js/builtins/ts/JSBufferConstructor.ts b/src/bun.js/builtins/ts/JSBufferConstructor.ts
deleted file mode 100644
index debc62d51..000000000
--- a/src/bun.js/builtins/ts/JSBufferConstructor.ts
+++ /dev/null
@@ -1,67 +0,0 @@
-export function from(items) {
- if ($isUndefinedOrNull(items)) {
- throw new TypeError(
- "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object.",
- );
- }
-
- // TODO: figure out why private symbol not found
- if (
- typeof items === "string" ||
- (typeof items === "object" &&
- ($isTypedArrayView(items) ||
- items instanceof ArrayBuffer ||
- items instanceof SharedArrayBuffer ||
- items instanceof String))
- ) {
- switch ($argumentCount()) {
- case 1: {
- return new $Buffer(items);
- }
- case 2: {
- return new $Buffer(items, $argument(1));
- }
- default: {
- return new $Buffer(items, $argument(1), $argument(2));
- }
- }
- }
-
- var arrayLike = $toObject(
- items,
- "The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object.",
- ) as ArrayLike<any>;
-
- if (!$isJSArray(arrayLike)) {
- const toPrimitive = $tryGetByIdWithWellKnownSymbol(items, "toPrimitive");
-
- if (toPrimitive) {
- const primitive = toPrimitive.$call(items, "string");
-
- if (typeof primitive === "string") {
- switch ($argumentCount()) {
- case 1: {
- return new $Buffer(primitive);
- }
- case 2: {
- return new $Buffer(primitive, $argument(1));
- }
- default: {
- return new $Buffer(primitive, $argument(1), $argument(2));
- }
- }
- }
- }
-
- if (!("length" in arrayLike) || $isCallable(arrayLike)) {
- throw new TypeError(
- "The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object.",
- );
- }
- }
-
- // Don't pass the second argument because Node's Buffer.from doesn't accept
- // a function and Uint8Array.from requires it if it exists
- // That means we cannot use $tailCallFowrardArguments here, sadly
- return new $Buffer(Uint8Array.from(arrayLike).buffer);
-}