1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00

LibJS: Implement Temporal.PlainTime.prototype.valueOf

This commit is contained in:
Timothy Flynn 2024-11-23 14:20:26 -05:00 committed by Tim Flynn
parent d639e9429f
commit e37c9eaeff
Notes: github-actions[bot] 2024-11-24 00:37:23 +00:00
3 changed files with 16 additions and 0 deletions

View file

@ -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");
}
}

View file

@ -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);
};
}

View file

@ -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");
});
});