|
1 /* |
|
2 * Copyright (C) 2010 Apple Inc. All Rights Reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
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. |
|
12 * |
|
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. |
|
24 */ |
|
25 |
|
26 #include "config.h" |
|
27 |
|
28 #ifdef SKIP_STATIC_CONSTRUCTORS_ON_GCC |
|
29 #define ATOMICSTRING_HIDE_GLOBALS 1 |
|
30 #endif |
|
31 |
|
32 #include "AtomicString.h" |
|
33 #include "StaticConstructors.h" |
|
34 #include "StringImpl.h" |
|
35 |
|
36 namespace WebCore { |
|
37 |
|
38 StringImpl* StringImpl::empty() |
|
39 { |
|
40 // FIXME: This works around a bug in our port of PCRE, that a regular expression |
|
41 // run on the empty string may still perform a read from the first element, and |
|
42 // as such we need this to be a valid pointer. No code should ever be reading |
|
43 // from a zero length string, so this should be able to be a non-null pointer |
|
44 // into the zero-page. |
|
45 // Replace this with 'reinterpret_cast<UChar*>(static_cast<intptr_t>(1))' once |
|
46 // PCRE goes away. |
|
47 static UChar emptyUCharData = 0; |
|
48 DEFINE_STATIC_LOCAL(StringImpl, emptyString, (&emptyUCharData, 0, ConstructStaticString)); |
|
49 return &emptyString; |
|
50 } |
|
51 /* |
|
52 JS_EXPORTDATA DEFINE_GLOBAL(AtomicString, nullAtom) |
|
53 JS_EXPORTDATA DEFINE_GLOBAL(AtomicString, emptyAtom, "") |
|
54 JS_EXPORTDATA DEFINE_GLOBAL(AtomicString, textAtom, "#text") |
|
55 JS_EXPORTDATA DEFINE_GLOBAL(AtomicString, commentAtom, "#comment") |
|
56 JS_EXPORTDATA DEFINE_GLOBAL(AtomicString, starAtom, "*") |
|
57 JS_EXPORTDATA DEFINE_GLOBAL(AtomicString, xmlAtom, "xml") |
|
58 JS_EXPORTDATA DEFINE_GLOBAL(AtomicString, xmlnsAtom, "xmlns") |
|
59 */ |
|
60 AtomicString nullAtom1; |
|
61 AtomicString emptyAtom1; |
|
62 AtomicString textAtom1; |
|
63 AtomicString commentAtom1; |
|
64 AtomicString starAtom1; |
|
65 AtomicString xmlAtom1; |
|
66 AtomicString xmlnsAtom1; |
|
67 |
|
68 void AtomicString::init() |
|
69 { |
|
70 static bool initialized; |
|
71 if (!initialized) { |
|
72 // Initialization is not thread safe, so this function must be called from the main thread first. |
|
73 ASSERT(isMainThread()); |
|
74 |
|
75 // Use placement new to initialize the globals. |
|
76 new ((void*)&nullAtom1) AtomicString; |
|
77 new ((void*)&emptyAtom1) AtomicString(""); |
|
78 new ((void*)&textAtom1) AtomicString("#text"); |
|
79 new ((void*)&commentAtom1) AtomicString("#comment"); |
|
80 new ((void*)&starAtom1) AtomicString("*"); |
|
81 new ((void*)&xmlAtom1) AtomicString("xml"); |
|
82 new ((void*)&xmlnsAtom1) AtomicString("xmlns"); |
|
83 |
|
84 initialized = true; |
|
85 } |
|
86 } |
|
87 |
|
88 const AtomicString& AtomicString::nullAtom2() { return nullAtom1;} |
|
89 const AtomicString& AtomicString::emptyAtom2() { return emptyAtom1;} |
|
90 const AtomicString& AtomicString::textAtom2() { return textAtom1;} |
|
91 const AtomicString& AtomicString::commentAtom2() { return commentAtom1;} |
|
92 const AtomicString& AtomicString::starAtom2() { return starAtom1;} |
|
93 const AtomicString& AtomicString::xmlAtom2() { return xmlAtom1;} |
|
94 const AtomicString& AtomicString::xmlnsAtom2() { return xmlnsAtom1;} |
|
95 |
|
96 } |