From e4383dc630b441bb3ad32ad98e5daa16ada82e1e Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 8 Nov 2023 15:51:15 +0000 Subject: [PATCH] Bug 1856338 - Part 1: Implement Temporal.TimeZone.prototype.equals. r=mgaudet Implement the changes from . Differential Revision: https://phabricator.services.mozilla.com/D189772 UltraBlame original commit: 71b919fe3767226aba654ed1bf4df099c27c4eed --- js/src/builtin/temporal/TemporalParser.cpp | 487 +++++++++++-- js/src/builtin/temporal/TemporalParser.h | 35 + js/src/builtin/temporal/TimeZone.cpp | 752 +++++++++++++++++++++ js/src/builtin/temporal/TimeZone.h | 78 +++ js/src/builtin/temporal/ZonedDateTime.cpp | 154 +---- 5 files changed, 1309 insertions(+), 197 deletions(-) diff --git a/js/src/builtin/temporal/TemporalParser.cpp b/js/src/builtin/temporal/TemporalParser.cpp index 6952005fa9a11..1dac6fb2055dd 100644 --- a/js/src/builtin/temporal/TemporalParser.cpp +++ b/js/src/builtin/temporal/TemporalParser.cpp @@ -5459,6 +5459,18 @@ Result TimeZoneAnnotation ParserError > +timeZoneIdentifier +( +) +; +mozilla +: +: +Result +< +TimeZoneAnnotation +ParserError +> timeZoneAnnotation ( ) @@ -5639,6 +5651,18 @@ mozilla : Result < +TimeZoneAnnotation +ParserError +> +parseTimeZoneIdentifier +( +) +; +mozilla +: +: +Result +< TimeZoneUTCOffset ParserError > @@ -7714,25 +7738,12 @@ CharT > : : -timeZoneAnnotation +timeZoneIdentifier ( ) { / / -TimeZoneAnnotation -: -/ -/ -[ -AnnotationCriticalFlag -? -TimeZoneIdentifier -] -/ -/ -/ -/ TimeZoneIdentifier : / @@ -7741,40 +7752,6 @@ TimeZoneIANAName / / TimeZoneUTCOffsetName -if -( -! -character -( -' -[ -' -) -) -{ -return -mozilla -: -: -Err -( -JSMSG_TEMPORAL_PARSER_BRACKET_BEFORE_TIMEZONE -) -; -} -/ -/ -Skip -over -the -optional -critical -flag -. -annotationCriticalFlag -( -) -; TimeZoneAnnotation result = @@ -7860,6 +7837,102 @@ unwrap ) ; } +return +result +; +} +template +< +typename +CharT +> +mozilla +: +: +Result +< +TimeZoneAnnotation +ParserError +> +TemporalParser +< +CharT +> +: +: +timeZoneAnnotation +( +) +{ +/ +/ +TimeZoneAnnotation +: +/ +/ +[ +AnnotationCriticalFlag +? +TimeZoneIdentifier +] +if +( +! +character +( +' +[ +' +) +) +{ +return +mozilla +: +: +Err +( +JSMSG_TEMPORAL_PARSER_BRACKET_BEFORE_TIMEZONE +) +; +} +/ +/ +Skip +over +the +optional +critical +flag +. +annotationCriticalFlag +( +) +; +auto +result += +timeZoneIdentifier +( +) +; +if +( +result +. +isErr +( +) +) +{ +return +result +. +propagateErr +( +) +; +} if ( ! @@ -9971,6 +10044,324 @@ mozilla : Result < +TimeZoneAnnotation +ParserError +> +TemporalParser +< +CharT +> +: +: +parseTimeZoneIdentifier +( +) +{ +auto +result += +timeZoneIdentifier +( +) +; +if +( +result +. +isErr +( +) +) +{ +return +result +. +propagateErr +( +) +; +} +if +( +! +reader_ +. +atEnd +( +) +) +{ +return +mozilla +: +: +Err +( +JSMSG_TEMPORAL_PARSER_GARBAGE_AFTER_INPUT +) +; +} +return +result +; +} +/ +* +* +* +ParseTimeZoneIdentifier +( +identifier +) +* +/ +template +< +typename +CharT +> +static +auto +ParseTimeZoneIdentifier +( +mozilla +: +: +Span +< +const +CharT +> +str +) +{ +TemporalParser +< +CharT +> +parser +( +str +) +; +return +parser +. +parseTimeZoneIdentifier +( +) +; +} +/ +* +* +* +ParseTimeZoneIdentifier +( +identifier +) +* +/ +static +auto +ParseTimeZoneIdentifier +( +Handle +< +JSLinearString +* +> +str +) +{ +JS +: +: +AutoCheckCannotGC +nogc +; +if +( +str +- +> +hasLatin1Chars +( +) +) +{ +return +ParseTimeZoneIdentifier +< +Latin1Char +> +( +str +- +> +latin1Range +( +nogc +) +) +; +} +return +ParseTimeZoneIdentifier +< +char16_t +> +( +str +- +> +twoByteRange +( +nogc +) +) +; +} +/ +* +* +* +ParseTimeZoneIdentifier +( +identifier +) +* +/ +bool +js +: +: +temporal +: +: +ParseTimeZoneIdentifier +( +JSContext +* +cx +Handle +< +JSString +* +> +str +MutableHandle +< +ParsedTimeZone +> +result +) +{ +Rooted +< +JSLinearString +* +> +linear +( +cx +str +- +> +ensureLinear +( +cx +) +) +; +if +( +! +linear +) +{ +return +false +; +} +/ +/ +Steps +1 +- +2 +. +auto +parseResult += +: +: +ParseTimeZoneIdentifier +( +linear +) +; +if +( +parseResult +. +isErr +( +) +) +{ +JS_ReportErrorNumberASCII +( +cx +GetErrorMessage +nullptr +parseResult +. +unwrapErr +( +) +) +; +return +false +; +} +auto +timeZone += +parseResult +. +unwrap +( +) +; +/ +/ +Steps +3 +- +4 +. +return +ParseTimeZoneAnnotation +( +cx +timeZone +linear +result +) +; +} +template +< +typename +CharT +> +mozilla +: +: +Result +< TimeZoneUTCOffset ParserError > diff --git a/js/src/builtin/temporal/TemporalParser.h b/js/src/builtin/temporal/TemporalParser.h index d04236f6e7a11..2e958eacd3697 100644 --- a/js/src/builtin/temporal/TemporalParser.h +++ b/js/src/builtin/temporal/TemporalParser.h @@ -356,6 +356,41 @@ result * * * +ParseTimeZoneIdentifier +( +identifier +) +* +/ +bool +ParseTimeZoneIdentifier +( +JSContext +* +cx +JS +: +: +Handle +< +JSString +* +> +str +JS +: +: +MutableHandle +< +ParsedTimeZone +> +result +) +; +/ +* +* +* ParseTimeZoneOffsetString ( isoString diff --git a/js/src/builtin/temporal/TimeZone.cpp b/js/src/builtin/temporal/TimeZone.cpp index 28a4d016702c2..d58c37b576ddb 100644 --- a/js/src/builtin/temporal/TimeZone.cpp +++ b/js/src/builtin/temporal/TimeZone.cpp @@ -6707,6 +6707,557 @@ n ; } / +* +* +* +TimeZoneEquals +( +one +two +) +* +/ +bool +js +: +: +temporal +: +: +TimeZoneEquals +( +JSContext +* +cx +Handle +< +JSString +* +> +one +Handle +< +JSString +* +> +two +bool +* +equals +) +{ +/ +/ +Steps +1 +- +3 +. +( +Not +applicable +) +/ +/ +Step +4 +. +if +( +! +EqualStrings +( +cx +one +two +equals +) +) +{ +return +false +; +} +if +( +* +equals +) +{ +return +true +; +} +/ +/ +Step +5 +. +Rooted +< +ParsedTimeZone +> +timeZoneOne +( +cx +) +; +if +( +! +ParseTimeZoneIdentifier +( +cx +one +& +timeZoneOne +) +) +{ +return +false +; +} +/ +/ +Step +6 +. +Rooted +< +ParsedTimeZone +> +timeZoneTwo +( +cx +) +; +if +( +! +ParseTimeZoneIdentifier +( +cx +two +& +timeZoneTwo +) +) +{ +return +false +; +} +/ +/ +Step +7 +. +if +( +timeZoneOne +. +name +( +) +& +& +timeZoneTwo +. +name +( +) +) +{ +/ +/ +Step +7 +. +a +. +Rooted +< +JSAtom +* +> +validTimeZoneOne +( +cx +) +; +if +( +! +IsValidTimeZoneName +( +cx +timeZoneOne +. +name +( +) +& +validTimeZoneOne +) +) +{ +return +false +; +} +if +( +! +validTimeZoneOne +) +{ +* +equals += +false +; +return +true +; +} +/ +/ +Step +7 +. +b +. +Rooted +< +JSAtom +* +> +validTimeZoneTwo +( +cx +) +; +if +( +! +IsValidTimeZoneName +( +cx +timeZoneTwo +. +name +( +) +& +validTimeZoneTwo +) +) +{ +return +false +; +} +if +( +! +validTimeZoneTwo +) +{ +* +equals += +false +; +return +true +; +} +/ +/ +Step +7 +. +c +and +9 +. +Rooted +< +JSString +* +> +canonicalOne +( +cx +CanonicalizeTimeZoneName +( +cx +validTimeZoneOne +) +) +; +if +( +! +canonicalOne +) +{ +return +false +; +} +JSString +* +canonicalTwo += +CanonicalizeTimeZoneName +( +cx +validTimeZoneTwo +) +; +if +( +! +canonicalTwo +) +{ +return +false +; +} +return +EqualStrings +( +cx +canonicalOne +canonicalTwo +equals +) +; +} +/ +/ +Step +8 +. +a +. +if +( +! +timeZoneOne +. +name +( +) +& +& +! +timeZoneTwo +. +name +( +) +) +{ +* +equals += +( +timeZoneOne +. +offset +( +) += += +timeZoneTwo +. +offset +( +) +) +; +return +true +; +} +/ +/ +Step +9 +. +* +equals += +false +; +return +true +; +} +/ +* +* +* +TimeZoneEquals +( +one +two +) +* +/ +bool +js +: +: +temporal +: +: +TimeZoneEquals +( +JSContext +* +cx +Handle +< +TimeZoneValue +> +one +Handle +< +TimeZoneValue +> +two +bool +* +equals +) +{ +/ +/ +Step +1 +. +if +( +one +. +isObject +( +) +& +& +two +. +isObject +( +) +& +& +one +. +toObject +( +) += += +two +. +toObject +( +) +) +{ +* +equals += +true +; +return +true +; +} +/ +/ +Step +2 +. +Rooted +< +JSString +* +> +timeZoneOne +( +cx +ToTemporalTimeZoneIdentifier +( +cx +one +) +) +; +if +( +! +timeZoneOne +) +{ +return +false +; +} +/ +/ +Step +3 +. +Rooted +< +JSString +* +> +timeZoneTwo +( +cx +ToTemporalTimeZoneIdentifier +( +cx +two +) +) +; +if +( +! +timeZoneTwo +) +{ +return +false +; +} +/ +/ +Steps +4 +- +9 +. +return +TimeZoneEquals +( +cx +timeZoneOne +timeZoneTwo +equals +) +; +} +/ / ES2019 draft @@ -10606,6 +11157,198 @@ TimeZone . prototype . +equals +( +other +) +* +/ +static +bool +TimeZone_equals +( +JSContext +* +cx +const +CallArgs +& +args +) +{ +Rooted +< +TimeZoneValue +> +timeZone +( +cx +& +args +. +thisv +( +) +. +toObject +( +) +) +; +/ +/ +FIXME +: +spec +bug +- +argument +needs +to +be +converted +to +time +zone +. +Rooted +< +TimeZoneValue +> +other +( +cx +) +; +if +( +! +ToTemporalTimeZone +( +cx +args +. +get +( +0 +) +& +other +) +) +{ +return +false +; +} +/ +/ +Step +3 +. +bool +equals +; +if +( +! +TimeZoneEquals +( +cx +timeZone +other +& +equals +) +) +{ +return +false +; +} +args +. +rval +( +) +. +setBoolean +( +equals +) +; +return +true +; +} +/ +* +* +* +Temporal +. +TimeZone +. +prototype +. +equals +( +other +) +* +/ +static +bool +TimeZone_equals +( +JSContext +* +cx +unsigned +argc +Value +* +vp +) +{ +/ +/ +Steps +1 +- +2 +. +CallArgs +args += +CallArgsFromVp +( +argc +vp +) +; +return +CallNonGenericMethod +< +IsTimeZone +TimeZone_equals +> +( +cx +args +) +; +} +/ +* +* +* +Temporal +. +TimeZone +. +prototype +. getOffsetNanosecondsFor ( instant @@ -12957,6 +13700,15 @@ TimeZone_prototype_methods JS_FN ( " +equals +" +TimeZone_equals +1 +0 +) +JS_FN +( +" getOffsetNanosecondsFor " TimeZone_getOffsetNanosecondsFor diff --git a/js/src/builtin/temporal/TimeZone.h b/js/src/builtin/temporal/TimeZone.h index d6525cd0a7198..2406f9938f545 100644 --- a/js/src/builtin/temporal/TimeZone.h +++ b/js/src/builtin/temporal/TimeZone.h @@ -1737,6 +1737,84 @@ timeZone * * * +TimeZoneEquals +( +one +two +) +* +/ +bool +TimeZoneEquals +( +JSContext +* +cx +JS +: +: +Handle +< +JSString +* +> +one +JS +: +: +Handle +< +JSString +* +> +two +bool +* +equals +) +; +/ +* +* +* +TimeZoneEquals +( +one +two +) +* +/ +bool +TimeZoneEquals +( +JSContext +* +cx +JS +: +: +Handle +< +TimeZoneValue +> +one +JS +: +: +Handle +< +TimeZoneValue +> +two +bool +* +equals +) +; +/ +* +* +* GetPlainDateTimeFor ( timeZone diff --git a/js/src/builtin/temporal/ZonedDateTime.cpp b/js/src/builtin/temporal/ZonedDateTime.cpp index 21d3832fc2589..65eb470b77d29 100644 --- a/js/src/builtin/temporal/ZonedDateTime.cpp +++ b/js/src/builtin/temporal/ZonedDateTime.cpp @@ -6238,7 +6238,7 @@ two / static bool -TimeZoneEquals +TimeZoneEqualsOrThrow ( JSContext * @@ -6253,9 +6253,6 @@ Handle TimeZoneValue > two -bool -* -equals ) { / @@ -6293,11 +6290,6 @@ toObject ) ) { -* -equals -= -true -; return true ; @@ -6337,156 +6329,20 @@ false Step 3 . -JSString -* -timeZoneTwo -= -ToTemporalTimeZoneIdentifier -( -cx -two -) -; -if -( -! -timeZoneTwo -) -{ -return -false -; -} -/ -/ -Steps -4 -- -5 -. -return -EqualStrings -( -cx -timeZoneOne -timeZoneTwo -equals -) -; -} -/ -* -* -* -TimeZoneEquals -( -one -two -) -* -/ -static -bool -TimeZoneEqualsOrThrow -( -JSContext -* -cx -Handle -< -TimeZoneValue -> -one -Handle -< -TimeZoneValue -> -two -) -{ -/ -/ -Step -1 -. -if -( -one -. -isObject -( -) -& -& -two -. -isObject -( -) -& -& -one -. -toObject -( -) -= -= -two -. -toObject -( -) -) -{ -return -true -; -} -/ -/ -Step -2 -. Rooted < JSString * > -timeZoneOne -( -cx -ToTemporalTimeZoneIdentifier +timeZoneTwo ( cx -one -) -) -; -if -( -! -timeZoneOne -) -{ -return -false -; -} -/ -/ -Step -3 -. -JSString -* -timeZoneTwo -= ToTemporalTimeZoneIdentifier ( cx two ) +) ; if ( @@ -6503,7 +6359,7 @@ false Steps 4 - -5 +9 . bool equals @@ -6511,7 +6367,7 @@ equals if ( ! -EqualStrings +TimeZoneEquals ( cx timeZoneOne