mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibJS: Add String.prototype.toUpperCase()
This commit is contained in:
parent
727031ac1b
commit
22f20cd51d
Notes:
sideshowbarker
2024-07-19 07:50:21 +09:00
Author: https://github.com/linusg
Commit: 22f20cd51d
Pull-request: https://github.com/SerenityOS/serenity/pull/1678
4 changed files with 31 additions and 0 deletions
|
@ -45,6 +45,7 @@ StringPrototype::StringPrototype()
|
||||||
put_native_function("startsWith", starts_with, 1);
|
put_native_function("startsWith", starts_with, 1);
|
||||||
put_native_function("indexOf", index_of, 1);
|
put_native_function("indexOf", index_of, 1);
|
||||||
put_native_function("toLowerCase", to_lowercase, 0);
|
put_native_function("toLowerCase", to_lowercase, 0);
|
||||||
|
put_native_function("toUpperCase", to_uppercase, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringPrototype::~StringPrototype()
|
StringPrototype::~StringPrototype()
|
||||||
|
@ -154,6 +155,14 @@ Value StringPrototype::to_lowercase(Interpreter& interpreter)
|
||||||
return js_string(interpreter, string_object->primitive_string()->string().to_lowercase());
|
return js_string(interpreter, string_object->primitive_string()->string().to_lowercase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value StringPrototype::to_uppercase(Interpreter& interpreter)
|
||||||
|
{
|
||||||
|
auto* string_object = string_object_from(interpreter);
|
||||||
|
if (!string_object)
|
||||||
|
return {};
|
||||||
|
return js_string(interpreter, string_object->primitive_string()->string().to_uppercase());
|
||||||
|
}
|
||||||
|
|
||||||
Value StringPrototype::length_getter(Interpreter& interpreter)
|
Value StringPrototype::length_getter(Interpreter& interpreter)
|
||||||
{
|
{
|
||||||
auto* this_object = interpreter.this_value().to_object(interpreter.heap());
|
auto* this_object = interpreter.this_value().to_object(interpreter.heap());
|
||||||
|
|
|
@ -43,6 +43,7 @@ private:
|
||||||
static Value starts_with(Interpreter&);
|
static Value starts_with(Interpreter&);
|
||||||
static Value index_of(Interpreter&);
|
static Value index_of(Interpreter&);
|
||||||
static Value to_lowercase(Interpreter&);
|
static Value to_lowercase(Interpreter&);
|
||||||
|
static Value to_uppercase(Interpreter&);
|
||||||
|
|
||||||
static Value length_getter(Interpreter&);
|
static Value length_getter(Interpreter&);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
try {
|
try {
|
||||||
|
// FIXME: Remove once we have the global String object
|
||||||
|
var String = { prototype: Object.getPrototypeOf("") };
|
||||||
|
|
||||||
|
assert(String.prototype.toLowerCase.length === 0);
|
||||||
|
|
||||||
assert("foo".toLowerCase() === "foo");
|
assert("foo".toLowerCase() === "foo");
|
||||||
assert("Foo".toLowerCase() === "foo");
|
assert("Foo".toLowerCase() === "foo");
|
||||||
assert("FOO".toLowerCase() === "foo");
|
assert("FOO".toLowerCase() === "foo");
|
||||||
|
|
16
Libraries/LibJS/Tests/String.prototype.toUpperCase.js
Normal file
16
Libraries/LibJS/Tests/String.prototype.toUpperCase.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
try {
|
||||||
|
// FIXME: Remove once we have the global String object
|
||||||
|
var String = { prototype: Object.getPrototypeOf("") };
|
||||||
|
|
||||||
|
assert(String.prototype.toUpperCase.length === 0);
|
||||||
|
|
||||||
|
assert("foo".toUpperCase() === "FOO");
|
||||||
|
assert("Foo".toUpperCase() === "FOO");
|
||||||
|
assert("FOO".toUpperCase() === "FOO");
|
||||||
|
|
||||||
|
assert(('b' + 'a' + + 'n' + 'a').toUpperCase() === "BANANA");
|
||||||
|
|
||||||
|
console.log("PASS");
|
||||||
|
} catch (e) {
|
||||||
|
console.log("FAIL: " + e);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue