#include "CodeBlock.h"
#include "DateConstructor.h"
#include "DatePrototype.h"
+#include "Error.h"
#include "ErrorConstructor.h"
#include "ErrorPrototype.h"
#include "FunctionConstructor.h"
#include "FunctionPrototype.h"
-#include "GlobalEvalFunction.h"
+#include "GetterSetter.h"
+#include "JSBoundFunction.h"
#include "JSFunction.h"
#include "JSGlobalObjectFunctions.h"
#include "JSLock.h"
#include "JSONObject.h"
#include "Interpreter.h"
+#include "Lookup.h"
#include "MathObject.h"
#include "NativeErrorConstructor.h"
#include "NativeErrorPrototype.h"
#include "ObjectConstructor.h"
#include "ObjectPrototype.h"
#include "Profiler.h"
-#include "PrototypeFunction.h"
#include "RegExpConstructor.h"
#include "RegExpMatchesArray.h"
#include "RegExpObject.h"
#include "StringPrototype.h"
#include "Debugger.h"
+#include "JSGlobalObject.lut.h"
+
namespace JSC {
+const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &JSVariableObject::s_info, 0, ExecState::globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) };
+
+const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript
+ , &shouldInterruptScriptBeforeTimeout
+};
+
+/* Source for JSGlobalObject.lut.h
+@begin globalObjectTable
+ parseInt globalFuncParseInt DontEnum|Function 2
+ parseFloat globalFuncParseFloat DontEnum|Function 1
+ isNaN globalFuncIsNaN DontEnum|Function 1
+ isFinite globalFuncIsFinite DontEnum|Function 1
+ escape globalFuncEscape DontEnum|Function 1
+ unescape globalFuncUnescape DontEnum|Function 1
+ decodeURI globalFuncDecodeURI DontEnum|Function 1
+ decodeURIComponent globalFuncDecodeURIComponent DontEnum|Function 1
+ encodeURI globalFuncEncodeURI DontEnum|Function 1
+ encodeURIComponent globalFuncEncodeURIComponent DontEnum|Function 1
+@end
+*/
+
ASSERT_CLASS_FITS_IN_CELL(JSGlobalObject);
// Default number of ticks before a timeout check should be done.
// Preferred number of milliseconds between each timeout check
static const int preferredScriptCheckTimeInterval = 1000;
-static inline void markIfNeeded(MarkStack& markStack, JSValue v)
-{
- if (v)
- markStack.append(v);
-}
-
-static inline void markIfNeeded(MarkStack& markStack, const RefPtr<Structure>& s)
+template <typename T> static inline void visitIfNeeded(SlotVisitor& visitor, WriteBarrier<T>* v)
{
- if (s)
- markIfNeeded(markStack, s->storedPrototype());
+ if (*v)
+ visitor.append(v);
}
JSGlobalObject::~JSGlobalObject()
{
- ASSERT(JSLock::currentThreadIsHoldingLock());
-
- if (d()->debugger)
- d()->debugger->detach(this);
+ if (m_debugger)
+ m_debugger->detach(this);
Profiler** profiler = Profiler::enabledProfilerReference();
if (UNLIKELY(*profiler != 0)) {
- (*profiler)->stopProfiling(globalExec(), UString());
+ (*profiler)->stopProfiling(this);
}
+}
- d()->next->d()->prev = d()->prev;
- d()->prev->d()->next = d()->next;
- JSGlobalObject*& headObject = head();
- if (headObject == this)
- headObject = d()->next;
- if (headObject == this)
- headObject = 0;
-
- HashSet<GlobalCodeBlock*>::const_iterator end = codeBlocks().end();
- for (HashSet<GlobalCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
- (*it)->clearGlobalObject();
-
- RegisterFile& registerFile = globalData()->interpreter->registerFile();
- if (registerFile.clearGlobalObject(this))
- registerFile.setNumGlobals(0);
- d()->destructor(d());
+void JSGlobalObject::destroy(JSCell* cell)
+{
+ jsCast<JSGlobalObject*>(cell)->JSGlobalObject::~JSGlobalObject();
}
void JSGlobalObject::init(JSObject* thisValue)
{
- ASSERT(JSLock::currentThreadIsHoldingLock());
-
+ ASSERT(globalData().apiLock().currentThreadIsHoldingLock());
+
structure()->disableSpecificFunctionTracking();
- d()->globalData = Heap::heap(this)->globalData();
- d()->globalScopeChain = ScopeChain(this, d()->globalData.get(), this, thisValue);
-
- JSGlobalObject::globalExec()->init(0, 0, d()->globalScopeChain.node(), CallFrame::noCaller(), 0, 0, 0);
+ m_globalScopeChain.set(globalData(), this, ScopeChainNode::create(0, this, &globalData(), this, thisValue));
- if (JSGlobalObject*& headObject = head()) {
- d()->prev = headObject;
- d()->next = headObject->d()->next;
- headObject->d()->next->d()->prev = this;
- headObject->d()->next = this;
- } else
- headObject = d()->next = d()->prev = this;
+ JSGlobalObject::globalExec()->init(0, 0, m_globalScopeChain.get(), CallFrame::noCaller(), 0, 0);
- d()->recursion = 0;
- d()->debugger = 0;
-
- d()->profileGroup = 0;
+ m_debugger = 0;
reset(prototype());
}
-void JSGlobalObject::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
+void JSGlobalObject::put(JSCell* cell, ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
{
- ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
+ JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
+ ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
- if (symbolTablePut(propertyName, value))
+ if (thisObject->symbolTablePut(exec, propertyName, value, slot.isStrictMode()))
return;
- JSVariableObject::put(exec, propertyName, value, slot);
+ JSVariableObject::put(thisObject, exec, propertyName, value, slot);
}
-void JSGlobalObject::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes)
+void JSGlobalObject::putDirectVirtual(JSObject* object, ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes)
{
- ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
+ JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
+ ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
- if (symbolTablePutWithAttributes(propertyName, value, attributes))
+ if (thisObject->symbolTablePutWithAttributes(exec->globalData(), propertyName, value, attributes))
return;
- JSValue valueBefore = getDirect(propertyName);
+ JSValue valueBefore = thisObject->getDirect(exec->globalData(), propertyName);
PutPropertySlot slot;
- JSVariableObject::put(exec, propertyName, value, slot);
+ JSVariableObject::put(thisObject, exec, propertyName, value, slot);
if (!valueBefore) {
- JSValue valueAfter = getDirect(propertyName);
+ JSValue valueAfter = thisObject->getDirect(exec->globalData(), propertyName);
if (valueAfter)
- JSObject::putWithAttributes(exec, propertyName, valueAfter, attributes);
+ JSObject::putDirectVirtual(thisObject, exec, propertyName, valueAfter, attributes);
}
}
-void JSGlobalObject::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunc, unsigned attributes)
+bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, bool shouldThrow)
{
+ JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
PropertySlot slot;
- if (!symbolTableGet(propertyName, slot))
- JSVariableObject::defineGetter(exec, propertyName, getterFunc, attributes);
+ // silently ignore attempts to add accessors aliasing vars.
+ if (descriptor.isAccessorDescriptor() && thisObject->symbolTableGet(propertyName, slot))
+ return false;
+ return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
}
-void JSGlobalObject::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunc, unsigned attributes)
-{
- PropertySlot slot;
- if (!symbolTableGet(propertyName, slot))
- JSVariableObject::defineSetter(exec, propertyName, setterFunc, attributes);
-}
static inline JSObject* lastInPrototypeChain(JSObject* object)
{
{
ExecState* exec = JSGlobalObject::globalExec();
- // Prototypes
-
- d()->functionPrototype = new (exec) FunctionPrototype(exec, FunctionPrototype::createStructure(jsNull())); // The real prototype will be set once ObjectPrototype is created.
- d()->prototypeFunctionStructure = PrototypeFunction::createStructure(d()->functionPrototype);
- NativeFunctionWrapper* callFunction = 0;
- NativeFunctionWrapper* applyFunction = 0;
- d()->functionPrototype->addFunctionProperties(exec, d()->prototypeFunctionStructure.get(), &callFunction, &applyFunction);
- d()->callFunction = callFunction;
- d()->applyFunction = applyFunction;
- d()->objectPrototype = new (exec) ObjectPrototype(exec, ObjectPrototype::createStructure(jsNull()), d()->prototypeFunctionStructure.get());
- d()->functionPrototype->structure()->setPrototypeWithoutTransition(d()->objectPrototype);
-
- d()->emptyObjectStructure = d()->objectPrototype->inheritorID();
-
- d()->functionStructure = JSFunction::createStructure(d()->functionPrototype);
- d()->callbackFunctionStructure = JSCallbackFunction::createStructure(d()->functionPrototype);
- d()->argumentsStructure = Arguments::createStructure(d()->objectPrototype);
- d()->callbackConstructorStructure = JSCallbackConstructor::createStructure(d()->objectPrototype);
- d()->callbackObjectStructure = JSCallbackObject<JSObject>::createStructure(d()->objectPrototype);
-
- d()->arrayPrototype = new (exec) ArrayPrototype(ArrayPrototype::createStructure(d()->objectPrototype));
- d()->arrayStructure = JSArray::createStructure(d()->arrayPrototype);
- d()->regExpMatchesArrayStructure = RegExpMatchesArray::createStructure(d()->arrayPrototype);
-
- d()->stringPrototype = new (exec) StringPrototype(exec, StringPrototype::createStructure(d()->objectPrototype));
- d()->stringObjectStructure = StringObject::createStructure(d()->stringPrototype);
-
- d()->booleanPrototype = new (exec) BooleanPrototype(exec, BooleanPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get());
- d()->booleanObjectStructure = BooleanObject::createStructure(d()->booleanPrototype);
-
- d()->numberPrototype = new (exec) NumberPrototype(exec, NumberPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get());
- d()->numberObjectStructure = NumberObject::createStructure(d()->numberPrototype);
-
- d()->datePrototype = new (exec) DatePrototype(exec, DatePrototype::createStructure(d()->objectPrototype));
- d()->dateStructure = DateInstance::createStructure(d()->datePrototype);
-
- d()->regExpPrototype = new (exec) RegExpPrototype(exec, RegExpPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get());
- d()->regExpStructure = RegExpObject::createStructure(d()->regExpPrototype);
+ m_functionPrototype.set(exec->globalData(), this, FunctionPrototype::create(exec, this, FunctionPrototype::createStructure(exec->globalData(), this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
+ m_functionStructure.set(exec->globalData(), this, JSFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
+ m_boundFunctionStructure.set(exec->globalData(), this, JSBoundFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
+ m_namedFunctionStructure.set(exec->globalData(), this, Structure::addPropertyTransition(exec->globalData(), m_functionStructure.get(), exec->globalData().propertyNames->name, DontDelete | ReadOnly | DontEnum, 0, m_functionNameOffset));
+ m_internalFunctionStructure.set(exec->globalData(), this, InternalFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
+ JSFunction* callFunction = 0;
+ JSFunction* applyFunction = 0;
+ m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction);
+ m_callFunction.set(exec->globalData(), this, callFunction);
+ m_applyFunction.set(exec->globalData(), this, applyFunction);
+ m_objectPrototype.set(exec->globalData(), this, ObjectPrototype::create(exec, this, ObjectPrototype::createStructure(exec->globalData(), this, jsNull())));
+ GetterSetter* protoAccessor = GetterSetter::create(exec);
+ protoAccessor->setGetter(exec->globalData(), JSFunction::create(exec, this, 0, Identifier(), globalFuncProtoGetter));
+ protoAccessor->setSetter(exec->globalData(), JSFunction::create(exec, this, 0, Identifier(), globalFuncProtoSetter));
+ m_objectPrototype->putDirectAccessor(exec->globalData(), exec->propertyNames().underscoreProto, protoAccessor, Accessor | DontEnum);
+ m_functionPrototype->structure()->setPrototypeWithoutTransition(exec->globalData(), m_objectPrototype.get());
+
+ m_emptyObjectStructure.set(exec->globalData(), this, m_objectPrototype->inheritorID(exec->globalData()));
+ m_nullPrototypeObjectStructure.set(exec->globalData(), this, createEmptyObjectStructure(exec->globalData(), this, jsNull()));
+
+ m_callbackFunctionStructure.set(exec->globalData(), this, JSCallbackFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
+ m_argumentsStructure.set(exec->globalData(), this, Arguments::createStructure(exec->globalData(), this, m_objectPrototype.get()));
+ m_callbackConstructorStructure.set(exec->globalData(), this, JSCallbackConstructor::createStructure(exec->globalData(), this, m_objectPrototype.get()));
+ m_callbackObjectStructure.set(exec->globalData(), this, JSCallbackObject<JSNonFinalObject>::createStructure(exec->globalData(), this, m_objectPrototype.get()));
+
+ m_arrayPrototype.set(exec->globalData(), this, ArrayPrototype::create(exec, this, ArrayPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
+ m_arrayStructure.set(exec->globalData(), this, JSArray::createStructure(exec->globalData(), this, m_arrayPrototype.get()));
+ m_regExpMatchesArrayStructure.set(exec->globalData(), this, RegExpMatchesArray::createStructure(exec->globalData(), this, m_arrayPrototype.get()));
+
+ m_stringPrototype.set(exec->globalData(), this, StringPrototype::create(exec, this, StringPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
+ m_stringObjectStructure.set(exec->globalData(), this, StringObject::createStructure(exec->globalData(), this, m_stringPrototype.get()));
+
+ m_booleanPrototype.set(exec->globalData(), this, BooleanPrototype::create(exec, this, BooleanPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
+ m_booleanObjectStructure.set(exec->globalData(), this, BooleanObject::createStructure(exec->globalData(), this, m_booleanPrototype.get()));
+
+ m_numberPrototype.set(exec->globalData(), this, NumberPrototype::create(exec, this, NumberPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
+ m_numberObjectStructure.set(exec->globalData(), this, NumberObject::createStructure(exec->globalData(), this, m_numberPrototype.get()));
+
+ m_datePrototype.set(exec->globalData(), this, DatePrototype::create(exec, this, DatePrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
+ m_dateStructure.set(exec->globalData(), this, DateInstance::createStructure(exec->globalData(), this, m_datePrototype.get()));
+
+ RegExp* emptyRegex = RegExp::create(exec->globalData(), "", NoFlags);
+
+ m_regExpPrototype.set(exec->globalData(), this, RegExpPrototype::create(exec, this, RegExpPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get()), emptyRegex));
+ m_regExpStructure.set(exec->globalData(), this, RegExpObject::createStructure(exec->globalData(), this, m_regExpPrototype.get()));
- d()->methodCallDummy = constructEmptyObject(exec);
+ m_methodCallDummy.set(exec->globalData(), this, constructEmptyObject(exec));
- ErrorPrototype* errorPrototype = new (exec) ErrorPrototype(exec, ErrorPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get());
- d()->errorStructure = ErrorInstance::createStructure(errorPrototype);
+ ErrorPrototype* errorPrototype = ErrorPrototype::create(exec, this, ErrorPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get()));
+ m_errorStructure.set(exec->globalData(), this, ErrorInstance::createStructure(exec->globalData(), this, errorPrototype));
// Constructors
- JSCell* objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructure(d()->functionPrototype), d()->objectPrototype, d()->prototypeFunctionStructure.get());
- JSCell* functionConstructor = new (exec) FunctionConstructor(exec, FunctionConstructor::createStructure(d()->functionPrototype), d()->functionPrototype);
- JSCell* arrayConstructor = new (exec) ArrayConstructor(exec, ArrayConstructor::createStructure(d()->functionPrototype), d()->arrayPrototype, d()->prototypeFunctionStructure.get());
- JSCell* stringConstructor = new (exec) StringConstructor(exec, StringConstructor::createStructure(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->stringPrototype);
- JSCell* booleanConstructor = new (exec) BooleanConstructor(exec, BooleanConstructor::createStructure(d()->functionPrototype), d()->booleanPrototype);
- JSCell* numberConstructor = new (exec) NumberConstructor(exec, NumberConstructor::createStructure(d()->functionPrototype), d()->numberPrototype);
- JSCell* dateConstructor = new (exec) DateConstructor(exec, DateConstructor::createStructure(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->datePrototype);
-
- d()->regExpConstructor = new (exec) RegExpConstructor(exec, RegExpConstructor::createStructure(d()->functionPrototype), d()->regExpPrototype);
-
- d()->errorConstructor = new (exec) ErrorConstructor(exec, ErrorConstructor::createStructure(d()->functionPrototype), errorPrototype);
-
- RefPtr<Structure> nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(errorPrototype);
- RefPtr<Structure> nativeErrorStructure = NativeErrorConstructor::createStructure(d()->functionPrototype);
-
- d()->evalErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, nativeErrorPrototypeStructure, "EvalError");
- d()->rangeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, nativeErrorPrototypeStructure, "RangeError");
- d()->referenceErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, nativeErrorPrototypeStructure, "ReferenceError");
- d()->syntaxErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, nativeErrorPrototypeStructure, "SyntaxError");
- d()->typeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, nativeErrorPrototypeStructure, "TypeError");
- d()->URIErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, nativeErrorPrototypeStructure, "URIError");
-
- d()->objectPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, objectConstructor, DontEnum);
- d()->functionPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, functionConstructor, DontEnum);
- d()->arrayPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, arrayConstructor, DontEnum);
- d()->booleanPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, booleanConstructor, DontEnum);
- d()->stringPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, stringConstructor, DontEnum);
- d()->numberPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, numberConstructor, DontEnum);
- d()->datePrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, dateConstructor, DontEnum);
- d()->regExpPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, d()->regExpConstructor, DontEnum);
- errorPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, d()->errorConstructor, DontEnum);
-
- // Set global constructors
-
- // FIXME: These properties could be handled by a static hash table.
-
- putDirectFunctionWithoutTransition(Identifier(exec, "Object"), objectConstructor, DontEnum);
- putDirectFunctionWithoutTransition(Identifier(exec, "Function"), functionConstructor, DontEnum);
- putDirectFunctionWithoutTransition(Identifier(exec, "Array"), arrayConstructor, DontEnum);
- putDirectFunctionWithoutTransition(Identifier(exec, "Boolean"), booleanConstructor, DontEnum);
- putDirectFunctionWithoutTransition(Identifier(exec, "String"), stringConstructor, DontEnum);
- putDirectFunctionWithoutTransition(Identifier(exec, "Number"), numberConstructor, DontEnum);
- putDirectFunctionWithoutTransition(Identifier(exec, "Date"), dateConstructor, DontEnum);
- putDirectFunctionWithoutTransition(Identifier(exec, "RegExp"), d()->regExpConstructor, DontEnum);
- putDirectFunctionWithoutTransition(Identifier(exec, "Error"), d()->errorConstructor, DontEnum);
- putDirectFunctionWithoutTransition(Identifier(exec, "EvalError"), d()->evalErrorConstructor);
- putDirectFunctionWithoutTransition(Identifier(exec, "RangeError"), d()->rangeErrorConstructor);
- putDirectFunctionWithoutTransition(Identifier(exec, "ReferenceError"), d()->referenceErrorConstructor);
- putDirectFunctionWithoutTransition(Identifier(exec, "SyntaxError"), d()->syntaxErrorConstructor);
- putDirectFunctionWithoutTransition(Identifier(exec, "TypeError"), d()->typeErrorConstructor);
- putDirectFunctionWithoutTransition(Identifier(exec, "URIError"), d()->URIErrorConstructor);
-
- // Set global values.
+ JSCell* objectConstructor = ObjectConstructor::create(exec, this, ObjectConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_objectPrototype.get());
+ JSCell* functionConstructor = FunctionConstructor::create(exec, this, FunctionConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_functionPrototype.get());
+ JSCell* arrayConstructor = ArrayConstructor::create(exec, this, ArrayConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_arrayPrototype.get());
+ JSCell* stringConstructor = StringConstructor::create(exec, this, StringConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_stringPrototype.get());
+ JSCell* booleanConstructor = BooleanConstructor::create(exec, this, BooleanConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_booleanPrototype.get());
+ JSCell* numberConstructor = NumberConstructor::create(exec, this, NumberConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_numberPrototype.get());
+ JSCell* dateConstructor = DateConstructor::create(exec, this, DateConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_datePrototype.get());
+
+ m_regExpConstructor.set(exec->globalData(), this, RegExpConstructor::create(exec, this, RegExpConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_regExpPrototype.get()));
+
+ m_errorConstructor.set(exec->globalData(), this, ErrorConstructor::create(exec, this, ErrorConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), errorPrototype));
+
+ Structure* nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(exec->globalData(), this, errorPrototype);
+ Structure* nativeErrorStructure = NativeErrorConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get());
+ m_evalErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "EvalError"));
+ m_rangeErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "RangeError"));
+ m_referenceErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "ReferenceError"));
+ m_syntaxErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "SyntaxError"));
+ m_typeErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "TypeError"));
+ m_URIErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "URIError"));
+
+ m_objectPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, objectConstructor, DontEnum);
+ m_functionPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, functionConstructor, DontEnum);
+ m_arrayPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, arrayConstructor, DontEnum);
+ m_booleanPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, booleanConstructor, DontEnum);
+ m_stringPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, stringConstructor, DontEnum);
+ m_numberPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, numberConstructor, DontEnum);
+ m_datePrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, dateConstructor, DontEnum);
+ m_regExpPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, m_regExpConstructor.get(), DontEnum);
+ errorPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, m_errorConstructor.get(), DontEnum);
+
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Object"), objectConstructor, DontEnum);
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Function"), functionConstructor, DontEnum);
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Array"), arrayConstructor, DontEnum);
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Boolean"), booleanConstructor, DontEnum);
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "String"), stringConstructor, DontEnum);
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Number"), numberConstructor, DontEnum);
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Date"), dateConstructor, DontEnum);
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "RegExp"), m_regExpConstructor.get(), DontEnum);
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Error"), m_errorConstructor.get(), DontEnum);
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "EvalError"), m_evalErrorConstructor.get(), DontEnum);
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "RangeError"), m_rangeErrorConstructor.get(), DontEnum);
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "ReferenceError"), m_referenceErrorConstructor.get(), DontEnum);
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "SyntaxError"), m_syntaxErrorConstructor.get(), DontEnum);
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "TypeError"), m_typeErrorConstructor.get(), DontEnum);
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "URIError"), m_URIErrorConstructor.get(), DontEnum);
+
+ m_evalFunction.set(exec->globalData(), this, JSFunction::create(exec, this, 1, exec->propertyNames().eval, globalFuncEval));
+ putDirectWithoutTransition(exec->globalData(), exec->propertyNames().eval, m_evalFunction.get(), DontEnum);
+
+ putDirectWithoutTransition(exec->globalData(), Identifier(exec, "JSON"), JSONObject::create(exec, this, JSONObject::createStructure(exec->globalData(), this, m_objectPrototype.get())), DontEnum);
+
GlobalPropertyInfo staticGlobals[] = {
- GlobalPropertyInfo(Identifier(exec, "Math"), new (exec) MathObject(exec, MathObject::createStructure(d()->objectPrototype)), DontEnum | DontDelete),
- GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(exec), DontEnum | DontDelete | ReadOnly),
- GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(exec, Inf), DontEnum | DontDelete | ReadOnly),
- GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete | ReadOnly),
- GlobalPropertyInfo(Identifier(exec, "JSON"), new (exec) JSONObject(JSONObject::createStructure(d()->objectPrototype)), DontEnum | DontDelete)
+ GlobalPropertyInfo(Identifier(exec, "Math"), MathObject::create(exec, this, MathObject::createStructure(exec->globalData(), this, m_objectPrototype.get())), DontEnum | DontDelete),
+ GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(), DontEnum | DontDelete | ReadOnly),
+ GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly),
+ GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete | ReadOnly)
};
+ addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
- addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo));
-
- // Set global functions.
-
- d()->evalFunction = new (exec) GlobalEvalFunction(exec, GlobalEvalFunction::createStructure(d()->functionPrototype), 1, exec->propertyNames().eval, globalFuncEval, this);
- putDirectFunctionWithoutTransition(exec, d()->evalFunction, DontEnum);
- putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 2, Identifier(exec, "parseInt"), globalFuncParseInt), DontEnum);
- putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "parseFloat"), globalFuncParseFloat), DontEnum);
- putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isNaN"), globalFuncIsNaN), DontEnum);
- putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isFinite"), globalFuncIsFinite), DontEnum);
- putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "escape"), globalFuncEscape), DontEnum);
- putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "unescape"), globalFuncUnescape), DontEnum);
- putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURI"), globalFuncDecodeURI), DontEnum);
- putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURIComponent"), globalFuncDecodeURIComponent), DontEnum);
- putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURI"), globalFuncEncodeURI), DontEnum);
- putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURIComponent"), globalFuncEncodeURIComponent), DontEnum);
-#ifndef NDEBUG
- putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "jscprint"), globalFuncJSCPrint), DontEnum);
-#endif
+ resetPrototype(exec->globalData(), prototype);
+}
- resetPrototype(prototype);
+void JSGlobalObject::createThrowTypeError(ExecState* exec)
+{
+ JSFunction* thrower = JSFunction::create(exec, this, 0, Identifier(), globalFuncThrowTypeError);
+ GetterSetter* getterSetter = GetterSetter::create(exec);
+ getterSetter->setGetter(exec->globalData(), thrower);
+ getterSetter->setSetter(exec->globalData(), thrower);
+ m_throwTypeErrorGetterSetter.set(exec->globalData(), this, getterSetter);
}
// Set prototype, and also insert the object prototype at the end of the chain.
-void JSGlobalObject::resetPrototype(JSValue prototype)
+void JSGlobalObject::resetPrototype(JSGlobalData& globalData, JSValue prototype)
{
- setPrototype(prototype);
+ setPrototype(globalData, prototype);
JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this);
- JSObject* objectPrototype = d()->objectPrototype;
+ JSObject* objectPrototype = m_objectPrototype.get();
if (oldLastInPrototypeChain != objectPrototype)
- oldLastInPrototypeChain->setPrototype(objectPrototype);
+ oldLastInPrototypeChain->setPrototype(globalData, objectPrototype);
}
-void JSGlobalObject::markChildren(MarkStack& markStack)
-{
- JSVariableObject::markChildren(markStack);
-
- HashSet<GlobalCodeBlock*>::const_iterator end = codeBlocks().end();
- for (HashSet<GlobalCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
- (*it)->markAggregate(markStack);
-
- RegisterFile& registerFile = globalData()->interpreter->registerFile();
- if (registerFile.globalObject() == this)
- registerFile.markGlobals(markStack, &globalData()->heap);
-
- markIfNeeded(markStack, d()->regExpConstructor);
- markIfNeeded(markStack, d()->errorConstructor);
- markIfNeeded(markStack, d()->evalErrorConstructor);
- markIfNeeded(markStack, d()->rangeErrorConstructor);
- markIfNeeded(markStack, d()->referenceErrorConstructor);
- markIfNeeded(markStack, d()->syntaxErrorConstructor);
- markIfNeeded(markStack, d()->typeErrorConstructor);
- markIfNeeded(markStack, d()->URIErrorConstructor);
-
- markIfNeeded(markStack, d()->evalFunction);
- markIfNeeded(markStack, d()->callFunction);
- markIfNeeded(markStack, d()->applyFunction);
-
- markIfNeeded(markStack, d()->objectPrototype);
- markIfNeeded(markStack, d()->functionPrototype);
- markIfNeeded(markStack, d()->arrayPrototype);
- markIfNeeded(markStack, d()->booleanPrototype);
- markIfNeeded(markStack, d()->stringPrototype);
- markIfNeeded(markStack, d()->numberPrototype);
- markIfNeeded(markStack, d()->datePrototype);
- markIfNeeded(markStack, d()->regExpPrototype);
-
- markIfNeeded(markStack, d()->methodCallDummy);
-
- markIfNeeded(markStack, d()->errorStructure);
- markIfNeeded(markStack, d()->argumentsStructure);
- markIfNeeded(markStack, d()->arrayStructure);
- markIfNeeded(markStack, d()->booleanObjectStructure);
- markIfNeeded(markStack, d()->callbackConstructorStructure);
- markIfNeeded(markStack, d()->callbackFunctionStructure);
- markIfNeeded(markStack, d()->callbackObjectStructure);
- markIfNeeded(markStack, d()->dateStructure);
- markIfNeeded(markStack, d()->emptyObjectStructure);
- markIfNeeded(markStack, d()->errorStructure);
- markIfNeeded(markStack, d()->functionStructure);
- markIfNeeded(markStack, d()->numberObjectStructure);
- markIfNeeded(markStack, d()->prototypeFunctionStructure);
- markIfNeeded(markStack, d()->regExpMatchesArrayStructure);
- markIfNeeded(markStack, d()->regExpStructure);
- markIfNeeded(markStack, d()->stringObjectStructure);
-
- // No need to mark the other structures, because their prototypes are all
- // guaranteed to be referenced elsewhere.
-
- Register* registerArray = d()->registerArray.get();
- if (!registerArray)
- return;
-
- size_t size = d()->registerArraySize;
- markStack.appendValues(reinterpret_cast<JSValue*>(registerArray), size);
+void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
+ COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
+ ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
+ JSVariableObject::visitChildren(thisObject, visitor);
+
+ visitIfNeeded(visitor, &thisObject->m_globalScopeChain);
+ visitIfNeeded(visitor, &thisObject->m_methodCallDummy);
+
+ visitIfNeeded(visitor, &thisObject->m_regExpConstructor);
+ visitIfNeeded(visitor, &thisObject->m_errorConstructor);
+ visitIfNeeded(visitor, &thisObject->m_evalErrorConstructor);
+ visitIfNeeded(visitor, &thisObject->m_rangeErrorConstructor);
+ visitIfNeeded(visitor, &thisObject->m_referenceErrorConstructor);
+ visitIfNeeded(visitor, &thisObject->m_syntaxErrorConstructor);
+ visitIfNeeded(visitor, &thisObject->m_typeErrorConstructor);
+ visitIfNeeded(visitor, &thisObject->m_URIErrorConstructor);
+
+ visitIfNeeded(visitor, &thisObject->m_evalFunction);
+ visitIfNeeded(visitor, &thisObject->m_callFunction);
+ visitIfNeeded(visitor, &thisObject->m_applyFunction);
+ visitIfNeeded(visitor, &thisObject->m_throwTypeErrorGetterSetter);
+
+ visitIfNeeded(visitor, &thisObject->m_objectPrototype);
+ visitIfNeeded(visitor, &thisObject->m_functionPrototype);
+ visitIfNeeded(visitor, &thisObject->m_arrayPrototype);
+ visitIfNeeded(visitor, &thisObject->m_booleanPrototype);
+ visitIfNeeded(visitor, &thisObject->m_stringPrototype);
+ visitIfNeeded(visitor, &thisObject->m_numberPrototype);
+ visitIfNeeded(visitor, &thisObject->m_datePrototype);
+ visitIfNeeded(visitor, &thisObject->m_regExpPrototype);
+
+ visitIfNeeded(visitor, &thisObject->m_argumentsStructure);
+ visitIfNeeded(visitor, &thisObject->m_arrayStructure);
+ visitIfNeeded(visitor, &thisObject->m_booleanObjectStructure);
+ visitIfNeeded(visitor, &thisObject->m_callbackConstructorStructure);
+ visitIfNeeded(visitor, &thisObject->m_callbackFunctionStructure);
+ visitIfNeeded(visitor, &thisObject->m_callbackObjectStructure);
+ visitIfNeeded(visitor, &thisObject->m_dateStructure);
+ visitIfNeeded(visitor, &thisObject->m_emptyObjectStructure);
+ visitIfNeeded(visitor, &thisObject->m_nullPrototypeObjectStructure);
+ visitIfNeeded(visitor, &thisObject->m_errorStructure);
+ visitIfNeeded(visitor, &thisObject->m_functionStructure);
+ visitIfNeeded(visitor, &thisObject->m_boundFunctionStructure);
+ visitIfNeeded(visitor, &thisObject->m_namedFunctionStructure);
+ visitIfNeeded(visitor, &thisObject->m_numberObjectStructure);
+ visitIfNeeded(visitor, &thisObject->m_regExpMatchesArrayStructure);
+ visitIfNeeded(visitor, &thisObject->m_regExpStructure);
+ visitIfNeeded(visitor, &thisObject->m_stringObjectStructure);
+ visitIfNeeded(visitor, &thisObject->m_internalFunctionStructure);
+
+ if (thisObject->m_registerArray) {
+ // Outside the execution of global code, when our variables are torn off,
+ // we can mark the torn-off array.
+ visitor.appendValues(thisObject->m_registerArray.get(), thisObject->m_registerArraySize);
+ } else if (thisObject->m_registers) {
+ // During execution of global code, when our variables are in the register file,
+ // the symbol table tells us how many variables there are, and registers
+ // points to where they end, and the registers used for execution begin.
+ visitor.appendValues(thisObject->m_registers - thisObject->symbolTable().size(), thisObject->symbolTable().size());
+ }
}
ExecState* JSGlobalObject::globalExec()
{
- return CallFrame::create(d()->globalCallFrame + RegisterFile::CallFrameHeaderSize);
+ return CallFrame::create(m_globalCallFrame + RegisterFile::CallFrameHeaderSize);
}
-bool JSGlobalObject::isDynamicScope(bool&) const
+void JSGlobalObject::resizeRegisters(size_t newSize)
{
- return true;
+ // Previous duplicate symbols may have created spare capacity in m_registerArray.
+ if (newSize <= m_registerArraySize)
+ return;
+
+ size_t oldSize = m_registerArraySize;
+ OwnArrayPtr<WriteBarrier<Unknown> > registerArray = adoptArrayPtr(new WriteBarrier<Unknown>[newSize]);
+ for (size_t i = 0; i < oldSize; ++i)
+ registerArray[i].set(globalData(), this, m_registerArray[i].get());
+ for (size_t i = oldSize; i < newSize; ++i)
+ registerArray[i].setUndefined();
+
+ WriteBarrier<Unknown>* registers = registerArray.get();
+ setRegisters(registers, registerArray.release(), newSize);
}
-void JSGlobalObject::copyGlobalsFrom(RegisterFile& registerFile)
+void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
{
- ASSERT(!d()->registerArray);
- ASSERT(!d()->registerArraySize);
+ resizeRegisters(symbolTable().size() + count);
- int numGlobals = registerFile.numGlobals();
- if (!numGlobals) {
- d()->registers = 0;
- return;
+ for (int i = 0; i < count; ++i) {
+ GlobalPropertyInfo& global = globals[i];
+ ASSERT(global.attributes & DontDelete);
+
+ int index = symbolTable().size();
+ SymbolTableEntry newEntry(index, global.attributes);
+ symbolTable().add(global.identifier.impl(), newEntry);
+ registerAt(index).set(globalData(), this, global.value);
}
-
- Register* registerArray = copyRegisterArray(registerFile.lastGlobal(), numGlobals);
- setRegisters(registerArray + numGlobals, registerArray, numGlobals);
}
-void JSGlobalObject::copyGlobalsTo(RegisterFile& registerFile)
+bool JSGlobalObject::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
- JSGlobalObject* lastGlobalObject = registerFile.globalObject();
- if (lastGlobalObject && lastGlobalObject != this)
- lastGlobalObject->copyGlobalsFrom(registerFile);
-
- registerFile.setGlobalObject(this);
- registerFile.setNumGlobals(symbolTable().size());
-
- if (d()->registerArray) {
- memcpy(registerFile.start() - d()->registerArraySize, d()->registerArray.get(), d()->registerArraySize * sizeof(Register));
- setRegisters(registerFile.start(), 0, 0);
- }
+ JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
+ if (getStaticFunctionSlot<JSVariableObject>(exec, ExecState::globalObjectTable(exec), thisObject, propertyName, slot))
+ return true;
+ return thisObject->symbolTableGet(propertyName, slot);
}
-void* JSGlobalObject::operator new(size_t size, JSGlobalData* globalData)
+bool JSGlobalObject::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
- return globalData->heap.allocate(size);
+ JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
+ if (getStaticFunctionDescriptor<JSVariableObject>(exec, ExecState::globalObjectTable(exec), thisObject, propertyName, descriptor))
+ return true;
+ return thisObject->symbolTableGet(propertyName, descriptor);
}
-void JSGlobalObject::destroyJSGlobalObjectData(void* jsGlobalObjectData)
+void JSGlobalObject::clearRareData(JSCell* cell)
{
- delete static_cast<JSGlobalObjectData*>(jsGlobalObjectData);
+ jsCast<JSGlobalObject*>(cell)->m_rareData.clear();
}
-DynamicGlobalObjectScope::DynamicGlobalObjectScope(CallFrame* callFrame, JSGlobalObject* dynamicGlobalObject)
- : m_dynamicGlobalObjectSlot(callFrame->globalData().dynamicGlobalObject)
+DynamicGlobalObjectScope::DynamicGlobalObjectScope(JSGlobalData& globalData, JSGlobalObject* dynamicGlobalObject)
+ : m_dynamicGlobalObjectSlot(globalData.dynamicGlobalObject)
, m_savedDynamicGlobalObject(m_dynamicGlobalObjectSlot)
{
if (!m_dynamicGlobalObjectSlot) {
-#if ENABLE(JIT)
- if (ExecutablePool::underMemoryPressure())
- callFrame->globalData().recompileAllJSFunctions();
+#if ENABLE(ASSEMBLER)
+ if (ExecutableAllocator::underMemoryPressure())
+ globalData.heap.discardAllCompiledCode();
#endif
+
m_dynamicGlobalObjectSlot = dynamicGlobalObject;
// Reset the date cache between JS invocations to force the VM
// to observe time zone changes.
- callFrame->globalData().resetDateCache();
+ globalData.resetDateCache();
}
}
+void slowValidateCell(JSGlobalObject* globalObject)
+{
+ if (!globalObject->isGlobalObject())
+ CRASH();
+ ASSERT_GC_OBJECT_INHERITS(globalObject, &JSGlobalObject::s_info);
+}
+
} // namespace JSC