@@ -75,7 +75,7 @@ public:
75
75
if (chars.begin () != nullptr ) {
76
76
return kj::str (chars);
77
77
} else {
78
- return nullptr ;
78
+ return kj::none ;
79
79
}
80
80
}
81
81
@@ -89,7 +89,7 @@ private:
89
89
kj::Maybe<kj::Exception> tryGetLastError () {
90
90
auto maybeErrorString = lol_html_take_last_error ();
91
91
if (maybeErrorString.data == nullptr ) {
92
- return nullptr ;
92
+ return kj::none ;
93
93
}
94
94
auto errorString = LolString (maybeErrorString);
95
95
return kj::Exception (kj::Exception::Type::FAILED, __FILE__, __LINE__,
@@ -146,12 +146,12 @@ public:
146
146
explicit TokenScope (jsg::Ref<T>& value)
147
147
: contentToken(value.addRef()) {}
148
148
~TokenScope () noexcept (false ) {
149
- KJ_IF_MAYBE (token, contentToken) {
150
- (* token) ->htmlContentScopeEnd ();
149
+ KJ_IF_SOME (token, contentToken) {
150
+ token->htmlContentScopeEnd ();
151
151
}
152
152
}
153
153
TokenScope (TokenScope&& o) : contentToken(kj::mv(o.contentToken)) {
154
- o.contentToken = nullptr ;
154
+ o.contentToken = kj::none ;
155
155
}
156
156
KJ_DISALLOW_COPY (TokenScope);
157
157
@@ -300,13 +300,13 @@ private:
300
300
// If a call to `lol-html` returned an error or propagated a user error from a handler
301
301
// (LOL_HTML_STOP for instance); we consider its instance as poisoned. Future calls to
302
302
// `lol_html_rewriter_write` and `lol_html_rewriter_end` will probably throw.
303
- return maybeException != nullptr ;
303
+ return maybeException != kj::none ;
304
304
}
305
305
306
306
void maybePoison (kj::Exception exception ) {
307
307
// Ignore this error if maybeException is already populated -- this error is probably just a
308
308
// secondary effect.
309
- if (maybeException == nullptr ) {
309
+ if (maybeException == kj::none ) {
310
310
maybeException = kj::mv (exception );
311
311
}
312
312
}
@@ -332,11 +332,11 @@ kj::Own<lol_html_HtmlRewriter> Rewriter::buildRewriter(
332
332
check (lol_html_rewriter_builder_add_element_content_handlers (
333
333
builder,
334
334
elementHandlers.selector ,
335
- element == nullptr ? nullptr : &Rewriter::thunk<Element>,
335
+ element == kj::none ? nullptr : &Rewriter::thunk<Element>,
336
336
element.orDefault (nullptr ),
337
- comments == nullptr ? nullptr : &Rewriter::thunk<Comment>,
337
+ comments == kj::none ? nullptr : &Rewriter::thunk<Comment>,
338
338
comments.orDefault (nullptr ),
339
- text == nullptr ? nullptr : &Rewriter::thunk<Text>,
339
+ text == kj::none ? nullptr : &Rewriter::thunk<Text>,
340
340
text.orDefault (nullptr )));
341
341
}
342
342
KJ_CASE_ONEOF (documentHandlers, UnregisteredDocumentHandlers) {
@@ -348,13 +348,13 @@ kj::Own<lol_html_HtmlRewriter> Rewriter::buildRewriter(
348
348
// Adding document content handlers cannot fail, so no need for check().
349
349
lol_html_rewriter_builder_add_document_content_handlers (
350
350
builder,
351
- doctype == nullptr ? nullptr : &Rewriter::thunk<Doctype>,
351
+ doctype == kj::none ? nullptr : &Rewriter::thunk<Doctype>,
352
352
doctype.orDefault (nullptr ),
353
- comments == nullptr ? nullptr : &Rewriter::thunk<Comment>,
353
+ comments == kj::none ? nullptr : &Rewriter::thunk<Comment>,
354
354
comments.orDefault (nullptr ),
355
- text == nullptr ? nullptr : &Rewriter::thunk<Text>,
355
+ text == kj::none ? nullptr : &Rewriter::thunk<Text>,
356
356
text.orDefault (nullptr ),
357
- end == nullptr ? nullptr : &Rewriter::thunk<DocumentEnd>,
357
+ end == kj::none ? nullptr : &Rewriter::thunk<DocumentEnd>,
358
358
end.orDefault (nullptr ));
359
359
}
360
360
}
@@ -406,7 +406,7 @@ const kj::FiberPool& getFiberPool() {
406
406
} // namespace
407
407
408
408
kj::Promise<void > Rewriter::write (const void * buffer, size_t size) {
409
- KJ_ASSERT (maybeWaitScope == nullptr );
409
+ KJ_ASSERT (maybeWaitScope == kj::none );
410
410
return getFiberPool ().startFiber ([this , buffer, size](kj::WaitScope& scope) {
411
411
maybeWaitScope = scope;
412
412
if (!isPoisoned ()) {
@@ -423,7 +423,7 @@ kj::Promise<void> Rewriter::write(const void* buffer, size_t size) {
423
423
424
424
kj::Promise<void > Rewriter::write (
425
425
kj::ArrayPtr<const kj::ArrayPtr<const byte>> pieces) {
426
- KJ_ASSERT (maybeWaitScope == nullptr );
426
+ KJ_ASSERT (maybeWaitScope == kj::none );
427
427
return getFiberPool ().startFiber ([this , pieces](kj::WaitScope& scope) {
428
428
maybeWaitScope = scope;
429
429
if (!isPoisoned ()) {
@@ -444,7 +444,7 @@ kj::Promise<void> Rewriter::write(
444
444
}
445
445
446
446
kj::Promise<void > Rewriter::end () {
447
- KJ_ASSERT (maybeWaitScope == nullptr );
447
+ KJ_ASSERT (maybeWaitScope == kj::none );
448
448
return getFiberPool ().startFiber ([this ](kj::WaitScope& scope) {
449
449
maybeWaitScope = scope;
450
450
if (!isPoisoned ()) {
@@ -467,21 +467,21 @@ void Rewriter::abort(kj::Exception reason) {
467
467
}
468
468
469
469
kj::Promise<void > Rewriter::finishWrite () {
470
- maybeWaitScope = nullptr ;
470
+ maybeWaitScope = kj::none ;
471
471
auto checkException = [this ]() -> kj::Promise<void > {
472
- KJ_ASSERT (writePromise == nullptr );
472
+ KJ_ASSERT (writePromise == kj::none );
473
473
474
- KJ_IF_MAYBE (exception , maybeException) {
475
- inner->abort (kj::cp (* exception ));
476
- return kj::cp (* exception );
474
+ KJ_IF_SOME (exception , maybeException) {
475
+ inner->abort (kj::cp (exception ));
476
+ return kj::cp (exception );
477
477
}
478
478
479
479
return kj::READY_NOW;
480
480
};
481
481
482
- KJ_IF_MAYBE (wp, writePromise) {
483
- KJ_DEFER (writePromise = nullptr );
484
- return wp-> then ([checkException]() {
482
+ KJ_IF_SOME (wp, writePromise) {
483
+ KJ_DEFER (writePromise = kj::none );
484
+ return wp. then ([checkException]() {
485
485
return checkException ();
486
486
});
487
487
}
@@ -505,7 +505,7 @@ lol_html_rewriter_directive_t Rewriter::thunkImpl(
505
505
}
506
506
507
507
try {
508
- KJ_IF_MAYBE (exception , kj::runCatchingExceptions ([&] {
508
+ KJ_IF_SOME (exception , kj::runCatchingExceptions ([&] {
509
509
// V8 has a thread local pointer that points to where the stack limit is on this thread which
510
510
// is tested for overflows when we enter any JS code. However since we're running in a fiber
511
511
// here, we're in an entirely different stack that V8 doesn't know about, so it gets confused
@@ -518,7 +518,7 @@ lol_html_rewriter_directive_t Rewriter::thunkImpl(
518
518
// need to unwind the stack because we're probably still inside a cool_thing_rewriter_write().
519
519
// We can't unwind with an exception across the Rust/C++ boundary, so instead we'll keep this
520
520
// exception around and disable all later handlers.
521
- maybePoison (kj::mv (* exception ));
521
+ maybePoison (kj::mv (exception ));
522
522
return LOL_HTML_STOP;
523
523
}
524
524
} catch (kj::CanceledException) {
@@ -602,8 +602,8 @@ void Rewriter::outputImpl(const char* buffer, size_t size) {
602
602
}
603
603
604
604
auto bufferCopy = kj::heapArray (buffer, size);
605
- KJ_IF_MAYBE (wp, writePromise) {
606
- *wp = wp-> then ([this , bufferCopy = kj::mv (bufferCopy)]() mutable {
605
+ KJ_IF_SOME (wp, writePromise) {
606
+ writePromise = wp. then ([this , bufferCopy = kj::mv (bufferCopy)]() mutable {
607
607
return inner->write (bufferCopy.begin (), bufferCopy.size ()).attach (kj::mv (bufferCopy));
608
608
});
609
609
} else {
@@ -654,16 +654,16 @@ kj::Maybe<kj::String> Element::getAttribute(kj::String name) {
654
654
&checkToken (impl).element , name.cStr (), name.size ()));
655
655
// TODO(perf): We could construct a v8::String directly here, saving a copy.
656
656
kj::Maybe kjAttr = attr.asKjString ();
657
- if (kjAttr != nullptr ) {
657
+ if (kjAttr != kj::none ) {
658
658
return kj::mv (kjAttr);
659
659
}
660
660
661
- KJ_IF_MAYBE (exception , tryGetLastError ()) {
662
- kj::throwFatalException (kj::mv (* exception ));
661
+ KJ_IF_SOME (exception , tryGetLastError ()) {
662
+ kj::throwFatalException (kj::mv (exception ));
663
663
}
664
664
665
665
// No error, just doesn't exist.
666
- return nullptr ;
666
+ return kj::none ;
667
667
}
668
668
669
669
bool Element::hasAttribute (kj::String name) {
@@ -733,7 +733,7 @@ void Element::onEndTag(ElementCallbackFunction&& callback) {
733
733
EndTag::EndTag (CType& endTag, Rewriter&): impl(endTag) {}
734
734
735
735
void EndTag::htmlContentScopeEnd () {
736
- impl = nullptr ;
736
+ impl = kj::none ;
737
737
}
738
738
739
739
kj::String EndTag::getName () {
@@ -771,7 +771,7 @@ jsg::Ref<EndTag> EndTag::remove() {
771
771
}
772
772
773
773
void Element::htmlContentScopeEnd () {
774
- impl = nullptr ;
774
+ impl = kj::none ;
775
775
}
776
776
777
777
Element::Impl::Impl (CType& element, Rewriter& rewriter): element(element), rewriter(rewriter) {}
@@ -799,7 +799,7 @@ Element::AttributesIterator::Next Element::AttributesIterator::next() {
799
799
// End of iteration.
800
800
// TODO(someday): Eagerly deallocate. Can't seem to nullify the Own without also nullifying the
801
801
// enclosing Maybe, however.
802
- return { true , nullptr };
802
+ return { true , kj::none };
803
803
}
804
804
805
805
auto name = LolString (lol_html_attribute_name_get (attribute));
@@ -809,7 +809,7 @@ Element::AttributesIterator::Next Element::AttributesIterator::next() {
809
809
}
810
810
811
811
void Element::AttributesIterator::htmlContentScopeEnd () {
812
- impl = nullptr ;
812
+ impl = kj::none ;
813
813
}
814
814
815
815
// =======================================================================================
@@ -868,7 +868,7 @@ jsg::Ref<Comment> Comment::remove() {
868
868
}
869
869
870
870
void Comment::htmlContentScopeEnd () {
871
- impl = nullptr ;
871
+ impl = kj::none ;
872
872
}
873
873
874
874
// =======================================================================================
@@ -928,7 +928,7 @@ jsg::Ref<Text> Text::remove() {
928
928
}
929
929
930
930
void Text::htmlContentScopeEnd () {
931
- impl = nullptr ;
931
+ impl = kj::none ;
932
932
}
933
933
934
934
// =======================================================================================
@@ -952,7 +952,7 @@ kj::Maybe<kj::String> Doctype::getSystemId() {
952
952
}
953
953
954
954
void Doctype::htmlContentScopeEnd () {
955
- impl = nullptr ;
955
+ impl = kj::none ;
956
956
}
957
957
958
958
// =======================================================================================
@@ -971,7 +971,7 @@ jsg::Ref<DocumentEnd> DocumentEnd::append(Content content, jsg::Optional<Content
971
971
}
972
972
973
973
void DocumentEnd::htmlContentScopeEnd () {
974
- impl = nullptr ;
974
+ impl = kj::none ;
975
975
}
976
976
977
977
// =======================================================================================
@@ -1026,7 +1026,7 @@ jsg::Ref<HTMLRewriter> HTMLRewriter::onDocument(DocumentContentHandlers&& handle
1026
1026
jsg::Ref<Response> HTMLRewriter::transform (jsg::Lock& js, jsg::Ref<Response> response) {
1027
1027
auto maybeInput = response->getBody ();
1028
1028
1029
- if (maybeInput == nullptr ) {
1029
+ if (maybeInput == kj::none ) {
1030
1030
// That was easy!
1031
1031
return kj::mv (response);
1032
1032
}
@@ -1042,12 +1042,12 @@ jsg::Ref<Response> HTMLRewriter::transform(jsg::Lock& js, jsg::Ref<Response> res
1042
1042
kj::String ownContentType;
1043
1043
kj::String encoding = kj::str (" utf-8" );
1044
1044
auto contentTypeKey = jsg::ByteString (kj::str (" content-type" ));
1045
- KJ_IF_MAYBE (contentType, response->getHeaders (js)->get (kj::mv (contentTypeKey))) {
1045
+ KJ_IF_SOME (contentType, response->getHeaders (js)->get (kj::mv (contentTypeKey))) {
1046
1046
// TODO(cleanup): readContentTypeParameter can be replaced with using
1047
1047
// workerd/util/mimetype.h directly.
1048
- KJ_IF_MAYBE (charset, readContentTypeParameter (* contentType, " charset" )) {
1049
- ownContentType = kj::mv (* contentType);
1050
- encoding = kj::mv (* charset);
1048
+ KJ_IF_SOME (charset, readContentTypeParameter (contentType, " charset" )) {
1049
+ ownContentType = kj::mv (contentType);
1050
+ encoding = kj::mv (charset);
1051
1051
}
1052
1052
}
1053
1053
0 commit comments