Difficult to use FormattedNumberRange and FormattedNumber as Maybe<> return type in v8

Description

In v8 code base, one design pattern is having a Maybe<T> as return type.

This in general work for may ICU type, for example

Maybe<icu::Formattable> ToFormattable(Isolate* isolate, Handle<Object> obj, const char* field)

in https://source.chromium.org/chromium/chromium/src/+/main:v8/src/objects/js-number-format.cc;l=1706?q=Maybe<icu::&ss=chromium

or

Maybe<icu::UnicodeString> of(Isolate* isolate, const char* code) const override {

in https://source.chromium.org/chromium/chromium/src/+/main:v8/src/objects/js-display-names.cc;l=127?q=Maybe<icu::&ss=chromium

or

Maybe<icu::Locale> CreateICULocale(const std::string& bcp47_locale) {

in https://source.chromium.org/chromium/chromium/src/+/main:v8/src/objects/intl-objects.cc;l=446;bpv=1;bpt=1?q=Maybe<icu::&ss=chromium

However it does not work with

FormattedNumberRange and FormattedNumber

 

If change the function

static Maybe<bool> FormatRange( Isolate* isolate, const icu::number::LocalizedNumberRangeFormatter& number_range_format, const IntlMathematicalValue& x, const IntlMathematicalValue& y, icu::number::FormattedNumberRange* output);

to

static Maybe<icu::number::FormattedNumberRange> FormatRange( Isolate* isolate, const icu::number::LocalizedNumberRangeFormatter& number_range_format, const IntlMathematicalValue& x, const IntlMathematicalValue& y);

It does not work and show me the following error message

../../include/v8-maybe.h:84:50: error: call to deleted constructor of 'icu_71::number::FormattedNumberRange' explicit Maybe(const T& t) : has_value_(true), value_(t) {} ^ ~ ../../include/v8-maybe.h:102:10: note: in instantiation of member function 'v8::Maybe<icu_71::number::FormattedNumberRange>::Maybe' requested here return Maybe<T>(t); ^ ../../src/objects/js-number-format.cc:1949:10: note: in instantiation of function template specialization 'v8::Just<icu_71::number::FormattedNumberRange>' requested here return Just(output); ^ ../../third_party/icu/source/i18n/unicode/numberrangeformatter.h:661:5: note: 'FormattedNumberRange' has been explicitly marked deleted here FormattedNumberRange(const FormattedNumberRange&) = delete; ^ 1 error generated. ninja: build stopped: subcommand failed.

The implementation of the Maybe tempalate can be found in

https://source.chromium.org/chromium/chromium/src/+/main:v8/include/v8-maybe.h;drc=8dfda019b0ba2f4953d36071b4601948e1bcf690;l=29

Same as FormattedNumber

Please help to figure out how can we change ICU api to let v8 use Maybe<> as return for FormattedNumber and FormattedNumberRange.

Activity

Show:

Frank Yung-Fong Tang 
May 26, 2022 at 5:10 PM

This issue is addressed in v8 side. I will mark this bug as invalid now.

Frank Yung-Fong Tang 
April 25, 2022 at 8:15 PM

It seems this is no longer an issue once https://chromium-review.googlesource.com/c/v8/v8/+/3606229 checked in. I will mark this bug as WaI one that cl lands into v8.

Markus Scherer 
April 24, 2022 at 6:03 PM

Maybe<T> should be made to work with types that are not copyable. These ICU types are at least movable.

Frank Yung-Fong Tang 
April 24, 2022 at 12:27 AM

Or what should we propose to v8 to make their Maybe to accept them?

Frank Yung-Fong Tang 
April 24, 2022 at 12:18 AM

So… what will be the draw back if they do not have deleted copy constructors?

Working as Designed

Details

Assignee

Reporter

Components

Priority

Created April 23, 2022 at 6:58 AM
Updated May 26, 2022 at 5:11 PM
Resolved May 26, 2022 at 5:11 PM