source: webkit/trunk/JavaScriptCore/VM/CodeBlock.h@ 37845

Last change on this file since 37845 was 37845, checked in by Darin Adler, 17 years ago

JavaScriptCore:

2008-10-24 Darin Adler <Darin Adler>

  • API/APICast.h:
  • API/JSCallbackConstructor.h:
  • API/JSCallbackFunction.cpp:
  • API/JSCallbackFunction.h:
  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h:
  • API/JSContextRef.cpp:
  • API/JSObjectRef.cpp:
  • API/JSValueRef.cpp:
  • VM/CTI.cpp:
  • VM/CTI.h:
  • VM/CodeBlock.cpp:
  • VM/CodeBlock.h:
  • VM/CodeGenerator.cpp:
  • VM/CodeGenerator.h:
  • VM/ExceptionHelpers.cpp:
  • VM/ExceptionHelpers.h:
  • VM/JSPropertyNameIterator.cpp:
  • VM/JSPropertyNameIterator.h:
  • VM/Machine.cpp:
  • VM/Machine.h:
  • VM/Register.h:
  • kjs/ArgList.cpp:
  • kjs/ArgList.h:
  • kjs/Arguments.cpp:
  • kjs/Arguments.h:
  • kjs/ArrayConstructor.cpp:
  • kjs/ArrayPrototype.cpp:
  • kjs/BooleanConstructor.cpp:
  • kjs/BooleanConstructor.h:
  • kjs/BooleanObject.h:
  • kjs/BooleanPrototype.cpp:
  • kjs/CallData.cpp:
  • kjs/CallData.h:
  • kjs/ConstructData.cpp:
  • kjs/ConstructData.h:
  • kjs/DateConstructor.cpp:
  • kjs/DateInstance.h:
  • kjs/DatePrototype.cpp:
  • kjs/DatePrototype.h:
  • kjs/DebuggerCallFrame.cpp:
  • kjs/DebuggerCallFrame.h:
  • kjs/ErrorConstructor.cpp:
  • kjs/ErrorPrototype.cpp:
  • kjs/ExecState.cpp:
  • kjs/ExecState.h:
  • kjs/FunctionConstructor.cpp:
  • kjs/FunctionPrototype.cpp:
  • kjs/FunctionPrototype.h:
  • kjs/GetterSetter.cpp:
  • kjs/GetterSetter.h:
  • kjs/InternalFunction.h:
  • kjs/JSActivation.cpp:
  • kjs/JSActivation.h:
  • kjs/JSArray.cpp:
  • kjs/JSArray.h:
  • kjs/JSCell.cpp:
  • kjs/JSCell.h:
  • kjs/JSFunction.cpp:
  • kjs/JSFunction.h:
  • kjs/JSGlobalData.h:
  • kjs/JSGlobalObject.cpp:
  • kjs/JSGlobalObject.h:
  • kjs/JSGlobalObjectFunctions.cpp:
  • kjs/JSGlobalObjectFunctions.h:
  • kjs/JSImmediate.cpp:
  • kjs/JSImmediate.h:
  • kjs/JSNotAnObject.cpp:
  • kjs/JSNotAnObject.h:
  • kjs/JSNumberCell.cpp:
  • kjs/JSNumberCell.h:
  • kjs/JSObject.cpp:
  • kjs/JSObject.h:
  • kjs/JSStaticScopeObject.cpp:
  • kjs/JSStaticScopeObject.h:
  • kjs/JSString.cpp:
  • kjs/JSString.h:
  • kjs/JSValue.h:
  • kjs/JSVariableObject.h:
  • kjs/JSWrapperObject.h:
  • kjs/MathObject.cpp:
  • kjs/MathObject.h:
  • kjs/NativeErrorConstructor.cpp:
  • kjs/NumberConstructor.cpp:
  • kjs/NumberConstructor.h:
  • kjs/NumberObject.cpp:
  • kjs/NumberObject.h:
  • kjs/NumberPrototype.cpp:
  • kjs/ObjectConstructor.cpp:
  • kjs/ObjectPrototype.cpp:
  • kjs/ObjectPrototype.h:
  • kjs/PropertyMap.h:
  • kjs/PropertySlot.cpp:
  • kjs/PropertySlot.h:
  • kjs/RegExpConstructor.cpp:
  • kjs/RegExpConstructor.h:
  • kjs/RegExpMatchesArray.h:
  • kjs/RegExpObject.cpp:
  • kjs/RegExpObject.h:
  • kjs/RegExpPrototype.cpp:
  • kjs/Shell.cpp:
  • kjs/StringConstructor.cpp:
  • kjs/StringObject.cpp:
  • kjs/StringObject.h:
  • kjs/StringObjectThatMasqueradesAsUndefined.h:
  • kjs/StringPrototype.cpp:
  • kjs/StructureID.cpp:
  • kjs/StructureID.h:
  • kjs/collector.cpp:
  • kjs/collector.h:
  • kjs/completion.h:
  • kjs/grammar.y:
  • kjs/interpreter.cpp:
  • kjs/interpreter.h:
  • kjs/lookup.cpp:
  • kjs/lookup.h:
  • kjs/nodes.h:
  • kjs/operations.cpp:
  • kjs/operations.h:
  • kjs/protect.h:
  • profiler/ProfileGenerator.cpp:
  • profiler/Profiler.cpp:
  • profiler/Profiler.h: Use JSValue* instead of JSValuePtr.

JavaScriptGlue:

2008-10-24 Darin Adler <Darin Adler>

  • JSObject.cpp: (nativeCallFunction):
  • JSUtils.cpp: (KJSValueToJSObject): (JSObjectKJSValue): (KJSValueToCFTypeInternal): (KJSValueToCFType):
  • JSUtils.h:
  • JSValueWrapper.cpp: (JSValueWrapper::JSValueWrapper): (JSValueWrapper::GetValue): (JSValueWrapper::JSObjectCopyProperty): (JSValueWrapper::JSObjectSetProperty): (JSValueWrapper::JSObjectCallFunction):
  • JSValueWrapper.h:
  • UserObjectImp.cpp: (UserObjectImp::callAsFunction): (UserObjectImp::userObjectGetter): (UserObjectImp::getOwnPropertySlot): (UserObjectImp::put): (UserObjectImp::toPrimitive):
  • UserObjectImp.h: (UserObjectImp::createStructureID): Use JSValue* instead of JSValuePtr.

WebCore:

2008-10-24 Darin Adler <Darin Adler>

  • bindings/js/JSAttrCustom.cpp:
  • bindings/js/JSCSSRuleCustom.cpp:
  • bindings/js/JSCSSStyleDeclarationCustom.cpp:
  • bindings/js/JSCSSValueCustom.cpp:
  • bindings/js/JSCanvasPixelArrayCustom.h:
  • bindings/js/JSCanvasRenderingContext2DCustom.cpp:
  • bindings/js/JSClipboardCustom.cpp:
  • bindings/js/JSConsoleCustom.cpp:
  • bindings/js/JSCustomSQLStatementCallback.cpp:
  • bindings/js/JSCustomSQLStatementErrorCallback.cpp:
  • bindings/js/JSCustomSQLTransactionCallback.cpp:
  • bindings/js/JSCustomSQLTransactionErrorCallback.cpp:
  • bindings/js/JSCustomVoidCallback.cpp:
  • bindings/js/JSCustomVoidCallback.h:
  • bindings/js/JSCustomXPathNSResolver.cpp:
  • bindings/js/JSCustomXPathNSResolver.h:
  • bindings/js/JSDOMApplicationCacheCustom.cpp:
  • bindings/js/JSDOMBinding.cpp:
  • bindings/js/JSDOMBinding.h:
  • bindings/js/JSDOMWindowBase.cpp:
  • bindings/js/JSDOMWindowBase.h:
  • bindings/js/JSDOMWindowCustom.cpp:
  • bindings/js/JSDOMWindowCustom.h:
  • bindings/js/JSDOMWindowShell.cpp:
  • bindings/js/JSDOMWindowShell.h:
  • bindings/js/JSDatabaseCustom.cpp:
  • bindings/js/JSDedicatedWorkerCustom.cpp:
  • bindings/js/JSDocumentCustom.cpp:
  • bindings/js/JSElementCustom.cpp:
  • bindings/js/JSEventCustom.cpp:
  • bindings/js/JSEventListener.cpp:
  • bindings/js/JSEventTarget.cpp:
  • bindings/js/JSEventTarget.h:
  • bindings/js/JSEventTargetBase.h:
  • bindings/js/JSEventTargetNodeCustom.cpp:
  • bindings/js/JSHTMLAllCollection.h:
  • bindings/js/JSHTMLAppletElementCustom.cpp:
  • bindings/js/JSHTMLCollectionCustom.cpp:
  • bindings/js/JSHTMLDocumentCustom.cpp:
  • bindings/js/JSHTMLEmbedElementCustom.cpp:
  • bindings/js/JSHTMLFormElementCustom.cpp:
  • bindings/js/JSHTMLFrameElementCustom.cpp:
  • bindings/js/JSHTMLFrameSetElementCustom.cpp:
  • bindings/js/JSHTMLIFrameElementCustom.cpp:
  • bindings/js/JSHTMLInputElementCustom.cpp:
  • bindings/js/JSHTMLObjectElementCustom.cpp:
  • bindings/js/JSHTMLOptionsCollectionCustom.cpp:
  • bindings/js/JSHTMLSelectElementCustom.cpp:
  • bindings/js/JSHTMLSelectElementCustom.h:
  • bindings/js/JSHistoryCustom.cpp:
  • bindings/js/JSImageDataCustom.cpp:
  • bindings/js/JSInspectedObjectWrapper.cpp:
  • bindings/js/JSInspectedObjectWrapper.h:
  • bindings/js/JSInspectorCallbackWrapper.cpp:
  • bindings/js/JSInspectorCallbackWrapper.h:
  • bindings/js/JSJavaScriptCallFrameCustom.cpp:
  • bindings/js/JSLocationCustom.cpp:
  • bindings/js/JSMessagePortCustom.cpp:
  • bindings/js/JSMimeTypeArrayCustom.cpp:
  • bindings/js/JSNamedNodeMapCustom.cpp:
  • bindings/js/JSNamedNodesCollection.cpp:
  • bindings/js/JSNamedNodesCollection.h:
  • bindings/js/JSNavigatorCustom.cpp:
  • bindings/js/JSNodeCustom.cpp:
  • bindings/js/JSNodeFilterCondition.cpp:
  • bindings/js/JSNodeFilterCondition.h:
  • bindings/js/JSNodeFilterCustom.cpp:
  • bindings/js/JSNodeIteratorCustom.cpp:
  • bindings/js/JSNodeListCustom.cpp:
  • bindings/js/JSPluginArrayCustom.cpp:
  • bindings/js/JSPluginCustom.cpp:
  • bindings/js/JSPluginElementFunctions.cpp:
  • bindings/js/JSPluginElementFunctions.h:
  • bindings/js/JSQuarantinedObjectWrapper.cpp:
  • bindings/js/JSQuarantinedObjectWrapper.h:
  • bindings/js/JSRGBColor.cpp:
  • bindings/js/JSRGBColor.h:
  • bindings/js/JSSQLResultSetRowListCustom.cpp:
  • bindings/js/JSSQLTransactionCustom.cpp:
  • bindings/js/JSSVGElementInstanceCustom.cpp:
  • bindings/js/JSSVGLengthCustom.cpp:
  • bindings/js/JSSVGMatrixCustom.cpp:
  • bindings/js/JSSVGPathSegCustom.cpp:
  • bindings/js/JSSVGPathSegListCustom.cpp:
  • bindings/js/JSSVGPointListCustom.cpp:
  • bindings/js/JSSVGTransformListCustom.cpp:
  • bindings/js/JSStorageCustom.cpp:
  • bindings/js/JSStyleSheetCustom.cpp:
  • bindings/js/JSStyleSheetListCustom.cpp:
  • bindings/js/JSTextCustom.cpp:
  • bindings/js/JSTreeWalkerCustom.cpp:
  • bindings/js/JSXMLHttpRequestCustom.cpp:
  • bindings/js/JSXMLHttpRequestUploadCustom.cpp:
  • bindings/js/JSXSLTProcessorCustom.cpp:
  • bindings/js/ScheduledAction.cpp:
  • bindings/js/ScheduledAction.h:
  • bindings/js/ScriptController.cpp:
  • bindings/js/ScriptController.h:
  • bindings/objc/WebScriptObject.mm:
  • bindings/objc/WebScriptObjectPrivate.h:
  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/NP_jsobject.cpp:
  • bridge/c/c_instance.cpp:
  • bridge/c/c_instance.h:
  • bridge/c/c_runtime.cpp:
  • bridge/c/c_runtime.h:
  • bridge/c/c_utility.cpp:
  • bridge/c/c_utility.h:
  • bridge/jni/jni_instance.cpp:
  • bridge/jni/jni_instance.h:
  • bridge/jni/jni_jsobject.h:
  • bridge/jni/jni_jsobject.mm:
  • bridge/jni/jni_objc.mm:
  • bridge/jni/jni_runtime.cpp:
  • bridge/jni/jni_runtime.h:
  • bridge/jni/jni_utility.cpp:
  • bridge/jni/jni_utility.h:
  • bridge/objc/WebScriptObject.h:
  • bridge/objc/objc_class.h:
  • bridge/objc/objc_class.mm:
  • bridge/objc/objc_instance.h:
  • bridge/objc/objc_instance.mm:
  • bridge/objc/objc_runtime.h:
  • bridge/objc/objc_runtime.mm:
  • bridge/objc/objc_utility.h:
  • bridge/objc/objc_utility.mm:
  • bridge/qt/qt_class.cpp:
  • bridge/qt/qt_class.h:
  • bridge/qt/qt_instance.cpp:
  • bridge/qt/qt_instance.h:
  • bridge/qt/qt_runtime.cpp:
  • bridge/qt/qt_runtime.h:
  • bridge/runtime.cpp:
  • bridge/runtime.h:
  • bridge/runtime_array.cpp:
  • bridge/runtime_array.h:
  • bridge/runtime_method.cpp:
  • bridge/runtime_method.h:
  • bridge/runtime_object.cpp:
  • bridge/runtime_object.h:
  • bridge/testqtbindings.cpp:
  • inspector/JavaScriptCallFrame.cpp:
  • inspector/JavaScriptCallFrame.h:
  • inspector/JavaScriptProfile.cpp:
  • inspector/JavaScriptProfile.h:
  • inspector/JavaScriptProfileNode.cpp:
  • inspector/JavaScriptProfileNode.h:
  • loader/FrameLoader.cpp:
  • loader/FrameLoader.h:
  • page/Console.cpp:
  • page/Console.h:
  • plugins/MimeTypeArray.h:
  • plugins/Plugin.h:
  • plugins/PluginArray.h:
  • plugins/PluginView.cpp:
  • xml/XMLHttpRequest.cpp: Use JSValue* instead of JSValuePtr.

WebKit/mac:

2008-10-24 Darin Adler <Darin Adler>

  • WebView/WebFrame.mm: (-[WebFrame _stringByEvaluatingJavaScriptFromString:forceUserGesture:]):
  • WebView/WebScriptDebugDelegate.mm: (-[WebScriptCallFrame _convertValueToObjcValue:]): (-[WebScriptCallFrame exception]): (-[WebScriptCallFrame evaluateWebScript:]):
  • WebView/WebView.mm: (aeDescFromJSValue): (-[WebView aeDescByEvaluatingJavaScriptFromString:]): Use JSValue* instead of JSValuePtr.

WebKit/qt:

2008-10-24 Darin Adler <Darin Adler>

  • Api/qwebframe.cpp: (QWebFrame::evaluateJavaScript): Use JSValue* instead of JSValuePtr.

WebKit/win:

2008-10-24 Darin Adler <Darin Adler>

  • WebScriptCallFrame.cpp: (WebScriptCallFrame::jsValueToString): (WebScriptCallFrame::stringByEvaluatingJavaScriptFromString): (WebScriptCallFrame::valueForVariable): (WebScriptCallFrame::valueByEvaluatingJavaScriptFromString):
  • WebScriptCallFrame.h:
  • WebView.cpp: (WebView::stringByEvaluatingJavaScriptFromString): Use JSValue* instead of JSValuePtr.

WebKit/wx:

2008-10-24 Darin Adler <Darin Adler>

  • WebFrame.cpp: (wxWebFrame::RunScript): Use JSValue* instead of JSValuePtr.
File size: 13.6 KB
Line 
1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Cameron Zwarich <[email protected]>
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef CodeBlock_h
31#define CodeBlock_h
32
33#include "Instruction.h"
34#include "JSGlobalObject.h"
35#include "nodes.h"
36#include "Parser.h"
37#include "SourceRange.h"
38#include "ustring.h"
39#include <wtf/RefPtr.h>
40#include <wtf/Vector.h>
41
42namespace JSC {
43
44 class ExecState;
45
46 enum CodeType { GlobalCode, EvalCode, FunctionCode };
47
48 static ALWAYS_INLINE int missingThisObjectMarker() { return std::numeric_limits<int>::max(); }
49
50 struct HandlerInfo {
51 uint32_t start;
52 uint32_t end;
53 uint32_t target;
54 uint32_t scopeDepth;
55 void* nativeCode;
56 };
57
58 struct ExpressionRangeInfo {
59 enum {
60 MaxOffset = (1 << 7) - 1,
61 MaxDivot = (1 << 25) - 1
62 };
63 uint32_t instructionOffset : 25;
64 uint32_t divotPoint : 25;
65 uint32_t startOffset : 7;
66 uint32_t endOffset : 7;
67 };
68
69 struct LineInfo {
70 uint32_t instructionOffset;
71 int32_t lineNumber;
72 };
73
74 struct OffsetLocation {
75 int32_t branchOffset;
76#if ENABLE(CTI)
77 void* ctiOffset;
78#endif
79 };
80
81 struct StructureStubInfo {
82 StructureStubInfo(unsigned opcodeIndex)
83 : opcodeIndex(opcodeIndex)
84 , stubRoutine(0)
85 , callReturnLocation(0)
86 , hotPathBegin(0)
87 {
88 }
89
90 unsigned opcodeIndex;
91 void* stubRoutine;
92 void* callReturnLocation;
93 void* hotPathBegin;
94 };
95
96 struct CallLinkInfo {
97 CallLinkInfo()
98 : callReturnLocation(0)
99 , hotPathBegin(0)
100 , hotPathOther(0)
101 , coldPathOther(0)
102 , callee(0)
103 {
104 }
105
106 unsigned opcodeIndex;
107 void* callReturnLocation;
108 void* hotPathBegin;
109 void* hotPathOther;
110 void* coldPathOther;
111 CodeBlock* callee;
112 unsigned position;
113
114 void setUnlinked() { callee = 0; }
115 bool isLinked() { return callee; }
116 };
117
118 inline void* getStructureStubInfoReturnLocation(StructureStubInfo* structureStubInfo)
119 {
120 return structureStubInfo->callReturnLocation;
121 }
122
123 // Binary chop algorithm, calls valueAtPosition on pre-sorted elements in array,
124 // compares result with key (KeyTypes should be comparable with '--', '<', '>').
125 // Optimized for cases where the array contains the key, checked by assertions.
126 template<typename ArrayType, typename KeyType, KeyType(*valueAtPosition)(ArrayType*)>
127 inline ArrayType* binaryChop(ArrayType* array, size_t size, KeyType key)
128 {
129 // The array must contain at least one element (pre-condition, array does conatin key).
130 // If the array only contains one element, no need to do the comparison.
131 while (size > 1) {
132 // Pick an element to check, half way through the array, and read the value.
133 int pos = (size - 1) >> 1;
134 KeyType val = valueAtPosition(&array[pos]);
135
136 // If the key matches, success!
137 if (val == key)
138 return &array[pos];
139 // The item we are looking for is smaller than the item being check; reduce the value of 'size',
140 // chopping off the right hand half of the array.
141 else if (key < val)
142 size = pos;
143 // Discard all values in the left hand half of the array, up to and including the item at pos.
144 else {
145 size -= (pos + 1);
146 array += (pos + 1);
147 }
148
149 // 'size' should never reach zero.
150 ASSERT(size);
151 }
152
153 // If we reach this point we've chopped down to one element, no need to check it matches
154 ASSERT(size == 1);
155 ASSERT(key == valueAtPosition(&array[0]));
156 return &array[0];
157 }
158
159 struct StringJumpTable {
160 typedef HashMap<RefPtr<UString::Rep>, OffsetLocation> StringOffsetTable;
161 StringOffsetTable offsetTable;
162#if ENABLE(CTI)
163 void* ctiDefault; // FIXME: it should not be necessary to store this.
164#endif
165
166 inline int32_t offsetForValue(UString::Rep* value, int32_t defaultOffset)
167 {
168 StringOffsetTable::const_iterator end = offsetTable.end();
169 StringOffsetTable::const_iterator loc = offsetTable.find(value);
170 if (loc == end)
171 return defaultOffset;
172 return loc->second.branchOffset;
173 }
174
175#if ENABLE(CTI)
176 inline void* ctiForValue(UString::Rep* value)
177 {
178 StringOffsetTable::const_iterator end = offsetTable.end();
179 StringOffsetTable::const_iterator loc = offsetTable.find(value);
180 if (loc == end)
181 return ctiDefault;
182 return loc->second.ctiOffset;
183 }
184#endif
185 };
186
187 struct SimpleJumpTable {
188 // FIXME: The two Vectors can be combind into one Vector<OffsetLocation>
189 Vector<int32_t> branchOffsets;
190 int32_t min;
191#if ENABLE(CTI)
192 Vector<void*> ctiOffsets;
193 void* ctiDefault;
194#endif
195
196 int32_t offsetForValue(int32_t value, int32_t defaultOffset);
197 void add(int32_t key, int32_t offset)
198 {
199 if (!branchOffsets[key])
200 branchOffsets[key] = offset;
201 }
202
203#if ENABLE(CTI)
204 inline void* ctiForValue(int32_t value)
205 {
206 if (value >= min && static_cast<uint32_t>(value - min) < ctiOffsets.size())
207 return ctiOffsets[value - min];
208 return ctiDefault;
209 }
210#endif
211 };
212
213 class EvalCodeCache {
214 public:
215 PassRefPtr<EvalNode> get(ExecState* exec, const UString& evalSource, ScopeChainNode* scopeChain, JSValue*& exceptionValue)
216 {
217 RefPtr<EvalNode> evalNode;
218
219 if (evalSource.size() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject())
220 evalNode = cacheMap.get(evalSource.rep());
221
222 if (!evalNode) {
223 int errLine;
224 UString errMsg;
225
226 SourceCode source = makeSource(evalSource);
227 evalNode = exec->globalData().parser->parse<EvalNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
228 if (evalNode) {
229 if (evalSource.size() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject() && cacheMap.size() < maxCacheEntries)
230 cacheMap.set(evalSource.rep(), evalNode);
231 } else {
232 exceptionValue = Error::create(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), NULL);
233 return 0;
234 }
235 }
236
237 return evalNode.release();
238 }
239
240 private:
241 static const int maxCacheableSourceLength = 256;
242 static const int maxCacheEntries = 64;
243
244 HashMap<RefPtr<UString::Rep>, RefPtr<EvalNode> > cacheMap;
245 };
246
247 struct CodeBlock {
248 CodeBlock(ScopeNode* ownerNode_, CodeType codeType_, PassRefPtr<SourceProvider> source_, unsigned sourceOffset_)
249 : ownerNode(ownerNode_)
250 , globalData(0)
251#if ENABLE(CTI)
252 , ctiCode(0)
253#endif
254 , numCalleeRegisters(0)
255 , numConstants(0)
256 , numVars(0)
257 , numParameters(0)
258 , needsFullScopeChain(ownerNode_->needsActivation())
259 , usesEval(ownerNode_->usesEval())
260 , codeType(codeType_)
261 , source(source_)
262 , sourceOffset(sourceOffset_)
263 {
264 ASSERT(source);
265 }
266
267 ~CodeBlock();
268
269#if ENABLE(CTI)
270 void unlinkCallers();
271#endif
272
273 void addCaller(CallLinkInfo* caller)
274 {
275 caller->callee = this;
276 caller->position = linkedCallerList.size();
277 linkedCallerList.append(caller);
278 }
279
280 void removeCaller(CallLinkInfo* caller)
281 {
282 unsigned pos = caller->position;
283 unsigned lastPos = linkedCallerList.size() - 1;
284
285 if (pos != lastPos) {
286 linkedCallerList[pos] = linkedCallerList[lastPos];
287 linkedCallerList[pos]->position = pos;
288 }
289 linkedCallerList.shrink(lastPos);
290 }
291
292#if !defined(NDEBUG) || ENABLE_SAMPLING_TOOL
293 void dump(ExecState*) const;
294 void printStructureIDs(const Instruction*) const;
295 void printStructureID(const char* name, const Instruction*, int operand) const;
296#endif
297 int expressionRangeForVPC(const Instruction*, int& divot, int& startOffset, int& endOffset);
298 int lineNumberForVPC(const Instruction* vPC);
299 bool getHandlerForVPC(const Instruction* vPC, Instruction*& target, int& scopeDepth);
300 void* nativeExceptionCodeForHandlerVPC(const Instruction* handlerVPC);
301
302 void mark();
303 void refStructureIDs(Instruction* vPC) const;
304 void derefStructureIDs(Instruction* vPC) const;
305
306 StructureStubInfo& getStubInfo(void* returnAddress)
307 {
308 return *(binaryChop<StructureStubInfo, void*, getStructureStubInfoReturnLocation>(propertyAccessInstructions.begin(), propertyAccessInstructions.size(), returnAddress));
309 }
310
311 ScopeNode* ownerNode;
312 JSGlobalData* globalData;
313#if ENABLE(CTI)
314 void* ctiCode;
315#endif
316
317 int numCalleeRegisters;
318
319 // NOTE: numConstants holds the number of constant registers allocated
320 // by the code generator, not the number of constant registers used.
321 // (Duplicate constants are uniqued during code generation, and spare
322 // constant registers may be allocated.)
323 int numConstants;
324 int numVars;
325 int numParameters;
326 int thisRegister;
327 bool needsFullScopeChain;
328 bool usesEval;
329 bool usesArguments;
330 CodeType codeType;
331 RefPtr<SourceProvider> source;
332 unsigned sourceOffset;
333
334 Vector<Instruction> instructions;
335 Vector<unsigned> globalResolveInstructions;
336 Vector<StructureStubInfo> propertyAccessInstructions;
337 Vector<CallLinkInfo> callLinkInfos;
338 Vector<CallLinkInfo*> linkedCallerList;
339
340 // Constant pool
341 Vector<Identifier> identifiers;
342 Vector<RefPtr<FuncDeclNode> > functions;
343 Vector<RefPtr<FuncExprNode> > functionExpressions;
344 Vector<Register> constantRegisters;
345 Vector<JSValue*> unexpectedConstants;
346 Vector<RefPtr<RegExp> > regexps;
347 Vector<HandlerInfo> exceptionHandlers;
348 Vector<ExpressionRangeInfo> expressionInfo;
349 Vector<LineInfo> lineInfo;
350
351 Vector<SimpleJumpTable> immediateSwitchJumpTables;
352 Vector<SimpleJumpTable> characterSwitchJumpTables;
353 Vector<StringJumpTable> stringSwitchJumpTables;
354
355 HashSet<unsigned, DefaultHash<unsigned>::Hash, WTF::UnsignedWithZeroKeyHashTraits<unsigned> > labels;
356
357#if ENABLE(CTI)
358 HashMap<void*, unsigned> ctiReturnAddressVPCMap;
359#endif
360
361 EvalCodeCache evalCodeCache;
362
363 private:
364#if !defined(NDEBUG) || ENABLE(SAMPLING_TOOL)
365 void dump(ExecState*, const Vector<Instruction>::const_iterator& begin, Vector<Instruction>::const_iterator&) const;
366#endif
367
368 };
369
370 // Program code is not marked by any function, so we make the global object
371 // responsible for marking it.
372
373 struct ProgramCodeBlock : public CodeBlock {
374 ProgramCodeBlock(ScopeNode* ownerNode_, CodeType codeType_, JSGlobalObject* globalObject_, PassRefPtr<SourceProvider> source_)
375 : CodeBlock(ownerNode_, codeType_, source_, 0)
376 , globalObject(globalObject_)
377 {
378 globalObject->codeBlocks().add(this);
379 }
380
381 ~ProgramCodeBlock()
382 {
383 if (globalObject)
384 globalObject->codeBlocks().remove(this);
385 }
386
387 JSGlobalObject* globalObject; // For program and eval nodes, the global object that marks the constant pool.
388 };
389
390 struct EvalCodeBlock : public ProgramCodeBlock {
391 EvalCodeBlock(ScopeNode* ownerNode_, JSGlobalObject* globalObject_, PassRefPtr<SourceProvider> source_)
392 : ProgramCodeBlock(ownerNode_, EvalCode, globalObject_, source_)
393 {
394 }
395 };
396
397} // namespace JSC
398
399#endif // CodeBlock_h
Note: See TracBrowser for help on using the repository browser.