mirror of
https://github.com/RGBCube/serenity
synced 2025-07-22 22:07:34 +00:00
LibJS: Add FIXMEs to a few functions that need UTF-16 handling
This commit is contained in:
parent
979e02c0a8
commit
248b79d687
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()))
|
if (index < 0 || index >= static_cast<i32>(string.length()))
|
||||||
return js_string(interpreter, String::empty());
|
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));
|
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()))
|
if (index < 0 || index >= static_cast<i32>(string.length()))
|
||||||
return js_nan();
|
return js_nan();
|
||||||
|
// FIXME: This should return the i'th UTF-16 code point.
|
||||||
return Value((i32)string[index]);
|
return Value((i32)string[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,6 +321,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substring)
|
||||||
if (interpreter.argument_count() == 0)
|
if (interpreter.argument_count() == 0)
|
||||||
return js_string(interpreter, string);
|
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 string_length = string.length();
|
||||||
auto index_start = min(interpreter.argument(0).to_size_t(interpreter), string_length);
|
auto index_start = min(interpreter.argument(0).to_size_t(interpreter), string_length);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -355,6 +358,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::includes)
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
// FIXME: position should index a UTF-16 codepoint view of the string.
|
||||||
size_t position = 0;
|
size_t position = 0;
|
||||||
if (interpreter.argument_count() >= 2) {
|
if (interpreter.argument_count() >= 2) {
|
||||||
position = interpreter.argument(1).to_size_t(interpreter);
|
position = interpreter.argument(1).to_size_t(interpreter);
|
||||||
|
@ -381,6 +385,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice)
|
||||||
if (interpreter.argument_count() == 0)
|
if (interpreter.argument_count() == 0)
|
||||||
return js_string(interpreter, string);
|
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 string_length = static_cast<i32>(string.length());
|
||||||
auto index_start = interpreter.argument(0).to_i32(interpreter);
|
auto index_start = interpreter.argument(0).to_i32(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
|
@ -429,10 +434,10 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::last_index_of)
|
||||||
return {};
|
return {};
|
||||||
if (search_string.length() > string.length())
|
if (search_string.length() > string.length())
|
||||||
return Value(-1);
|
return Value(-1);
|
||||||
|
|
||||||
auto max_index = string.length() - search_string.length();
|
auto max_index = string.length() - search_string.length();
|
||||||
auto from_index = max_index;
|
auto from_index = max_index;
|
||||||
if (interpreter.argument_count() >= 2) {
|
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);
|
from_index = min(interpreter.argument(1).to_size_t(interpreter), max_index);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -251,6 +251,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::atob)
|
||||||
auto string = interpreter.argument(0).to_string(interpreter);
|
auto string = interpreter.argument(0).to_string(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
|
// FIXME: This should convert string from a byte string to LibJS's internal string encoding (UTF-8).
|
||||||
auto decoded = decode_base64(StringView(string));
|
auto decoded = decode_base64(StringView(string));
|
||||||
return JS::js_string(interpreter, String::copy(decoded));
|
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);
|
auto string = interpreter.argument(0).to_string(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
|
// FIXME: This should convert string to a non-UTF-8 byte string first.
|
||||||
auto encoded = encode_base64(StringView(string));
|
auto encoded = encode_base64(StringView(string));
|
||||||
return JS::js_string(interpreter, String::copy(encoded));
|
return JS::js_string(interpreter, String::copy(encoded));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue