1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:37:45 +00:00

LibJS: Implement Temporal.TimeZone.prototype.toJSON()

This commit is contained in:
Linus Groh 2021-07-08 20:43:15 +01:00
parent 8d00504ff2
commit 7f0fe352e2
3 changed files with 26 additions and 0 deletions

View file

@ -24,6 +24,7 @@ void TimeZonePrototype::initialize(GlobalObject& global_object)
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(vm.names.toString, to_string, 0, attr);
define_native_function(vm.names.toJSON, to_json, 0, attr);
// 11.4.2 Temporal.TimeZone.prototype[ @@toStringTag ], https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), "Temporal.TimeZone"), Attribute::Configurable);
@ -55,4 +56,14 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::to_string)
return js_string(vm, time_zone->identifier());
}
// 11.4.12 Temporal.TimeZone.prototype.toJSON ( ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.tojson
JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::to_json)
{
// 1. Let timeZone be the this value.
auto time_zone = vm.this_value(global_object);
// 2. Return ? ToString(timeZone).
return js_string(vm, time_zone.to_string(global_object));
}
}

View file

@ -20,6 +20,7 @@ public:
private:
JS_DECLARE_NATIVE_FUNCTION(to_string);
JS_DECLARE_NATIVE_FUNCTION(to_json);
};
}