source: webkit/trunk/JavaScriptCore/runtime/PropertyNameArray.h@ 44076

Last change on this file since 44076 was 41232, checked in by [email protected], 16 years ago

JavaScriptCore:

2009-02-25 Geoffrey Garen <[email protected]>

Reviewed by Maciej Stachowiak.


Fixed <rdar://problem/6611174> REGRESSION (r36701): Unable to select
messages on hotmail (24052)


The bug was that for-in enumeration used a cached prototype chain without
validating that it was up-to-date.


This led me to refactor prototype chain caching so it was easier to work
with and harder to get wrong.


After a bit of inlining, this patch is performance-neutral on SunSpider
and the v8 benchmarks.

  • interpreter/Interpreter.cpp: (JSC::Interpreter::tryCachePutByID): (JSC::Interpreter::tryCacheGetByID):
  • jit/JITStubs.cpp: (JSC::JITStubs::tryCachePutByID): (JSC::JITStubs::tryCacheGetByID): (JSC::JITStubs::cti_op_get_by_id_proto_list): Use the new refactored goodness. See lines beginning with "-" and smile.
  • runtime/JSGlobalObject.h: (JSC::Structure::prototypeForLookup): A shout out to const.
  • runtime/JSPropertyNameIterator.h: (JSC::JSPropertyNameIterator::next): We can use a pointer comparison to see if our cached structure chain is equal to the object's structure chain, since in the case of a cache hit, we share references to the same structure chain.
  • runtime/Operations.h: (JSC::countPrototypeChainEntriesAndCheckForProxies): Use the new refactored goodness.
  • runtime/PropertyNameArray.h: (JSC::PropertyNameArray::PropertyNameArray): (JSC::PropertyNameArray::setShouldCache): (JSC::PropertyNameArray::shouldCache): Renamed "cacheable" to "shouldCache" to communicate that the client is specifying a recommendation, not a capability.


  • runtime/Structure.cpp: (JSC::Structure::Structure): No need to initialize a RefPtr. (JSC::Structure::getEnumerablePropertyNames): Moved some code into helper functions.

(JSC::Structure::prototypeChain): New centralized accessor for a prototype
chain. Revalidates on every access, since the objects in the prototype
chain may have mutated.

(JSC::Structure::isValid): Helper function for revalidating a cached
prototype chain.

(JSC::Structure::getEnumerableNamesFromPropertyTable):
(JSC::Structure::getEnumerableNamesFromClassInfoTable): Factored out of
getEnumerablePropertyNames.

  • runtime/Structure.h:
  • runtime/StructureChain.cpp: (JSC::StructureChain::StructureChain):
  • runtime/StructureChain.h: (JSC::StructureChain::create): No need for structureChainsAreEqual, since we use pointer equality now. Refactored StructureChain to make a little more sense and eliminate special cases for null prototypes.

LayoutTests:

2009-02-24 Geoffrey Garen <[email protected]>

Reviewed by Maciej Stachowiak.


Added a test for <rdar://problem/6611174> REGRESSION (r36701): Unable to
select messages on hotmail (24052)

  • fast/js/for-in-cached-expected.txt: Added.
  • fast/js/for-in-cached.html: Added.
  • fast/js/resources/for-in-cached.js: Added. (forIn):
  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1/*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#ifndef PropertyNameArray_h
22#define PropertyNameArray_h
23
24#include "CallFrame.h"
25#include "Identifier.h"
26#include "Structure.h"
27#include <wtf/HashSet.h>
28#include <wtf/Vector.h>
29
30namespace JSC {
31
32 class PropertyNameArrayData : public RefCounted<PropertyNameArrayData> {
33 public:
34 typedef Vector<Identifier, 20> PropertyNameVector;
35 typedef PropertyNameVector::const_iterator const_iterator;
36
37 static PassRefPtr<PropertyNameArrayData> create() { return adoptRef(new PropertyNameArrayData); }
38
39 const_iterator begin() const { return m_propertyNameVector.begin(); }
40 const_iterator end() const { return m_propertyNameVector.end(); }
41
42 PropertyNameVector& propertyNameVector() { return m_propertyNameVector; }
43
44 void setCachedStructure(Structure* structure) { m_cachedStructure = structure; }
45 Structure* cachedStructure() const { return m_cachedStructure; }
46
47 void setCachedPrototypeChain(PassRefPtr<StructureChain> cachedPrototypeChain) { m_cachedPrototypeChain = cachedPrototypeChain; }
48 StructureChain* cachedPrototypeChain() { return m_cachedPrototypeChain.get(); }
49
50 private:
51 PropertyNameArrayData()
52 : m_cachedStructure(0)
53 {
54 }
55
56 PropertyNameVector m_propertyNameVector;
57 Structure* m_cachedStructure;
58 RefPtr<StructureChain> m_cachedPrototypeChain;
59 };
60
61 class PropertyNameArray {
62 public:
63 typedef PropertyNameArrayData::const_iterator const_iterator;
64
65 PropertyNameArray(JSGlobalData* globalData)
66 : m_data(PropertyNameArrayData::create())
67 , m_globalData(globalData)
68 , m_shouldCache(true)
69 {
70 }
71
72 PropertyNameArray(ExecState* exec)
73 : m_data(PropertyNameArrayData::create())
74 , m_globalData(&exec->globalData())
75 , m_shouldCache(true)
76 {
77 }
78
79 JSGlobalData* globalData() { return m_globalData; }
80
81 void add(const Identifier& identifier) { add(identifier.ustring().rep()); }
82 void add(UString::Rep*);
83 void addKnownUnique(UString::Rep* identifier) { m_data->propertyNameVector().append(Identifier(m_globalData, identifier)); }
84
85 size_t size() const { return m_data->propertyNameVector().size(); }
86
87 Identifier& operator[](unsigned i) { return m_data->propertyNameVector()[i]; }
88 const Identifier& operator[](unsigned i) const { return m_data->propertyNameVector()[i]; }
89
90 const_iterator begin() const { return m_data->begin(); }
91 const_iterator end() const { return m_data->end(); }
92
93 void setData(PassRefPtr<PropertyNameArrayData> data) { m_data = data; }
94 PropertyNameArrayData* data() { return m_data.get(); }
95
96 PassRefPtr<PropertyNameArrayData> releaseData() { return m_data.release(); }
97
98 void setShouldCache(bool shouldCache) { m_shouldCache = shouldCache; }
99 bool shouldCache() const { return m_shouldCache; }
100
101 private:
102 typedef HashSet<UString::Rep*, PtrHash<UString::Rep*> > IdentifierSet;
103
104 RefPtr<PropertyNameArrayData> m_data;
105 IdentifierSet m_set;
106 JSGlobalData* m_globalData;
107 bool m_shouldCache;
108 };
109
110} // namespace JSC
111
112#endif // PropertyNameArray_h
Note: See TracBrowser for help on using the repository browser.