}
-Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) {
- Isolate* isolate = string->GetIsolate();
- Factory* factory = isolate->factory();
-
- int int_index = static_cast<int>(index);
- if (int_index < 0 || int_index >= string->length()) {
- return factory->undefined_value();
- }
-
- Handle<Object> char_at = Object::GetProperty(
- isolate->js_builtins_object(),
- factory->char_at_string()).ToHandleChecked();
- if (!char_at->IsJSFunction()) {
- return factory->undefined_value();
- }
-
- Handle<Object> index_object = factory->NewNumberFromInt(int_index);
- Handle<Object> index_arg[] = { index_object };
- Handle<Object> result;
- if (!TryCall(Handle<JSFunction>::cast(char_at),
- string,
- arraysize(index_arg),
- index_arg).ToHandle(&result)) {
- return factory->undefined_value();
- }
- return result;
-}
-
-
Handle<String> Execution::GetStackTraceLine(Handle<Object> recv,
Handle<JSFunction> fun,
Handle<Object> pos,
MUST_USE_RESULT static MaybeHandle<JSRegExp> NewJSRegExp(
Handle<String> pattern, Handle<String> flags);
- // Used to implement [] notation on strings (calls JS code)
- static Handle<Object> CharAt(Handle<String> str, uint32_t index);
-
static Handle<Object> GetFunctionFor();
static Handle<String> GetStackTraceLine(Handle<Object> recv,
Handle<JSFunction> fun,
// Returns a single character string where first character equals
// string->Get(index).
static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) {
- if (index < static_cast<uint32_t>(string->length())) {
- Factory* factory = string->GetIsolate()->factory();
- return factory->LookupSingleCharacterStringFromCode(
- String::Flatten(string)->Get(index));
- }
- return Execution::CharAt(string, index);
+ DCHECK_LT(index, static_cast<uint32_t>(string->length()));
+ Factory* factory = string->GetIsolate()->factory();
+ return factory->LookupSingleCharacterStringFromCode(
+ String::Flatten(string)->Get(index));
}
Handle<Object> object,
uint32_t index) {
// Handle [] indexing on Strings
- if (object->IsString()) {
+ if (object->IsString() &&
+ index < static_cast<uint32_t>(String::cast(*object)->length())) {
Handle<Object> result = GetCharAt(Handle<String>::cast(object), index);
if (!result->IsUndefined()) return result;
}