source: webkit/trunk/JavaScriptCore/kjs/JSGlobalObject.cpp@ 37427

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

JavaScriptCore:

2008-10-08 Darin Adler <Darin Adler>

Reviewed by Cameron Zwarich.

Add CallFrame as a synonym for ExecState. Arguably, some day we should switch every
client over to the new name.

Use CallFrame* consistently rather than Register* or ExecState* in low-level code such
as Machine.cpp and CTI.cpp. Similarly, use callFrame rather than r as its name and use
accessor functions to get at things in the frame.

Eliminate other uses of ExecState* that aren't needed, replacing in some cases with
JSGlobalData* and in other cases eliminating them entirely.

  • API/JSObjectRef.cpp: (JSObjectMakeFunctionWithCallback): (JSObjectMakeFunction): (JSObjectHasProperty): (JSObjectGetProperty): (JSObjectSetProperty): (JSObjectDeleteProperty):
  • API/OpaqueJSString.cpp:
  • API/OpaqueJSString.h:
  • VM/CTI.cpp: (JSC::CTI::getConstant): (JSC::CTI::emitGetArg): (JSC::CTI::emitGetPutArg): (JSC::CTI::getConstantImmediateNumericArg): (JSC::CTI::printOpcodeOperandTypes): (JSC::CTI::CTI): (JSC::CTI::compileOpCall): (JSC::CTI::compileBinaryArithOp): (JSC::CTI::privateCompileMainPass): (JSC::CTI::privateCompile): (JSC::CTI::privateCompileGetByIdProto): (JSC::CTI::privateCompileGetByIdChain): (JSC::CTI::compileRegExp):
  • VM/CTI.h:
  • VM/CodeBlock.h:
  • VM/CodeGenerator.cpp: (JSC::CodeGenerator::emitEqualityOp): (JSC::CodeGenerator::emitLoad): (JSC::CodeGenerator::emitUnexpectedLoad): (JSC::CodeGenerator::emitConstruct):
  • VM/CodeGenerator.h:
  • VM/Machine.cpp: (JSC::jsLess): (JSC::jsLessEq): (JSC::jsAddSlowCase): (JSC::jsAdd): (JSC::jsTypeStringForValue): (JSC::Machine::resolve): (JSC::Machine::resolveSkip): (JSC::Machine::resolveGlobal): (JSC::inlineResolveBase): (JSC::Machine::resolveBase): (JSC::Machine::resolveBaseAndProperty): (JSC::Machine::resolveBaseAndFunc): (JSC::Machine::slideRegisterWindowForCall): (JSC::isNotObject): (JSC::Machine::callEval): (JSC::Machine::dumpCallFrame): (JSC::Machine::dumpRegisters): (JSC::Machine::unwindCallFrame): (JSC::Machine::throwException): (JSC::DynamicGlobalObjectScope::DynamicGlobalObjectScope): (JSC::DynamicGlobalObjectScope::~DynamicGlobalObjectScope): (JSC::Machine::execute): (JSC::Machine::debug): (JSC::Machine::createExceptionScope): (JSC::cachePrototypeChain): (JSC::Machine::tryCachePutByID): (JSC::Machine::tryCacheGetByID): (JSC::Machine::privateExecute): (JSC::Machine::retrieveArguments): (JSC::Machine::retrieveCaller): (JSC::Machine::retrieveLastCaller): (JSC::Machine::findFunctionCallFrame): (JSC::Machine::getArgumentsData): (JSC::Machine::tryCTICachePutByID): (JSC::Machine::getCTIArrayLengthTrampoline): (JSC::Machine::getCTIStringLengthTrampoline): (JSC::Machine::tryCTICacheGetByID): (JSC::Machine::cti_op_convert_this): (JSC::Machine::cti_op_end): (JSC::Machine::cti_op_add): (JSC::Machine::cti_op_pre_inc): (JSC::Machine::cti_timeout_check): (JSC::Machine::cti_op_loop_if_less): (JSC::Machine::cti_op_loop_if_lesseq): (JSC::Machine::cti_op_new_object): (JSC::Machine::cti_op_put_by_id): (JSC::Machine::cti_op_put_by_id_second): (JSC::Machine::cti_op_put_by_id_generic): (JSC::Machine::cti_op_put_by_id_fail): (JSC::Machine::cti_op_get_by_id): (JSC::Machine::cti_op_get_by_id_second): (JSC::Machine::cti_op_get_by_id_generic): (JSC::Machine::cti_op_get_by_id_fail): (JSC::Machine::cti_op_instanceof): (JSC::Machine::cti_op_del_by_id): (JSC::Machine::cti_op_mul): (JSC::Machine::cti_op_new_func): (JSC::Machine::cti_op_call_JSFunction): (JSC::Machine::cti_vm_compile): (JSC::Machine::cti_op_push_activation): (JSC::Machine::cti_op_call_NotJSFunction): (JSC::Machine::cti_op_create_arguments): (JSC::Machine::cti_op_tear_off_activation): (JSC::Machine::cti_op_tear_off_arguments): (JSC::Machine::cti_op_ret_profiler): (JSC::Machine::cti_op_ret_scopeChain): (JSC::Machine::cti_op_new_array): (JSC::Machine::cti_op_resolve): (JSC::Machine::cti_op_construct_JSConstruct): (JSC::Machine::cti_op_construct_NotJSConstruct): (JSC::Machine::cti_op_get_by_val): (JSC::Machine::cti_op_resolve_func): (JSC::Machine::cti_op_sub): (JSC::Machine::cti_op_put_by_val): (JSC::Machine::cti_op_put_by_val_array): (JSC::Machine::cti_op_lesseq): (JSC::Machine::cti_op_loop_if_true): (JSC::Machine::cti_op_negate): (JSC::Machine::cti_op_resolve_base): (JSC::Machine::cti_op_resolve_skip): (JSC::Machine::cti_op_resolve_global): (JSC::Machine::cti_op_div): (JSC::Machine::cti_op_pre_dec): (JSC::Machine::cti_op_jless): (JSC::Machine::cti_op_not): (JSC::Machine::cti_op_jtrue): (JSC::Machine::cti_op_post_inc): (JSC::Machine::cti_op_eq): (JSC::Machine::cti_op_lshift): (JSC::Machine::cti_op_bitand): (JSC::Machine::cti_op_rshift): (JSC::Machine::cti_op_bitnot): (JSC::Machine::cti_op_resolve_with_base): (JSC::Machine::cti_op_new_func_exp): (JSC::Machine::cti_op_mod): (JSC::Machine::cti_op_less): (JSC::Machine::cti_op_neq): (JSC::Machine::cti_op_post_dec): (JSC::Machine::cti_op_urshift): (JSC::Machine::cti_op_bitxor): (JSC::Machine::cti_op_new_regexp): (JSC::Machine::cti_op_bitor): (JSC::Machine::cti_op_call_eval): (JSC::Machine::cti_op_throw): (JSC::Machine::cti_op_get_pnames): (JSC::Machine::cti_op_next_pname): (JSC::Machine::cti_op_push_scope): (JSC::Machine::cti_op_pop_scope): (JSC::Machine::cti_op_typeof): (JSC::Machine::cti_op_to_jsnumber): (JSC::Machine::cti_op_in): (JSC::Machine::cti_op_push_new_scope): (JSC::Machine::cti_op_jmp_scopes): (JSC::Machine::cti_op_put_by_index): (JSC::Machine::cti_op_switch_imm): (JSC::Machine::cti_op_switch_char): (JSC::Machine::cti_op_switch_string): (JSC::Machine::cti_op_del_by_val): (JSC::Machine::cti_op_put_getter): (JSC::Machine::cti_op_put_setter): (JSC::Machine::cti_op_new_error): (JSC::Machine::cti_op_debug): (JSC::Machine::cti_vm_throw):
  • VM/Machine.h:
  • VM/Register.h:
  • VM/RegisterFile.h:
  • kjs/Arguments.h:
  • kjs/DebuggerCallFrame.cpp: (JSC::DebuggerCallFrame::functionName): (JSC::DebuggerCallFrame::type): (JSC::DebuggerCallFrame::thisObject): (JSC::DebuggerCallFrame::evaluate):
  • kjs/DebuggerCallFrame.h:
  • kjs/ExecState.cpp: (JSC::CallFrame::thisValue):
  • kjs/ExecState.h:
  • kjs/FunctionConstructor.cpp: (JSC::constructFunction):
  • kjs/JSActivation.cpp: (JSC::JSActivation::JSActivation): (JSC::JSActivation::argumentsGetter):
  • kjs/JSActivation.h:
  • kjs/JSGlobalObject.cpp: (JSC::JSGlobalObject::init):
  • kjs/JSGlobalObjectFunctions.cpp: (JSC::globalFuncEval):
  • kjs/JSVariableObject.h:
  • kjs/Parser.cpp: (JSC::Parser::parse):
  • kjs/RegExpConstructor.cpp: (JSC::constructRegExp):
  • kjs/RegExpPrototype.cpp: (JSC::regExpProtoFuncCompile):
  • kjs/Shell.cpp: (prettyPrintScript):
  • kjs/StringPrototype.cpp: (JSC::stringProtoFuncMatch): (JSC::stringProtoFuncSearch):
  • kjs/identifier.cpp: (JSC::Identifier::checkSameIdentifierTable):
  • kjs/interpreter.cpp: (JSC::Interpreter::checkSyntax): (JSC::Interpreter::evaluate):
  • kjs/nodes.cpp: (JSC::ThrowableExpressionData::emitThrowError): (JSC::RegExpNode::emitCode): (JSC::ArrayNode::emitCode): (JSC::InstanceOfNode::emitCode):
  • kjs/nodes.h:
  • kjs/regexp.cpp: (JSC::RegExp::RegExp): (JSC::RegExp::create):
  • kjs/regexp.h:
  • profiler/HeavyProfile.h:
  • profiler/Profile.h:
  • wrec/WREC.cpp:
  • wrec/WREC.h:

WebKit/mac:

2008-10-08 Darin Adler <Darin Adler>

Reviewed by Cameron Zwarich.

  • WebView/WebScriptDebugger.mm: (WebScriptDebugger::WebScriptDebugger): Update since DebuggerCallFrame is simpler now.
  • Property svn:eol-style set to native
File size: 21.4 KB
Line 
1/*
2 * Copyright (C) 2007, 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#include "config.h"
31#include "JSGlobalObject.h"
32
33#include "JSCallbackConstructor.h"
34#include "JSCallbackFunction.h"
35#include "JSCallbackObject.h"
36
37#include "Arguments.h"
38#include "ArrayConstructor.h"
39#include "ArrayPrototype.h"
40#include "BooleanConstructor.h"
41#include "BooleanPrototype.h"
42#include "CodeBlock.h"
43#include "DateConstructor.h"
44#include "DatePrototype.h"
45#include "ErrorConstructor.h"
46#include "ErrorPrototype.h"
47#include "FunctionConstructor.h"
48#include "FunctionPrototype.h"
49#include "GlobalEvalFunction.h"
50#include "JSGlobalObjectFunctions.h"
51#include "JSLock.h"
52#include "Machine.h"
53#include "MathObject.h"
54#include "NativeErrorConstructor.h"
55#include "NativeErrorPrototype.h"
56#include "NumberConstructor.h"
57#include "NumberPrototype.h"
58#include "ObjectConstructor.h"
59#include "ObjectPrototype.h"
60#include "Profiler.h"
61#include "PrototypeFunction.h"
62#include "RegExpConstructor.h"
63#include "RegExpMatchesArray.h"
64#include "RegExpObject.h"
65#include "RegExpPrototype.h"
66#include "ScopeChainMark.h"
67#include "StringConstructor.h"
68#include "StringPrototype.h"
69#include "debugger.h"
70
71namespace JSC {
72
73ASSERT_CLASS_FITS_IN_CELL(JSGlobalObject);
74
75// Default number of ticks before a timeout check should be done.
76static const int initialTickCountThreshold = 255;
77
78// Preferred number of milliseconds between each timeout check
79static const int preferredScriptCheckTimeInterval = 1000;
80
81static inline void markIfNeeded(JSValue* v)
82{
83 if (v && !v->marked())
84 v->mark();
85}
86
87static inline void markIfNeeded(const RefPtr<StructureID>& s)
88{
89 if (s)
90 s->mark();
91}
92
93JSGlobalObject::~JSGlobalObject()
94{
95 ASSERT(JSLock::currentThreadIsHoldingLock());
96
97 if (d()->debugger)
98 d()->debugger->detach(this);
99
100 Profiler** profiler = Profiler::enabledProfilerReference();
101 if (UNLIKELY(*profiler != 0)) {
102 (*profiler)->stopProfiling(globalExec(), UString());
103 }
104
105 d()->next->d()->prev = d()->prev;
106 d()->prev->d()->next = d()->next;
107 JSGlobalObject*& headObject = head();
108 if (headObject == this)
109 headObject = d()->next;
110 if (headObject == this)
111 headObject = 0;
112
113 HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end();
114 for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
115 (*it)->globalObject = 0;
116
117 RegisterFile& registerFile = globalData()->machine->registerFile();
118 if (registerFile.globalObject() == this) {
119 registerFile.setGlobalObject(0);
120 registerFile.setNumGlobals(0);
121 }
122 delete d();
123}
124
125void JSGlobalObject::init(JSObject* thisValue)
126{
127 ASSERT(JSLock::currentThreadIsHoldingLock());
128
129 d()->globalData = Heap::heap(this)->globalData();
130 d()->globalScopeChain = ScopeChain(this, d()->globalData.get(), thisValue);
131
132 JSGlobalObject::globalExec()->init(0, 0, d()->globalScopeChain.node(), CallFrame::noCaller(), 0, 0, 0);
133
134 if (JSGlobalObject*& headObject = head()) {
135 d()->prev = headObject;
136 d()->next = headObject->d()->next;
137 headObject->d()->next->d()->prev = this;
138 headObject->d()->next = this;
139 } else
140 headObject = d()->next = d()->prev = this;
141
142 d()->recursion = 0;
143 d()->debugger = 0;
144
145 d()->profileGroup = 0;
146
147 reset(prototype());
148}
149
150void JSGlobalObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value, PutPropertySlot& slot)
151{
152 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
153
154 if (symbolTablePut(propertyName, value))
155 return;
156 JSVariableObject::put(exec, propertyName, value, slot);
157}
158
159void JSGlobalObject::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue* value, unsigned attributes)
160{
161 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
162
163 if (symbolTablePutWithAttributes(propertyName, value, attributes))
164 return;
165
166 JSValue* valueBefore = getDirect(propertyName);
167 PutPropertySlot slot;
168 JSVariableObject::put(exec, propertyName, value, slot);
169 if (!valueBefore) {
170 if (JSValue* valueAfter = getDirect(propertyName))
171 putDirect(propertyName, valueAfter, attributes);
172 }
173}
174
175void JSGlobalObject::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunc)
176{
177 PropertySlot slot;
178 if (!symbolTableGet(propertyName, slot))
179 JSVariableObject::defineGetter(exec, propertyName, getterFunc);
180}
181
182void JSGlobalObject::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunc)
183{
184 PropertySlot slot;
185 if (!symbolTableGet(propertyName, slot))
186 JSVariableObject::defineSetter(exec, propertyName, setterFunc);
187}
188
189static inline JSObject* lastInPrototypeChain(JSObject* object)
190{
191 JSObject* o = object;
192 while (o->prototype()->isObject())
193 o = static_cast<JSObject*>(o->prototype());
194 return o;
195}
196
197void JSGlobalObject::reset(JSValue* prototype)
198{
199 ExecState* exec = JSGlobalObject::globalExec();
200
201 // Prototypes
202
203 d()->functionPrototype = new (exec) FunctionPrototype(exec);
204 d()->functionStructure = JSFunction::createStructureID(d()->functionPrototype);
205 d()->callbackFunctionStructure = JSCallbackFunction::createStructureID(d()->functionPrototype);
206 d()->prototypeFunctionStructure = PrototypeFunction::createStructureID(d()->functionPrototype);
207 d()->functionPrototype->addFunctionProperties(exec, d()->prototypeFunctionStructure.get());
208 d()->objectPrototype = new (exec) ObjectPrototype(exec, d()->prototypeFunctionStructure.get());
209 d()->emptyObjectStructure = d()->objectPrototype->inheritorID();
210 d()->functionPrototype->setPrototype(d()->objectPrototype);
211 d()->argumentsStructure = Arguments::createStructureID(d()->objectPrototype);
212 d()->callbackConstructorStructure = JSCallbackConstructor::createStructureID(d()->objectPrototype);
213 d()->callbackObjectStructure = JSCallbackObject<JSObject>::createStructureID(d()->objectPrototype);
214 d()->arrayPrototype = new (exec) ArrayPrototype(ArrayPrototype::createStructureID(d()->objectPrototype));
215 d()->arrayStructure = JSArray::createStructureID(d()->arrayPrototype);
216 d()->regExpMatchesArrayStructure = RegExpMatchesArray::createStructureID(d()->arrayPrototype);
217 d()->stringPrototype = new (exec) StringPrototype(exec, StringPrototype::createStructureID(d()->objectPrototype));
218 d()->stringObjectStructure = StringObject::createStructureID(d()->stringPrototype);
219 d()->booleanPrototype = new (exec) BooleanPrototype(exec, BooleanPrototype::createStructureID(d()->objectPrototype), d()->prototypeFunctionStructure.get());
220 d()->booleanObjectStructure = BooleanObject::createStructureID(d()->booleanPrototype);
221 d()->numberPrototype = new (exec) NumberPrototype(exec, NumberPrototype::createStructureID(d()->objectPrototype), d()->prototypeFunctionStructure.get());
222 d()->numberObjectStructure = NumberObject::createStructureID(d()->numberPrototype);
223 d()->datePrototype = new (exec) DatePrototype(exec, DatePrototype::createStructureID(d()->objectPrototype));
224 d()->dateStructure = DateInstance::createStructureID(d()->datePrototype);
225 d()->regExpPrototype = new (exec) RegExpPrototype(exec, RegExpPrototype::createStructureID(d()->objectPrototype), d()->prototypeFunctionStructure.get());
226 d()->regExpStructure = RegExpObject::createStructureID(d()->regExpPrototype);
227 ErrorPrototype* errorPrototype = new (exec) ErrorPrototype(exec, ErrorPrototype::createStructureID(d()->objectPrototype), d()->prototypeFunctionStructure.get());
228 d()->errorStructure = ErrorInstance::createStructureID(errorPrototype);
229
230 RefPtr<StructureID> nativeErrorPrototypeStructure = NativeErrorPrototype::createStructureID(errorPrototype);
231
232 NativeErrorPrototype* evalErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "EvalError", "EvalError");
233 NativeErrorPrototype* rangeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "RangeError", "RangeError");
234 NativeErrorPrototype* referenceErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "ReferenceError", "ReferenceError");
235 NativeErrorPrototype* syntaxErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "SyntaxError", "SyntaxError");
236 NativeErrorPrototype* typeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "TypeError", "TypeError");
237 NativeErrorPrototype* URIErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "URIError", "URIError");
238
239 // Constructors
240
241 JSValue* objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructureID(d()->functionPrototype), d()->objectPrototype);
242 JSValue* functionConstructor = new (exec) FunctionConstructor(exec, FunctionConstructor::createStructureID(d()->functionPrototype), d()->functionPrototype);
243 JSValue* arrayConstructor = new (exec) ArrayConstructor(exec, ArrayConstructor::createStructureID(d()->functionPrototype), d()->arrayPrototype);
244 JSValue* stringConstructor = new (exec) StringConstructor(exec, StringConstructor::createStructureID(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->stringPrototype);
245 JSValue* booleanConstructor = new (exec) BooleanConstructor(exec, BooleanConstructor::createStructureID(d()->functionPrototype), d()->booleanPrototype);
246 JSValue* numberConstructor = new (exec) NumberConstructor(exec, NumberConstructor::createStructureID(d()->functionPrototype), d()->numberPrototype);
247 JSValue* dateConstructor = new (exec) DateConstructor(exec, DateConstructor::createStructureID(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->datePrototype);
248
249 d()->regExpConstructor = new (exec) RegExpConstructor(exec, RegExpConstructor::createStructureID(d()->functionPrototype), d()->regExpPrototype);
250
251 d()->errorConstructor = new (exec) ErrorConstructor(exec, ErrorConstructor::createStructureID(d()->functionPrototype), errorPrototype);
252
253 RefPtr<StructureID> nativeErrorStructure = NativeErrorConstructor::createStructureID(d()->functionPrototype);
254
255 d()->evalErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, evalErrorPrototype);
256 d()->rangeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, rangeErrorPrototype);
257 d()->referenceErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, referenceErrorPrototype);
258 d()->syntaxErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, syntaxErrorPrototype);
259 d()->typeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, typeErrorPrototype);
260 d()->URIErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, URIErrorPrototype);
261
262 d()->functionPrototype->putDirect(exec->propertyNames().constructor, functionConstructor, DontEnum);
263
264 d()->objectPrototype->putDirect(exec->propertyNames().constructor, objectConstructor, DontEnum);
265 d()->functionPrototype->putDirect(exec->propertyNames().constructor, functionConstructor, DontEnum);
266 d()->arrayPrototype->putDirect(exec->propertyNames().constructor, arrayConstructor, DontEnum);
267 d()->booleanPrototype->putDirect(exec->propertyNames().constructor, booleanConstructor, DontEnum);
268 d()->stringPrototype->putDirect(exec->propertyNames().constructor, stringConstructor, DontEnum);
269 d()->numberPrototype->putDirect(exec->propertyNames().constructor, numberConstructor, DontEnum);
270 d()->datePrototype->putDirect(exec->propertyNames().constructor, dateConstructor, DontEnum);
271 d()->regExpPrototype->putDirect(exec->propertyNames().constructor, d()->regExpConstructor, DontEnum);
272 errorPrototype->putDirect(exec->propertyNames().constructor, d()->errorConstructor, DontEnum);
273 evalErrorPrototype->putDirect(exec->propertyNames().constructor, d()->evalErrorConstructor, DontEnum);
274 rangeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->rangeErrorConstructor, DontEnum);
275 referenceErrorPrototype->putDirect(exec->propertyNames().constructor, d()->referenceErrorConstructor, DontEnum);
276 syntaxErrorPrototype->putDirect(exec->propertyNames().constructor, d()->syntaxErrorConstructor, DontEnum);
277 typeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->typeErrorConstructor, DontEnum);
278 URIErrorPrototype->putDirect(exec->propertyNames().constructor, d()->URIErrorConstructor, DontEnum);
279
280 // Set global constructors
281
282 // FIXME: These properties could be handled by a static hash table.
283
284 putDirect(Identifier(exec, "Object"), objectConstructor, DontEnum);
285 putDirect(Identifier(exec, "Function"), functionConstructor, DontEnum);
286 putDirect(Identifier(exec, "Array"), arrayConstructor, DontEnum);
287 putDirect(Identifier(exec, "Boolean"), booleanConstructor, DontEnum);
288 putDirect(Identifier(exec, "String"), stringConstructor, DontEnum);
289 putDirect(Identifier(exec, "Number"), numberConstructor, DontEnum);
290 putDirect(Identifier(exec, "Date"), dateConstructor, DontEnum);
291 putDirect(Identifier(exec, "RegExp"), d()->regExpConstructor, DontEnum);
292 putDirect(Identifier(exec, "Error"), d()->errorConstructor, DontEnum);
293 putDirect(Identifier(exec, "EvalError"), d()->evalErrorConstructor);
294 putDirect(Identifier(exec, "RangeError"), d()->rangeErrorConstructor);
295 putDirect(Identifier(exec, "ReferenceError"), d()->referenceErrorConstructor);
296 putDirect(Identifier(exec, "SyntaxError"), d()->syntaxErrorConstructor);
297 putDirect(Identifier(exec, "TypeError"), d()->typeErrorConstructor);
298 putDirect(Identifier(exec, "URIError"), d()->URIErrorConstructor);
299
300 // Set global values.
301 GlobalPropertyInfo staticGlobals[] = {
302 GlobalPropertyInfo(Identifier(exec, "Math"), new (exec) MathObject(exec, MathObject::createStructureID(d()->objectPrototype)), DontEnum | DontDelete),
303 GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(exec), DontEnum | DontDelete),
304 GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(exec, Inf), DontEnum | DontDelete),
305 GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete)
306 };
307
308 addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo));
309
310 // Set global functions.
311
312 d()->evalFunction = new (exec) GlobalEvalFunction(exec, GlobalEvalFunction::createStructureID(d()->functionPrototype), 1, exec->propertyNames().eval, globalFuncEval, this);
313 putDirectFunction(exec, d()->evalFunction, DontEnum);
314 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 2, Identifier(exec, "parseInt"), globalFuncParseInt), DontEnum);
315 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "parseFloat"), globalFuncParseFloat), DontEnum);
316 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isNaN"), globalFuncIsNaN), DontEnum);
317 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isFinite"), globalFuncIsFinite), DontEnum);
318 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "escape"), globalFuncEscape), DontEnum);
319 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "unescape"), globalFuncUnescape), DontEnum);
320 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURI"), globalFuncDecodeURI), DontEnum);
321 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURIComponent"), globalFuncDecodeURIComponent), DontEnum);
322 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURI"), globalFuncEncodeURI), DontEnum);
323 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURIComponent"), globalFuncEncodeURIComponent), DontEnum);
324#ifndef NDEBUG
325 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "kjsprint"), globalFuncKJSPrint), DontEnum);
326#endif
327
328 resetPrototype(prototype);
329}
330
331// Set prototype, and also insert the object prototype at the end of the chain.
332void JSGlobalObject::resetPrototype(JSValue* prototype)
333{
334 setPrototype(prototype);
335 lastInPrototypeChain(this)->setPrototype(d()->objectPrototype);
336}
337
338void JSGlobalObject::setTimeoutTime(unsigned timeoutTime)
339{
340 globalData()->machine->setTimeoutTime(timeoutTime);
341}
342
343void JSGlobalObject::startTimeoutCheck()
344{
345 globalData()->machine->startTimeoutCheck();
346}
347
348void JSGlobalObject::stopTimeoutCheck()
349{
350 globalData()->machine->stopTimeoutCheck();
351}
352
353void JSGlobalObject::mark()
354{
355 JSVariableObject::mark();
356
357 HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end();
358 for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
359 (*it)->mark();
360
361 RegisterFile& registerFile = globalData()->machine->registerFile();
362 if (registerFile.globalObject() == this)
363 registerFile.markGlobals(&globalData()->heap);
364
365 markIfNeeded(d()->regExpConstructor);
366 markIfNeeded(d()->errorConstructor);
367 markIfNeeded(d()->evalErrorConstructor);
368 markIfNeeded(d()->rangeErrorConstructor);
369 markIfNeeded(d()->referenceErrorConstructor);
370 markIfNeeded(d()->syntaxErrorConstructor);
371 markIfNeeded(d()->typeErrorConstructor);
372 markIfNeeded(d()->URIErrorConstructor);
373
374 markIfNeeded(d()->evalFunction);
375
376 markIfNeeded(d()->objectPrototype);
377 markIfNeeded(d()->functionPrototype);
378 markIfNeeded(d()->arrayPrototype);
379 markIfNeeded(d()->booleanPrototype);
380 markIfNeeded(d()->stringPrototype);
381 markIfNeeded(d()->numberPrototype);
382 markIfNeeded(d()->datePrototype);
383 markIfNeeded(d()->regExpPrototype);
384
385 markIfNeeded(d()->errorStructure);
386
387 // No need to mark the other structures, because their prototypes are all
388 // guaranteed to be referenced elsewhere.
389
390 Register* registerArray = d()->registerArray.get();
391 if (!registerArray)
392 return;
393
394 size_t size = d()->registerArraySize;
395 for (size_t i = 0; i < size; ++i) {
396 Register& r = registerArray[i];
397 if (!r.marked())
398 r.mark();
399 }
400}
401
402JSGlobalObject* JSGlobalObject::toGlobalObject(ExecState*) const
403{
404 return const_cast<JSGlobalObject*>(this);
405}
406
407ExecState* JSGlobalObject::globalExec()
408{
409 return CallFrame::create(d()->globalCallFrame + RegisterFile::CallFrameHeaderSize);
410}
411
412bool JSGlobalObject::isDynamicScope() const
413{
414 return true;
415}
416
417void JSGlobalObject::copyGlobalsFrom(RegisterFile& registerFile)
418{
419 ASSERT(!d()->registerArray);
420 ASSERT(!d()->registerArraySize);
421
422 int numGlobals = registerFile.numGlobals();
423 if (!numGlobals) {
424 d()->registers = 0;
425 return;
426 }
427
428 Register* registerArray = copyRegisterArray(registerFile.lastGlobal(), numGlobals);
429 setRegisters(registerArray + numGlobals, registerArray, numGlobals);
430}
431
432void JSGlobalObject::copyGlobalsTo(RegisterFile& registerFile)
433{
434 JSGlobalObject* lastGlobalObject = registerFile.globalObject();
435 if (lastGlobalObject && lastGlobalObject != this)
436 lastGlobalObject->copyGlobalsFrom(registerFile);
437
438 registerFile.setGlobalObject(this);
439 registerFile.setNumGlobals(symbolTable().size());
440
441 if (d()->registerArray) {
442 memcpy(registerFile.start() - d()->registerArraySize, d()->registerArray.get(), d()->registerArraySize * sizeof(Register));
443 setRegisters(registerFile.start(), 0, 0);
444 }
445}
446
447void* JSGlobalObject::operator new(size_t size, JSGlobalData* globalData)
448{
449#ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
450 return globalData->heap.inlineAllocate(size);
451#else
452 return globalData->heap.allocate(size);
453#endif
454}
455
456} // namespace JSC
Note: See TracBrowser for help on using the repository browser.