Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
2723041
Emit online event before Worker entrypoint runs
Apr 1, 2025
8f3786d
Accept callback in MessagePort.close
Apr 3, 2025
2b3ae71
Merge branch 'main' into ben/worker-threads-2
Apr 7, 2025
bc420e4
Pass test-worker-type-check.js
Apr 8, 2025
354f2cc
Use more appropriate #include for errors
Apr 8, 2025
638c4b4
Correct receiveMessageOnPort error message
Apr 8, 2025
9ba5b89
Add passing test
Apr 8, 2025
dd7e5d4
Use defaultGlobalObject
Apr 8, 2025
580ca99
Merge branch 'main' into ben/worker-threads-2
Apr 8, 2025
b74476c
Fire worker event on process
Apr 8, 2025
cf5ad47
Support worker environment data
Apr 9, 2025
513c326
Add test-worker-abort-on-uncaught-exception-terminate.js
Apr 9, 2025
38b20fb
Refine error message for duplicates in transferList
Apr 9, 2025
288dcd0
`bun run clang-format`
190n Apr 9, 2025
bd5f3aa
Do not unref worker on main thread when terminated
Apr 10, 2025
b7c7627
Terminate the VM in Worker.requestTerminate()
Apr 10, 2025
2d59005
Add missing files
Apr 10, 2025
8c6aa4e
Handle termination exception in next tick queue
Apr 10, 2025
2705a7b
Use exit code 1 if Worker entry point fails to load
Apr 10, 2025
e857f54
Allow termination exception while fetching builtin
Apr 10, 2025
7b40950
Clean up exception handling in BunProcess.cpp
Apr 11, 2025
604ae71
Add more exception checks to JSNextTickQueue
Apr 11, 2025
37fae6b
Merge branch 'main' into ben/worker-threads-2
Apr 11, 2025
ed5966c
Fix crash on workerData with no options
Apr 11, 2025
5d8217f
Fix null environment data
Apr 11, 2025
5aeb80d
Do not propagate termination exception to event loop
Apr 11, 2025
91a58f4
Un-todo "worker terminating forcefully properly interrupts" and fix e…
Apr 11, 2025
097d298
Resolve Worker entrypoint on worker thread instead of main
Apr 11, 2025
741c8d9
new tests
Apr 11, 2025
518345b
Delete TODO
Apr 11, 2025
a9e6207
Rename Worker.requestTerminate -> notifyNeedTermination to align with…
Apr 12, 2025
67b8cb2
Fix not firing messages sent before Worker started
Apr 12, 2025
e3d5602
Fix expectations in worker_threads test to align with Node
Apr 12, 2025
9284503
Add comment
Apr 12, 2025
ecc3622
Use code 0 for workers terminated before they start running
Apr 12, 2025
1a9412c
Use right exit code for workers terminated at different times
Apr 14, 2025
9b68b63
Update test for behavior changes
Apr 14, 2025
e934134
Do not terminate worker in isMainThread test
Apr 14, 2025
8e411f2
WIP StatWatcher fixes
Apr 15, 2025
577f0c2
Fix overriding process.exit code
Apr 15, 2025
0abd2ef
Revert "Accept callback in MessagePort.close"
Apr 15, 2025
3451e49
Remove failing test
Apr 15, 2025
10dba91
Use threadId -1 for exited Workers
Apr 15, 2025
01ecf80
Fix test-worker-http2-generic-streams-terminate.js
Apr 15, 2025
924b87d
Merge branch 'main' into ben/worker-threads-2
Apr 16, 2025
f54bfd7
Do not call UDP socket error handler on termination exception
Apr 16, 2025
5f4b7e0
Add exception checks in evaluateCommonJSModuleOnce
Apr 16, 2025
4874af1
cleanup
Apr 16, 2025
5abdc42
Merge branch 'main' into ben/worker-threads-2
Apr 18, 2025
3437062
Do not call uv_library_shutdown
Apr 18, 2025
26c9443
Add exception checks to createNodeURLBinding
Apr 18, 2025
2d51c9e
Run skipped test
Apr 18, 2025
7d20028
Add some exception checks
Apr 18, 2025
3d25e86
Add exception checks
Apr 21, 2025
fcb73cf
Merge branch 'main' into ben/worker-threads-2
Apr 21, 2025
981820f
Forbid termination exception in test-timeout-behavior
Apr 21, 2025
8c43780
Do not expose termination exception when test times out
Apr 21, 2025
84dd637
empty commit to see if zig fmt action is fixed
Apr 21, 2025
bd686ad
Merge branch 'main' into ben/worker-threads-2
Apr 23, 2025
8e54de3
clean up worker_thread_check.ts
Apr 30, 2025
1c98754
Merge branch 'main' into ben/worker-threads-2
Apr 30, 2025
16e9278
Merge branch 'main' into ben/worker-threads-2
Apr 30, 2025
baaf33e
Undo faster termination change and remove associated tests
Apr 30, 2025
18c19ea
don't wait 10 seconds
Apr 30, 2025
d630139
delete test-worker-voluntarily-exit-followed-by-throw
Apr 30, 2025
6d182f3
delete test-worker-process-exit-async-module
Apr 30, 2025
721ac4c
delete test-worker-abort-on-uncaught-exception-terminate
Apr 30, 2025
59ab6b5
skip broken test
May 2, 2025
a8dc6f4
add ScriptExecutionContextIdentifier binding
May 2, 2025
5fc5c54
replace translate-c symbol instead of ptrCasting
May 2, 2025
c985ea3
error checking
May 2, 2025
84bbd9d
Merge branch 'main' into ben/worker-threads-2
May 2, 2025
35435f7
finish merge
May 2, 2025
b2cc48d
try unref
May 2, 2025
38d3978
no conflicts
May 2, 2025
97004c9
remove broken tests
May 3, 2025
ba11565
clean up fireEarlyMessages
May 3, 2025
f832301
try this
May 3, 2025
b5bdf12
Add comment
May 5, 2025
504e88e
Remove nodeWorkerObjectSymbol
May 5, 2025
9f3ff0c
Merge branch 'main' into ben/worker-threads-2
May 5, 2025
6dcc4ae
Address review feedback
May 5, 2025
bd50e62
Remove unnecessary exception check
May 5, 2025
7b0774c
Check URLs are valid
May 5, 2025
308d338
Merge branch 'main' into ben/worker-threads-2
Jarred-Sumner May 6, 2025
e74482f
Use JSBoundFunction instead of BoundEmitFunction
May 6, 2025
bed568b
Undo bindings changes
May 6, 2025
3eb6a3f
Add some exception checks
May 6, 2025
51a5f4e
Delete unnecessary overload
May 7, 2025
05ab606
Use helper methods for errors
May 7, 2025
84e6cae
Delete some exception checks
May 7, 2025
d613137
review suggestion
May 7, 2025
a588751
slop
May 7, 2025
dd8083c
Split up assertions in createNodeURLBinding
May 7, 2025
6ec45e3
Use one helper function to emit events on the next tick
May 7, 2025
a52b52a
Fix environmentData crash
May 8, 2025
f2cacbc
Add test
May 8, 2025
fe4c2e2
Merge branch 'main' into ben/worker-threads-2
May 8, 2025
725ef9f
Revert "Use helper methods for errors"
May 8, 2025
326f9e0
Fix RefPtr error and debug logs
May 9, 2025
90f6978
Fix StatWatcher errors
May 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/Global.zig
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,6 @@ pub export fn Bun__onExit() void {
std.mem.doNotOptimizeAway(&Bun__atexit);

Output.Source.Stdio.restore();

if (Environment.isWindows) {
bun.windows.libuv.uv_library_shutdown();
}
}

comptime {
Expand Down
21 changes: 10 additions & 11 deletions src/bun.js/api/bun/udp_socket.zig
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn onDrain(socket: *uws.udp.Socket) callconv(.C) void {
event_loop.enter();
defer event_loop.exit();
_ = callback.call(this.globalThis, this.thisValue, &.{this.thisValue}) catch |err| {
_ = this.callErrorHandler(.zero, &.{this.globalThis.takeException(err)});
this.callErrorHandler(.zero, this.globalThis.takeException(err));
};
}

Expand Down Expand Up @@ -111,7 +111,7 @@ fn onData(socket: *uws.udp.Socket, buf: *uws.udp.PacketBuffer, packets: c_int) c
JSC.jsNumber(port),
hostname_string.transferToJS(globalThis),
}) catch |err| {
_ = udpSocket.callErrorHandler(.zero, &.{udpSocket.globalThis.takeException(err)});
udpSocket.callErrorHandler(.zero, udpSocket.globalThis.takeException(err));
};
}
}
Expand Down Expand Up @@ -375,22 +375,21 @@ pub const UDPSocket = struct {
pub fn callErrorHandler(
this: *This,
thisValue: JSValue,
err: []const JSValue,
) bool {
err: JSValue,
) void {
const callback = this.config.on_error;
const globalThis = this.globalThis;
const vm = globalThis.bunVM();

if (err.isTerminationException(vm.jsc)) {
return;
}
if (callback == .zero) {
if (err.len > 0)
_ = vm.uncaughtException(globalThis, err[0], false);

return false;
_ = vm.uncaughtException(globalThis, err, false);
return;
}

_ = callback.call(globalThis, thisValue, err) catch |e| globalThis.reportActiveExceptionAsUnhandled(e);

return true;
_ = callback.call(globalThis, thisValue, &.{err}) catch |e| globalThis.reportActiveExceptionAsUnhandled(e);
}

pub fn setBroadcast(this: *This, globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSValue {
Expand Down
19 changes: 16 additions & 3 deletions src/bun.js/bindings/BunInjectedScriptHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ static JSObject* objectForEventTargetListeners(VM& vm, JSGlobalObject* exec, Eve
auto* scriptExecutionContext = eventTarget->scriptExecutionContext();
if (!scriptExecutionContext)
return nullptr;
auto scope = DECLARE_THROW_SCOPE(vm);

JSObject* listeners = nullptr;

for (auto& eventType : eventTarget->eventTypes()) {
unsigned listenersForEventIndex = 0;
auto* listenersForEvent = constructEmptyArray(exec, nullptr);
RETURN_IF_EXCEPTION(scope, {});

for (auto& eventListener : eventTarget->eventListeners(eventType)) {
if (!is<JSEventListener>(eventListener->callback()))
Expand All @@ -74,6 +76,7 @@ static JSObject* objectForEventTargetListeners(VM& vm, JSGlobalObject* exec, Eve
continue;

auto* propertiesForListener = constructEmptyObject(exec);
RETURN_IF_EXCEPTION(scope, {});
propertiesForListener->putDirect(vm, Identifier::fromString(vm, "callback"_s), jsFunction);
propertiesForListener->putDirect(vm, Identifier::fromString(vm, "capture"_s), jsBoolean(eventListener->useCapture()));
propertiesForListener->putDirect(vm, Identifier::fromString(vm, "passive"_s), jsBoolean(eventListener->isPassive()));
Expand All @@ -82,8 +85,10 @@ static JSObject* objectForEventTargetListeners(VM& vm, JSGlobalObject* exec, Eve
}

if (listenersForEventIndex) {
if (!listeners)
if (!listeners) {
listeners = constructEmptyObject(exec);
RETURN_IF_EXCEPTION(scope, {});
}
listeners->putDirect(vm, Identifier::fromString(vm, eventType), listenersForEvent);
}
}
Expand Down Expand Up @@ -121,6 +126,7 @@ JSValue BunInjectedScriptHost::getInternalProperties(VM& vm, JSGlobalObject* exe
if (auto* worker = JSWorker::toWrapped(vm, value)) {
unsigned index = 0;
auto* array = constructEmptyArray(exec, nullptr);
RETURN_IF_EXCEPTION(scope, {});

String name = worker->name();
if (!name.isEmpty())
Expand All @@ -142,13 +148,15 @@ JSValue BunInjectedScriptHost::getInternalProperties(VM& vm, JSGlobalObject* exe
if (type == JSDOMWrapperType) {
if (auto* headers = jsDynamicCast<JSFetchHeaders*>(value)) {
auto* array = constructEmptyArray(exec, nullptr);
RETURN_IF_EXCEPTION(scope, {});
constructDataProperties(vm, exec, array, WebCore::getInternalProperties(vm, exec, headers));
RETURN_IF_EXCEPTION(scope, {});
return array;
}

if (auto* formData = jsDynamicCast<JSDOMFormData*>(value)) {
auto* array = constructEmptyArray(exec, nullptr);
RETURN_IF_EXCEPTION(scope, {});
constructDataProperties(vm, exec, array, WebCore::getInternalProperties(vm, exec, formData));
RETURN_IF_EXCEPTION(scope, {});
return array;
Expand All @@ -157,20 +165,23 @@ JSValue BunInjectedScriptHost::getInternalProperties(VM& vm, JSGlobalObject* exe
} else if (type == JSAsJSONType) {
if (auto* params = jsDynamicCast<JSURLSearchParams*>(value)) {
auto* array = constructEmptyArray(exec, nullptr);
RETURN_IF_EXCEPTION(scope, {});
constructDataProperties(vm, exec, array, WebCore::getInternalProperties(vm, exec, params));
RETURN_IF_EXCEPTION(scope, {});
return array;
}

if (auto* cookie = jsDynamicCast<JSCookie*>(value)) {
auto* array = constructEmptyArray(exec, nullptr);
RETURN_IF_EXCEPTION(scope, {});
constructDataProperties(vm, exec, array, WebCore::getInternalProperties(vm, exec, cookie));
RETURN_IF_EXCEPTION(scope, {});
return array;
}

if (auto* cookieMap = jsDynamicCast<JSCookieMap*>(value)) {
auto* array = constructEmptyArray(exec, nullptr);
RETURN_IF_EXCEPTION(scope, {});
constructDataProperties(vm, exec, array, WebCore::getInternalProperties(vm, exec, cookieMap));
RETURN_IF_EXCEPTION(scope, {});
return array;
Expand All @@ -181,11 +192,13 @@ JSValue BunInjectedScriptHost::getInternalProperties(VM& vm, JSGlobalObject* exe
if (auto* eventTarget = JSEventTarget::toWrapped(vm, value)) {
unsigned index = 0;
auto* array = constructEmptyArray(exec, nullptr);
RETURN_IF_EXCEPTION(scope, {});

if (auto* listeners = objectForEventTargetListeners(vm, exec, eventTarget))
if (auto* listeners = objectForEventTargetListeners(vm, exec, eventTarget)) {
array->putDirectIndex(exec, index++, constructInternalProperty(vm, exec, "listeners"_s, listeners));
RETURN_IF_EXCEPTION(scope, {});
}

RETURN_IF_EXCEPTION(scope, {});
return array;
}

Expand Down
Loading