mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-19 09:17:38 +03:00
LibJS: Implement Temporal.Calendar.prototype.id
This commit is contained in:
parent
3ee169d8e7
commit
466c5bc96d
Notes:
sideshowbarker
2024-07-18 09:00:19 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/466c5bc96d0 Pull-request: https://github.com/SerenityOS/serenity/pull/8753 Reviewed-by: https://github.com/IdanHo ✅
@ -26,6 +26,7 @@ void CalendarPrototype::initialize(GlobalObject& global_object)
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), "Temporal.Calendar"), Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_accessor(vm.names.id, id_getter, {}, Attribute::Configurable);
|
||||
define_native_function(vm.names.toString, to_string, 0, attr);
|
||||
define_native_function(vm.names.toJSON, to_json, 0, attr);
|
||||
}
|
||||
@ -43,6 +44,16 @@ static Calendar* typed_this(GlobalObject& global_object)
|
||||
return static_cast<Calendar*>(this_object);
|
||||
}
|
||||
|
||||
// 12.4.3 get Temporal.Calendar.prototype.id, https://tc39.es/proposal-temporal/#sec-get-temporal.calendar.prototype.id
|
||||
JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::id_getter)
|
||||
{
|
||||
// 1. Let calendar be the this value.
|
||||
auto calendar = vm.this_value(global_object);
|
||||
|
||||
// 2. Return ? ToString(calendar).
|
||||
return js_string(vm, calendar.to_string(global_object));
|
||||
}
|
||||
|
||||
// 12.4.23 Temporal.Calendar.prototype.toString ( ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.tostring
|
||||
JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::to_string)
|
||||
{
|
||||
|
@ -19,6 +19,7 @@ public:
|
||||
virtual ~CalendarPrototype() override = default;
|
||||
|
||||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(id_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_json);
|
||||
};
|
||||
|
@ -29,8 +29,7 @@ describe("normal behavior", () => {
|
||||
|
||||
test("basic functionality", () => {
|
||||
const calendar = new Temporal.Calendar("iso8601");
|
||||
// FIXME: Enable this once Temporal.Calendar.prototype.id is implemented
|
||||
// expect(calendar.id).toBe("iso8601");
|
||||
expect(calendar.id).toBe("iso8601");
|
||||
expect(typeof calendar).toBe("object");
|
||||
expect(calendar).toBeInstanceOf(Temporal.Calendar);
|
||||
expect(Object.getPrototypeOf(calendar)).toBe(Temporal.Calendar.prototype);
|
||||
|
@ -0,0 +1,10 @@
|
||||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const calendar = new Temporal.Calendar("iso8601");
|
||||
expect(calendar.id).toBe("iso8601");
|
||||
});
|
||||
|
||||
test("works with any this value", () => {
|
||||
expect(Reflect.get(Temporal.Calendar.prototype, "id", "foo")).toBe("foo");
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user