Changeset 279447 in webkit for trunk/Source/JavaScriptCore/parser/VariableEnvironment.h
- Timestamp:
- Jun 30, 2021, 7:03:55 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/VariableEnvironment.h
r278591 r279447 75 75 } 76 76 77 void dump(PrintStream&) const; 78 77 79 private: 78 80 enum Traits : uint16_t { … … 108 110 PrivateNameEntry(uint16_t traits = 0) { m_bits = traits; } 109 111 110 ALWAYS_INLINE bool isUsed() const { return m_bits & IsUsed; }111 ALWAYS_INLINE bool isDeclared() const { return m_bits & IsDeclared; }112 112 ALWAYS_INLINE bool isMethod() const { return m_bits & IsMethod; } 113 113 ALWAYS_INLINE bool isSetter() const { return m_bits & IsSetter; } … … 118 118 bool isPrivateMethodOrAccessor() const { return isMethod() || isSetter() || isGetter(); } 119 119 120 ALWAYS_INLINE void setIsUsed() { m_bits |= IsUsed; }121 ALWAYS_INLINE void setIsDeclared() { m_bits |= IsDeclared; }122 123 120 uint16_t bits() const { return m_bits; } 124 121 … … 130 127 enum Traits : uint16_t { 131 128 None = 0, 132 IsUsed = 1 << 0, 133 IsDeclared = 1 << 1, 134 IsMethod = 1 << 2, 135 IsGetter = 1 << 3, 136 IsSetter = 1 << 4, 137 IsStatic = 1 << 5, 129 IsMethod = 1 << 0, 130 IsGetter = 1 << 1, 131 IsSetter = 1 << 2, 132 IsStatic = 1 << 3, 138 133 }; 139 134 … … 207 202 208 203 ALWAYS_INLINE Map::AddResult declarePrivateField(const Identifier& identifier) { return declarePrivateField(identifier.impl()); } 209 ALWAYS_INLINE void usePrivateName(const Identifier& identifier) { usePrivateName(identifier.impl()); }210 204 211 205 bool declarePrivateMethod(const Identifier& identifier) { return declarePrivateMethod(identifier.impl()); } … … 233 227 PrivateDeclarationResult declarePrivateGetter(const RefPtr<UniquedStringImpl>& identifier, PrivateNameEntry::Traits modifierTraits = PrivateNameEntry::Traits::None); 234 228 235 Map::AddResult declarePrivateField(const RefPtr<UniquedStringImpl>& identifier) 236 { 237 auto& meta = getOrAddPrivateName(identifier.get()); 238 meta.setIsDeclared(); 239 auto entry = VariableEnvironmentEntry(); 240 entry.setIsPrivateField(); 241 entry.setIsConst(); 242 entry.setIsCaptured(); 243 return m_map.add(identifier, entry); 244 } 245 void usePrivateName(const RefPtr<UniquedStringImpl>& identifier) 246 { 247 auto& meta = getOrAddPrivateName(identifier.get()); 248 meta.setIsUsed(); 249 if (meta.isDeclared()) 250 find(identifier)->value.setIsCaptured(); 251 } 229 Map::AddResult declarePrivateField(const RefPtr<UniquedStringImpl>&); 252 230 253 231 ALWAYS_INLINE PrivateNamesRange privateNames() const … … 263 241 return 0; 264 242 return m_rareData->m_privateNames.size(); 243 } 244 245 ALWAYS_INLINE PrivateNameEnvironment* privateNameEnvironment() 246 { 247 if (!m_rareData) 248 return nullptr; 249 return &m_rareData->m_privateNames; 265 250 } 266 251 … … 305 290 } 306 291 307 ALWAYS_INLINE void copyPrivateNamesTo(VariableEnvironment& other) const308 {309 if (!m_rareData)310 return;311 if (!other.m_rareData)312 other.m_rareData = WTF::makeUnique<VariableEnvironment::RareData>();313 if (privateNamesSize() > 0) {314 for (auto entry : privateNames()) {315 if (!(entry.value.isUsed() && entry.value.isDeclared()))316 other.m_rareData->m_privateNames.add(entry.key, entry.value);317 }318 }319 }320 321 292 ALWAYS_INLINE void addPrivateNamesFrom(const PrivateNameEnvironment* privateNameEnvironment) 322 293 { … … 327 298 m_rareData = makeUnique<VariableEnvironment::RareData>(); 328 299 329 for (auto entry : *privateNameEnvironment) { 330 ASSERT(entry.value.isDeclared()); 300 for (auto entry : *privateNameEnvironment) 331 301 m_rareData->m_privateNames.add(entry.key, entry.value); 332 }333 }334 335 ALWAYS_INLINE void copyUndeclaredPrivateNamesTo(VariableEnvironment& outer) const {336 // Used by the Parser to transfer recorded uses of PrivateNames from an337 // inner PrivateNameEnvironment into an outer one, in case a PNE is used338 // earlier in the source code than it is defined.339 if (privateNamesSize() > 0) {340 for (auto entry : privateNames()) {341 if (entry.value.isUsed() && !entry.value.isDeclared())342 outer.getOrAddPrivateName(entry.key.get()).setIsUsed();343 }344 }345 302 } 346 303 … … 357 314 PrivateNameEnvironment m_privateNames; 358 315 }; 316 317 void dump(PrintStream&) const; 359 318 360 319 private:
Note:
See TracChangeset
for help on using the changeset viewer.