LibJS: Add String.prototype.valueOf()

It should have its own and not inherit from the Object prototype.
This commit is contained in:
Linus Groh 2021-06-06 16:51:49 +01:00 committed by Andreas Kling
parent 8d7ec28924
commit e9a0759b16
Notes: sideshowbarker 2024-07-18 12:45:16 +09:00
2 changed files with 7 additions and 0 deletions

View File

@ -61,6 +61,7 @@ void StringPrototype::initialize(GlobalObject& global_object)
define_native_function(vm.names.toLowerCase, to_lowercase, 0, attr);
define_native_function(vm.names.toUpperCase, to_uppercase, 0, attr);
define_native_function(vm.names.toString, to_string, 0, attr);
define_native_function(vm.names.valueOf, value_of, 0, attr);
define_native_function(vm.names.padStart, pad_start, 1, attr);
define_native_function(vm.names.padEnd, pad_end, 1, attr);
define_native_function(vm.names.trim, trim, 0, attr);
@ -278,6 +279,11 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_string)
return this_string_value(global_object, vm.this_value(global_object));
}
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::value_of)
{
return this_string_value(global_object, vm.this_value(global_object));
}
enum class PadPlacement {
Start,
End,

View File

@ -28,6 +28,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(to_lowercase);
JS_DECLARE_NATIVE_FUNCTION(to_uppercase);
JS_DECLARE_NATIVE_FUNCTION(to_string);
JS_DECLARE_NATIVE_FUNCTION(value_of);
JS_DECLARE_NATIVE_FUNCTION(pad_start);
JS_DECLARE_NATIVE_FUNCTION(pad_end);
JS_DECLARE_NATIVE_FUNCTION(substring);