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

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

Issue 1769043003: Revert of [key-accumulator] Starting to reimplement the key-accumulator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « src/runtime/runtime-array.cc ('k') | test/mjsunit/for-in.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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/elements.h"
9 #include "src/factory.h" 8 #include "src/factory.h"
10 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
11 #include "src/keys.h"
12 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
13 11
14 namespace v8 { 12 namespace v8 {
15 namespace internal { 13 namespace internal {
16 14
17 namespace { 15 namespace {
18 16
19 // Returns either a FixedArray or, if the given {receiver} has an enum cache 17 // Returns either a FixedArray or, if the given {receiver} has an enum cache
20 // that contains all enumerable properties of the {receiver} and its prototypes 18 // that contains all enumerable properties of the {receiver} and its prototypes
21 // have none, the map of the {receiver}. This is used to speed up the check for 19 // have none, the map of the {receiver}. This is used to speed up the check for
22 // deletions during a for-in. 20 // deletions during a for-in.
23 MaybeHandle<HeapObject> Enumerate(Handle<JSReceiver> receiver) { 21 MaybeHandle<HeapObject> Enumerate(Handle<JSReceiver> receiver) {
24 Isolate* const isolate = receiver->GetIsolate(); 22 Isolate* const isolate = receiver->GetIsolate();
25 FastKeyAccumulator accumulator(isolate, receiver, INCLUDE_PROTOS,
26 ENUMERABLE_STRINGS);
27 // Test if we have an enum cache for {receiver}. 23 // Test if we have an enum cache for {receiver}.
28 if (!accumulator.is_receiver_simple_enum()) { 24 if (!receiver->IsSimpleEnum()) {
29 Handle<FixedArray> keys; 25 Handle<FixedArray> keys;
30 ASSIGN_RETURN_ON_EXCEPTION(isolate, keys, accumulator.GetKeys(KEEP_NUMBERS), 26 ASSIGN_RETURN_ON_EXCEPTION(
31 HeapObject); 27 isolate, keys,
28 JSReceiver::GetKeys(receiver, INCLUDE_PROTOS, ENUMERABLE_STRINGS),
29 HeapObject);
32 // Test again, since cache may have been built by GetKeys() calls above. 30 // Test again, since cache may have been built by GetKeys() calls above.
33 if (!accumulator.is_receiver_simple_enum()) return keys; 31 if (!receiver->IsSimpleEnum()) return keys;
34 } 32 }
35 return handle(receiver->map(), isolate); 33 return handle(receiver->map(), isolate);
36 } 34 }
37 35
38 36
39 MaybeHandle<Object> Filter(Handle<JSReceiver> receiver, Handle<Object> key) { 37 MaybeHandle<Object> Filter(Handle<JSReceiver> receiver, Handle<Object> key) {
40 Isolate* const isolate = receiver->GetIsolate(); 38 Isolate* const isolate = receiver->GetIsolate();
39 // TODO(turbofan): Fast case for array indices.
41 Handle<Name> name; 40 Handle<Name> name;
42 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, Object::ToName(isolate, key), 41 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, Object::ToName(isolate, key),
43 Object); 42 Object);
44 // Directly check for elements if the key is a smi and avoid a conversion
45 // roundtrip (Number -> Name -> Number).
46 if (key->IsNumber() && receiver->map()->OnlyHasSimpleProperties()) {
47 Handle<JSObject> object = Handle<JSObject>::cast(receiver);
48 ElementsAccessor* accessor = object->GetElementsAccessor();
49 DCHECK_LT(key->Number(), kMaxUInt32);
50 if (accessor->HasElement(object, key->Number(), ONLY_ENUMERABLE)) {
51 return name;
52 }
53 }
54 Maybe<bool> result = JSReceiver::HasProperty(receiver, name); 43 Maybe<bool> result = JSReceiver::HasProperty(receiver, name);
55 MAYBE_RETURN_NULL(result); 44 MAYBE_RETURN_NULL(result);
56 if (result.FromJust()) return name; 45 if (result.FromJust()) return name;
57 return isolate->factory()->undefined_value(); 46 return isolate->factory()->undefined_value();
58 } 47 }
59 48
60 } // namespace 49 } // namespace
61 50
62 51
63 RUNTIME_FUNCTION(Runtime_ForInEnumerate) { 52 RUNTIME_FUNCTION(Runtime_ForInEnumerate) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 SealHandleScope scope(isolate); 133 SealHandleScope scope(isolate);
145 DCHECK_EQ(1, args.length()); 134 DCHECK_EQ(1, args.length());
146 CONVERT_SMI_ARG_CHECKED(index, 0); 135 CONVERT_SMI_ARG_CHECKED(index, 0);
147 DCHECK_LE(0, index); 136 DCHECK_LE(0, index);
148 DCHECK_LT(index, Smi::kMaxValue); 137 DCHECK_LT(index, Smi::kMaxValue);
149 return Smi::FromInt(index + 1); 138 return Smi::FromInt(index + 1);
150 } 139 }
151 140
152 } // namespace internal 141 } // namespace internal
153 } // namespace v8 142 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-array.cc ('k') | test/mjsunit/for-in.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698