mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibJS: Add FIXMEs to a few functions that need UTF-16 handling
This commit is contained in:
parent
979e02c0a8
commit
248b79d687
Notes:
sideshowbarker
2024-07-19 04:40:31 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/248b79d6872 Pull-request: https://github.com/SerenityOS/serenity/pull/2852 Reviewed-by: https://github.com/awesomekling
2 changed files with 8 additions and 1 deletions
|
@ -109,6 +109,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_at)
|
|||
}
|
||||
if (index < 0 || index >= static_cast<i32>(string.length()))
|
||||
return js_string(interpreter, String::empty());
|
||||
// FIXME: This should return a character corresponding to the i'th UTF-16 code point.
|
||||
return js_string(interpreter, string.substring(index, 1));
|
||||
}
|
||||
|
||||
|
@ -125,6 +126,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_code_at)
|
|||
}
|
||||
if (index < 0 || index >= static_cast<i32>(string.length()))
|
||||
return js_nan();
|
||||
// FIXME: This should return the i'th UTF-16 code point.
|
||||
return Value((i32)string[index]);
|
||||
}
|
||||
|
||||
|
@ -319,6 +321,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substring)
|
|||
if (interpreter.argument_count() == 0)
|
||||
return js_string(interpreter, string);
|
||||
|
||||
// FIXME: index_start and index_end should index a UTF-16 codepoint view of the string.
|
||||
auto string_length = string.length();
|
||||
auto index_start = min(interpreter.argument(0).to_size_t(interpreter), string_length);
|
||||
if (interpreter.exception())
|
||||
|
@ -355,6 +358,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::includes)
|
|||
if (interpreter.exception())
|
||||
return {};
|
||||
|
||||
// FIXME: position should index a UTF-16 codepoint view of the string.
|
||||
size_t position = 0;
|
||||
if (interpreter.argument_count() >= 2) {
|
||||
position = interpreter.argument(1).to_size_t(interpreter);
|
||||
|
@ -381,6 +385,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice)
|
|||
if (interpreter.argument_count() == 0)
|
||||
return js_string(interpreter, string);
|
||||
|
||||
// FIXME: index_start and index_end should index a UTF-16 codepoint view of the string.
|
||||
auto string_length = static_cast<i32>(string.length());
|
||||
auto index_start = interpreter.argument(0).to_i32(interpreter);
|
||||
if (interpreter.exception())
|
||||
|
@ -429,10 +434,10 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::last_index_of)
|
|||
return {};
|
||||
if (search_string.length() > string.length())
|
||||
return Value(-1);
|
||||
|
||||
auto max_index = string.length() - search_string.length();
|
||||
auto from_index = max_index;
|
||||
if (interpreter.argument_count() >= 2) {
|
||||
// FIXME: from_index should index a UTF-16 codepoint view of the string.
|
||||
from_index = min(interpreter.argument(1).to_size_t(interpreter), max_index);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
|
|
|
@ -251,6 +251,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::atob)
|
|||
auto string = interpreter.argument(0).to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
// FIXME: This should convert string from a byte string to LibJS's internal string encoding (UTF-8).
|
||||
auto decoded = decode_base64(StringView(string));
|
||||
return JS::js_string(interpreter, String::copy(decoded));
|
||||
}
|
||||
|
@ -265,6 +266,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::btoa)
|
|||
auto string = interpreter.argument(0).to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
// FIXME: This should convert string to a non-UTF-8 byte string first.
|
||||
auto encoded = encode_base64(StringView(string));
|
||||
return JS::js_string(interpreter, String::copy(encoded));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue