Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: src/runtime/runtime-array.cc

Issue 2146293003: [builtins] implement Array.prototype.includes in TurboFan (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: debug fixup Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 #include "src/conversions-inl.h" 9 #include "src/conversions-inl.h"
10 #include "src/elements.h" 10 #include "src/elements.h"
(...skipping 14 matching lines...) Expand all
25 CHECK(length->IsSmi()); 25 CHECK(length->IsSmi());
26 CHECK(Smi::cast(length)->value() == 0); 26 CHECK(Smi::cast(length)->value() == 0);
27 CHECK(prototype->HasFastSmiOrObjectElements()); 27 CHECK(prototype->HasFastSmiOrObjectElements());
28 // This is necessary to enable fast checks for absence of elements 28 // This is necessary to enable fast checks for absence of elements
29 // on Array.prototype and below. 29 // on Array.prototype and below.
30 prototype->set_elements(isolate->heap()->empty_fixed_array()); 30 prototype->set_elements(isolate->heap()->empty_fixed_array());
31 return Smi::FromInt(0); 31 return Smi::FromInt(0);
32 } 32 }
33 33
34 static void InstallCode(Isolate* isolate, Handle<JSObject> holder, 34 static void InstallCode(Isolate* isolate, Handle<JSObject> holder,
35 const char* name, Handle<Code> code) { 35 const char* name, Handle<Code> code, int argc = -1) {
36 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); 36 Handle<String> key = isolate->factory()->InternalizeUtf8String(name);
37 Handle<JSFunction> optimized = 37 Handle<JSFunction> optimized =
38 isolate->factory()->NewFunctionWithoutPrototype(key, code); 38 isolate->factory()->NewFunctionWithoutPrototype(key, code);
39 optimized->shared()->DontAdaptArguments(); 39 if (argc < 0) {
40 optimized->shared()->DontAdaptArguments();
41 } else {
42 optimized->shared()->set_internal_formal_parameter_count(argc);
43 }
40 JSObject::AddProperty(holder, key, optimized, NONE); 44 JSObject::AddProperty(holder, key, optimized, NONE);
41 } 45 }
42 46
43 static void InstallBuiltin(Isolate* isolate, Handle<JSObject> holder, 47 static void InstallBuiltin(Isolate* isolate, Handle<JSObject> holder,
44 const char* name, Builtins::Name builtin_name) { 48 const char* name, Builtins::Name builtin_name,
49 int argc = -1) {
45 InstallCode(isolate, holder, name, 50 InstallCode(isolate, holder, name,
46 handle(isolate->builtins()->builtin(builtin_name), isolate)); 51 handle(isolate->builtins()->builtin(builtin_name), isolate),
52 argc);
47 } 53 }
48 54
49 RUNTIME_FUNCTION(Runtime_SpecialArrayFunctions) { 55 RUNTIME_FUNCTION(Runtime_SpecialArrayFunctions) {
50 HandleScope scope(isolate); 56 HandleScope scope(isolate);
51 DCHECK(args.length() == 0); 57 DCHECK(args.length() == 0);
52 Handle<JSObject> holder = 58 Handle<JSObject> holder =
53 isolate->factory()->NewJSObject(isolate->object_function()); 59 isolate->factory()->NewJSObject(isolate->object_function());
54 60
55 InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop); 61 InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop);
56 FastArrayPushStub stub(isolate); 62 FastArrayPushStub stub(isolate);
57 InstallCode(isolate, holder, "push", stub.GetCode()); 63 InstallCode(isolate, holder, "push", stub.GetCode());
58 InstallBuiltin(isolate, holder, "shift", Builtins::kArrayShift); 64 InstallBuiltin(isolate, holder, "shift", Builtins::kArrayShift);
59 InstallBuiltin(isolate, holder, "unshift", Builtins::kArrayUnshift); 65 InstallBuiltin(isolate, holder, "unshift", Builtins::kArrayUnshift);
60 InstallBuiltin(isolate, holder, "slice", Builtins::kArraySlice); 66 InstallBuiltin(isolate, holder, "slice", Builtins::kArraySlice);
61 InstallBuiltin(isolate, holder, "splice", Builtins::kArraySplice); 67 InstallBuiltin(isolate, holder, "splice", Builtins::kArraySplice);
68 InstallBuiltin(isolate, holder, "includes", Builtins::kArrayIncludes, 2);
62 69
63 return *holder; 70 return *holder;
64 } 71 }
65 72
66 73
67 RUNTIME_FUNCTION(Runtime_FixedArrayGet) { 74 RUNTIME_FUNCTION(Runtime_FixedArrayGet) {
68 SealHandleScope shs(isolate); 75 SealHandleScope shs(isolate);
69 DCHECK(args.length() == 2); 76 DCHECK(args.length() == 2);
70 CONVERT_ARG_CHECKED(FixedArray, object, 0); 77 CONVERT_ARG_CHECKED(FixedArray, object, 0);
71 CONVERT_SMI_ARG_CHECKED(index, 1); 78 CONVERT_SMI_ARG_CHECKED(index, 1);
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 439
433 440
434 RUNTIME_FUNCTION(Runtime_ArraySpeciesConstructor) { 441 RUNTIME_FUNCTION(Runtime_ArraySpeciesConstructor) {
435 HandleScope scope(isolate); 442 HandleScope scope(isolate);
436 DCHECK(args.length() == 1); 443 DCHECK(args.length() == 1);
437 CONVERT_ARG_HANDLE_CHECKED(Object, original_array, 0); 444 CONVERT_ARG_HANDLE_CHECKED(Object, original_array, 0);
438 RETURN_RESULT_OR_FAILURE( 445 RETURN_RESULT_OR_FAILURE(
439 isolate, Object::ArraySpeciesConstructor(isolate, original_array)); 446 isolate, Object::ArraySpeciesConstructor(isolate, original_array));
440 } 447 }
441 448
449 // ES7 22.1.3.11 Array.prototype.includes
450 RUNTIME_FUNCTION(Runtime_ArrayIncludes_Slow) {
451 HandleScope shs(isolate);
452 DCHECK(args.length() == 3);
453 CONVERT_ARG_HANDLE_CHECKED(Object, search_element, 1);
454 CONVERT_ARG_HANDLE_CHECKED(Object, from_index, 2);
455
456 // Let O be ? ToObject(this value).
457 Handle<JSReceiver> object;
458 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
459 isolate, object, Object::ToObject(isolate, handle(args[0], isolate)));
460
461 // Rest of the algorithm...
462 Maybe<bool> result =
463 JSReceiver::IncludesValue(isolate, object, search_element, from_index);
464 MAYBE_RETURN(result, isolate->heap()->exception());
465 return isolate->heap()->ToBoolean(result.FromJust());
466 }
467
442 } // namespace internal 468 } // namespace internal
443 } // namespace v8 469 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698