mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
bun run clang-format (#14148)
Co-authored-by: Electroid <Electroid@users.noreply.github.com>
This commit is contained in:
55
.github/workflows/clang-format.yml
vendored
Normal file
55
.github/workflows/clang-format.yml
vendored
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
name: clang-format
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
workflow_dispatch:
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- ".github/workflows/clang-format.yml"
|
||||||
|
- ".clang-format"
|
||||||
|
- "package.json"
|
||||||
|
- "scripts/**"
|
||||||
|
- "cmake/**"
|
||||||
|
- "src/**/*.{c,cpp,h,hpp}"
|
||||||
|
- "packages/**/*.{c,cpp,h,hpp}"
|
||||||
|
|
||||||
|
env:
|
||||||
|
BUN_VERSION: "1.1.27"
|
||||||
|
LLVM_VERSION: "18.1.8"
|
||||||
|
LLVM_VERSION_MAJOR: "18"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
clang-format:
|
||||||
|
name: clang-format
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
sparse-checkout: |
|
||||||
|
.github
|
||||||
|
.clang-format
|
||||||
|
package.json
|
||||||
|
scripts
|
||||||
|
cmake
|
||||||
|
src
|
||||||
|
packages
|
||||||
|
- name: Setup Bun
|
||||||
|
uses: ./.github/actions/setup-bun
|
||||||
|
with:
|
||||||
|
bun-version: ${{ env.BUN_VERSION }}
|
||||||
|
- name: Install LLVM
|
||||||
|
run: |
|
||||||
|
curl -fsSL https://apt.llvm.org/llvm.sh | sudo bash -s -- ${{ env.LLVM_VERSION_MAJOR }} all
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y ninja-build ccache
|
||||||
|
- name: Format
|
||||||
|
run: |
|
||||||
|
bun run clang-format -DLLVM_VERSION=${{ env.LLVM_VERSION }}
|
||||||
|
- name: Commit
|
||||||
|
uses: stefanzweifel/git-auto-commit-action@v5
|
||||||
|
with:
|
||||||
|
commit_message: "`bun run clang-format`"
|
||||||
3
.github/workflows/run-format.yml
vendored
3
.github/workflows/run-format.yml
vendored
@@ -47,9 +47,6 @@ jobs:
|
|||||||
- name: Format Zig
|
- name: Format Zig
|
||||||
run: |
|
run: |
|
||||||
bun fmt:zig
|
bun fmt:zig
|
||||||
- name: Format Cpp
|
|
||||||
run: |
|
|
||||||
bun fmt:cpp
|
|
||||||
- name: Commit
|
- name: Commit
|
||||||
uses: stefanzweifel/git-auto-commit-action@v5
|
uses: stefanzweifel/git-auto-commit-action@v5
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -39,3 +39,7 @@ include(SetupRust)
|
|||||||
# --- Targets ---
|
# --- Targets ---
|
||||||
|
|
||||||
include(BuildBun)
|
include(BuildBun)
|
||||||
|
|
||||||
|
# --- Analysis ---
|
||||||
|
|
||||||
|
include(RunClangFormat)
|
||||||
|
|||||||
@@ -377,12 +377,12 @@ function(register_command)
|
|||||||
get_source_file_property(generated ${output} GENERATED)
|
get_source_file_property(generated ${output} GENERATED)
|
||||||
if(generated)
|
if(generated)
|
||||||
list(REMOVE_ITEM CMD_EFFECTIVE_OUTPUTS ${output})
|
list(REMOVE_ITEM CMD_EFFECTIVE_OUTPUTS ${output})
|
||||||
list(APPEND CMD_EFFECTIVE_OUTPUTS ${output}.always_run)
|
list(APPEND CMD_EFFECTIVE_OUTPUTS ${output}.always_run_${CMD_TARGET})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
if(CMD_ALWAYS_RUN)
|
if(CMD_ALWAYS_RUN)
|
||||||
list(APPEND CMD_EFFECTIVE_OUTPUTS ${CMD_CWD}/.always_run)
|
list(APPEND CMD_EFFECTIVE_OUTPUTS ${CMD_CWD}/.always_run_${CMD_TARGET})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMD_TARGET_PHASE)
|
if(CMD_TARGET_PHASE)
|
||||||
|
|||||||
37
cmake/analysis/RunClangFormat.cmake
Normal file
37
cmake/analysis/RunClangFormat.cmake
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
find_command(
|
||||||
|
VARIABLE
|
||||||
|
CLANG_FORMAT_PROGRAM
|
||||||
|
COMMAND
|
||||||
|
clang-format
|
||||||
|
REQUIRED
|
||||||
|
OFF
|
||||||
|
)
|
||||||
|
|
||||||
|
set(CLANG_FORMAT_SOURCES ${BUN_C_SOURCES} ${BUN_CXX_SOURCES})
|
||||||
|
|
||||||
|
register_command(
|
||||||
|
TARGET
|
||||||
|
clang-format-check
|
||||||
|
COMMENT
|
||||||
|
"Running clang-format"
|
||||||
|
COMMAND
|
||||||
|
${CLANG_FORMAT_PROGRAM}
|
||||||
|
-Werror
|
||||||
|
--dry-run
|
||||||
|
--verbose
|
||||||
|
${CLANG_FORMAT_SOURCES}
|
||||||
|
ALWAYS_RUN
|
||||||
|
)
|
||||||
|
|
||||||
|
register_command(
|
||||||
|
TARGET
|
||||||
|
clang-format
|
||||||
|
COMMENT
|
||||||
|
"Fixing clang-format"
|
||||||
|
COMMAND
|
||||||
|
${CLANG_FORMAT_PROGRAM}
|
||||||
|
-i # edits files in-place
|
||||||
|
--verbose
|
||||||
|
${CLANG_FORMAT_SOURCES}
|
||||||
|
ALWAYS_RUN
|
||||||
|
)
|
||||||
@@ -577,6 +577,10 @@ file(GLOB BUN_C_SOURCES ${CONFIGURE_DEPENDS}
|
|||||||
${BUN_USOCKETS_SOURCE}/src/crypto/*.c
|
${BUN_USOCKETS_SOURCE}/src/crypto/*.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
list(APPEND BUN_C_SOURCES ${CWD}/src/bun.js/bindings/windows/musl-memmem.c)
|
||||||
|
endif()
|
||||||
|
|
||||||
register_repository(
|
register_repository(
|
||||||
NAME
|
NAME
|
||||||
picohttpparser
|
picohttpparser
|
||||||
@@ -588,15 +592,10 @@ register_repository(
|
|||||||
picohttpparser.c
|
picohttpparser.c
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND BUN_C_SOURCES ${VENDOR_PATH}/picohttpparser/picohttpparser.c)
|
|
||||||
|
|
||||||
if(WIN32)
|
|
||||||
list(APPEND BUN_C_SOURCES ${CWD}/src/bun.js/bindings/windows/musl-memmem.c)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
list(APPEND BUN_CPP_SOURCES
|
list(APPEND BUN_CPP_SOURCES
|
||||||
${BUN_C_SOURCES}
|
${BUN_C_SOURCES}
|
||||||
${BUN_CXX_SOURCES}
|
${BUN_CXX_SOURCES}
|
||||||
|
${VENDOR_PATH}/picohttpparser/picohttpparser.c
|
||||||
${BUN_ZIG_GENERATED_CLASSES_OUTPUTS}
|
${BUN_ZIG_GENERATED_CLASSES_OUTPUTS}
|
||||||
${BUN_JS_SINK_OUTPUTS}
|
${BUN_JS_SINK_OUTPUTS}
|
||||||
${BUN_JAVASCRIPT_OUTPUTS}
|
${BUN_JAVASCRIPT_OUTPUTS}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
"bump": "bun ./scripts/bump.ts",
|
"bump": "bun ./scripts/bump.ts",
|
||||||
"typecheck": "tsc --noEmit && cd test && bun run typecheck",
|
"typecheck": "tsc --noEmit && cd test && bun run typecheck",
|
||||||
"fmt": "prettier --config=.prettierrc-ci --write --cache './{.vscode,src,test,bench,packages/{bun-types,bun-inspector-*,bun-vscode,bun-debug-adapter-protocol}}/**/*.{mjs,ts,tsx,js,jsx}'",
|
"fmt": "prettier --config=.prettierrc-ci --write --cache './{.vscode,src,test,bench,packages/{bun-types,bun-inspector-*,bun-vscode,bun-debug-adapter-protocol}}/**/*.{mjs,ts,tsx,js,jsx}'",
|
||||||
"fmt:cpp": "clang-format -i src/bun.js/bindings/**/*.{cpp,h} --verbose",
|
"fmt:cpp": "bun run clang-format",
|
||||||
"fmt:zig": "bun run zig:fmt",
|
"fmt:zig": "bun run zig:fmt",
|
||||||
"lint": "eslint './**/*.d.ts' --cache",
|
"lint": "eslint './**/*.d.ts' --cache",
|
||||||
"lint:fix": "eslint './**/*.d.ts' --cache --fix",
|
"lint:fix": "eslint './**/*.d.ts' --cache --fix",
|
||||||
@@ -54,6 +54,8 @@
|
|||||||
"zig:fmt": "bun run zig fmt src/*.zig src/*/*.zig src/*/*/*.zig src/*/*/*/*.zig",
|
"zig:fmt": "bun run zig fmt src/*.zig src/*/*.zig src/*/*/*.zig src/*/*/*/*.zig",
|
||||||
"zig:check": "bun run zig build check --summary new",
|
"zig:check": "bun run zig build check --summary new",
|
||||||
"zig:check-all": "bun run zig build check-all --summary new",
|
"zig:check-all": "bun run zig build check-all --summary new",
|
||||||
"zig:check-windows": "bun run zig build check-windows --summary new"
|
"zig:check-windows": "bun run zig build check-windows --summary new",
|
||||||
|
"clang-format": "bun run build --target clang-format",
|
||||||
|
"clang-format:check": "bun run build --target clang-format-check"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/bun-usockets/.clang-format
Normal file
1
packages/bun-usockets/.clang-format
Normal file
@@ -0,0 +1 @@
|
|||||||
|
DisableFormat: true
|
||||||
1
packages/bun-uws/.clang-format
Normal file
1
packages/bun-uws/.clang-format
Normal file
@@ -0,0 +1 @@
|
|||||||
|
DisableFormat: true
|
||||||
@@ -120,19 +120,13 @@ static void addInspector(void* app, JSC::JSGlobalObject* globalObject)
|
|||||||
globalObject->setInspectable(true);
|
globalObject->setInspectable(true);
|
||||||
*ws->getUserData() = new SSLBunInspectorConnection(ws, globalObject);
|
*ws->getUserData() = new SSLBunInspectorConnection(ws, globalObject);
|
||||||
SSLBunInspectorConnection* inspector = *ws->getUserData();
|
SSLBunInspectorConnection* inspector = *ws->getUserData();
|
||||||
inspector->onOpen(globalObject);
|
inspector->onOpen(globalObject); },
|
||||||
//
|
|
||||||
},
|
|
||||||
.message = [](auto* ws, std::string_view message, uWS::OpCode opCode) {
|
.message = [](auto* ws, std::string_view message, uWS::OpCode opCode) {
|
||||||
SSLBunInspectorConnection* inspector = *(SSLBunInspectorConnection**)ws->getUserData();
|
SSLBunInspectorConnection* inspector = *(SSLBunInspectorConnection**)ws->getUserData();
|
||||||
inspector->onMessage(message);
|
inspector->onMessage(message); },
|
||||||
//
|
|
||||||
},
|
|
||||||
.drain = [](auto* ws) {
|
.drain = [](auto* ws) {
|
||||||
SSLBunInspectorConnection* inspector = *(SSLBunInspectorConnection**)ws->getUserData();
|
SSLBunInspectorConnection* inspector = *(SSLBunInspectorConnection**)ws->getUserData();
|
||||||
inspector->drain();
|
inspector->drain(); },
|
||||||
//
|
|
||||||
},
|
|
||||||
.ping = [](auto* /*ws*/, std::string_view) {
|
.ping = [](auto* /*ws*/, std::string_view) {
|
||||||
/* Not implemented yet */ },
|
/* Not implemented yet */ },
|
||||||
.pong = [](auto* /*ws*/, std::string_view) {
|
.pong = [](auto* /*ws*/, std::string_view) {
|
||||||
@@ -162,19 +156,13 @@ static void addInspector(void* app, JSC::JSGlobalObject* globalObject)
|
|||||||
globalObject->setInspectable(true);
|
globalObject->setInspectable(true);
|
||||||
*ws->getUserData() = new BunInspectorConnectionNoSSL(ws, globalObject);
|
*ws->getUserData() = new BunInspectorConnectionNoSSL(ws, globalObject);
|
||||||
BunInspectorConnectionNoSSL* inspector = *ws->getUserData();
|
BunInspectorConnectionNoSSL* inspector = *ws->getUserData();
|
||||||
inspector->onOpen(globalObject);
|
inspector->onOpen(globalObject); },
|
||||||
//
|
|
||||||
},
|
|
||||||
.message = [](auto* ws, std::string_view message, uWS::OpCode opCode) {
|
.message = [](auto* ws, std::string_view message, uWS::OpCode opCode) {
|
||||||
BunInspectorConnectionNoSSL* inspector = *(BunInspectorConnectionNoSSL**)ws->getUserData();
|
BunInspectorConnectionNoSSL* inspector = *(BunInspectorConnectionNoSSL**)ws->getUserData();
|
||||||
inspector->onMessage(message);
|
inspector->onMessage(message); },
|
||||||
//
|
|
||||||
},
|
|
||||||
.drain = [](auto* ws) {
|
.drain = [](auto* ws) {
|
||||||
BunInspectorConnectionNoSSL* inspector = *(BunInspectorConnectionNoSSL**)ws->getUserData();
|
BunInspectorConnectionNoSSL* inspector = *(BunInspectorConnectionNoSSL**)ws->getUserData();
|
||||||
inspector->drain();
|
inspector->drain(); },
|
||||||
//
|
|
||||||
},
|
|
||||||
.ping = [](auto* /*ws*/, std::string_view) {
|
.ping = [](auto* /*ws*/, std::string_view) {
|
||||||
/* Not implemented yet */ },
|
/* Not implemented yet */ },
|
||||||
.pong = [](auto* /*ws*/, std::string_view) {
|
.pong = [](auto* /*ws*/, std::string_view) {
|
||||||
@@ -190,7 +178,8 @@ static void addInspector(void* app, JSC::JSGlobalObject* globalObject)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void Bun__addInspector(bool isSSL, void* app, JSC::JSGlobalObject* globalObject)
|
extern "C" void
|
||||||
|
Bun__addInspector(bool isSSL, void* app, JSC::JSGlobalObject* globalObject)
|
||||||
{
|
{
|
||||||
if (isSSL) {
|
if (isSSL) {
|
||||||
addInspector<true>((uWS::TemplatedApp<true>*)app, globalObject);
|
addInspector<true>((uWS::TemplatedApp<true>*)app, globalObject);
|
||||||
|
|||||||
@@ -320,7 +320,8 @@ static JSValue constructBunShell(VM& vm, JSObject* bunObject)
|
|||||||
|
|
||||||
// This value currently depends on a zig feature flag
|
// This value currently depends on a zig feature flag
|
||||||
extern "C" JSC::EncodedJSValue Bun__getTemporaryDevServer(JSC::JSGlobalObject* bunObject);
|
extern "C" JSC::EncodedJSValue Bun__getTemporaryDevServer(JSC::JSGlobalObject* bunObject);
|
||||||
static JSValue constructBunKit(VM& vm, JSObject* bunObject) {
|
static JSValue constructBunKit(VM& vm, JSObject* bunObject)
|
||||||
|
{
|
||||||
return JSC::JSValue::decode(Bun__getTemporaryDevServer(bunObject->globalObject()));
|
return JSC::JSValue::decode(Bun__getTemporaryDevServer(bunObject->globalObject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -382,7 +382,7 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen,
|
|||||||
return JSValue::encode(jsUndefined());
|
return JSValue::encode(jsUndefined());
|
||||||
}
|
}
|
||||||
|
|
||||||
JSC::EncodedJSValue (*napi_register_module_v1)(JSC::JSGlobalObject* globalObject,
|
JSC::EncodedJSValue (*napi_register_module_v1)(JSC::JSGlobalObject * globalObject,
|
||||||
JSC::EncodedJSValue exports);
|
JSC::EncodedJSValue exports);
|
||||||
#if OS(WINDOWS)
|
#if OS(WINDOWS)
|
||||||
#define dlsym GetProcAddress
|
#define dlsym GetProcAddress
|
||||||
@@ -702,82 +702,82 @@ static void loadSignalNumberMap()
|
|||||||
signalNameToNumberMap->add(signalNames[9], SIGKILL);
|
signalNameToNumberMap->add(signalNames[9], SIGKILL);
|
||||||
signalNameToNumberMap->add(signalNames[15], SIGTERM);
|
signalNameToNumberMap->add(signalNames[15], SIGTERM);
|
||||||
#else
|
#else
|
||||||
signalNameToNumberMap->add(signalNames[0], SIGHUP);
|
signalNameToNumberMap->add(signalNames[0], SIGHUP);
|
||||||
signalNameToNumberMap->add(signalNames[1], SIGINT);
|
signalNameToNumberMap->add(signalNames[1], SIGINT);
|
||||||
signalNameToNumberMap->add(signalNames[2], SIGQUIT);
|
signalNameToNumberMap->add(signalNames[2], SIGQUIT);
|
||||||
signalNameToNumberMap->add(signalNames[3], SIGILL);
|
signalNameToNumberMap->add(signalNames[3], SIGILL);
|
||||||
#ifdef SIGTRAP
|
#ifdef SIGTRAP
|
||||||
signalNameToNumberMap->add(signalNames[4], SIGTRAP);
|
signalNameToNumberMap->add(signalNames[4], SIGTRAP);
|
||||||
#endif
|
#endif
|
||||||
signalNameToNumberMap->add(signalNames[5], SIGABRT);
|
signalNameToNumberMap->add(signalNames[5], SIGABRT);
|
||||||
#ifdef SIGIOT
|
#ifdef SIGIOT
|
||||||
signalNameToNumberMap->add(signalNames[6], SIGIOT);
|
signalNameToNumberMap->add(signalNames[6], SIGIOT);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGBUS
|
#ifdef SIGBUS
|
||||||
signalNameToNumberMap->add(signalNames[7], SIGBUS);
|
signalNameToNumberMap->add(signalNames[7], SIGBUS);
|
||||||
#endif
|
#endif
|
||||||
signalNameToNumberMap->add(signalNames[8], SIGFPE);
|
signalNameToNumberMap->add(signalNames[8], SIGFPE);
|
||||||
signalNameToNumberMap->add(signalNames[9], SIGKILL);
|
signalNameToNumberMap->add(signalNames[9], SIGKILL);
|
||||||
#ifdef SIGUSR1
|
#ifdef SIGUSR1
|
||||||
signalNameToNumberMap->add(signalNames[10], SIGUSR1);
|
signalNameToNumberMap->add(signalNames[10], SIGUSR1);
|
||||||
#endif
|
#endif
|
||||||
signalNameToNumberMap->add(signalNames[11], SIGSEGV);
|
signalNameToNumberMap->add(signalNames[11], SIGSEGV);
|
||||||
#ifdef SIGUSR2
|
#ifdef SIGUSR2
|
||||||
signalNameToNumberMap->add(signalNames[12], SIGUSR2);
|
signalNameToNumberMap->add(signalNames[12], SIGUSR2);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGPIPE
|
#ifdef SIGPIPE
|
||||||
signalNameToNumberMap->add(signalNames[13], SIGPIPE);
|
signalNameToNumberMap->add(signalNames[13], SIGPIPE);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGALRM
|
#ifdef SIGALRM
|
||||||
signalNameToNumberMap->add(signalNames[14], SIGALRM);
|
signalNameToNumberMap->add(signalNames[14], SIGALRM);
|
||||||
#endif
|
#endif
|
||||||
signalNameToNumberMap->add(signalNames[15], SIGTERM);
|
signalNameToNumberMap->add(signalNames[15], SIGTERM);
|
||||||
#ifdef SIGCHLD
|
#ifdef SIGCHLD
|
||||||
signalNameToNumberMap->add(signalNames[16], SIGCHLD);
|
signalNameToNumberMap->add(signalNames[16], SIGCHLD);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGCONT
|
#ifdef SIGCONT
|
||||||
signalNameToNumberMap->add(signalNames[17], SIGCONT);
|
signalNameToNumberMap->add(signalNames[17], SIGCONT);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGSTOP
|
#ifdef SIGSTOP
|
||||||
signalNameToNumberMap->add(signalNames[18], SIGSTOP);
|
signalNameToNumberMap->add(signalNames[18], SIGSTOP);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGTSTP
|
#ifdef SIGTSTP
|
||||||
signalNameToNumberMap->add(signalNames[19], SIGTSTP);
|
signalNameToNumberMap->add(signalNames[19], SIGTSTP);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGTTIN
|
#ifdef SIGTTIN
|
||||||
signalNameToNumberMap->add(signalNames[20], SIGTTIN);
|
signalNameToNumberMap->add(signalNames[20], SIGTTIN);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGTTOU
|
#ifdef SIGTTOU
|
||||||
signalNameToNumberMap->add(signalNames[21], SIGTTOU);
|
signalNameToNumberMap->add(signalNames[21], SIGTTOU);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGURG
|
#ifdef SIGURG
|
||||||
signalNameToNumberMap->add(signalNames[22], SIGURG);
|
signalNameToNumberMap->add(signalNames[22], SIGURG);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGXCPU
|
#ifdef SIGXCPU
|
||||||
signalNameToNumberMap->add(signalNames[23], SIGXCPU);
|
signalNameToNumberMap->add(signalNames[23], SIGXCPU);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGXFSZ
|
#ifdef SIGXFSZ
|
||||||
signalNameToNumberMap->add(signalNames[24], SIGXFSZ);
|
signalNameToNumberMap->add(signalNames[24], SIGXFSZ);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGVTALRM
|
#ifdef SIGVTALRM
|
||||||
signalNameToNumberMap->add(signalNames[25], SIGVTALRM);
|
signalNameToNumberMap->add(signalNames[25], SIGVTALRM);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGPROF
|
#ifdef SIGPROF
|
||||||
signalNameToNumberMap->add(signalNames[26], SIGPROF);
|
signalNameToNumberMap->add(signalNames[26], SIGPROF);
|
||||||
#endif
|
#endif
|
||||||
signalNameToNumberMap->add(signalNames[27], SIGWINCH);
|
signalNameToNumberMap->add(signalNames[27], SIGWINCH);
|
||||||
#ifdef SIGIO
|
#ifdef SIGIO
|
||||||
signalNameToNumberMap->add(signalNames[28], SIGIO);
|
signalNameToNumberMap->add(signalNames[28], SIGIO);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGINFO
|
#ifdef SIGINFO
|
||||||
signalNameToNumberMap->add(signalNames[29], SIGINFO);
|
signalNameToNumberMap->add(signalNames[29], SIGINFO);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SIGINFO
|
#ifndef SIGINFO
|
||||||
signalNameToNumberMap->add(signalNames[29], 255);
|
signalNameToNumberMap->add(signalNames[29], 255);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGSYS
|
#ifdef SIGSYS
|
||||||
signalNameToNumberMap->add(signalNames[30], SIGSYS);
|
signalNameToNumberMap->add(signalNames[30], SIGSYS);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4883,7 +4883,7 @@ extern "C" void JSC__VM__getAPILock(JSC::VM* vm)
|
|||||||
vm->apiLock().lock();
|
vm->apiLock().lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void JSC__VM__releaseAPILock(JSC::VM* vm)
|
extern "C" void JSC__VM__releaseAPILock(JSC::VM* vm)
|
||||||
{
|
{
|
||||||
// https://github.com/WebKit/WebKit/blob/6cb5017d237ef7cb898582a22f05acca22322845/Source/JavaScriptCore/runtime/JSLock.cpp#L72
|
// https://github.com/WebKit/WebKit/blob/6cb5017d237ef7cb898582a22f05acca22322845/Source/JavaScriptCore/runtime/JSLock.cpp#L72
|
||||||
RefPtr<JSLock> apiLock(&vm->apiLock());
|
RefPtr<JSLock> apiLock(&vm->apiLock());
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ void generateNativeModule_BunObject(JSC::JSGlobalObject *lexicalGlobalObject,
|
|||||||
JSC::MarkedArgumentBuffer &exportValues) {
|
JSC::MarkedArgumentBuffer &exportValues) {
|
||||||
// FIXME: this does not add each property as a top level export
|
// FIXME: this does not add each property as a top level export
|
||||||
JSC::VM &vm = lexicalGlobalObject->vm();
|
JSC::VM &vm = lexicalGlobalObject->vm();
|
||||||
Zig::GlobalObject *globalObject = jsCast<Zig::GlobalObject *>(lexicalGlobalObject);
|
Zig::GlobalObject *globalObject =
|
||||||
|
jsCast<Zig::GlobalObject *>(lexicalGlobalObject);
|
||||||
|
|
||||||
JSObject *object = globalObject->bunObject();
|
JSObject *object = globalObject->bunObject();
|
||||||
|
|
||||||
|
|||||||
@@ -18,24 +18,25 @@ extern "C" mach_port_t io_darwin_create_machport(uint64_t wakeup, int32_t fd,
|
|||||||
kern_return_t kr = mach_port_allocate(self, MACH_PORT_RIGHT_RECEIVE, &port);
|
kern_return_t kr = mach_port_allocate(self, MACH_PORT_RIGHT_RECEIVE, &port);
|
||||||
|
|
||||||
if (UNLIKELY(kr != KERN_SUCCESS)) {
|
if (UNLIKELY(kr != KERN_SUCCESS)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert a send right into the port since we also use this to send
|
// Insert a send right into the port since we also use this to send
|
||||||
kr = mach_port_insert_right(self, port, port, MACH_MSG_TYPE_MAKE_SEND);
|
kr = mach_port_insert_right(self, port, port, MACH_MSG_TYPE_MAKE_SEND);
|
||||||
if (UNLIKELY(kr != KERN_SUCCESS)) {
|
if (UNLIKELY(kr != KERN_SUCCESS)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify the port queue size to be 1 because we are only
|
// Modify the port queue size to be 1 because we are only
|
||||||
// using it for notifications and not for any other purpose.
|
// using it for notifications and not for any other purpose.
|
||||||
mach_port_limits_t limits = { .mpl_qlimit = 1 };
|
mach_port_limits_t limits = {.mpl_qlimit = 1};
|
||||||
kr = mach_port_set_attributes(self, port, MACH_PORT_LIMITS_INFO, (mach_port_info_t)&limits, MACH_PORT_LIMITS_INFO_COUNT);
|
kr = mach_port_set_attributes(self, port, MACH_PORT_LIMITS_INFO,
|
||||||
|
(mach_port_info_t)&limits,
|
||||||
if (UNLIKELY(kr != KERN_SUCCESS)) {
|
MACH_PORT_LIMITS_INFO_COUNT);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (UNLIKELY(kr != KERN_SUCCESS)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Configure the event to directly receive the Mach message as part of the
|
// Configure the event to directly receive the Mach message as part of the
|
||||||
// kevent64() call.
|
// kevent64() call.
|
||||||
@@ -85,37 +86,32 @@ extern "C" bool io_darwin_schedule_wakeup(mach_port_t waker) {
|
|||||||
.msgh_id = 0,
|
.msgh_id = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
mach_msg_return_t kr = mach_msg(
|
mach_msg_return_t kr = mach_msg(&msg, MACH_SEND_MSG | MACH_SEND_TIMEOUT,
|
||||||
&msg,
|
msg.msgh_size, 0, MACH_PORT_NULL,
|
||||||
MACH_SEND_MSG | MACH_SEND_TIMEOUT,
|
0, // Fail instantly if the port is full
|
||||||
msg.msgh_size,
|
MACH_PORT_NULL);
|
||||||
0,
|
|
||||||
MACH_PORT_NULL,
|
|
||||||
0, // Fail instantly if the port is full
|
|
||||||
MACH_PORT_NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
switch (kr) {
|
|
||||||
case MACH_MSG_SUCCESS: {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This means that the send would've blocked because the
|
|
||||||
// queue is full. We assume success because the port is full.
|
|
||||||
case MACH_SEND_TIMED_OUT: {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// No space means it will wake up.
|
switch (kr) {
|
||||||
case MACH_SEND_NO_BUFFER: {
|
case MACH_MSG_SUCCESS: {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
// This means that the send would've blocked because the
|
||||||
ASSERT_NOT_REACHED_WITH_MESSAGE("mach_msg failed with %x", kr);
|
// queue is full. We assume success because the port is full.
|
||||||
return false;
|
case MACH_SEND_TIMED_OUT: {
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No space means it will wake up.
|
||||||
|
case MACH_SEND_NO_BUFFER: {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
ASSERT_NOT_REACHED_WITH_MESSAGE("mach_msg failed with %x", kr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -1,82 +1,89 @@
|
|||||||
#include "KitDevGlobalObject.h"
|
#include "KitDevGlobalObject.h"
|
||||||
#include "JavaScriptCore/GlobalObjectMethodTable.h"
|
|
||||||
#include "JSNextTickQueue.h"
|
#include "JSNextTickQueue.h"
|
||||||
|
#include "JavaScriptCore/GlobalObjectMethodTable.h"
|
||||||
#include "headers-handwritten.h"
|
#include "headers-handwritten.h"
|
||||||
|
|
||||||
namespace Kit {
|
namespace Kit {
|
||||||
|
|
||||||
#define INHERIT_HOOK_METHOD(name) Zig::GlobalObject::s_globalObjectMethodTable. name
|
#define INHERIT_HOOK_METHOD(name) \
|
||||||
|
Zig::GlobalObject::s_globalObjectMethodTable.name
|
||||||
|
|
||||||
const JSC::GlobalObjectMethodTable DevGlobalObject::s_globalObjectMethodTable = {
|
const JSC::GlobalObjectMethodTable DevGlobalObject::s_globalObjectMethodTable =
|
||||||
INHERIT_HOOK_METHOD(supportsRichSourceInfo),
|
{
|
||||||
INHERIT_HOOK_METHOD(shouldInterruptScript),
|
INHERIT_HOOK_METHOD(supportsRichSourceInfo),
|
||||||
INHERIT_HOOK_METHOD(javaScriptRuntimeFlags),
|
INHERIT_HOOK_METHOD(shouldInterruptScript),
|
||||||
INHERIT_HOOK_METHOD(queueMicrotaskToEventLoop),
|
INHERIT_HOOK_METHOD(javaScriptRuntimeFlags),
|
||||||
INHERIT_HOOK_METHOD(shouldInterruptScriptBeforeTimeout),
|
INHERIT_HOOK_METHOD(queueMicrotaskToEventLoop),
|
||||||
INHERIT_HOOK_METHOD(moduleLoaderImportModule),
|
INHERIT_HOOK_METHOD(shouldInterruptScriptBeforeTimeout),
|
||||||
INHERIT_HOOK_METHOD(moduleLoaderResolve),
|
INHERIT_HOOK_METHOD(moduleLoaderImportModule),
|
||||||
INHERIT_HOOK_METHOD(moduleLoaderFetch),
|
INHERIT_HOOK_METHOD(moduleLoaderResolve),
|
||||||
INHERIT_HOOK_METHOD(moduleLoaderCreateImportMetaProperties),
|
INHERIT_HOOK_METHOD(moduleLoaderFetch),
|
||||||
INHERIT_HOOK_METHOD(moduleLoaderEvaluate),
|
INHERIT_HOOK_METHOD(moduleLoaderCreateImportMetaProperties),
|
||||||
INHERIT_HOOK_METHOD(promiseRejectionTracker),
|
INHERIT_HOOK_METHOD(moduleLoaderEvaluate),
|
||||||
INHERIT_HOOK_METHOD(reportUncaughtExceptionAtEventLoop),
|
INHERIT_HOOK_METHOD(promiseRejectionTracker),
|
||||||
INHERIT_HOOK_METHOD(currentScriptExecutionOwner),
|
INHERIT_HOOK_METHOD(reportUncaughtExceptionAtEventLoop),
|
||||||
INHERIT_HOOK_METHOD(scriptExecutionStatus),
|
INHERIT_HOOK_METHOD(currentScriptExecutionOwner),
|
||||||
INHERIT_HOOK_METHOD(reportViolationForUnsafeEval),
|
INHERIT_HOOK_METHOD(scriptExecutionStatus),
|
||||||
INHERIT_HOOK_METHOD(defaultLanguage),
|
INHERIT_HOOK_METHOD(reportViolationForUnsafeEval),
|
||||||
INHERIT_HOOK_METHOD(compileStreaming),
|
INHERIT_HOOK_METHOD(defaultLanguage),
|
||||||
INHERIT_HOOK_METHOD(instantiateStreaming),
|
INHERIT_HOOK_METHOD(compileStreaming),
|
||||||
INHERIT_HOOK_METHOD(deriveShadowRealmGlobalObject),
|
INHERIT_HOOK_METHOD(instantiateStreaming),
|
||||||
INHERIT_HOOK_METHOD(codeForEval),
|
INHERIT_HOOK_METHOD(deriveShadowRealmGlobalObject),
|
||||||
INHERIT_HOOK_METHOD(canCompileStrings),
|
INHERIT_HOOK_METHOD(codeForEval),
|
||||||
|
INHERIT_HOOK_METHOD(canCompileStrings),
|
||||||
};
|
};
|
||||||
|
|
||||||
DevGlobalObject* DevGlobalObject::create(JSC::VM& vm, JSC::Structure* structure, const JSC::GlobalObjectMethodTable* methodTable)
|
DevGlobalObject *
|
||||||
{
|
DevGlobalObject::create(JSC::VM &vm, JSC::Structure *structure,
|
||||||
DevGlobalObject* ptr = new (NotNull, JSC::allocateCell<DevGlobalObject>(vm)) DevGlobalObject(vm, structure, methodTable);
|
const JSC::GlobalObjectMethodTable *methodTable) {
|
||||||
ptr->finishCreation(vm);
|
DevGlobalObject *ptr = new (NotNull, JSC::allocateCell<DevGlobalObject>(vm))
|
||||||
return ptr;
|
DevGlobalObject(vm, structure, methodTable);
|
||||||
|
ptr->finishCreation(vm);
|
||||||
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevGlobalObject::finishCreation(JSC::VM &vm) {
|
void DevGlobalObject::finishCreation(JSC::VM &vm) {
|
||||||
Base::finishCreation(vm);
|
Base::finishCreation(vm);
|
||||||
ASSERT(inherits(info()));
|
ASSERT(inherits(info()));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" BunVirtualMachine* Bun__getVM();
|
extern "C" BunVirtualMachine *Bun__getVM();
|
||||||
|
|
||||||
// A lot of this function is taken from 'Zig__GlobalObject__create'
|
// A lot of this function is taken from 'Zig__GlobalObject__create'
|
||||||
extern "C" DevGlobalObject* KitCreateDevGlobal(DevServer* owner, void* console) {
|
extern "C" DevGlobalObject *KitCreateDevGlobal(DevServer *owner,
|
||||||
JSC::VM& vm = JSC::VM::create(JSC::HeapType::Large).leakRef();
|
void *console) {
|
||||||
vm.heap.acquireAccess();
|
JSC::VM &vm = JSC::VM::create(JSC::HeapType::Large).leakRef();
|
||||||
JSC::JSLockHolder locker(vm);
|
vm.heap.acquireAccess();
|
||||||
BunVirtualMachine* bunVM = Bun__getVM();
|
JSC::JSLockHolder locker(vm);
|
||||||
WebCore::JSVMClientData::create(&vm, bunVM);
|
BunVirtualMachine *bunVM = Bun__getVM();
|
||||||
|
WebCore::JSVMClientData::create(&vm, bunVM);
|
||||||
|
|
||||||
JSC::Structure* structure = DevGlobalObject::createStructure(vm);
|
JSC::Structure *structure = DevGlobalObject::createStructure(vm);
|
||||||
DevGlobalObject* global = DevGlobalObject::create(vm, structure, &DevGlobalObject::s_globalObjectMethodTable);
|
DevGlobalObject *global = DevGlobalObject::create(
|
||||||
if (!global)
|
vm, structure, &DevGlobalObject::s_globalObjectMethodTable);
|
||||||
BUN_PANIC("Failed to create DevGlobalObject");
|
if (!global)
|
||||||
|
BUN_PANIC("Failed to create DevGlobalObject");
|
||||||
|
|
||||||
global->m_devServer = owner;
|
global->m_devServer = owner;
|
||||||
global->m_bunVM = bunVM;
|
global->m_bunVM = bunVM;
|
||||||
|
|
||||||
JSC::gcProtect(global);
|
JSC::gcProtect(global);
|
||||||
|
|
||||||
global->setConsole(console);
|
global->setConsole(console);
|
||||||
global->setStackTraceLimit(10); // Node.js defaults to 10
|
global->setStackTraceLimit(10); // Node.js defaults to 10
|
||||||
|
|
||||||
// vm.setOnComputeErrorInfo(computeErrorInfoWrapper);
|
// vm.setOnComputeErrorInfo(computeErrorInfoWrapper);
|
||||||
vm.setOnEachMicrotaskTick([global](JSC::VM& vm) -> void {
|
vm.setOnEachMicrotaskTick([global](JSC::VM &vm) -> void {
|
||||||
if (auto nextTickQueue = global->m_nextTickQueue.get()) {
|
if (auto nextTickQueue = global->m_nextTickQueue.get()) {
|
||||||
global->resetOnEachMicrotaskTick();
|
global->resetOnEachMicrotaskTick();
|
||||||
Bun::JSNextTickQueue* queue = jsCast<Bun::JSNextTickQueue*>(nextTickQueue);
|
Bun::JSNextTickQueue *queue =
|
||||||
queue->drain(vm, global);
|
jsCast<Bun::JSNextTickQueue *>(nextTickQueue);
|
||||||
return;
|
queue->drain(vm, global);
|
||||||
}
|
return;
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return global;
|
return global;
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // namespace Kit
|
}; // namespace Kit
|
||||||
|
|||||||
Reference in New Issue
Block a user