Changeset 4206 in webkit for trunk/JavaScriptCore/kjs/identifier.cpp
- Timestamp:
- Apr 29, 2003, 11:26:29 AM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/identifier.cpp
r3745 r4206 20 20 */ 21 21 22 // For JavaScriptCore we need to avoid having static constructors. 23 // Our strategy is to declare the global objects with a different type (initialized to 0) 24 // and then use placement new to initialize the global objects later. This is not completely 25 // portable, and it would be good to figure out a 100% clean way that still avoids code that 26 // runs at init time. 27 28 #if APPLE_CHANGES 29 #define AVOID_STATIC_CONSTRUCTORS 1 30 #endif 31 32 #if AVOID_STATIC_CONSTRUCTORS 33 #define KJS_IDENTIFIER_HIDE_GLOBALS 1 34 #endif 35 22 36 #include "identifier.h" 23 37 … … 43 57 44 58 #endif 45 46 extern const Identifier argumentsPropertyName("arguments");47 extern const Identifier calleePropertyName("callee");48 extern const Identifier constructorPropertyName("constructor");49 extern const Identifier lengthPropertyName("length");50 extern const Identifier messagePropertyName("message");51 extern const Identifier namePropertyName("name");52 extern const Identifier prototypePropertyName("prototype");53 extern const Identifier specialPrototypePropertyName("__proto__");54 extern const Identifier toLocaleStringPropertyName("toLocaleString");55 extern const Identifier toStringPropertyName("toString");56 extern const Identifier valueOfPropertyName("valueOf");57 59 58 60 const int _minTableSize = 64; … … 301 303 } 302 304 305 // Global constants for property name strings. 306 307 #if !AVOID_STATIC_CONSTRUCTORS 308 // Define an Identifier in the normal way. 309 #define DEFINE_GLOBAL(name, string) extern const Identifier name ## PropertyName(string); 310 #else 311 // Define an Identifier-sized array of pointers to avoid static initialization. 312 // Use an array of pointers instead of an array of char in case there is some alignment issue. 313 #define DEFINE_GLOBAL(name, string) \ 314 void * name ## PropertyName[(sizeof(Identifier) + sizeof(void *) - 1) / sizeof(void *)]; 315 #endif 316 317 #define CALL_DEFINE_GLOBAL(name) DEFINE_GLOBAL(name, #name) 318 KJS_IDENTIFIER_EACH_GLOBAL(CALL_DEFINE_GLOBAL) 319 DEFINE_GLOBAL(specialPrototype, "__proto__") 320 321 void Identifier::init() 322 { 323 #if AVOID_STATIC_CONSTRUCTORS 324 static bool initialized; 325 if (!initialized) { 326 // Use placement new to initialize the globals. 327 #define PLACEMENT_NEW_GLOBAL(name, string) new (&name ## PropertyName) Identifier(string); 328 #define CALL_PLACEMENT_NEW_GLOBAL(name) PLACEMENT_NEW_GLOBAL(name, #name) 329 KJS_IDENTIFIER_EACH_GLOBAL(CALL_PLACEMENT_NEW_GLOBAL) 330 PLACEMENT_NEW_GLOBAL(specialPrototype, "__proto__") 331 initialized = true; 332 } 333 #endif 334 } 335 303 336 } // namespace KJS
Note:
See TracChangeset
for help on using the changeset viewer.