mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibJS: Implement Temporal.Duration.prototype.valueOf
This commit is contained in:
parent
c715711f88
commit
f57ff63432
Notes:
github-actions[bot]
2024-11-21 00:05:28 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/f57ff634328 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2431 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/shannonbooth ✅
3 changed files with 16 additions and 0 deletions
|
@ -46,6 +46,7 @@ void DurationPrototype::initialize(Realm& realm)
|
||||||
define_native_function(realm, vm.names.toString, to_string, 0, attr);
|
define_native_function(realm, vm.names.toString, to_string, 0, attr);
|
||||||
define_native_function(realm, vm.names.toJSON, to_json, 0, attr);
|
define_native_function(realm, vm.names.toJSON, to_json, 0, attr);
|
||||||
define_native_function(realm, vm.names.toLocaleString, to_locale_string, 0, attr);
|
define_native_function(realm, vm.names.toLocaleString, to_locale_string, 0, attr);
|
||||||
|
define_native_function(realm, vm.names.valueOf, value_of, 0, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.3.3 get Temporal.Duration.prototype.years, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.years
|
// 7.3.3 get Temporal.Duration.prototype.years, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.years
|
||||||
|
@ -582,4 +583,11 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::to_locale_string)
|
||||||
return PrimitiveString::create(vm, temporal_duration_to_string(duration, Auto {}));
|
return PrimitiveString::create(vm, temporal_duration_to_string(duration, Auto {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
return vm.throw_completion<TypeError>(ErrorType::Convert, "Temporal.Duration", "a primitive value");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ private:
|
||||||
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(to_json);
|
JS_DECLARE_NATIVE_FUNCTION(to_json);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(to_locale_string);
|
JS_DECLARE_NATIVE_FUNCTION(to_locale_string);
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
describe("errors", () => {
|
||||||
|
test("throws TypeError", () => {
|
||||||
|
expect(() => {
|
||||||
|
new Temporal.Duration().valueOf();
|
||||||
|
}).toThrowWithMessage(TypeError, "Cannot convert Temporal.Duration to a primitive value");
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue