mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:47:35 +00:00
LibJS: Implement Temporal.Calendar.prototype.toJSON()
This commit is contained in:
parent
83bbbbe567
commit
3ee169d8e7
3 changed files with 26 additions and 0 deletions
|
@ -27,6 +27,7 @@ void CalendarPrototype::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);
|
||||
}
|
||||
|
||||
static Calendar* typed_this(GlobalObject& global_object)
|
||||
|
@ -55,4 +56,14 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::to_string)
|
|||
return js_string(vm, calendar->identifier());
|
||||
}
|
||||
|
||||
// 12.4.24 Temporal.Calendar.prototype.toJSON ( ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.tojson
|
||||
JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::to_json)
|
||||
{
|
||||
// 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public:
|
|||
|
||||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_json);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 0", () => {
|
||||
expect(Temporal.Calendar.prototype.toJSON).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
const calendar = new Temporal.Calendar("iso8601");
|
||||
expect(calendar.toJSON()).toBe("iso8601");
|
||||
});
|
||||
|
||||
test("works with any this value", () => {
|
||||
expect(Temporal.Calendar.prototype.toJSON.call("foo")).toBe("foo");
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue