source: webkit/trunk/JavaScriptCore/kjs/fpconst.cpp@ 4206

Last change on this file since 4206 was 4206, checked in by darin, 22 years ago

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().
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.8 KB
Line 
1/*
2 * Copyright (C) 2003 Apple Computer, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19
20#include <config.h>
21
22// This file exists because JavaScriptCore needs to define the NaN and Inf globals in a way
23// that does not use a static initializer so we don't have a framework initialization routine.
24
25// The trick is to define the NaN and Inf globals with a different type than the declaration.
26// This trick works because the mangled name of the globals does not include the type, although
27// I'm not sure that's guaranteed. There could be alignment issues with this, since arrays of
28// characters don't necessarily need the same alignment doubles do, but for now it seems to work.
29// It would be good to figure out a 100% clean way that still avoids code that runs at init time.
30
31namespace KJS {
32
33#ifdef WORDS_BIGENDIAN
34 extern const unsigned char NaN[sizeof(double)] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 };
35 extern const unsigned char Inf[sizeof(double)] = { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 };
36#else
37 extern const unsigned char NaN[sizeof(double)] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f };
38 extern const unsigned char Inf[sizeof(double)] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
39#endif
40
41};
Note: See TracBrowser for help on using the repository browser.