mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 10:12:25 -05:00
LibJS: Implement Temporal.PlainDate.prototype.valueOf
This commit is contained in:
parent
f8b593a7df
commit
06ef32818e
Notes:
github-actions[bot]
2024-11-23 13:47:36 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/06ef32818e3 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2513 Reviewed-by: https://github.com/shannonbooth ✅
3 changed files with 16 additions and 0 deletions
|
@ -62,6 +62,7 @@ void PlainDatePrototype::initialize(Realm& realm)
|
|||
define_native_function(realm, vm.names.toString, to_string, 0, attr);
|
||||
define_native_function(realm, vm.names.toLocaleString, to_locale_string, 0, attr);
|
||||
define_native_function(realm, vm.names.toJSON, to_json, 0, attr);
|
||||
define_native_function(realm, vm.names.valueOf, value_of, 0, attr);
|
||||
}
|
||||
|
||||
// 3.3.3 get Temporal.PlainDate.prototype.calendarId, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.calendarid
|
||||
|
@ -401,4 +402,11 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_json)
|
|||
return PrimitiveString::create(vm, temporal_date_to_string(temporal_date, ShowCalendar::Auto));
|
||||
}
|
||||
|
||||
// 3.3.33 Temporal.PlainDate.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.valueof
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::value_of)
|
||||
{
|
||||
// 1. Throw a TypeError exception.
|
||||
return vm.throw_completion<TypeError>(ErrorType::Convert, "Temporal.PlainDate", "a primitive value");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_locale_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_json);
|
||||
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
describe("errors", () => {
|
||||
test("throws TypeError", () => {
|
||||
expect(() => {
|
||||
new Temporal.PlainDate(2021, 7, 21).valueOf();
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert Temporal.PlainDate to a primitive value");
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue