diff options
author | Linus Groh <mail@linusgroh.de> | 2021-08-05 21:35:40 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-08-05 23:15:27 +0100 |
commit | 20300bd7c415c1865530bad990645364f7144da4 (patch) | |
tree | 821095839ae814c72b4ddea0fc418ce9b9997820 /Userland/Libraries | |
parent | 3e909c0c49d687f1e1aa53cf9a8ed7ffecffbf2a (diff) | |
download | serenity-20300bd7c415c1865530bad990645364f7144da4.zip |
LibJS: Implement Temporal.ZonedDateTime.prototype.valueOf()
Diffstat (limited to 'Userland/Libraries')
3 files changed, 23 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp index f96070a902..12d40b098d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp @@ -56,6 +56,9 @@ void ZonedDateTimePrototype::initialize(GlobalObject& global_object) define_native_accessor(vm.names.inLeapYear, in_leap_year_getter, {}, Attribute::Configurable); define_native_accessor(vm.names.offsetNanoseconds, offset_nanoseconds_getter, {}, Attribute::Configurable); define_native_accessor(vm.names.offset, offset_getter, {}, Attribute::Configurable); + + u8 attr = Attribute::Writable | Attribute::Configurable; + define_native_function(vm.names.valueOf, value_of, 0, attr); } static ZonedDateTime* typed_this(GlobalObject& global_object) @@ -691,4 +694,12 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::offset_getter) return js_string(vm, move(*offset_string)); } +// 6.3.44 Temporal.ZonedDateTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.valueof +JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::value_of) +{ + // 1. Throw a TypeError exception. + vm.throw_exception<TypeError>(global_object, ErrorType::Convert, "Temporal.ZonedDateTime", "a primitive value"); + return {}; +} + } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.h b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.h index da58688653..02b0393d05 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.h @@ -45,6 +45,7 @@ private: JS_DECLARE_NATIVE_FUNCTION(in_leap_year_getter); JS_DECLARE_NATIVE_FUNCTION(offset_nanoseconds_getter); JS_DECLARE_NATIVE_FUNCTION(offset_getter); + JS_DECLARE_NATIVE_FUNCTION(value_of); }; } diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/ZonedDateTime/ZonedDateTime.prototype.valueOf.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/ZonedDateTime/ZonedDateTime.prototype.valueOf.js new file mode 100644 index 0000000000..bf65a5b641 --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/ZonedDateTime/ZonedDateTime.prototype.valueOf.js @@ -0,0 +1,11 @@ +test("errors", () => { + test("throws TypeError", () => { + const timeZone = new Temporal.TimeZone("UTC"); + expect(() => { + new Temporal.ZonedDateTime(0n, timeZone).valueOf(); + }).toThrowWithMessage( + TypeError, + "Cannot convert Temporal.ZonedDateTime to a primitive value" + ); + }); +}); |