Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/workerd/api/basics.c++
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ void AbortSignal::serialize(jsg::Lock& js, jsg::Serializer& serializer) {
auto& ioContext = IoContext::current();
// Keep track of every AbortSignal cloned from this one.
// If this->triggerAbort(...) is called, each rpcClient will be informed.
rpcClients.add(ioContext.addObject(kj::heap<AbortTriggerRpcClient>(kj::mv(triggerCap))));
rpcClients.add(ioContext.createObject<AbortTriggerRpcClient>(kj::mv(triggerCap)));
}

jsg::Ref<AbortSignal> AbortSignal::deserialize(
Expand Down
4 changes: 2 additions & 2 deletions src/workerd/api/container.c++
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ void Container::startMonitor() {
}).fork();

currentMonitor =
IoContext::current().addObject(kj::heap<Monitor>(kj::mv(monitor), ++nextMonitorGeneration));
IoContext::current().createObject<Monitor>(kj::mv(monitor), ++nextMonitorGeneration);
}

jsg::Promise<void> Container::setLabels(jsg::Lock& js, jsg::Dict<kj::String> labels) {
Expand Down Expand Up @@ -1487,7 +1487,7 @@ jsg::Ref<Fetcher> Container::getTcpPort(jsg::Lock& js, int port) {
auto portState = [&]() -> kj::Rc<TcpPortState> {
if (util::Autogate::isEnabled(util::AutogateKey::CONTAINER_TUNNEL_REUSE)) {
if (tcpPortStates == kj::none) {
tcpPortStates = ioctx.addObject(kj::heap<kj::HashMap<int, kj::Rc<TcpPortState>>>());
tcpPortStates = ioctx.createObject<kj::HashMap<int, kj::Rc<TcpPortState>>>();
}
auto& states = *KJ_ASSERT_NONNULL(tcpPortStates);

Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/sockets.c++
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ jsg::Ref<Socket> Socket::deserialize(
// socket is being torn down, so there is nothing to wire up). The wiring runs JS that can throw
// with no user code on the stack, so each body is wrapped in JSG_TRY/JSG_CATCH and reports via
// js.reportError() (matching the queueMicrotask() pattern in global-scope.c++).
auto disconnectedOwn = ioContext.addObject(kj::heap<kj::Promise<bool>>(kj::mv(disconnected)));
auto disconnectedOwn = ioContext.createObject<kj::Promise<bool>>(kj::mv(disconnected));
js.v8Context()->GetMicrotaskQueue()->EnqueueMicrotask(js.v8Isolate,
js.wrapSimpleFunction(js.v8Context(),
JSG_VISITABLE_LAMBDA((self = socket.addRef(), disconnected = kj::mv(disconnectedOwn)),
Expand Down
4 changes: 2 additions & 2 deletions src/workerd/api/sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class Socket: public jsg::Object {
kj::Maybe<kj::String> domain,
bool isDefaultFetchPort,
jsg::PromiseResolverPair<SocketInfo> openedPrPair)
: connectionData(context.addObject(kj::heap<ConnectionData>(
kj::mv(tlsStarter), kj::mv(connectionStream), kj::mv(watchForDisconnectTask)))),
: connectionData(context.createObject<ConnectionData>(
kj::mv(tlsStarter), kj::mv(connectionStream), kj::mv(watchForDisconnectTask))),
readable(kj::mv(readableParam)),
writable(kj::mv(writable)),
closedResolver(kj::mv(closedPrPair.resolver)),
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/sql.c++
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static constexpr uint SQL_STATEMENT_CACHE_MAX_SIZE = 1024 * 1024;

SqlStorage::SqlStorage(jsg::Ref<DurableObjectStorage> storage)
: storage(kj::mv(storage)),
statementCache(IoContext::current().addObject(kj::heap<StatementCache>())) {}
statementCache(IoContext::current().createObject<StatementCache>()) {}

SqlStorage::~SqlStorage() {}

Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/streams/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class WritableStreamInternalController: public WritableStreamController {
kj::Maybe<uint64_t> maybeHighWaterMark = kj::none,
kj::Maybe<jsg::Promise<void>> maybeClosureWaitable = kj::none)
: state(State::create<IoOwn<Writable>>(
IoContext::current().addObject(kj::heap<Writable>(kj::mv(writable))))),
IoContext::current().createObject<Writable>(kj::mv(writable)))),
observer(kj::mv(observer)),
maybeHighWaterMark(maybeHighWaterMark),
maybeClosureWaitable(kj::mv(maybeClosureWaitable)) {}
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/sync-kv.c++
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jsg::Ref<SyncKvStorage::ListIterator> SyncKvStorage::list(
KJ_UNWRAP_OR(DurableObjectStorageOperations::compileListOptions(asyncOptions), {
// Key range is empty. Return empty map.
return js.alloc<SyncKvStorage::ListIterator>(
IoContext::current().addObject(kj::heap<SqliteKv::ListCursor>(nullptr)));
IoContext::current().createObject<SqliteKv::ListCursor>(nullptr));
});

auto cursor = sqliteKv.list(start, end, limit, reverse ? SqliteKv::REVERSE : SqliteKv::FORWARD)
Expand Down
6 changes: 3 additions & 3 deletions src/workerd/api/web-socket.c++
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ LegacyWebSocketAdapter::LegacyWebSocketAdapter(jsg::Lock& js,
ws,
kj::mv(KJ_REQUIRE_NONNULL(package.maybeTags)),
package.closedOutgoingConnection)),
outgoingMessages(IoContext::current().addObject(kj::heap<OutgoingMessagesMap>())) {}
outgoingMessages(IoContext::current().createObject<OutgoingMessagesMap>()) {}
// This constructor is used when reinstantiating a websocket that had been hibernating, which is
// why we can go straight to the Accepted state. However, note that we are actually in the
// `Hibernatable` "sub-state"!
Expand All @@ -292,7 +292,7 @@ LegacyWebSocketAdapter::LegacyWebSocketAdapter(
: BinaryType::ARRAYBUFFER),
allowHalfOpen(!FeatureFlags::get(js).getWebSocketAutoReplyToClose()),
farNative(nullptr),
outgoingMessages(IoContext::current().addObject(kj::heap<OutgoingMessagesMap>())) {
outgoingMessages(IoContext::current().createObject<OutgoingMessagesMap>()) {
auto nativeObj = kj::heap<Native>();
nativeObj->state.init<AwaitingAcceptanceOrCoupling>(kj::mv(native));
farNative = IoContext::current().addObject(kj::mv(nativeObj));
Expand All @@ -305,7 +305,7 @@ LegacyWebSocketAdapter::LegacyWebSocketAdapter(jsg::Lock& js, WebSocket& shell,
: BinaryType::ARRAYBUFFER),
allowHalfOpen(!FeatureFlags::get(js).getWebSocketAutoReplyToClose()),
farNative(nullptr),
outgoingMessages(IoContext::current().addObject(kj::heap<OutgoingMessagesMap>())) {
outgoingMessages(IoContext::current().createObject<OutgoingMessagesMap>()) {
auto nativeObj = kj::heap<Native>();
nativeObj->state.init<AwaitingConnection>();
farNative = IoContext::current().addObject(kj::mv(nativeObj));
Expand Down
6 changes: 6 additions & 0 deletions src/workerd/io/io-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,12 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler
template <typename T>
IoOwn<T> addObject(kj::Rc<T> obj);

// Shortcut for addObject(kj::heap(...)) to avoid having to write kj::heap() in every call site.
template <typename T, typename... Params>
IoOwn<T> createObject(Params&&... params) {
return addObject(kj::heap<T>(kj::fwd<Params>(params)...));
}

// Like addObject() but takes a functor, returning a functor which holds the original functor
// under an `IoOwn`, and so will stop working if the IoContext is no longer valid. This is
// particularly useful for passing to `jsg::Promise::then()` when you need the continuation to
Expand Down
Loading