Ignore:
Timestamp:
Apr 29, 2003, 11:26:29 AM (22 years ago)
Author:
darin
Message:

Reviewed by John.

  • fixed 2959353 -- eliminate globally initialized objects from JavaScriptCore
  • JavaScriptCore.pbproj/project.pbxproj: Added fpconst.cpp.
  • kjs/fpconst.cpp: Added. Defines KJS::NaN and KJS::Inf in a way that does not require a framework init routine.
  • kjs/identifier.h: Use a new KJS_IDENTIFIER_EACH_GLOBAL macro so we can do things to the entire set of identifiers easily. Also added an init function that sets up these globals in a way that does not require a framework init routine.
  • kjs/identifier.cpp: (Identifier::init): Initialize the property ane globals in a way that does not require a framework init routine.
  • kjs/internal.cpp: (InterpreterImp::initGlobalObject): Call Identifier::init.
  • kjs/ustring.h: Remove UChar::null and UString::null, and add UString::null(). We can't have a global object of a class that has a constructor if we want to avoid framework init routines, and luckily very little code relies on these.
  • kjs/ustring.cpp: (UCharReference::ref): Use our own global specific to this function rather than returning UChar::null when past the end of the string. This is dangerous because if the caller modifies it, that affects what all subsequent callers will see. (UString::Rep::create): Added assertions. (UString::UString): Got rid of code here that used to set up UString::null. (UString::null): Added. Returns a global null string, and can be used in some of the places where we used to use the UString::null global. (UString::operator[]): Fixed case where this used to return UChar::null to return '\0' instead.
  • kjs/regexp.cpp: (RegExp::match): Change uses of UString::null to UString::null().
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/identifier.cpp

    r3745 r4206  
    2020 */
    2121
     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
    2236#include "identifier.h"
    2337
     
    4357
    4458#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");
    5759
    5860const int _minTableSize = 64;
     
    301303}
    302304
     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)
     318KJS_IDENTIFIER_EACH_GLOBAL(CALL_DEFINE_GLOBAL)
     319DEFINE_GLOBAL(specialPrototype, "__proto__")
     320
     321void 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
    303336} // namespace KJS
Note: See TracChangeset for help on using the changeset viewer.