Skip to content

Commit

Permalink
Update Temporal.Now.timeZone() to timeZoneId()
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=265121

Reviewed by Yusuke Suzuki.

The Temporal API spec has changed such that Temporal.Now now has a timeZoneId method instead of a timeZone method.
This patch adapts our implementation accordingly.

* JSTests/complex/temporal-now-timezone-check.js:
* JSTests/complex/temporal-now-timezone-with-broken-tz.js:
* JSTests/test262/expectations.yaml: Mark 12 test cases as passing.
* Source/JavaScriptCore/runtime/TemporalNow.cpp:

Canonical link: https://commits.webkit.org/271003@main
  • Loading branch information
rkirsling committed Nov 21, 2023
1 parent ee55f47 commit 8ec78f0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
2 changes: 1 addition & 1 deletion JSTests/complex/temporal-now-timezone-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ function shouldBe(actual, expected) {
throw new Error('bad value: ' + actual);
}

shouldBe(Temporal.Now.timeZone().id, `America/Los_Angeles`);
shouldBe(Temporal.Now.timeZoneId(), `America/Los_Angeles`);
2 changes: 1 addition & 1 deletion JSTests/complex/temporal-now-timezone-with-broken-tz.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ function shouldBe(actual, expected) {
throw new Error('bad value: ' + actual);
}

shouldBe(Temporal.Now.timeZone().id, `UTC`);
shouldBe(Temporal.Now.timeZoneId(), `UTC`);
18 changes: 0 additions & 18 deletions JSTests/test262/expectations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -340,24 +340,6 @@ test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfTrunc.js:
test/built-ins/Temporal/Instant/prototype/until/roundingmode-trunc.js:
default: 'Test262Error: rounds to hours (rounding mode = trunc, negative case) hours result Expected SameValue(«-376436», «-376435») to be true'
strict mode: 'Test262Error: rounds to hours (rounding mode = trunc, negative case) hours result Expected SameValue(«-376436», «-376435») to be true'
test/built-ins/Temporal/Now/timeZoneId/extensible.js:
default: 'Test262Error: Object.isExtensible(Temporal.Now.timeZoneId) must return true'
strict mode: 'Test262Error: Object.isExtensible(Temporal.Now.timeZoneId) must return true'
test/built-ins/Temporal/Now/timeZoneId/length.js:
default: "TypeError: undefined is not an object (evaluating 'Object.getOwnPropertyDescriptor(obj, name)')"
strict mode: "TypeError: undefined is not an object (evaluating 'Object.getOwnPropertyDescriptor(obj, name)')"
test/built-ins/Temporal/Now/timeZoneId/name.js:
default: "TypeError: undefined is not an object (evaluating 'Temporal.Now.timeZoneId.name')"
strict mode: "TypeError: undefined is not an object (evaluating 'Temporal.Now.timeZoneId.name')"
test/built-ins/Temporal/Now/timeZoneId/not-a-constructor.js:
default: 'Test262Error: isConstructor invoked with a non-function value'
strict mode: 'Test262Error: isConstructor invoked with a non-function value'
test/built-ins/Temporal/Now/timeZoneId/prop-desc.js:
default: 'Test262Error: typeof is function Expected SameValue(«undefined», «function») to be true'
strict mode: 'Test262Error: typeof is function Expected SameValue(«undefined», «function») to be true'
test/built-ins/Temporal/Now/timeZoneId/return-value.js:
default: "TypeError: Temporal.Now.timeZoneId is not a function. (In 'Temporal.Now.timeZoneId()', 'Temporal.Now.timeZoneId' is undefined)"
strict mode: "TypeError: Temporal.Now.timeZoneId is not a function. (In 'Temporal.Now.timeZoneId()', 'Temporal.Now.timeZoneId' is undefined)"
test/built-ins/Temporal/PlainDate/calendar-case-insensitive.js:
default: 'Test262Error: Calendar is case-insensitive Expected SameValue(«undefined», «iso8601») to be true'
strict mode: 'Test262Error: Calendar is case-insensitive Expected SameValue(«undefined», «iso8601») to be true'
Expand Down
17 changes: 6 additions & 11 deletions Source/JavaScriptCore/runtime/TemporalNow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace JSC {
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(TemporalNow);

static JSC_DECLARE_HOST_FUNCTION(temporalNowFuncInstant);
static JSC_DECLARE_HOST_FUNCTION(temporalNowFuncTimeZone);
static JSC_DECLARE_HOST_FUNCTION(temporalNowFuncTimeZoneId);

} // namespace JSC

Expand All @@ -44,7 +44,7 @@ namespace JSC {
/* Source for TemporalNow.lut.h
@begin temporalNowTable
instant temporalNowFuncInstant DontEnum|Function 0
timeZone temporalNowFuncTimeZone DontEnum|Function 0
timeZoneId temporalNowFuncTimeZoneId DontEnum|Function 0
@end
*/

Expand Down Expand Up @@ -80,17 +80,12 @@ JSC_DEFINE_HOST_FUNCTION(temporalNowFuncInstant, (JSGlobalObject* globalObject,
return JSValue::encode(TemporalInstant::tryCreateIfValid(globalObject, ISO8601::ExactTime::now()));
}

// https://tc39.es/proposal-temporal/#sec-temporal.now.timezone
// https://tc39.es/proposal-temporal/#sec-temporal-systemtimezone
JSC_DEFINE_HOST_FUNCTION(temporalNowFuncTimeZone, (JSGlobalObject* globalObject, CallFrame*))
// https://tc39.es/proposal-temporal/#sec-temporal.now.timezoneid
// https://tc39.es/proposal-temporal/#sec-temporal-systemtimezoneidentifier
JSC_DEFINE_HOST_FUNCTION(temporalNowFuncTimeZoneId, (JSGlobalObject* globalObject, CallFrame*))
{
VM& vm = globalObject->vm();

String timeZoneString = vm.dateCache.defaultTimeZone();
std::optional<TimeZoneID> identifier = ISO8601::parseTimeZoneName(timeZoneString);
if (!identifier)
return JSValue::encode(TemporalTimeZone::createFromUTCOffset(vm, globalObject->timeZoneStructure(), 0));
return JSValue::encode(TemporalTimeZone::createFromID(vm, globalObject->timeZoneStructure(), identifier.value()));
return JSValue::encode(jsNontrivialString(vm, vm.dateCache.defaultTimeZone()));
}

} // namespace JSC

0 comments on commit 8ec78f0

Please sign in to comment.