diff --git a/src/workerd/api/analytics-engine-impl.h b/src/workerd/api/analytics-engine-impl.h index bdc9a36b677..7e9a75ea3a1 100644 --- a/src/workerd/api/analytics-engine-impl.h +++ b/src/workerd/api/analytics-engine-impl.h @@ -98,8 +98,8 @@ void setBlobs( uint index = 1; size_t sizeSum = 0; for (auto& item: arr) { - KJ_IF_MAYBE(*i, item) { - KJ_SWITCH_ONEOF(*i) { + KJ_IF_SOME(i, item) { + KJ_SWITCH_ONEOF(i) { KJ_CASE_ONEOF(val, kj::Array) { value = val.asBytes(); } @@ -190,8 +190,8 @@ void setIndexes( } auto item = kj::mv(arr[0]); kj::ArrayPtr value; - KJ_IF_MAYBE(*i, item) { - KJ_SWITCH_ONEOF(*i) { + KJ_IF_SOME(i, item) { + KJ_SWITCH_ONEOF(i) { KJ_CASE_ONEOF(val, kj::Array) { value = val.asBytes(); } diff --git a/src/workerd/api/analytics-engine.c++ b/src/workerd/api/analytics-engine.c++ index 21be38f7808..9778f7415ea 100644 --- a/src/workerd/api/analytics-engine.c++ +++ b/src/workerd/api/analytics-engine.c++ @@ -25,15 +25,15 @@ void AnalyticsEngine::writeDataPoint(jsg::Lock& js, aeEvent.setIndex1(""_kj.asBytes()); kj::StringPtr errorPrefix = "writeDataPoint(): "_kj; - KJ_IF_MAYBE(ev, event) { - KJ_IF_MAYBE(indexes, ev->indexes) { - setIndexes(aeEvent, *indexes, errorPrefix); + KJ_IF_SOME(ev, event) { + KJ_IF_SOME(indexes, ev.indexes) { + setIndexes(aeEvent, indexes, errorPrefix); } - KJ_IF_MAYBE(blobs, ev->blobs) { - setBlobs(aeEvent, *blobs, errorPrefix); + KJ_IF_SOME(blobs, ev.blobs) { + setBlobs(aeEvent, blobs, errorPrefix); } - KJ_IF_MAYBE(doubles, ev->doubles) { - setDoubles(aeEvent, *doubles, errorPrefix); + KJ_IF_SOME(doubles, ev.doubles) { + setDoubles(aeEvent, doubles, errorPrefix); } } }); diff --git a/src/workerd/api/blob.c++ b/src/workerd/api/blob.c++ index 2c40813f6c4..b79e9633714 100644 --- a/src/workerd/api/blob.c++ +++ b/src/workerd/api/blob.c++ @@ -81,9 +81,9 @@ static kj::String normalizeType(kj::String type) { jsg::Ref Blob::constructor(jsg::Optional bits, jsg::Optional options) { kj::String type; // note: default value is intentionally empty string - KJ_IF_MAYBE(o, options) { - KJ_IF_MAYBE(t, o->type) { - type = normalizeType(kj::mv(*t)); + KJ_IF_SOME(o, options) { + KJ_IF_SOME(t, o.type) { + type = normalizeType(kj::mv(t)); } } @@ -156,7 +156,7 @@ public: if (encoding == StreamEncoding::IDENTITY) { return unread.size(); } else { - return nullptr; + return kj::none; } } @@ -196,16 +196,16 @@ jsg::Ref File::constructor(jsg::Optional bits, kj::String name, jsg::Optional options) { kj::String type; // note: default value is intentionally empty string kj::Maybe maybeLastModified; - KJ_IF_MAYBE(o, options) { - KJ_IF_MAYBE(t, o->type) { - type = normalizeType(kj::mv(*t)); + KJ_IF_SOME(o, options) { + KJ_IF_SOME(t, o.type) { + type = normalizeType(kj::mv(t)); } - maybeLastModified = o->lastModified; + maybeLastModified = o.lastModified; } double lastModified; - KJ_IF_MAYBE(m, maybeLastModified) { - lastModified = *m; + KJ_IF_SOME(m, maybeLastModified) { + lastModified = m; } else { lastModified = dateNow(); } diff --git a/src/workerd/api/blob.h b/src/workerd/api/blob.h index f526204c339..c3ad6b57dfc 100644 --- a/src/workerd/api/blob.h +++ b/src/workerd/api/blob.h @@ -66,8 +66,8 @@ class Blob: public jsg::Object { kj::String type; void visitForGc(jsg::GcVisitor& visitor) { - KJ_IF_MAYBE(b, ownData.tryGet>()) { - visitor.visit(*b); + KJ_IF_SOME(b, ownData.tryGet>()) { + visitor.visit(b); } } diff --git a/src/workerd/api/cache.c++ b/src/workerd/api/cache.c++ index 69f23f051f9..2763e845dde 100644 --- a/src/workerd/api/cache.c++ +++ b/src/workerd/api/cache.c++ @@ -44,13 +44,15 @@ kj::StringPtr validateUrl(kj::StringPtr url) { // But, that might mean e.g. discarding fragments ("hashes", stuff after a '#'), which would // be a change in behavior that could subtly affect production workers... - constexpr auto urlOptions = kj::Url::Options { .percentDecode = false, .allowEmpty = true }; - KJ_IF_MAYBE(parsed, kj::Url::tryParse(url, kj::Url::HTTP_PROXY_REQUEST, urlOptions)) { - return url; - } else { - JSG_FAIL_REQUIRE(TypeError, - "Invalid URL. Cache API keys must be fully-qualified, valid URLs."); - } + static constexpr auto urlOptions = kj::Url::Options { + .percentDecode = false, + .allowEmpty = true, + }; + + JSG_REQUIRE(kj::Url::tryParse(url, kj::Url::HTTP_PROXY_REQUEST, urlOptions) != kj::none, + TypeError, "Invalid URL. Cache API keys must be fully-qualified, valid URLs."); + + return url; } } // namespace @@ -99,8 +101,8 @@ jsg::Promise>> Cache::match( response.body = response.body.attach(kj::mv(httpClient)); kj::StringPtr cacheStatus; - KJ_IF_MAYBE(cs, response.headers->get(context.getHeaderIds().cfCacheStatus)) { - cacheStatus = *cs; + KJ_IF_SOME(cs, response.headers->get(context.getHeaderIds().cfCacheStatus)) { + cacheStatus = cs; } else { // This is an internal error representing a violation of the contract between us and // the cache. Since it is always conformant to return undefined from Cache::match() @@ -131,7 +133,7 @@ jsg::Promise>> Cache::match( return makeHttpResponse( js, kj::HttpMethod::GET, {}, response.statusCode, response.statusText, *response.headers, - kj::mv(response.body), nullptr); + kj::mv(response.body), kj::none); }); }); } @@ -179,8 +181,8 @@ jsg::Promise Cache::put(jsg::Lock& js, Request::Info requestOrUrl, kj::String contentLength; kj::StringPtr connectionHeaders[kj::HttpHeaders::CONNECTION_HEADERS_COUNT]; - KJ_IF_MAYBE(ebs, expectedBodySize) { - contentLength = kj::str(*ebs); + KJ_IF_SOME(ebs, expectedBodySize) { + contentLength = kj::str(ebs); connectionHeaders[kj::HttpHeaders::BuiltinIndices::CONTENT_LENGTH] = contentLength; } else { connectionHeaders[kj::HttpHeaders::BuiltinIndices::TRANSFER_ENCODING] = "chunked"; @@ -248,8 +250,8 @@ jsg::Promise Cache::put(jsg::Lock& js, Request::Info requestOrUrl, TypeError, "Cannot cache response to a range request (206 Partial Content)."); auto responseHeadersRef = jsResponse->getHeaders(js); - KJ_IF_MAYBE(vary, responseHeadersRef->get(jsg::ByteString(kj::str("vary")))) { - JSG_REQUIRE(vary->findFirst('*') == nullptr, + KJ_IF_SOME(vary, responseHeadersRef->get(jsg::ByteString(kj::str("vary")))) { + JSG_REQUIRE(vary.findFirst('*') == nullptr, TypeError, "Cannot cache response with 'Vary: *' header."); } @@ -278,7 +280,7 @@ jsg::Promise Cache::put(jsg::Lock& js, Request::Info requestOrUrl, // We need to send the response to our serializer immediately in order to fulfill Cache.put()'s // contract: the caller should be able to observe that the response body is disturbed as soon // as put() returns. - auto serializePromise = jsResponse->send(js, serializer, {}, nullptr); + auto serializePromise = jsResponse->send(js, serializer, {}, kj::none); auto payload = serializer.getPayload(); // TODO(someday): Implement Cache API in preview. This bail-out lives all the way down here, @@ -296,8 +298,8 @@ jsg::Promise Cache::put(jsg::Lock& js, Request::Info requestOrUrl, auto makeCachePutStream = [&context, stream = kj::mv(payload.stream)](jsg::Lock& js) mutable { return context.makeCachePutStream(js, kj::mv(stream)); }; - KJ_IF_MAYBE(p, context.waitForOutputLocksIfNecessary()) { - startStreamPromise = context.awaitIo(js, kj::mv(*p), kj::mv(makeCachePutStream)); + KJ_IF_SOME(p, context.waitForOutputLocksIfNecessary()) { + startStreamPromise = context.awaitIo(js, kj::mv(p), kj::mv(makeCachePutStream)); } else { startStreamPromise = makeCachePutStream(js); } @@ -308,7 +310,7 @@ jsg::Promise Cache::put(jsg::Lock& js, Request::Info requestOrUrl, writePayloadHeadersPromise = kj::mv(payload.writeHeadersPromise)] (jsg::Lock& js, kj::Maybe> maybeStream) mutable -> jsg::Promise { - if (maybeStream == nullptr) { + if (maybeStream == kj::none) { // Cache API PUT quota must have been exceeded. return js.resolvedPromise(); } diff --git a/src/workerd/api/cf-property.c++ b/src/workerd/api/cf-property.c++ index a196ae8e3b1..133896e7eb0 100644 --- a/src/workerd/api/cf-property.c++ +++ b/src/workerd/api/cf-property.c++ @@ -39,8 +39,8 @@ static void handleDefaultBotManagement(jsg::Lock& js, jsg::JsObject handle) { } CfProperty::CfProperty(kj::Maybe unparsed) { - KJ_IF_MAYBE(str, unparsed) { - value = kj::str(*str); + KJ_IF_SOME(str, unparsed) { + value = kj::str(str); } } @@ -48,8 +48,8 @@ CfProperty::CfProperty(jsg::Lock& js, const jsg::JsObject& object) : CfProperty(kj::Maybe(jsg::JsRef(js, object))) {} CfProperty::CfProperty(kj::Maybe>&& parsed) { - KJ_IF_MAYBE(v, parsed) { - value = kj::mv(*v); + KJ_IF_SOME(v, parsed) { + value = kj::mv(v); } } @@ -60,8 +60,8 @@ jsg::Optional CfProperty::get(jsg::Lock& js) { } jsg::Optional> CfProperty::getRef(jsg::Lock& js) { - KJ_IF_MAYBE(cf, value) { - KJ_SWITCH_ONEOF(*cf) { + KJ_IF_SOME(cf, value) { + KJ_SWITCH_ONEOF(cf) { KJ_CASE_ONEOF(parsed, jsg::JsRef) { return parsed.addRef(js); } @@ -82,13 +82,13 @@ jsg::Optional> CfProperty::getRef(jsg::Lock& js) { } } - return nullptr; + return kj::none; } kj::Maybe CfProperty::serialize(jsg::Lock& js) { - KJ_IF_MAYBE(cf, value) { - KJ_SWITCH_ONEOF(*cf) { + KJ_IF_SOME(cf, value) { + KJ_SWITCH_ONEOF(cf) { KJ_CASE_ONEOF(parsed, jsg::JsRef) { return jsg::JsValue(parsed.getHandle(js)).toJson(js); } @@ -105,7 +105,7 @@ kj::Maybe CfProperty::serialize(jsg::Lock& js) { } } - return nullptr; + return kj::none; } CfProperty CfProperty::deepClone(jsg::Lock& js) { @@ -118,8 +118,8 @@ CfProperty CfProperty::deepClone(jsg::Lock& js) { // TODO(cleanup): With a bit of refactoring we can preserve the lazy parsing // optimization through the clone. But for now, let's just do the easy thing. getRef(js); - KJ_IF_MAYBE(cf, value) { - KJ_SWITCH_ONEOF(*cf) { + KJ_IF_SOME(cf, value) { + KJ_SWITCH_ONEOF(cf) { KJ_CASE_ONEOF(parsed, jsg::JsRef) { return CfProperty(jsg::JsRef(js, parsed.getHandle(js).jsonClone(js))); } @@ -133,8 +133,8 @@ CfProperty CfProperty::deepClone(jsg::Lock& js) { } void CfProperty::visitForGc(jsg::GcVisitor& visitor) { - KJ_IF_MAYBE(cf, value) { - KJ_SWITCH_ONEOF(*cf) { + KJ_IF_SOME(cf, value) { + KJ_SWITCH_ONEOF(cf) { KJ_CASE_ONEOF(parsed, jsg::JsRef) { visitor.visit(parsed); } diff --git a/src/workerd/api/encoding.c++ b/src/workerd/api/encoding.c++ index dcdacd1e6b9..a68c61330f0 100644 --- a/src/workerd/api/encoding.c++ +++ b/src/workerd/api/encoding.c++ @@ -291,7 +291,7 @@ kj::Maybe IcuDecoder::create(Encoding encoding, bool fatal, bool ign if (fatal) { status = U_ZERO_ERROR; ucnv_setToUCallBack(inner, UCNV_TO_U_CALLBACK_STOP, nullptr, nullptr, nullptr, &status); - if (U_FAILURE(status)) return nullptr; + if (U_FAILURE(status)) return kj::none; } return IcuDecoder(encoding, inner, ignoreBom); @@ -381,7 +381,7 @@ kj::Maybe IcuDecoder::decode( flush, &status); - if (U_FAILURE(status)) return nullptr; + if (U_FAILURE(status)) return kj::none; auto omitInitialBom = false; auto length = std::distance(result.begin(), dest); @@ -423,13 +423,13 @@ TextDecoder::constructor(jsg::Optional maybeLabel, return kj::str("\"", label, "\" is not a valid encoding."); }; - KJ_IF_MAYBE(label, maybeLabel) { - encoding = getEncodingForLabel(*label); + KJ_IF_SOME(label, maybeLabel) { + encoding = getEncodingForLabel(label); JSG_REQUIRE(encoding != Encoding::Replacement && encoding != Encoding::X_User_Defined && encoding != Encoding::INVALID, RangeError, - errorMessage(*label)); + errorMessage(label)); } if (encoding == Encoding::Windows_1252) { diff --git a/src/workerd/api/form-data.c++ b/src/workerd/api/form-data.c++ index 3b2ca13c232..3979acdbd9b 100644 --- a/src/workerd/api/form-data.c++ +++ b/src/workerd/api/form-data.c++ @@ -163,7 +163,7 @@ void parseFormData(kj::Vector& data, kj::StringPtr boundary, message = message.slice(0, message.size() - uint(message.back() == '\r')); } - if (filename == nullptr || convertFilesToStrings) { + if (filename == kj::none || convertFilesToStrings) { data.add(FormData::Entry { kj::mv(name), kj::str(message) }); } else { data.add(FormData::Entry { @@ -180,8 +180,8 @@ blobToFile(kj::StringPtr name, kj::OneOf, jsg::Ref, kj::Str jsg::Optional filename) { auto fromBlob = [&](jsg::Ref blob) { kj::String fn; - KJ_IF_MAYBE(f, filename) { - fn = kj::mv(*f); + KJ_IF_SOME(f, filename) { + fn = kj::mv(f); } else { fn = kj::str(name); } @@ -191,7 +191,7 @@ blobToFile(kj::StringPtr name, kj::OneOf, jsg::Ref, kj::Str KJ_SWITCH_ONEOF(value) { KJ_CASE_ONEOF(file, jsg::Ref) { - if (filename == nullptr) { + if (filename == kj::none) { return kj::mv(file); } else { // Need to substitute filename. @@ -300,21 +300,21 @@ FormData::EntryType FormData::clone(FormData::EntryType& value) { void FormData::parse(kj::ArrayPtr rawText, kj::StringPtr contentType, bool convertFilesToStrings) { - KJ_IF_MAYBE(parsed, MimeType::tryParse(contentType)) { - auto& params = parsed->params(); - if (MimeType::FORM_DATA == *parsed) { + KJ_IF_SOME(parsed, MimeType::tryParse(contentType)) { + auto& params = parsed.params(); + if (MimeType::FORM_DATA == parsed) { auto& boundary = JSG_REQUIRE_NONNULL(params.find("boundary"_kj), TypeError, "No boundary string in Content-Type header. The multipart/form-data MIME " "type requires a boundary parameter, e.g. 'Content-Type: multipart/form-data; " "boundary=\"abcd\"'. See RFC 7578, section 4."); parseFormData(data, boundary, rawText, convertFilesToStrings); return; - } else if (MimeType::FORM_URLENCODED == *parsed) { + } else if (MimeType::FORM_URLENCODED == parsed) { // Let's read the charset so we can barf if the body isn't UTF-8. // // TODO(conform): Transcode to UTF-8, like the spec tells us to. - KJ_IF_MAYBE(charsetParam, params.find("charset"_kj)) { - auto charset = kj::str(*charsetParam); + KJ_IF_SOME(charsetParam, params.find("charset"_kj)) { + auto charset = kj::str(charsetParam); JSG_REQUIRE(strcasecmp(charset.cStr(), "utf-8") == 0 || strcasecmp(charset.cStr(), "utf8") == 0 || strcasecmp(charset.cStr(), "unicode-1-1-utf-8") == 0, @@ -359,7 +359,7 @@ kj::Maybe, kj::String>> FormData::get(kj::String name) return clone(v); } } - return nullptr; + return kj::none; } kj::Array, kj::String>> FormData::getAll(kj::String name) { @@ -415,8 +415,8 @@ void FormData::forEach( // Here, if the thisArg is not passed, or is passed explicitly as a null or // undefined, then undefined is used as the thisArg. auto receiver = js.v8Undefined(); - KJ_IF_MAYBE(arg, thisArg) { - auto handle = arg->getHandle(js); + KJ_IF_SOME(arg, thisArg) { + auto handle = arg.getHandle(js); if (!handle->IsNullOrUndefined()) { receiver = handle; } diff --git a/src/workerd/api/hibernatable-web-socket.c++ b/src/workerd/api/hibernatable-web-socket.c++ index 7ff9fbc662b..3c33f8a4b7b 100644 --- a/src/workerd/api/hibernatable-web-socket.c++ +++ b/src/workerd/api/hibernatable-web-socket.c++ @@ -66,7 +66,7 @@ kj::Promise HibernatableWebSocketCustomEve // We definitely have an actor by this point. Let's set the hibernation manager on the actor // before we start running any events that might need to access it. auto& a = KJ_REQUIRE_NONNULL(context.getActor()); - if (a.getHibernationManager() == nullptr) { + if (a.getHibernationManager() == kj::none) { a.setHibernationManager(kj::addRef(KJ_REQUIRE_NONNULL(manager))); } @@ -130,8 +130,8 @@ kj::Promise auto req = dispatcher.castAs< rpc::HibernatableWebSocketEventDispatcher>().hibernatableWebSocketEventRequest(); - KJ_IF_MAYBE(rpcParameters, params.tryGet>()) { - req.setMessage((*rpcParameters)->getMessage()); + KJ_IF_SOME(rpcParameters, params.tryGet>()) { + req.setMessage(rpcParameters->getMessage()); } else { auto message = req.initMessage(); auto payload = message.initPayload(); diff --git a/src/workerd/api/hibernatable-web-socket.h b/src/workerd/api/hibernatable-web-socket.h index 2831118f460..27c1914c6b5 100644 --- a/src/workerd/api/hibernatable-web-socket.h +++ b/src/workerd/api/hibernatable-web-socket.h @@ -56,7 +56,7 @@ class HibernatableWebSocketCustomEventImpl final: public WorkerInterface::Custom uint16_t typeId, kj::TaskSet& waitUntilTasks, kj::Own params, - kj::Maybe manager=nullptr) + kj::Maybe manager=kj::none) : typeId(typeId), waitUntilTasks(waitUntilTasks), params(kj::mv(params)) {} HibernatableWebSocketCustomEventImpl( uint16_t typeId, @@ -83,10 +83,10 @@ class HibernatableWebSocketCustomEventImpl final: public WorkerInterface::Custom // Returns `params`, but if we have a HibernationReader we convert it to a // HibernatableSocketParams first. HibernatableSocketParams consumeParams() { - KJ_IF_MAYBE(p, params.tryGet>()) { + KJ_IF_SOME(p, params.tryGet>()) { kj::Maybe eventParameters; - auto websocketId = kj::str((*p)->getMessage().getWebsocketId()); - auto payload = (*p)->getMessage().getPayload(); + auto websocketId = kj::str(p->getMessage().getWebsocketId()); + auto payload = p->getMessage().getPayload(); switch(payload.which()) { case rpc::HibernatableWebSocketEventMessage::Payload::TEXT: { eventParameters.emplace(kj::str(payload.getText()), kj::mv(websocketId)); diff --git a/src/workerd/api/trace.c++ b/src/workerd/api/trace.c++ index e2de701aeae..2d8d4ef5adc 100644 --- a/src/workerd/api/trace.c++ +++ b/src/workerd/api/trace.c++ @@ -28,7 +28,7 @@ kj::Array> TailEvent::getEvents() { namespace { kj::Maybe getTraceTimestamp(const Trace& trace) { if (trace.eventTimestamp == kj::UNIX_EPOCH) { - return nullptr; + return kj::none; } if (isPredictableModeForTest()) { return 0.0; @@ -136,8 +136,8 @@ kj::Own getFetchRequestDetail( } kj::Maybe getTraceEvent(jsg::Lock& js, const Trace& trace) { - KJ_IF_MAYBE(e, trace.eventInfo) { - KJ_SWITCH_ONEOF(*e) { + KJ_IF_SOME(e, trace.eventInfo) { + KJ_SWITCH_ONEOF(e) { KJ_CASE_ONEOF(fetch, Trace::FetchEventInfo) { return kj::Maybe(jsg::alloc(js, trace, fetch, trace.fetchResponseInfo)); } @@ -158,7 +158,7 @@ kj::Maybe getTraceEvent(jsg::Lock& js, const Trace& trace) } } } - return nullptr; + return kj::none; } } // namespace