source: webkit/trunk/JavaScriptCore/runtime/JSGlobalObject.cpp@ 73091

Last change on this file since 73091 was 70496, checked in by [email protected], 15 years ago

2010-10-25 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough.

Remove exec and globalData arguments from jsNumber
https://bugs.webkit.org/show_bug.cgi?id=48270

Remove the now unused exec and globalData arguments from jsNumber
and mechanically update all users of jsNumber.

  • API/JSValueRef.cpp: (JSValueMakeNumber):
  • bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::emitLoad):
  • bytecompiler/NodesCodegen.cpp: (JSC::ArrayNode::emitBytecode):
  • jit/JITArithmetic.cpp: (JSC::JIT::emit_op_mod):
  • jit/JITArithmetic32_64.cpp: (JSC::JIT::emit_op_mod):
  • jit/JITOpcodes.cpp: (JSC::JIT::emit_op_jfalse): (JSC::JIT::emit_op_jtrue):
  • jit/JITStubs.cpp: (JSC::DEFINE_STUB_FUNCTION):
  • jsc.cpp: (functionRun):
  • runtime/Arguments.cpp: (JSC::Arguments::getOwnPropertySlot): (JSC::Arguments::getOwnPropertyDescriptor):
  • runtime/ArrayConstructor.cpp: (JSC::ArrayConstructor::ArrayConstructor):
  • runtime/ArrayPrototype.cpp: (JSC::arrayProtoFuncPop): (JSC::arrayProtoFuncPush): (JSC::arrayProtoFuncShift): (JSC::arrayProtoFuncSplice): (JSC::arrayProtoFuncUnShift): (JSC::arrayProtoFuncFilter): (JSC::arrayProtoFuncMap): (JSC::arrayProtoFuncEvery): (JSC::arrayProtoFuncForEach): (JSC::arrayProtoFuncSome): (JSC::arrayProtoFuncReduce): (JSC::arrayProtoFuncReduceRight): (JSC::arrayProtoFuncIndexOf): (JSC::arrayProtoFuncLastIndexOf):
  • runtime/BooleanConstructor.cpp: (JSC::BooleanConstructor::BooleanConstructor):
  • runtime/CachedTranscendentalFunction.h: (JSC::CachedTranscendentalFunction::operator()):
  • runtime/DateConstructor.cpp: (JSC::DateConstructor::DateConstructor): (JSC::dateParse): (JSC::dateNow): (JSC::dateUTC):
  • runtime/DateInstance.cpp: (JSC::DateInstance::DateInstance):
  • runtime/DatePrototype.cpp: (JSC::dateProtoFuncGetFullYear): (JSC::dateProtoFuncGetUTCFullYear): (JSC::dateProtoFuncGetMonth): (JSC::dateProtoFuncGetUTCMonth): (JSC::dateProtoFuncGetDate): (JSC::dateProtoFuncGetUTCDate): (JSC::dateProtoFuncGetDay): (JSC::dateProtoFuncGetUTCDay): (JSC::dateProtoFuncGetHours): (JSC::dateProtoFuncGetUTCHours): (JSC::dateProtoFuncGetMinutes): (JSC::dateProtoFuncGetUTCMinutes): (JSC::dateProtoFuncGetSeconds): (JSC::dateProtoFuncGetUTCSeconds): (JSC::dateProtoFuncGetMilliSeconds): (JSC::dateProtoFuncGetUTCMilliseconds): (JSC::dateProtoFuncGetTimezoneOffset): (JSC::dateProtoFuncSetTime): (JSC::setNewValueFromTimeArgs): (JSC::setNewValueFromDateArgs): (JSC::dateProtoFuncSetYear): (JSC::dateProtoFuncGetYear):
  • runtime/Error.cpp: (JSC::addErrorSourceInfo): (JSC::addErrorDivotInfo):
  • runtime/ErrorConstructor.cpp: (JSC::ErrorConstructor::ErrorConstructor):
  • runtime/FunctionConstructor.cpp: (JSC::FunctionConstructor::FunctionConstructor):
  • runtime/FunctionPrototype.cpp: (JSC::FunctionPrototype::FunctionPrototype):
  • runtime/JSArray.cpp: (JSC::JSArray::getOwnPropertySlot): (JSC::JSArray::getOwnPropertyDescriptor):
  • runtime/JSByteArray.cpp: (JSC::JSByteArray::JSByteArray):
  • runtime/JSByteArray.h: (JSC::JSByteArray::getIndex):
  • runtime/JSFunction.cpp: (JSC::JSFunction::JSFunction): (JSC::JSFunction::lengthGetter): (JSC::JSFunction::getOwnPropertyDescriptor):
  • runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::reset):
  • runtime/JSGlobalObjectFunctions.cpp: (JSC::globalFuncParseInt): (JSC::globalFuncParseFloat):
  • runtime/JSNumberCell.h: (JSC::JSValue::JSValue): (JSC::jsNaN): (JSC::JSValue::toJSNumber):
  • runtime/JSONObject.cpp: (JSC::unwrapBoxedPrimitive): (JSC::PropertyNameForFunctionCall::value): (JSC::JSONStringify):
  • runtime/JSString.cpp: (JSC::JSString::getStringPropertyDescriptor):
  • runtime/JSString.h: (JSC::JSString::getStringPropertySlot):
  • runtime/JSValue.h: (JSC::jsDoubleNumber): (JSC::jsNumber): (JSC::jsNaN): (JSC::JSValue::JSValue): (JSC::JSValue::toJSNumber):
  • runtime/LiteralParser.cpp: (JSC::LiteralParser::parse):
  • runtime/MathObject.cpp: (JSC::MathObject::MathObject): (JSC::mathProtoFuncAbs): (JSC::mathProtoFuncACos): (JSC::mathProtoFuncASin): (JSC::mathProtoFuncATan): (JSC::mathProtoFuncATan2): (JSC::mathProtoFuncCeil): (JSC::mathProtoFuncCos): (JSC::mathProtoFuncExp): (JSC::mathProtoFuncFloor): (JSC::mathProtoFuncLog): (JSC::mathProtoFuncMax): (JSC::mathProtoFuncMin): (JSC::mathProtoFuncPow): (JSC::mathProtoFuncRandom): (JSC::mathProtoFuncRound): (JSC::mathProtoFuncSin): (JSC::mathProtoFuncSqrt): (JSC::mathProtoFuncTan):
  • runtime/NativeErrorConstructor.cpp: (JSC::NativeErrorConstructor::NativeErrorConstructor):
  • runtime/NumberConstructor.cpp: (JSC::NumberConstructor::NumberConstructor): (JSC::numberConstructorNaNValue): (JSC::numberConstructorNegInfinity): (JSC::numberConstructorPosInfinity): (JSC::numberConstructorMaxValue): (JSC::numberConstructorMinValue): (JSC::constructWithNumberConstructor): (JSC::callNumberConstructor):
  • runtime/NumberPrototype.cpp: (JSC::NumberPrototype::NumberPrototype):
  • runtime/ObjectConstructor.cpp: (JSC::ObjectConstructor::ObjectConstructor):
  • runtime/Operations.cpp: (JSC::jsAddSlowCase):
  • runtime/Operations.h: (JSC::jsAdd):
  • runtime/PrototypeFunction.cpp: (JSC::PrototypeFunction::PrototypeFunction):
  • runtime/RegExpConstructor.cpp: (JSC::RegExpConstructor::RegExpConstructor): (JSC::RegExpMatchesArray::fillArrayInstance):
  • runtime/RegExpObject.cpp: (JSC::regExpObjectLastIndex):
  • runtime/StringConstructor.cpp: (JSC::StringConstructor::StringConstructor):
  • runtime/StringPrototype.cpp: (JSC::StringPrototype::StringPrototype): (JSC::stringProtoFuncReplace): (JSC::stringProtoFuncCharCodeAt): (JSC::stringProtoFuncIndexOf): (JSC::stringProtoFuncLastIndexOf): (JSC::stringProtoFuncSearch): (JSC::stringProtoFuncLocaleCompare):

2010-10-25 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough.

Remove exec and globalData arguments from jsNumber
https://bugs.webkit.org/show_bug.cgi?id=48270

Don't pass exec to jsNumber

  • JSUtils.cpp: (JSObjectKJSValue):
  • UserObjectImp.cpp: (UserObjectImp::toPrimitive):

2010-10-25 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough.

Remove exec and globalData arguments from jsNumber
https://bugs.webkit.org/show_bug.cgi?id=48270

Mechanical removal of exec parameter to jsNumber.

  • bindings/js/JSAudioConstructor.cpp: (WebCore::JSAudioConstructor::JSAudioConstructor):
  • bindings/js/JSCSSStyleDeclarationCustom.cpp: (WebCore::JSCSSStyleDeclaration::nameGetter):
  • bindings/js/JSCoordinatesCustom.cpp: (WebCore::JSCoordinates::altitude): (WebCore::JSCoordinates::altitudeAccuracy): (WebCore::JSCoordinates::heading): (WebCore::JSCoordinates::speed):
  • bindings/js/JSDOMWindowCustom.cpp: (WebCore::JSDOMWindow::setTimeout): (WebCore::JSDOMWindow::setInterval):
  • bindings/js/JSDeviceMotionEventCustom.cpp: (WebCore::createAccelerationObject): (WebCore::createRotationRateObject): (WebCore::JSDeviceMotionEvent::interval):
  • bindings/js/JSDeviceOrientationEventCustom.cpp: (WebCore::JSDeviceOrientationEvent::alpha): (WebCore::JSDeviceOrientationEvent::beta): (WebCore::JSDeviceOrientationEvent::gamma):
  • bindings/js/JSGeolocationCustom.cpp: (WebCore::JSGeolocation::watchPosition):
  • bindings/js/JSHTMLInputElementCustom.cpp: (WebCore::JSHTMLInputElement::selectionStart): (WebCore::JSHTMLInputElement::selectionEnd):
  • bindings/js/JSHTMLOptionsCollectionCustom.cpp: (WebCore::JSHTMLOptionsCollection::length):
  • bindings/js/JSIDBKeyCustom.cpp: (WebCore::toJS):
  • bindings/js/JSInjectedScriptHostCustom.cpp: (WebCore::InjectedScriptHost::createInjectedScript): (WebCore::JSInjectedScriptHost::pushNodePathToFrontend):
  • bindings/js/JSOptionConstructor.cpp: (WebCore::JSOptionConstructor::JSOptionConstructor):
  • bindings/js/JSSQLResultSetRowListCustom.cpp: (WebCore::JSSQLResultSetRowList::item):
  • bindings/js/JSSVGLengthCustom.cpp: (WebCore::JSSVGLength::value):
  • bindings/js/JSScriptProfileNodeCustom.cpp: (WebCore::JSScriptProfileNode::callUID):
  • bindings/js/JSWebGLRenderingContextCustom.cpp: (WebCore::toJS):
  • bindings/js/JSWorkerContextCustom.cpp: (WebCore::JSWorkerContext::setTimeout): (WebCore::JSWorkerContext::setInterval):
  • bindings/js/JSWorkerContextErrorHandler.cpp: (WebCore::JSWorkerContextErrorHandler::handleEvent):
  • bindings/js/ScriptFunctionCall.cpp: (WebCore::ScriptCallArgumentHandler::appendArgument):
  • bindings/js/SerializedScriptValue.cpp: (WebCore::CloneDeserializer::readTerminal):
  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/c/c_instance.cpp: (JSC::Bindings::CInstance::numberValue):
  • bridge/c/c_utility.cpp: (JSC::Bindings::convertNPVariantToValue):
  • bridge/jni/jsc/JNIBridgeJSC.cpp: (JavaField::valueFromInstance): (JavaArray::valueAt):
  • bridge/jni/jsc/JavaInstanceJSC.cpp: (JavaInstance::numberValue): (JavaInstance::invokeMethod):
  • bridge/objc/objc_instance.mm: (ObjcInstance::numberValue):
  • bridge/objc/objc_utility.mm: (JSC::Bindings::convertObjcValueToValue):
  • bridge/runtime_array.cpp: (JSC::RuntimeArray::lengthGetter):
  • bridge/runtime_method.cpp: (JSC::RuntimeMethod::lengthGetter):

2010-10-25 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough.

Remove exec and globalData arguments from jsNumber
https://bugs.webkit.org/show_bug.cgi?id=48270

Mechanical removal of exec parameter to jsNumber

  • Plugins/Hosted/NetscapePluginInstanceProxy.mm: (WebKit::NetscapePluginInstanceProxy::demarshalValueFromArray):
  • Plugins/Hosted/ProxyInstance.mm: (WebKit::ProxyInstance::numberValue):

2010-10-25 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough.

Remove exec and globalData arguments from jsNumber
https://bugs.webkit.org/show_bug.cgi?id=48270

Mechanical removal of exec parameter to jsNumber

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