aboutsummaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js')
-rw-r--r--src/js/_codegen/build-functions.ts33
-rw-r--r--src/js/_codegen/static-hash-tables.ts42
-rw-r--r--src/js/builtins/ProcessObjectInternals.ts21
-rw-r--r--src/js/out/WebCoreJSBuiltins.cpp8
-rw-r--r--src/js/out/WebCoreJSBuiltins.h11
5 files changed, 42 insertions, 73 deletions
diff --git a/src/js/_codegen/build-functions.ts b/src/js/_codegen/build-functions.ts
index fcce0263a..0f752e8a1 100644
--- a/src/js/_codegen/build-functions.ts
+++ b/src/js/_codegen/build-functions.ts
@@ -3,38 +3,7 @@ import path from "path";
import { sliceSourceCode } from "./builtin-parser";
import { applyGlobalReplacements, define } from "./replacements";
import { cap, fmtCPPString, low } from "./helpers";
-import { spawn } from "bun";
-
-async function createStaticHashtables() {
- const STATIC_HASH_TABLES = ["src/bun.js/bindings/Process.cpp", "src/bun.js/bindings/BunObject.cpp"];
- console.time("Creating static hash tables...");
- const create_hash_table = path.join(import.meta.dir, "../../../src/bun.js/scripts/create_hash_table");
- if (!create_hash_table) {
- console.warn(
- "Could not find create_hash_table executable. Run `bun i` or clone webkit to build static hash tables",
- );
- return;
- }
- for (let cpp of STATIC_HASH_TABLES) {
- cpp = path.join(import.meta.dir, "../../../", cpp);
- const { stdout, exited } = spawn({
- cmd: [create_hash_table, cpp],
- stdout: "pipe",
- stderr: "inherit",
- });
- await exited;
- let str = await new Response(stdout).text();
- str = str.replaceAll(/^\/\/.*$/gm, "");
- str = str.replaceAll(/^#include.*$/gm, "");
- str = str.replaceAll(`namespace JSC {`, "");
- str = str.replaceAll(`} // namespace JSC`, "");
- str = "// File generated via `make generate-builtins`\n" + str.trim() + "\n";
- await Bun.write(cpp.replace(/\.cpp$/, ".lut.h"), str);
- }
- console.timeEnd("Creating static hash tables...");
-}
-const staticHashTablePromise = createStaticHashtables();
console.log("Bundling Bun builtin functions...");
const MINIFY = process.argv.includes("--minify") || process.argv.includes("-m");
@@ -634,8 +603,6 @@ if (!KEEP_TMP) {
await rmSync(TMP_DIR, { recursive: true });
}
-await staticHashTablePromise;
-
console.log(
`Embedded JS size: %s bytes (across %s functions, %s files)`,
totalJSSize,
diff --git a/src/js/_codegen/static-hash-tables.ts b/src/js/_codegen/static-hash-tables.ts
new file mode 100644
index 000000000..be2aa908d
--- /dev/null
+++ b/src/js/_codegen/static-hash-tables.ts
@@ -0,0 +1,42 @@
+// TODO: move this file somewhere else. it doesnt make sense in src/js/
+// it generates C++ code not related to javascript at all
+import { spawn } from "bun";
+import path from "../node/path";
+
+const STATIC_HASH_TABLES = [
+ //
+ "src/bun.js/bindings/BunObject.cpp",
+ "src/bun.js/bindings/ZigGlobalObject.lut.txt",
+ "src/bun.js/bindings/Process.cpp",
+ "src/bun.js/bindings/ProcessBindingConstants.cpp",
+ "src/bun.js/bindings/ProcessBindingNatives.cpp",
+];
+
+console.time("Creating static hash tables...");
+const create_hash_table = path.join(import.meta.dir, "../../../src/bun.js/scripts/create_hash_table");
+if (!create_hash_table) {
+ console.warn("Could not find create_hash_table executable. Run `bun i` or clone webkit to build static hash tables");
+ process.exit(1);
+}
+
+await Promise.all(
+ STATIC_HASH_TABLES.map(async cpp => {
+ cpp = path.join(import.meta.dir, "../../../", cpp);
+ const { stdout, exited } = spawn({
+ cmd: [create_hash_table, cpp],
+ stdout: "pipe",
+ stderr: "inherit",
+ });
+ await exited;
+ let str = await new Response(stdout).text();
+ str = str.replaceAll(/^\/\/.*$/gm, "");
+ str = str.replaceAll(/^#include.*$/gm, "");
+ str = str.replaceAll(`namespace JSC {`, "");
+ str = str.replaceAll(`} // namespace JSC`, "");
+ str = "// File generated via `make static-hash-table` / `make cpp`\n" + str.trim() + "\n";
+ await Bun.write(cpp.replace(/\.cpp$/, ".lut.h").replace(/(\.lut)?\.txt$/, ".lut.h"), str);
+ console.log("Wrote", path.relative(process.cwd(), cpp.replace(/\.cpp$/, ".lut.h")));
+ }),
+);
+
+console.timeEnd("Creating static hash tables...");
diff --git a/src/js/builtins/ProcessObjectInternals.ts b/src/js/builtins/ProcessObjectInternals.ts
index 2bb8648df..ef8f1f9ce 100644
--- a/src/js/builtins/ProcessObjectInternals.ts
+++ b/src/js/builtins/ProcessObjectInternals.ts
@@ -24,27 +24,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-// TODO: move this to native code?
-export function binding(bindingName) {
- if (bindingName === "constants") {
- return $processBindingConstants;
- }
- const issue = {
- fs: 3546,
- buffer: 2020,
- natives: 2254,
- uv: 2891,
- }[bindingName];
- if (issue) {
- throw new Error(
- `process.binding("${bindingName}") is not implemented in Bun. Track the status & thumbs up the issue: https://github.com/oven-sh/bun/issues/${issue}`,
- );
- }
- throw new TypeError(
- `process.binding("${bindingName}") is not implemented in Bun. If that breaks something, please file an issue and include a reproducible code sample.`,
- );
-}
-
export function getStdioWriteStream(fd) {
const tty = require("node:tty");
diff --git a/src/js/out/WebCoreJSBuiltins.cpp b/src/js/out/WebCoreJSBuiltins.cpp
index 94e249711..cc537687a 100644
--- a/src/js/out/WebCoreJSBuiltins.cpp
+++ b/src/js/out/WebCoreJSBuiltins.cpp
@@ -634,14 +634,6 @@ WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
#undef DEFINE_BUILTIN_GENERATOR
/* ProcessObjectInternals.ts */
-// binding
-const JSC::ConstructAbility s_processObjectInternalsBindingCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
-const JSC::ConstructorKind s_processObjectInternalsBindingCodeConstructorKind = JSC::ConstructorKind::None;
-const JSC::ImplementationVisibility s_processObjectInternalsBindingCodeImplementationVisibility = JSC::ImplementationVisibility::Public;
-const int s_processObjectInternalsBindingCodeLength = 569;
-static const JSC::Intrinsic s_processObjectInternalsBindingCodeIntrinsic = JSC::NoIntrinsic;
-const char* const s_processObjectInternalsBindingCode = "(function (bindingName) {\"use strict\";\n if (bindingName === \"constants\")\n return @processBindingConstants;\n const issue = {\n fs: 3546,\n buffer: 2020,\n natives: 2254,\n uv: 2891\n }[bindingName];\n if (issue)\n throw new Error(`process.binding(\"${bindingName}\") is not implemented in Bun. Track the status & thumbs up the issue: https://github.com/oven-sh/bun/issues/${issue}`);\n @throwTypeError(`process.binding(\"${bindingName}\") is not implemented in Bun. If that breaks something, please file an issue and include a reproducible code sample.`);\n})\n";
-
// getStdioWriteStream
const JSC::ConstructAbility s_processObjectInternalsGetStdioWriteStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_processObjectInternalsGetStdioWriteStreamCodeConstructorKind = JSC::ConstructorKind::None;
diff --git a/src/js/out/WebCoreJSBuiltins.h b/src/js/out/WebCoreJSBuiltins.h
index 4fc91dbd9..6e97db4d7 100644
--- a/src/js/out/WebCoreJSBuiltins.h
+++ b/src/js/out/WebCoreJSBuiltins.h
@@ -1155,14 +1155,6 @@ inline void TransformStreamInternalsBuiltinFunctions::visit(Visitor& visitor)
template void TransformStreamInternalsBuiltinFunctions::visit(JSC::AbstractSlotVisitor&);
template void TransformStreamInternalsBuiltinFunctions::visit(JSC::SlotVisitor&);
/* ProcessObjectInternals.ts */
-// binding
-#define WEBCORE_BUILTIN_PROCESSOBJECTINTERNALS_BINDING 1
-extern const char* const s_processObjectInternalsBindingCode;
-extern const int s_processObjectInternalsBindingCodeLength;
-extern const JSC::ConstructAbility s_processObjectInternalsBindingCodeConstructAbility;
-extern const JSC::ConstructorKind s_processObjectInternalsBindingCodeConstructorKind;
-extern const JSC::ImplementationVisibility s_processObjectInternalsBindingCodeImplementationVisibility;
-
// getStdioWriteStream
#define WEBCORE_BUILTIN_PROCESSOBJECTINTERNALS_GETSTDIOWRITESTREAM 1
extern const char* const s_processObjectInternalsGetStdioWriteStreamCode;
@@ -1188,19 +1180,16 @@ extern const JSC::ConstructorKind s_processObjectInternalsInitializeNextTickQueu
extern const JSC::ImplementationVisibility s_processObjectInternalsInitializeNextTickQueueCodeImplementationVisibility;
#define WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_DATA(macro) \
- macro(binding, processObjectInternalsBinding, 1) \
macro(getStdioWriteStream, processObjectInternalsGetStdioWriteStream, 1) \
macro(getStdinStream, processObjectInternalsGetStdinStream, 1) \
macro(initializeNextTickQueue, processObjectInternalsInitializeNextTickQueue, 4) \
#define WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_CODE(macro) \
- macro(processObjectInternalsBindingCode, binding, ASCIILiteral(), s_processObjectInternalsBindingCodeLength) \
macro(processObjectInternalsGetStdioWriteStreamCode, getStdioWriteStream, ASCIILiteral(), s_processObjectInternalsGetStdioWriteStreamCodeLength) \
macro(processObjectInternalsGetStdinStreamCode, getStdinStream, ASCIILiteral(), s_processObjectInternalsGetStdinStreamCodeLength) \
macro(processObjectInternalsInitializeNextTickQueueCode, initializeNextTickQueue, ASCIILiteral(), s_processObjectInternalsInitializeNextTickQueueCodeLength) \
#define WEBCORE_FOREACH_PROCESSOBJECTINTERNALS_BUILTIN_FUNCTION_NAME(macro) \
- macro(binding) \
macro(getStdioWriteStream) \
macro(getStdinStream) \
macro(initializeNextTickQueue) \