Index: src/runtime/runtime-array.cc |
diff --git a/src/runtime/runtime-array.cc b/src/runtime/runtime-array.cc |
index 6664c814006798046ef7a6ffa279788e04146a49..d451b96e1bbf5772923c3cec2549725bac6caa13 100644 |
--- a/src/runtime/runtime-array.cc |
+++ b/src/runtime/runtime-array.cc |
@@ -32,18 +32,24 @@ RUNTIME_FUNCTION(Runtime_FinishArrayPrototypeSetup) { |
} |
static void InstallCode(Isolate* isolate, Handle<JSObject> holder, |
- const char* name, Handle<Code> code) { |
+ const char* name, Handle<Code> code, int argc = -1) { |
Handle<String> key = isolate->factory()->InternalizeUtf8String(name); |
Handle<JSFunction> optimized = |
isolate->factory()->NewFunctionWithoutPrototype(key, code); |
- optimized->shared()->DontAdaptArguments(); |
+ if (argc < 0) { |
+ optimized->shared()->DontAdaptArguments(); |
+ } else { |
+ optimized->shared()->set_internal_formal_parameter_count(argc); |
+ } |
JSObject::AddProperty(holder, key, optimized, NONE); |
} |
static void InstallBuiltin(Isolate* isolate, Handle<JSObject> holder, |
- const char* name, Builtins::Name builtin_name) { |
+ const char* name, Builtins::Name builtin_name, |
+ int argc = -1) { |
InstallCode(isolate, holder, name, |
- handle(isolate->builtins()->builtin(builtin_name), isolate)); |
+ handle(isolate->builtins()->builtin(builtin_name), isolate), |
+ argc); |
} |
RUNTIME_FUNCTION(Runtime_SpecialArrayFunctions) { |
@@ -59,6 +65,7 @@ RUNTIME_FUNCTION(Runtime_SpecialArrayFunctions) { |
InstallBuiltin(isolate, holder, "unshift", Builtins::kArrayUnshift); |
InstallBuiltin(isolate, holder, "slice", Builtins::kArraySlice); |
InstallBuiltin(isolate, holder, "splice", Builtins::kArraySplice); |
+ InstallBuiltin(isolate, holder, "includes", Builtins::kArrayIncludes, 2); |
return *holder; |
} |
@@ -439,5 +446,24 @@ RUNTIME_FUNCTION(Runtime_ArraySpeciesConstructor) { |
isolate, Object::ArraySpeciesConstructor(isolate, original_array)); |
} |
+// ES7 22.1.3.11 Array.prototype.includes |
+RUNTIME_FUNCTION(Runtime_ArrayIncludes_Slow) { |
+ HandleScope shs(isolate); |
+ DCHECK(args.length() == 3); |
+ CONVERT_ARG_HANDLE_CHECKED(Object, search_element, 1); |
+ CONVERT_ARG_HANDLE_CHECKED(Object, from_index, 2); |
+ |
+ // Let O be ? ToObject(this value). |
+ Handle<JSReceiver> object; |
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
+ isolate, object, Object::ToObject(isolate, handle(args[0], isolate))); |
+ |
+ // Rest of the algorithm... |
+ Maybe<bool> result = |
+ JSReceiver::IncludesValue(isolate, object, search_element, from_index); |
+ MAYBE_RETURN(result, isolate->heap()->exception()); |
+ return isolate->heap()->ToBoolean(result.FromJust()); |
+} |
+ |
} // namespace internal |
} // namespace v8 |