Ignore:
Timestamp:
Sep 5, 2013, 10:50:33 PM (12 years ago)
Author:
[email protected]
Message:

Make it simpler to introduce new data types to the global object
https://bugs.webkit.org/show_bug.cgi?id=120801

Reviewed by Gavin Barraclough.

Add an iterator macro that lists all the "simple" ES types (e.g. type
consists of instance, constructor, and prototype classes). So that
we don't need to have every new type litter JSGlobalObject.{cpp,h} with
members, accessors, and manual GC visiting.

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::visitChildren):

  • runtime/JSGlobalObject.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r154916 r155177  
    4949class ArrayPrototype;
    5050class BooleanPrototype;
    51 class DatePrototype;
    5251class Debugger;
    5352class ErrorConstructor;
     
    6463class JSStack;
    6564class LLIntOffsetsExtractor;
    66 class MapPrototype;
    6765class NativeErrorConstructor;
    6866class ProgramCodeBlock;
     
    7068class RegExpConstructor;
    7169class RegExpPrototype;
    72 class SetPrototype;
    7370class SourceCode;
    7471struct ActivationStackNode;
    7572struct HashTable;
     73
     74#define FOR_EACH_SIMPLE_BUILTIN_TYPE(macro) \
     75    macro(Set, set, set, JSSet, Set) \
     76    macro(Map, map, map, JSMap, Map) \
     77    macro(Date, date, date, DateInstance, Date) \
     78    macro(String, string, stringObject, StringObject, String) \
     79    macro(Boolean, boolean, booleanObject, BooleanObject, Boolean) \
     80    macro(Number, number, numberObject, NumberObject, Number) \
     81    macro(Error, error, error, ErrorInstance, Error) \
     82    macro(JSArrayBuffer, arrayBuffer, arrayBuffer, JSArrayBuffer, ArrayBuffer) \
     83
     84#define DECLARE_SIMPLE_BUILTIN_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
     85    class JS ## capitalName; \
     86    class capitalName ## Prototype; \
     87    class capitalName ## Constructor;
     88
     89FOR_EACH_SIMPLE_BUILTIN_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
     90
     91#undef DECLARE_SIMPLE_BUILTIN_TYPE
    7692
    7793typedef Vector<ExecState*, 16> ExecStateStack;
     
    145161    WriteBarrier<FunctionPrototype> m_functionPrototype;
    146162    WriteBarrier<ArrayPrototype> m_arrayPrototype;
    147     WriteBarrier<BooleanPrototype> m_booleanPrototype;
    148     WriteBarrier<StringPrototype> m_stringPrototype;
    149     WriteBarrier<NumberPrototype> m_numberPrototype;
    150     WriteBarrier<DatePrototype> m_datePrototype;
    151163    WriteBarrier<RegExpPrototype> m_regExpPrototype;
    152     WriteBarrier<ErrorPrototype> m_errorPrototype;
    153164    WriteBarrier<JSPromisePrototype> m_promisePrototype;
    154165    WriteBarrier<JSPromiseResolverPrototype> m_promiseResolverPrototype;
    155     WriteBarrier<MapPrototype> m_mapPrototype;
    156     WriteBarrier<SetPrototype> m_setPrototype;
    157166
    158167    WriteBarrier<Structure> m_withScopeStructure;
     
    166175    // Lists the structures we should use during allocation for these particular indexing shapes.
    167176    WriteBarrier<Structure> m_arrayStructureForIndexingShapeDuringAllocation[NumberOfIndexingShapes];
    168        
    169     WriteBarrier<Structure> m_booleanObjectStructure;
     177
    170178    WriteBarrier<Structure> m_callbackConstructorStructure;
    171179    WriteBarrier<Structure> m_callbackFunctionStructure;
     
    175183    WriteBarrier<Structure> m_objcWrapperObjectStructure;
    176184#endif
    177     WriteBarrier<Structure> m_dateStructure;
    178185    WriteBarrier<Structure> m_nullPrototypeObjectStructure;
    179     WriteBarrier<Structure> m_errorStructure;
    180186    WriteBarrier<Structure> m_functionStructure;
    181187    WriteBarrier<Structure> m_boundFunctionStructure;
    182188    WriteBarrier<Structure> m_namedFunctionStructure;
    183189    PropertyOffset m_functionNameOffset;
    184     WriteBarrier<Structure> m_numberObjectStructure;
    185190    WriteBarrier<Structure> m_privateNameStructure;
    186191    WriteBarrier<Structure> m_regExpMatchesArrayStructure;
    187192    WriteBarrier<Structure> m_regExpStructure;
    188     WriteBarrier<Structure> m_stringObjectStructure;
    189193    WriteBarrier<Structure> m_internalFunctionStructure;
    190194
     
    197201
    198202    WriteBarrier<Structure> m_mapDataStructure;
    199     WriteBarrier<Structure> m_mapStructure;
    200     WriteBarrier<Structure> m_setStructure;
    201    
    202     WriteBarrier<JSArrayBufferPrototype> m_arrayBufferPrototype;
    203     WriteBarrier<Structure> m_arrayBufferStructure;
    204    
     203
     204#define DEFINE_STORAGE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
     205    WriteBarrier<capitalName ## Prototype> m_ ## lowerName ## Prototype; \
     206    WriteBarrier<Structure> m_ ## properName ## Structure;
     207
     208    FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
     209
     210#undef DEFINE_STORAGE_FOR_SIMPLE_TYPE
     211
    205212    struct TypedArrayData {
    206213        WriteBarrier<JSObject> prototype;
     
    405412
    406413    JSArrayBufferPrototype* arrayBufferPrototype() const { return m_arrayBufferPrototype.get(); }
    407     Structure* arrayBufferStructure() const { return m_arrayBufferStructure.get(); }
    408    
     414
     415#define DEFINE_ACCESSORS_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
     416    Structure* properName ## Structure() { return m_ ## properName ## Structure.get(); }
     417
     418    FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
     419
     420#undef DEFINE_ACCESSORS_FOR_SIMPLE_TYPE
     421
    409422    Structure* typedArrayStructure(TypedArrayType type) const
    410423    {
Note: See TracChangeset for help on using the changeset viewer.