Changeset 238988 in webkit
- Timestamp:
- Dec 7, 2018 4:25:43 PM (5 years ago)
- Location:
- releases/WebKitGTK/webkit-2.22/Source/JavaScriptCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
releases/WebKitGTK/webkit-2.22/Source/JavaScriptCore/ChangeLog
r238987 r238988 1 2018-09-14 Mark Lam <mark.lam@apple.com> 2 3 Refactor some ForInContext code for better encapsulation. 4 https://bugs.webkit.org/show_bug.cgi?id=189626 5 <rdar://problem/44466415> 6 7 Reviewed by Keith Miller. 8 9 1. Add a ForInContext::m_type field to store the context type. This does not 10 increase the class size, but eliminates the need for a virtual call to get the 11 type. 12 13 Note: we still need a virtual destructor because we'll be mingling 14 IndexedForInContexts and StructureForInContexts in the BytecodeGenerator::m_forInContextStack. 15 16 2. Add ForInContext::isIndexedForInContext() and ForInContext::isStructureForInContext() 17 convenience methods. 18 19 3. Add ForInContext::asIndexedForInContext() and ForInContext::asStructureForInContext() 20 to do the casting to the subclass types. This ensures that we'll properly 21 assert that the casting is legal. 22 23 * bytecompiler/BytecodeGenerator.cpp: 24 (JSC::BytecodeGenerator::emitGetByVal): 25 (JSC::BytecodeGenerator::popIndexedForInScope): 26 (JSC::BytecodeGenerator::popStructureForInScope): 27 * bytecompiler/BytecodeGenerator.h: 28 (JSC::ForInContext::type const): 29 (JSC::ForInContext::isIndexedForInContext const): 30 (JSC::ForInContext::isStructureForInContext const): 31 (JSC::ForInContext::asIndexedForInContext): 32 (JSC::ForInContext::asStructureForInContext): 33 (JSC::ForInContext::ForInContext): 34 (JSC::StructureForInContext::StructureForInContext): 35 (JSC::IndexedForInContext::IndexedForInContext): 36 (JSC::ForInContext::~ForInContext): Deleted. 37 1 38 2018-08-24 Yusuke Suzuki <yusukesuzuki@slowstart.org> 2 39 -
releases/WebKitGTK/webkit-2.22/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
r238987 r238988 2913 2913 unsigned instIndex = instructions().size(); 2914 2914 2915 if (context.type() == ForInContext::IndexedForInContextType) { 2916 static_cast<IndexedForInContext&>(context).addGetInst(instIndex, property->index()); 2917 property = static_cast<IndexedForInContext&>(context).index(); 2915 if (context.isIndexedForInContext()) { 2916 auto& indexedContext = context.asIndexedForInContext(); 2917 indexedContext.addGetInst(instIndex, property->index()); 2918 property = indexedContext.index(); 2918 2919 break; 2919 2920 } 2920 2921 2921 ASSERT(context.type() == ForInContext::StructureForInContextType); 2922 StructureForInContext& structureContext = static_cast<StructureForInContext&>(context); 2922 StructureForInContext& structureContext = context.asStructureForInContext(); 2923 2923 UnlinkedValueProfile profile = emitProfiledOpcode(op_get_direct_pname); 2924 2924 instructions().append(kill(dst)); … … 4632 4632 if (!localRegister) 4633 4633 return; 4634 4635 ASSERT(m_forInContextStack.last()->type() == ForInContext::IndexedForInContextType); 4636 static_cast<IndexedForInContext&>(m_forInContextStack.last().get()).finalize(*this); 4634 m_forInContextStack.last()->asIndexedForInContext().finalize(*this); 4637 4635 m_forInContextStack.removeLast(); 4638 4636 } … … 4744 4742 if (!localRegister) 4745 4743 return; 4746 ASSERT(m_forInContextStack.last()->type() == ForInContext::StructureForInContextType); 4747 static_cast<StructureForInContext&>(m_forInContextStack.last().get()).finalize(*this); 4744 m_forInContextStack.last()->asStructureForInContext().finalize(*this); 4748 4745 m_forInContextStack.removeLast(); 4749 4746 } -
releases/WebKitGTK/webkit-2.22/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
r238986 r238988 57 57 class JSImmutableButterfly; 58 58 class Identifier; 59 class IndexedForInContext; 60 class StructureForInContext; 59 61 60 62 enum ExpectedFunction { … … 181 183 WTF_MAKE_NONCOPYABLE(ForInContext); 182 184 public: 183 ForInContext(RegisterID* localRegister) 184 : m_localRegister(localRegister) 185 , m_isValid(true) 186 { 187 } 188 189 virtual ~ForInContext() 190 { 191 } 185 virtual ~ForInContext() = default; 192 186 193 187 bool isValid() const { return m_isValid; } 194 188 void invalidate() { m_isValid = false; } 195 189 196 enum ForInContextType{197 StructureForInContextType,198 IndexedForInContextType190 enum class Type : uint8_t { 191 IndexedForIn, 192 StructureForIn 199 193 }; 200 virtual ForInContextType type() const = 0; 194 195 Type type() const { return m_type; } 196 bool isIndexedForInContext() const { return m_type == Type::IndexedForIn; } 197 bool isStructureForInContext() const { return m_type == Type::StructureForIn; } 198 199 IndexedForInContext& asIndexedForInContext() 200 { 201 ASSERT(isIndexedForInContext()); 202 return *reinterpret_cast<IndexedForInContext*>(this); 203 } 204 205 StructureForInContext& asStructureForInContext() 206 { 207 ASSERT(isStructureForInContext()); 208 return *reinterpret_cast<StructureForInContext*>(this); 209 } 201 210 202 211 RegisterID* local() const { return m_localRegister.get(); } 212 213 protected: 214 ForInContext(RegisterID* localRegister, Type type) 215 : m_localRegister(localRegister) 216 , m_type(type) 217 { } 203 218 204 219 private: 205 220 RefPtr<RegisterID> m_localRegister; 206 bool m_isValid; 221 bool m_isValid { true }; 222 Type m_type; 207 223 }; 208 224 … … 212 228 213 229 StructureForInContext(RegisterID* localRegister, RegisterID* indexRegister, RegisterID* propertyRegister, RegisterID* enumeratorRegister) 214 : ForInContext(localRegister )230 : ForInContext(localRegister, Type::StructureForIn) 215 231 , m_indexRegister(indexRegister) 216 232 , m_propertyRegister(propertyRegister) 217 233 , m_enumeratorRegister(enumeratorRegister) 218 234 { 219 }220 221 ForInContextType type() const override222 {223 return StructureForInContextType;224 235 } 225 236 … … 245 256 public: 246 257 IndexedForInContext(RegisterID* localRegister, RegisterID* indexRegister) 247 : ForInContext(localRegister )258 : ForInContext(localRegister, Type::IndexedForIn) 248 259 , m_indexRegister(indexRegister) 249 260 { 250 }251 252 ForInContextType type() const override253 {254 return IndexedForInContextType;255 261 } 256 262
Note: See TracChangeset
for help on using the changeset viewer.