Changeset 20310 in webkit for trunk/JavaScriptCore/kjs/identifier.cpp
- Timestamp:
- Mar 18, 2007, 10:43:47 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/identifier.cpp
r20004 r20310 21 21 22 22 #include "config.h" 23 // For JavaScriptCore we need to avoid having static constructors.24 // Our strategy is to declare the global objects with a different type (initialized to 0)25 // and then use placement new to initialize the global objects later. This is not completely26 // portable, and it would be good to figure out a 100% clean way that still avoids code that27 // runs at init time.28 29 #if !PLATFORM(WIN_OS) // can't get this to compile on Visual C++ yet30 #define AVOID_STATIC_CONSTRUCTORS 131 #else32 #define AVOID_STATIC_CONSTRUCTORS 033 #endif34 35 #if AVOID_STATIC_CONSTRUCTORS36 #define KJS_IDENTIFIER_HIDE_GLOBALS 137 #endif38 23 39 24 #include "identifier.h" … … 210 195 } 211 196 212 // Global constants for property name strings.213 214 #if !AVOID_STATIC_CONSTRUCTORS215 // Define an Identifier in the normal way.216 #define DEFINE_GLOBAL(name, string) extern const Identifier name(string);217 #else218 // Define an Identifier-sized array of pointers to avoid static initialization.219 // Use an array of pointers instead of an array of char in case there is some alignment issue.220 #define DEFINE_GLOBAL(name, string) \221 void * name[(sizeof(Identifier) + sizeof(void *) - 1) / sizeof(void *)];222 #endif223 224 const char * const nullCString = 0;225 226 DEFINE_GLOBAL(nullIdentifier, nullCString)227 DEFINE_GLOBAL(specialPrototypePropertyName, "__proto__")228 229 #define DEFINE_PROPERTY_NAME_GLOBAL(name) DEFINE_GLOBAL(name ## PropertyName, #name)230 KJS_IDENTIFIER_EACH_PROPERTY_NAME_GLOBAL(DEFINE_PROPERTY_NAME_GLOBAL)231 232 void Identifier::init()233 {234 #if AVOID_STATIC_CONSTRUCTORS235 static bool initialized;236 if (!initialized) {237 // Use placement new to initialize the globals.238 239 new (&nullIdentifier) Identifier(nullCString);240 new (&specialPrototypePropertyName) Identifier("__proto__");241 242 #define PLACEMENT_NEW_PROPERTY_NAME_GLOBAL(name) new(&name ## PropertyName) Identifier(#name);243 KJS_IDENTIFIER_EACH_PROPERTY_NAME_GLOBAL(PLACEMENT_NEW_PROPERTY_NAME_GLOBAL)244 245 initialized = true;246 }247 #endif248 }249 250 197 } // namespace KJS
Note:
See TracChangeset
for help on using the changeset viewer.