mirror of
https://github.com/Samsung/escargot.git
synced 2026-06-22 10:01:50 +00:00
implement String.prototype.charAt
Signed-off-by: seonghyun kim <sh8281.kim@samsung.com>
This commit is contained in:
parent
f374f035f3
commit
d9948bcded
2 changed files with 30 additions and 1 deletions
|
|
@ -298,6 +298,31 @@ static Value builtinStringCharCodeAt(ExecutionState& state, Value thisValue, siz
|
|||
return ret;
|
||||
}
|
||||
|
||||
static Value builtinStringCharAt(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
|
||||
{
|
||||
RESOLVE_THIS_BINDING_TO_STRING(str, String, charAt);
|
||||
|
||||
int64_t position;
|
||||
if (argc == 0) {
|
||||
position = 0;
|
||||
} else if (argc > 0) {
|
||||
position = argv[0].toInteger(state);
|
||||
} else {
|
||||
return Value(String::emptyString);
|
||||
}
|
||||
|
||||
if (LIKELY(0 <= position && position < (int64_t)str->length())) {
|
||||
char16_t c = str->charAt(position);
|
||||
if (LIKELY(c < ESCARGOT_ASCII_TABLE_MAX)) {
|
||||
return state.context()->staticStrings().asciiTable[c].string();
|
||||
} else {
|
||||
return String::fromCharCode(c);
|
||||
}
|
||||
} else {
|
||||
return String::emptyString;
|
||||
}
|
||||
}
|
||||
|
||||
static Value builtinStringFromCharCode(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
|
||||
{
|
||||
if (argc == 1) {
|
||||
|
|
@ -377,6 +402,10 @@ void GlobalObject::installString(ExecutionState& state)
|
|||
m_stringPrototype->defineOwnPropertyThrowsException(state, ObjectPropertyName(state.context()->staticStrings().charCodeAt),
|
||||
ObjectPropertyDescriptorForDefineOwnProperty(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().charCodeAt, builtinStringCharCodeAt, 1, nullptr, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptorForDefineOwnProperty::PresentAttribute)(ObjectPropertyDescriptorForDefineOwnProperty::WritablePresent | ObjectPropertyDescriptorForDefineOwnProperty::ConfigurablePresent)));
|
||||
|
||||
m_stringPrototype->defineOwnPropertyThrowsException(state, ObjectPropertyName(state.context()->staticStrings().charAt),
|
||||
ObjectPropertyDescriptorForDefineOwnProperty(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().charAt, builtinStringCharAt, 1, nullptr, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptorForDefineOwnProperty::PresentAttribute)(ObjectPropertyDescriptorForDefineOwnProperty::WritablePresent | ObjectPropertyDescriptorForDefineOwnProperty::ConfigurablePresent)));
|
||||
|
||||
|
||||
m_string->defineOwnPropertyThrowsException(state, ObjectPropertyName(state.context()->staticStrings().fromCharCode),
|
||||
ObjectPropertyDescriptorForDefineOwnProperty(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().fromCharCode, builtinStringFromCharCode, 1, nullptr, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptorForDefineOwnProperty::PresentAttribute)(ObjectPropertyDescriptorForDefineOwnProperty::WritablePresent | ObjectPropertyDescriptorForDefineOwnProperty::ConfigurablePresent)));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue