1c523a444b
Reason for revert: let me quickly revert the revert, wut? Goal: my CL should not be in the tree! Original issue's description: > Reland of [runtime] Do not use the enum-cache for non-prototype objects. (patchset #1 id:1 of https://codereview.chromium.org/1619803003/ ) > > Reason for revert: > the deopt issues have been taken care of by benedikt > > Original issue's description: > > Revert of [runtime] Do not use the enum-cache for non-prototype objects. (patchset #10 id:180001 of https://codereview.chromium.org/1608523002/ ) > > > > Reason for revert: > > tanks for-in significantly > > > > Original issue's description: > > > [runtime] Do not use the enum-cache for keys retrieval. > > > > > > Currently we fail to properly handle shadowed properties. If the > > > receiver defines a non-enumerable property that reappears on the > > > prototype as enumerable it incorrectly shows up in [[Enumerate]]. > > > By extending the KeyAccumulator to track non-enumerable properties > > > we can now properly filter them out when seeing them further up in > > > the prototype-chain. > > > > > > BUG=v8:705 > > > LOG=y > > > > > > Committed: https://crrev.com/ed24dfe80d1da0827b8571839ee52c03ad09c9c7 > > > Cr-Commit-Position: refs/heads/master@{#33405} > > > > TBR=jkummerow@chromium.org,bmeurer@chromium.org > > # Not skipping CQ checks because original CL landed more than 1 days ago. > > BUG=v8:705 > > LOG=n > > > > Committed: https://crrev.com/6e0573c6fff1c3041bab106d1197ab1b64aa9a6a > > Cr-Commit-Position: refs/heads/master@{#33443} > > TBR=jkummerow@chromium.org,bmeurer@chromium.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=v8:705 > > Committed: https://crrev.com/5569e270eda517b5ea74e3a7676b3230cbe2f7a9 > Cr-Commit-Position: refs/heads/master@{#33458} TBR=jkummerow@chromium.org,bmeurer@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=v8:705 Review URL: https://codereview.chromium.org/1614313003 Cr-Commit-Position: refs/heads/master@{#33459}
94 lines
3.8 KiB
C++
94 lines
3.8 KiB
C++
// Copyright 2012 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef V8_KEY_ACCUMULATOR_H_
|
|
#define V8_KEY_ACCUMULATOR_H_
|
|
|
|
#include "src/isolate.h"
|
|
#include "src/objects.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
enum AddKeyConversion { DO_NOT_CONVERT, CONVERT_TO_ARRAY_INDEX, PROXY_MAGIC };
|
|
|
|
// This is a helper class for JSReceiver::GetKeys which collects and sorts keys.
|
|
// GetKeys needs to sort keys per prototype level, first showing the integer
|
|
// indices from elements then the strings from the properties. However, this
|
|
// does not apply to proxies which are in full control of how the keys are
|
|
// sorted.
|
|
//
|
|
// For performance reasons the KeyAccumulator internally separates integer keys
|
|
// in |elements_| into sorted lists per prototype level. String keys are
|
|
// collected in |string_properties_|, a single OrderedHashSet (similar for
|
|
// Symbols in |symbol_properties_|. To separate the keys per level later when
|
|
// assembling the final list, |levelLengths_| keeps track of the number of
|
|
// String and Symbol keys per level.
|
|
//
|
|
// Only unique keys are kept by the KeyAccumulator, strings are stored in a
|
|
// HashSet for inexpensive lookups. Integer keys are kept in sorted lists which
|
|
// are more compact and allow for reasonably fast includes check.
|
|
class KeyAccumulator final BASE_EMBEDDED {
|
|
public:
|
|
KeyAccumulator(Isolate* isolate, PropertyFilter filter)
|
|
: isolate_(isolate), filter_(filter) {}
|
|
~KeyAccumulator();
|
|
|
|
bool AddKey(uint32_t key);
|
|
bool AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT);
|
|
bool AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT);
|
|
void AddKeys(Handle<FixedArray> array,
|
|
AddKeyConversion convert = DO_NOT_CONVERT);
|
|
void AddKeys(Handle<JSObject> array,
|
|
AddKeyConversion convert = DO_NOT_CONVERT);
|
|
void AddKeysFromProxy(Handle<JSObject> array);
|
|
Maybe<bool> AddKeysFromProxy(Handle<JSProxy> proxy, Handle<FixedArray> keys);
|
|
void AddElementKeysFromInterceptor(Handle<JSObject> array);
|
|
// Jump to the next level, pushing the current |levelLength_| to
|
|
// |levelLengths_| and adding a new list to |elements_|.
|
|
void NextPrototype();
|
|
// Sort the integer indices in the last list in |elements_|
|
|
void SortCurrentElementsList();
|
|
Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS);
|
|
int length() { return length_; }
|
|
Isolate* isolate() { return isolate_; }
|
|
|
|
private:
|
|
bool AddIntegerKey(uint32_t key);
|
|
bool AddStringKey(Handle<Object> key, AddKeyConversion convert);
|
|
bool AddSymbolKey(Handle<Object> array);
|
|
void SortCurrentElementsListRemoveDuplicates();
|
|
|
|
Isolate* isolate_;
|
|
PropertyFilter filter_;
|
|
// |elements_| contains the sorted element keys (indices) per level.
|
|
std::vector<std::vector<uint32_t>*> elements_;
|
|
// |protoLengths_| contains the total number of keys (elements + properties)
|
|
// per level. Negative values mark counts for a level with keys from a proxy.
|
|
std::vector<int> level_lengths_;
|
|
// |string_properties_| contains the unique String property keys for all
|
|
// levels in insertion order per level.
|
|
Handle<OrderedHashSet> string_properties_;
|
|
// |symbol_properties_| contains the unique Symbol property keys for all
|
|
// levels in insertion order per level.
|
|
Handle<OrderedHashSet> symbol_properties_;
|
|
// |length_| keeps track of the total number of all element and property keys.
|
|
int length_ = 0;
|
|
// |levelLength_| keeps track of the number of String keys in the current
|
|
// level.
|
|
int level_string_length_ = 0;
|
|
// |levelSymbolLength_| keeps track of the number of Symbol keys in the
|
|
// current level.
|
|
int level_symbol_length_ = 0;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(KeyAccumulator);
|
|
};
|
|
|
|
|
|
} // namespace internal
|
|
} // namespace v8
|
|
|
|
|
|
#endif // V8_KEY_ACCUMULATOR_H_
|