Changeset 227692 in webkit
- Timestamp:
- Jan 26, 2018, 1:14:17 PM (7 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r227685 r227692 1 2018-01-26 Mark Lam <mark.lam@apple.com> 2 3 We should only append ParserArenaDeletable pointers to ParserArena::m_deletableObjects. 4 https://bugs.webkit.org/show_bug.cgi?id=182180 5 <rdar://problem/36460697> 6 7 Reviewed by Michael Saboff. 8 9 Some parser Node subclasses extend ParserArenaDeletable via multiple inheritance, 10 but not as the Node's first base class. ParserArena::m_deletableObjects is 11 expecting pointers to objects of the shape of ParserArenaDeletable. We ensure 12 this by allocating the Node subclass, and casting it to ParserArenaDeletable to 13 get the correct pointer to append to ParserArena::m_deletableObjects. 14 15 To simplify things, we introduce a JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED 16 (analogous to WTF_MAKE_FAST_ALLOCATED) for use in Node subclasses that extends 17 ParserArenaDeletable. 18 19 * parser/NodeConstructors.h: 20 (JSC::ParserArenaDeletable::operator new): 21 * parser/Nodes.h: 22 * parser/ParserArena.h: 23 (JSC::ParserArena::allocateDeletable): 24 1 25 2018-01-26 Joseph Pecoraro <pecoraro@apple.com> 2 26 -
trunk/Source/JavaScriptCore/parser/NodeConstructors.h
r226650 r227692 31 31 } 32 32 33 template<typename T> 33 34 inline void* ParserArenaDeletable::operator new(size_t size, ParserArena& parserArena) 34 35 { 35 return parserArena.allocateDeletable (size);36 return parserArena.allocateDeletable<T>(size); 36 37 } 37 38 -
trunk/Source/JavaScriptCore/parser/Nodes.h
r226650 r227692 114 114 // ParserArenaDeletable objects are deleted when the arena is deleted. 115 115 // Clients must not call delete directly on such objects. 116 void* operator new(size_t, ParserArena&); 117 }; 116 template<typename T> void* operator new(size_t, ParserArena&); 117 }; 118 119 #define JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED_IMPL(__classToNew) \ 120 void* operator new(size_t size, ParserArena& parserArena) \ 121 { \ 122 return ParserArenaDeletable::operator new<__classToNew>(size, parserArena); \ 123 } 124 125 #define JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(__classToNew) \ 126 public: \ 127 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED_IMPL(__classToNew) \ 128 private: \ 129 typedef int __thisIsHereToForceASemicolonAfterThisMacro 118 130 119 131 class ParserArenaRoot { … … 239 251 240 252 class VariableEnvironmentNode : public ParserArenaDeletable { 253 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(VariableEnvironmentNode); 241 254 public: 242 255 typedef DeclarationStacks::FunctionStack FunctionStack; … … 1414 1427 1415 1428 class BlockNode : public StatementNode, public VariableEnvironmentNode { 1416 public: 1417 using ParserArenaDeletable::operator new; 1418 1429 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(BlockNode); 1430 public: 1419 1431 BlockNode(const JSTokenLocation&, SourceElements*, VariableEnvironment&, FunctionStack&&); 1420 1432 … … 1537 1549 1538 1550 class ForNode : public StatementNode, public VariableEnvironmentNode { 1539 public: 1540 using ParserArenaDeletable::operator new; 1541 1551 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ForNode); 1552 public: 1542 1553 ForNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, ExpressionNode* expr3, StatementNode*, VariableEnvironment&); 1543 1554 … … 1554 1565 1555 1566 class EnumerationNode : public StatementNode, public ThrowableExpressionData, public VariableEnvironmentNode { 1556 public: 1557 using ParserArenaDeletable::operator new; 1558 1567 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(EnumerationNode); 1568 public: 1559 1569 EnumerationNode(const JSTokenLocation&, ExpressionNode*, ExpressionNode*, StatementNode*, VariableEnvironment&); 1560 1570 … … 1569 1579 1570 1580 class ForInNode : public EnumerationNode { 1581 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ForInNode); 1571 1582 public: 1572 1583 ForInNode(const JSTokenLocation&, ExpressionNode*, ExpressionNode*, StatementNode*, VariableEnvironment&); … … 1580 1591 1581 1592 class ForOfNode : public EnumerationNode { 1593 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ForOfNode); 1582 1594 public: 1583 1595 ForOfNode(bool, const JSTokenLocation&, ExpressionNode*, ExpressionNode*, StatementNode*, VariableEnvironment&); … … 1669 1681 1670 1682 class TryNode : public StatementNode, public VariableEnvironmentNode { 1671 public: 1672 using ParserArenaDeletable::operator new; 1673 1683 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(TryNode); 1684 public: 1674 1685 TryNode(const JSTokenLocation&, StatementNode* tryBlock, DestructuringPatternNode* catchPattern, StatementNode* catchBlock, VariableEnvironment& catchEnvironment, StatementNode* finallyBlock); 1675 1686 … … 1685 1696 class ScopeNode : public StatementNode, public ParserArenaRoot, public VariableEnvironmentNode { 1686 1697 public: 1698 // ScopeNode is never directly instantiate. The life-cycle of its derived classes are 1699 // managed using std::unique_ptr. Hence, though ScopeNode extends VariableEnvironmentNode, 1700 // which in turn extends ParserArenaDeletable, we don't want to use ParserArenaDeletable's 1701 // new for allocation. 1702 using ParserArenaRoot::operator new; 1687 1703 1688 1704 ScopeNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, bool inStrictContext); 1689 1705 ScopeNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, const SourceCode&, SourceElements*, VariableEnvironment&, FunctionStack&&, VariableEnvironment&, UniquedStringImplPtrSet&&, CodeFeatures, InnerArrowFunctionCodeFeatures, int numConstants); 1690 1691 using ParserArenaRoot::operator new;1692 1706 1693 1707 const SourceCode& source() const { return m_source; } … … 1832 1846 1833 1847 class ImportSpecifierListNode : public ParserArenaDeletable { 1848 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ImportSpecifierListNode); 1834 1849 public: 1835 1850 typedef Vector<ImportSpecifierNode*, 3> Specifiers; … … 1922 1937 1923 1938 class ExportSpecifierListNode : public ParserArenaDeletable { 1939 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ExportSpecifierListNode); 1924 1940 public: 1925 1941 typedef Vector<ExportSpecifierNode*, 3> Specifiers; … … 1950 1966 1951 1967 class FunctionMetadataNode final : public Node, public ParserArenaDeletable { 1952 public: 1953 using ParserArenaDeletable::operator new; 1954 1968 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(FunctionMetadataNode); 1969 public: 1955 1970 FunctionMetadataNode( 1956 1971 ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, … … 2121 2136 2122 2137 class ClassExprNode final : public ExpressionNode, public VariableEnvironmentNode { 2123 public: 2124 using ParserArenaDeletable::operator new; 2125 2138 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ClassExprNode); 2139 public: 2126 2140 ClassExprNode(const JSTokenLocation&, const Identifier&, const SourceCode& classSource, 2127 2141 VariableEnvironment& classEnvironment, ExpressionNode* constructorExpresssion, … … 2165 2179 2166 2180 class ArrayPatternNode : public DestructuringPatternNode, public ThrowableExpressionData, public ParserArenaDeletable { 2167 public: 2168 using ParserArenaDeletable::operator new; 2169 2181 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ArrayPatternNode); 2182 public: 2170 2183 ArrayPatternNode(); 2171 2184 enum class BindingType { … … 2195 2208 2196 2209 class ObjectPatternNode : public DestructuringPatternNode, public ThrowableExpressionData, public ParserArenaDeletable { 2197 public: 2198 using ParserArenaDeletable::operator new; 2199 2210 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(ObjectPatternNode); 2211 public: 2200 2212 ObjectPatternNode(); 2201 2213 enum class BindingType { … … 2313 2325 2314 2326 class FunctionParameters : public ParserArenaDeletable { 2327 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(FunctionParameters); 2315 2328 public: 2316 2329 FunctionParameters(); … … 2411 2424 2412 2425 class SwitchNode : public StatementNode, public VariableEnvironmentNode { 2413 public: 2414 using ParserArenaDeletable::operator new; 2415 2426 JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(SwitchNode); 2427 public: 2416 2428 SwitchNode(const JSTokenLocation&, ExpressionNode*, CaseBlockNode*, VariableEnvironment&, FunctionStack&&); 2417 2429 -
trunk/Source/JavaScriptCore/parser/ParserArena.h
r206525 r227692 1 1 /* 2 * Copyright (C) 2009 Apple Inc. All rights reserved.2 * Copyright (C) 2009-2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 29 29 #include "Identifier.h" 30 30 #include <array> 31 #include <type_traits> 31 32 #include <wtf/SegmentedVector.h> 32 33 … … 154 155 } 155 156 157 template<typename T, typename = std::enable_if_t<std::is_base_of<ParserArenaDeletable, T>::value>> 156 158 void* allocateDeletable(size_t size) 157 159 { 158 ParserArenaDeletable* deletable = static_cast<ParserArenaDeletable*>(allocateFreeable(size)); 160 // T may extend ParserArenaDeletable via multiple inheritance, but not as T's first 161 // base class. m_deletableObjects is expecting pointers to objects of the shape of 162 // ParserArenaDeletable. We ensure this by allocating T, and casting it to 163 // ParserArenaDeletable to get the correct pointer to append to m_deletableObjects. 164 T* instance = static_cast<T*>(allocateFreeable(size)); 165 ParserArenaDeletable* deletable = static_cast<ParserArenaDeletable*>(instance); 159 166 m_deletableObjects.append(deletable); 160 return deletable;167 return instance; 161 168 } 162 169
Note:
See TracChangeset
for help on using the changeset viewer.