mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:07:35 +00:00
LibJS: Implement Temporal.PlainDate.prototype.valueOf
This commit is contained in:
parent
3c62b661f4
commit
68aad5d8fa
3 changed files with 20 additions and 0 deletions
|
@ -26,6 +26,9 @@ void PlainDatePrototype::initialize(GlobalObject& global_object)
|
||||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), "Temporal.PlainDate"), Attribute::Configurable);
|
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), "Temporal.PlainDate"), Attribute::Configurable);
|
||||||
|
|
||||||
define_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable);
|
define_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable);
|
||||||
|
|
||||||
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||||
|
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PlainDate* typed_this(GlobalObject& global_object)
|
static PlainDate* typed_this(GlobalObject& global_object)
|
||||||
|
@ -54,4 +57,12 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::calendar_getter)
|
||||||
return Value(&temporal_date->calendar());
|
return Value(&temporal_date->calendar());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3.3.31 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.
|
||||||
|
vm.throw_exception<TypeError>(global_object, ErrorType::Convert, "Temporal.PlainDate", "a primitive value");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
||||||
|
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
test("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
Add a link
Reference in a new issue