mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-19 09:17:38 +03:00
LibJS: Implement Temporal.Duration.prototype.valueOf()
This commit is contained in:
parent
a06b034a9a
commit
8daf35e1b1
Notes:
sideshowbarker
2024-07-18 08:57:27 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/8daf35e1b1a Pull-request: https://github.com/SerenityOS/serenity/pull/8794 Reviewed-by: https://github.com/IdanHo ✅
@ -37,6 +37,9 @@ void DurationPrototype::initialize(GlobalObject& global_object)
|
||||
define_native_accessor(vm.names.nanoseconds, nanoseconds_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.sign, sign_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.blank, blank_getter, {}, Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
||||
}
|
||||
|
||||
static Duration* typed_this(GlobalObject& global_object)
|
||||
@ -215,4 +218,12 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::blank_getter)
|
||||
return Value(false);
|
||||
}
|
||||
|
||||
// 7.3.25 Temporal.Duration.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.valueof
|
||||
JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::value_of)
|
||||
{
|
||||
// 1. Throw a TypeError exception.
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::Convert, "Temporal.Duration", "a primitive value");
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(nanoseconds_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(sign_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(blank_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
test("errors", () => {
|
||||
test("throws TypeError", () => {
|
||||
expect(() => {
|
||||
new Temporal.Duration().valueOf();
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert Temporal.Duration to a primitive value");
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user