1 | /*
|
---|
2 | * Copyright (C) 2008 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 | *
|
---|
8 | * 1. Redistributions of source code must retain the above copyright
|
---|
9 | * notice, this list of conditions and the following disclaimer.
|
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer in the
|
---|
12 | * documentation and/or other materials provided with the distribution.
|
---|
13 | * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
|
---|
14 | * its contributors may be used to endorse or promote products derived
|
---|
15 | * from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
|
---|
18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
|
---|
21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include "config.h"
|
---|
30 | #include "JSGlobalData.h"
|
---|
31 |
|
---|
32 | #include "collector.h"
|
---|
33 | #include "CommonIdentifiers.h"
|
---|
34 | #include "lexer.h"
|
---|
35 | #include "list.h"
|
---|
36 | #include "lookup.h"
|
---|
37 | #include "nodes.h"
|
---|
38 | #include "parser.h"
|
---|
39 |
|
---|
40 | #if USE(MULTIPLE_THREADS)
|
---|
41 | #include <wtf/ThreadSpecific.h>
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | using namespace WTF;
|
---|
45 |
|
---|
46 | namespace KJS {
|
---|
47 |
|
---|
48 | extern const HashTable arrayTable;
|
---|
49 | extern const HashTable dateTable;
|
---|
50 | extern const HashTable mathTable;
|
---|
51 | extern const HashTable numberTable;
|
---|
52 | extern const HashTable RegExpImpTable;
|
---|
53 | extern const HashTable RegExpObjectImpTable;
|
---|
54 | extern const HashTable stringTable;
|
---|
55 |
|
---|
56 |
|
---|
57 | JSGlobalData::JSGlobalData()
|
---|
58 | // : heap(new Heap)
|
---|
59 | #if USE(MULTIPLE_THREADS)
|
---|
60 | : arrayTable(new HashTable(KJS::arrayTable))
|
---|
61 | , dateTable(new HashTable(KJS::dateTable))
|
---|
62 | , mathTable(new HashTable(KJS::mathTable))
|
---|
63 | , numberTable(new HashTable(KJS::numberTable))
|
---|
64 | , RegExpImpTable(new HashTable(KJS::RegExpImpTable))
|
---|
65 | , RegExpObjectImpTable(new HashTable(KJS::RegExpObjectImpTable))
|
---|
66 | , stringTable(new HashTable(KJS::stringTable))
|
---|
67 | #else
|
---|
68 | : arrayTable(&KJS::arrayTable)
|
---|
69 | , dateTable(&KJS::dateTable)
|
---|
70 | , mathTable(&KJS::mathTable)
|
---|
71 | , numberTable(&KJS::numberTable)
|
---|
72 | , RegExpImpTable(&KJS::RegExpImpTable)
|
---|
73 | , RegExpObjectImpTable(&KJS::RegExpObjectImpTable)
|
---|
74 | , stringTable(&KJS::stringTable)
|
---|
75 | #endif
|
---|
76 | , identifierTable(createIdentifierTable())
|
---|
77 | , propertyNames(new CommonIdentifiers(this))
|
---|
78 | , lexer(new Lexer)
|
---|
79 | , parser(new Parser)
|
---|
80 | , head(0)
|
---|
81 | {
|
---|
82 | }
|
---|
83 |
|
---|
84 | JSGlobalData::~JSGlobalData()
|
---|
85 | {
|
---|
86 | #if USE(MULTIPLE_THREADS)
|
---|
87 | delete[] arrayTable->table;
|
---|
88 | delete[] dateTable->table;
|
---|
89 | delete[] mathTable->table;
|
---|
90 | delete[] numberTable->table;
|
---|
91 | delete[] RegExpImpTable->table;
|
---|
92 | delete[] RegExpObjectImpTable->table;
|
---|
93 | delete[] stringTable->table;
|
---|
94 | delete arrayTable;
|
---|
95 | delete dateTable;
|
---|
96 | delete mathTable;
|
---|
97 | delete numberTable;
|
---|
98 | delete RegExpImpTable;
|
---|
99 | delete RegExpObjectImpTable;
|
---|
100 | delete stringTable;
|
---|
101 |
|
---|
102 | delete parser;
|
---|
103 | delete lexer;
|
---|
104 |
|
---|
105 | delete propertyNames;
|
---|
106 | deleteIdentifierTable(identifierTable);
|
---|
107 | #endif
|
---|
108 | }
|
---|
109 |
|
---|
110 | JSGlobalData& JSGlobalData::threadInstance()
|
---|
111 | {
|
---|
112 | #if USE(MULTIPLE_THREADS)
|
---|
113 | static ThreadSpecific<JSGlobalData> sharedInstance;
|
---|
114 | return *sharedInstance;
|
---|
115 | #else
|
---|
116 | return globalSharedInstance();
|
---|
117 | #endif
|
---|
118 | }
|
---|
119 |
|
---|
120 | }
|
---|