source: webkit/trunk/JavaScriptCore/runtime/JSGlobalData.h@ 44550

Last change on this file since 44550 was 44550, checked in by [email protected], 16 years ago

Bug 26249: Support JSON.stringify
<https://bugs.webkit.org/show_bug.cgi?id=26249>

Reviewed by Sam Weinig.

Implement JSON.stringify. This patch handles all the semantics of the ES5
JSON.stringify function, including replacer functions and arrays and both
string and numeric gap arguments.

Currently uses a clamped recursive algorithm basically identical to the spec
description but with a few minor tweaks for performance and corrected semantics
discussed in the es-discuss mailing list.

  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
1/*
2 * Copyright (C) 2008, 2009 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#ifndef JSGlobalData_h
30#define JSGlobalData_h
31
32#include "Collector.h"
33#include "ExecutableAllocator.h"
34#include "JITStubs.h"
35#include "JSValue.h"
36#include "SmallStrings.h"
37#include "TimeoutChecker.h"
38#include <wtf/Forward.h>
39#include <wtf/HashMap.h>
40#include <wtf/RefCounted.h>
41
42struct OpaqueJSClass;
43struct OpaqueJSClassContextData;
44
45namespace JSC {
46
47 class CommonIdentifiers;
48 class FunctionBodyNode;
49 class IdentifierTable;
50 class Instruction;
51 class Interpreter;
52 class JSGlobalObject;
53 class JSObject;
54 class Lexer;
55 class Parser;
56 class ScopeNode;
57 class Structure;
58 class UString;
59 struct HashTable;
60 struct VPtrSet;
61
62 class JSGlobalData : public RefCounted<JSGlobalData> {
63 public:
64 struct ClientData {
65 virtual ~ClientData() = 0;
66 };
67
68 static bool sharedInstanceExists();
69 static JSGlobalData& sharedInstance();
70
71 static PassRefPtr<JSGlobalData> create(bool isShared = false);
72 static PassRefPtr<JSGlobalData> createLeaked();
73 ~JSGlobalData();
74
75#if ENABLE(JSC_MULTIPLE_THREADS)
76 // Will start tracking threads that use the heap, which is resource-heavy.
77 void makeUsableFromMultipleThreads() { heap.makeUsableFromMultipleThreads(); }
78#endif
79
80 bool isSharedInstance;
81 ClientData* clientData;
82
83 const HashTable* arrayTable;
84 const HashTable* dateTable;
85 const HashTable* jsonTable;
86 const HashTable* mathTable;
87 const HashTable* numberTable;
88 const HashTable* regExpTable;
89 const HashTable* regExpConstructorTable;
90 const HashTable* stringTable;
91
92 RefPtr<Structure> activationStructure;
93 RefPtr<Structure> interruptedExecutionErrorStructure;
94 RefPtr<Structure> staticScopeStructure;
95 RefPtr<Structure> stringStructure;
96 RefPtr<Structure> notAnObjectErrorStubStructure;
97 RefPtr<Structure> notAnObjectStructure;
98#if !USE(ALTERNATE_JSIMMEDIATE)
99 RefPtr<Structure> numberStructure;
100#endif
101
102 void* jsArrayVPtr;
103 void* jsByteArrayVPtr;
104 void* jsStringVPtr;
105 void* jsFunctionVPtr;
106
107 IdentifierTable* identifierTable;
108 CommonIdentifiers* propertyNames;
109 const MarkedArgumentBuffer* emptyList; // Lists are supposed to be allocated on the stack to have their elements properly marked, which is not the case here - but this list has nothing to mark.
110 SmallStrings smallStrings;
111
112#if ENABLE(ASSEMBLER)
113 ExecutableAllocator executableAllocator;
114#endif
115
116 Lexer* lexer;
117 Parser* parser;
118 Interpreter* interpreter;
119#if ENABLE(JIT)
120 JITThunks jitStubs;
121 FunctionBodyNode* nativeFunctionThunk()
122 {
123 if (!lazyNativeFunctionThunk)
124 createNativeThunk();
125 return lazyNativeFunctionThunk.get();
126 }
127 RefPtr<FunctionBodyNode> lazyNativeFunctionThunk;
128#endif
129 TimeoutChecker timeoutChecker;
130 Heap heap;
131
132 JSValue exception;
133#if ENABLE(JIT)
134 void* exceptionLocation;
135#endif
136
137 const Vector<Instruction>& numericCompareFunction(ExecState*);
138 Vector<Instruction> lazyNumericCompareFunction;
139 bool initializingLazyNumericCompareFunction;
140
141 HashMap<OpaqueJSClass*, OpaqueJSClassContextData*> opaqueJSClassData;
142
143 JSGlobalObject* head;
144 JSGlobalObject* dynamicGlobalObject;
145
146 HashSet<JSObject*> arrayVisitedElements;
147
148 ScopeNode* scopeNodeBeingReparsed;
149
150 private:
151 JSGlobalData(bool isShared, const VPtrSet&);
152 static JSGlobalData*& sharedInstanceInternal();
153 void createNativeThunk();
154 };
155
156} // namespace JSC
157
158#endif // JSGlobalData_h
Note: See TracBrowser for help on using the repository browser.