]>
git.saurik.com Git - apple/javascriptcore.git/blob - wtf/text/StringStatics.cpp
2 * Copyright (C) 2010 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifdef SKIP_STATIC_CONSTRUCTORS_ON_GCC
29 #define ATOMICSTRING_HIDE_GLOBALS 1
32 #include "AtomicString.h"
33 #include "DynamicAnnotations.h"
34 #include "StaticConstructors.h"
35 #include "StringImpl.h"
39 StringImpl
* StringImpl::empty()
41 // FIXME: This works around a bug in our port of PCRE, that a regular expression
42 // run on the empty string may still perform a read from the first element, and
43 // as such we need this to be a valid pointer. No code should ever be reading
44 // from a zero length string, so this should be able to be a non-null pointer
45 // into the zero-page.
46 // Replace this with 'reinterpret_cast<UChar*>(static_cast<intptr_t>(1))' once
48 static UChar emptyUCharData
= 0;
49 DEFINE_STATIC_LOCAL(StringImpl
, emptyString
, (&emptyUCharData
, 0, ConstructStaticString
));
50 WTF_ANNOTATE_BENIGN_RACE(&emptyString
, "Benign race on StringImpl::emptyString reference counter");
54 JS_EXPORTDATA
DEFINE_GLOBAL(AtomicString
, nullAtom
)
55 JS_EXPORTDATA
DEFINE_GLOBAL(AtomicString
, emptyAtom
, "")
56 JS_EXPORTDATA
DEFINE_GLOBAL(AtomicString
, textAtom
, "#text")
57 JS_EXPORTDATA
DEFINE_GLOBAL(AtomicString
, commentAtom
, "#comment")
58 JS_EXPORTDATA
DEFINE_GLOBAL(AtomicString
, starAtom
, "*")
59 JS_EXPORTDATA
DEFINE_GLOBAL(AtomicString
, xmlAtom
, "xml")
60 JS_EXPORTDATA
DEFINE_GLOBAL(AtomicString
, xmlnsAtom
, "xmlns")
62 void AtomicString::init()
64 static bool initialized
;
66 // On iPhone WebKit, isMainThread() tests for the Web Thread, so use pthread_main_np() instead.
67 ASSERT(pthread_main_np());
69 // Use placement new to initialize the globals.
70 new ((void*)&nullAtom
) AtomicString
;
71 new ((void*)&emptyAtom
) AtomicString("");
72 new ((void*)&textAtom
) AtomicString("#text");
73 new ((void*)&commentAtom
) AtomicString("#comment");
74 new ((void*)&starAtom
) AtomicString("*");
75 new ((void*)&xmlAtom
) AtomicString("xml");
76 new ((void*)&xmlnsAtom
) AtomicString("xmlns");