| Index: src/builtins/builtins-string.cc
|
| diff --git a/src/builtins/builtins-string.cc b/src/builtins/builtins-string.cc
|
| index 238c760b5fbb43ffdcb0ab7d2fc971ddc3bbee23..9fcd62336146768bf0bb62df0ebda5f3816e2025 100644
|
| --- a/src/builtins/builtins-string.cc
|
| +++ b/src/builtins/builtins-string.cc
|
| @@ -781,6 +781,41 @@ void Builtins::Generate_StringPrototypeCharCodeAt(
|
| assembler->Return(result);
|
| }
|
|
|
| +// ES6 section 21.1.3.7
|
| +// String.prototype.includes ( searchString [ , position ] )
|
| +BUILTIN(StringPrototypeIncludes) {
|
| + HandleScope handle_scope(isolate);
|
| + TO_THIS_STRING(str, "String.prototype.includes");
|
| +
|
| + // Check if the search string is a regExp and fail if it is.
|
| + Handle<Object> search = args.atOrUndefined(isolate, 1);
|
| + Maybe<bool> is_reg_exp = Object::IsRegExp(isolate, search);
|
| + if (is_reg_exp.IsNothing()) {
|
| + DCHECK(isolate->has_pending_exception());
|
| + return isolate->heap()->exception();
|
| + }
|
| + if (is_reg_exp.FromJust()) {
|
| + THROW_NEW_ERROR_RETURN_FAILURE(
|
| + isolate, NewTypeError(MessageTemplate::kFirstArgumentNotRegExp,
|
| + isolate->factory()->NewStringFromStaticChars(
|
| + "String.prototype.includes")));
|
| + }
|
| + Handle<String> search_string;
|
| + ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, search_string,
|
| + Object::ToString(isolate, search));
|
| + Handle<Object> position;
|
| + ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
| + isolate, position,
|
| + Object::ToInteger(isolate, args.atOrUndefined(isolate, 2)));
|
| +
|
| + double index = std::max(position->Number(), 0.0);
|
| + index = std::min(index, static_cast<double>(str->length()));
|
| +
|
| + int index_in_str = String::IndexOf(isolate, str, search_string,
|
| + static_cast<uint32_t>(index));
|
| + return *isolate->factory()->ToBoolean(index_in_str != -1);
|
| +}
|
| +
|
| // ES6 section 21.1.3.8 String.prototype.indexOf ( searchString [ , position ] )
|
| BUILTIN(StringPrototypeIndexOf) {
|
| HandleScope handle_scope(isolate);
|
|
|