mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibJS: Implement Temporal.PlainTime.prototype.valueOf
This commit is contained in:
@@ -46,6 +46,7 @@ void PlainTimePrototype::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);
|
||||
}
|
||||
|
||||
// 4.3.3 get Temporal.PlainTime.prototype.hour, https://tc39.es/proposal-temporal/#sec-get-temporal.plaintime.prototype.hour
|
||||
@@ -336,4 +337,11 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_json)
|
||||
return PrimitiveString::create(vm, time_record_to_string(temporal_time->time(), Auto {}));
|
||||
}
|
||||
|
||||
// 4.3.19 Temporal.PlainTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.valueof
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::value_of)
|
||||
{
|
||||
// 1. Throw a TypeError exception.
|
||||
return vm.throw_completion<TypeError>(ErrorType::Convert, "Temporal.PlainTime", "a primitive value");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,6 +39,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.PlainTime(19, 54, 38).valueOf();
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert Temporal.PlainTime to a primitive value");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user