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

Side by Side Diff: src/objects.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <memory> 9 #include <memory>
10 #include <sstream> 10 #include <sstream>
(...skipping 18979 matching lines...) Expand 10 before | Expand all | Expand 10 after
18990 18990
18991 bool JSReceiver::HasProxyInPrototype(Isolate* isolate) { 18991 bool JSReceiver::HasProxyInPrototype(Isolate* isolate) {
18992 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, 18992 for (PrototypeIterator iter(isolate, this, kStartAtReceiver,
18993 PrototypeIterator::END_AT_NULL); 18993 PrototypeIterator::END_AT_NULL);
18994 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { 18994 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) {
18995 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; 18995 if (iter.GetCurrent<Object>()->IsJSProxy()) return true;
18996 } 18996 }
18997 return false; 18997 return false;
18998 } 18998 }
18999 18999
19000 Maybe<bool> JSReceiver::IncludesValue(Isolate* isolate,
19001 Handle<JSReceiver> object,
19002 Handle<Object> value,
19003 Handle<Object> from_index) {
Camillo Bruni 2016/08/01 07:23:47 nit: Any particular reason this has to be on JSRec
caitp 2016/08/01 15:10:45 had moved it here to make it easy to share the c++
19004 // Let len be ? ToLength(? Get(O, "length")).
19005 int64_t len;
19006 {
19007 Handle<Object> len_;
19008 if (object->map()->instance_type() == JS_ARRAY_TYPE) {
19009 len_ = handle(JSArray::cast(*object)->length(), isolate);
Camillo Bruni 2016/08/01 07:23:47 nit: A JSArray can only have sane length values (0
caitp 2016/08/01 15:10:45 updated to use ToArrayLength() for JS_ARRAY_TYPE
19010 } else {
19011 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
19012 isolate, len_,
19013 Object::GetProperty(object, isolate->factory()->length_string()),
19014 Nothing<bool>());
19015 }
19016 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
19017 isolate, len_, Object::ToLength(isolate, len_), Nothing<bool>());
19018 len = static_cast<int64_t>(len_->Number());
19019 DCHECK_EQ(len, len_->Number());
19020 }
19021
19022 if (len == 0) return Just(false);
19023
19024 // Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
19025 // produces the value 0.)
19026 int64_t start_from;
19027 {
19028 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, from_index,
19029 Object::ToInteger(isolate, from_index),
19030 Nothing<bool>());
19031 double fp = from_index->Number();
19032 if (fp > len) return Just(false);
19033 start_from = static_cast<int64_t>(fp);
19034 }
19035
19036 int64_t index;
19037 if (start_from >= 0) {
19038 index = start_from;
19039 } else {
19040 index = len + start_from;
19041 if (index < 0) {
19042 index = 0;
19043 }
19044 }
19045
19046 // If the receiver is not a special receiver type, and the length is a valid
19047 // element index, perform fast operation tailored to specific ElementsKinds.
19048 if (object->map()->instance_type() > LAST_SPECIAL_RECEIVER_TYPE &&
19049 len < kMaxUInt32 &&
19050 JSObject::PrototypeHasNoElements(isolate, JSObject::cast(*object))) {
19051 Handle<JSObject> obj = Handle<JSObject>::cast(object);
19052 ElementsAccessor* elements = obj->GetElementsAccessor();
19053 return elements->IncludesValue(isolate, obj, value,
19054 static_cast<uint32_t>(index),
19055 static_cast<uint32_t>(len));
19056 }
19057
19058 // Otherwise, perform slow lookups for special receiver types
19059 for (; index < len; ++index) {
19060 // Let elementK be the result of ? Get(O, ! ToString(k)).
19061 Handle<Object> element_k;
19062 {
19063 Handle<Object> index_obj = isolate->factory()->NewNumberFromInt64(index);
19064 bool success;
19065 LookupIterator it = LookupIterator::PropertyOrElement(
19066 isolate, object, index_obj, &success);
19067 DCHECK(success);
19068 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
19069 isolate, element_k, Object::GetProperty(&it), Nothing<bool>());
19070 }
19071
19072 // If SameValueZero(searchElement, elementK) is true, return true.
19073 if (value->SameValueZero(*element_k)) return Just(true);
19074 }
19075 return Just(false);
19076 }
19077
19000 } // namespace internal 19078 } // namespace internal
19001 } // namespace v8 19079 } // namespace v8
OLDNEW
« src/elements.cc ('K') | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698