X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/runtime/JSGlobalObject.cpp diff --git a/runtime/JSGlobalObject.cpp b/runtime/JSGlobalObject.cpp index dc68bde..10bf177 100644 --- a/runtime/JSGlobalObject.cpp +++ b/runtime/JSGlobalObject.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2007, 2008, 2009, 2014, 2015 Apple Inc. All rights reserved. * Copyright (C) 2008 Cameron Zwarich (cwzwarich@uwaterloo.ca) * * Redistribution and use in source and binary forms, with or without @@ -7,13 +7,13 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -30,61 +30,137 @@ #include "config.h" #include "JSGlobalObject.h" -#include "JSCallbackConstructor.h" -#include "JSCallbackFunction.h" -#include "JSCallbackObject.h" - -#include "Arguments.h" #include "ArrayConstructor.h" +#include "ArrayIteratorPrototype.h" #include "ArrayPrototype.h" #include "BooleanConstructor.h" #include "BooleanPrototype.h" +#include "BuiltinNames.h" +#include "ClonedArguments.h" #include "CodeBlock.h" +#include "CodeCache.h" +#include "ConsolePrototype.h" #include "DateConstructor.h" #include "DatePrototype.h" +#include "Debugger.h" +#include "DebuggerScope.h" +#include "DirectArguments.h" #include "Error.h" #include "ErrorConstructor.h" #include "ErrorPrototype.h" #include "FunctionConstructor.h" #include "FunctionPrototype.h" #include "GetterSetter.h" +#include "HeapIterationScope.h" +#include "Interpreter.h" +#include "IteratorPrototype.h" +#include "JSAPIWrapperObject.h" +#include "JSArrayBuffer.h" +#include "JSArrayBufferConstructor.h" +#include "JSArrayBufferPrototype.h" +#include "JSArrayIterator.h" #include "JSBoundFunction.h" +#include "JSCInlines.h" +#include "JSCallbackConstructor.h" +#include "JSCallbackFunction.h" +#include "JSCallbackObject.h" +#include "JSCatchScope.h" +#include "JSConsole.h" +#include "JSDataView.h" +#include "JSDataViewPrototype.h" +#include "JSDollarVM.h" +#include "JSDollarVMPrototype.h" #include "JSFunction.h" +#include "JSFunctionNameScope.h" +#include "JSGenericTypedArrayViewConstructorInlines.h" +#include "JSGenericTypedArrayViewInlines.h" +#include "JSGenericTypedArrayViewPrototypeInlines.h" #include "JSGlobalObjectFunctions.h" +#include "JSJob.h" +#include "JSLexicalEnvironment.h" #include "JSLock.h" +#include "JSMap.h" +#include "JSMapIterator.h" #include "JSONObject.h" -#include "Interpreter.h" +#include "JSSet.h" +#include "JSSetIterator.h" +#include "JSStringIterator.h" +#include "JSTemplateRegistryKey.h" +#include "JSTypedArrayConstructors.h" +#include "JSTypedArrayPrototypes.h" +#include "JSTypedArrays.h" +#include "JSWeakMap.h" +#include "JSWeakSet.h" +#include "JSWithScope.h" +#include "LegacyProfiler.h" #include "Lookup.h" +#include "MapConstructor.h" +#include "MapIteratorPrototype.h" +#include "MapPrototype.h" #include "MathObject.h" +#include "Microtask.h" #include "NativeErrorConstructor.h" #include "NativeErrorPrototype.h" +#include "NullGetterFunction.h" +#include "NullSetterFunction.h" #include "NumberConstructor.h" #include "NumberPrototype.h" +#include "ObjCCallbackFunction.h" #include "ObjectConstructor.h" #include "ObjectPrototype.h" -#include "Profiler.h" +#include "ParserError.h" #include "RegExpConstructor.h" #include "RegExpMatchesArray.h" #include "RegExpObject.h" #include "RegExpPrototype.h" -#include "ScopeChainMark.h" +#include "ScopedArguments.h" +#include "SetConstructor.h" +#include "SetIteratorPrototype.h" +#include "SetPrototype.h" +#include "StrictEvalActivation.h" #include "StringConstructor.h" +#include "StringIteratorPrototype.h" #include "StringPrototype.h" -#include "Debugger.h" +#include "Symbol.h" +#include "SymbolConstructor.h" +#include "SymbolPrototype.h" +#include "VariableWriteFireDetail.h" +#include "WeakGCMapInlines.h" +#include "WeakMapConstructor.h" +#include "WeakMapPrototype.h" +#include "WeakSetConstructor.h" +#include "WeakSetPrototype.h" + +#if ENABLE(INTL) +#include "IntlObject.h" +#endif // ENABLE(INTL) + +#if ENABLE(PROMISES) +#include "JSPromise.h" +#include "JSPromiseConstructor.h" +#include "JSPromisePrototype.h" +#endif // ENABLE(PROMISES) + +#if ENABLE(REMOTE_INSPECTOR) +#include "JSGlobalObjectDebuggable.h" +#include "JSGlobalObjectInspectorController.h" +#endif + +#if ENABLE(WEB_REPLAY) +#include "EmptyInputCursor.h" +#include "JSReplayInputs.h" +#endif #include "JSGlobalObject.lut.h" namespace JSC { -const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &JSVariableObject::s_info, 0, ExecState::globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) }; +const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, &globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) }; -const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript - , &shouldInterruptScriptBeforeTimeout -}; +const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, 0, &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 @@ -97,89 +173,428 @@ const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &all @end */ -ASSERT_CLASS_FITS_IN_CELL(JSGlobalObject); +static EncodedJSValue JSC_HOST_CALL getTemplateObject(ExecState* exec) +{ + JSValue thisValue = exec->thisValue(); + ASSERT(thisValue.inherits(JSTemplateRegistryKey::info())); + return JSValue::encode(exec->lexicalGlobalObject()->templateRegistry().getTemplateObject(exec, jsCast(thisValue)->templateRegistryKey())); +} + -// Default number of ticks before a timeout check should be done. -static const int initialTickCountThreshold = 255; +static EncodedJSValue JSC_HOST_CALL enqueueJob(ExecState* exec) +{ + VM& vm = exec->vm(); + JSGlobalObject* globalObject = exec->lexicalGlobalObject(); + + JSValue job = exec->argument(0); + JSValue arguments = exec->argument(1); + ASSERT(arguments.inherits(JSArray::info())); + + globalObject->queueMicrotask(createJSJob(vm, job, jsCast(arguments))); -// Preferred number of milliseconds between each timeout check -static const int preferredScriptCheckTimeInterval = 1000; + return JSValue::encode(jsUndefined()); +} -template static inline void visitIfNeeded(SlotVisitor& visitor, WriteBarrier* v) +JSGlobalObject::JSGlobalObject(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable) + : Base(vm, structure, 0) + , m_vm(vm) +#if ENABLE(WEB_REPLAY) + , m_inputCursor(EmptyInputCursor::create()) +#endif + , m_masqueradesAsUndefinedWatchpoint(adoptRef(new WatchpointSet(IsWatched))) + , m_havingABadTimeWatchpoint(adoptRef(new WatchpointSet(IsWatched))) + , m_varInjectionWatchpoint(adoptRef(new WatchpointSet(IsWatched))) + , m_weakRandom(Options::forceWeakRandomSeed() ? Options::forcedWeakRandomSeed() : static_cast(randomNumber() * (std::numeric_limits::max() + 1.0))) + , m_templateRegistry(vm) + , m_evalEnabled(true) + , m_runtimeFlags() + , m_consoleClient(nullptr) + , m_globalObjectMethodTable(globalObjectMethodTable ? globalObjectMethodTable : &s_globalObjectMethodTable) { - if (*v) - visitor.append(v); } JSGlobalObject::~JSGlobalObject() { +#if ENABLE(REMOTE_INSPECTOR) + m_inspectorController->globalObjectDestroyed(); +#endif + if (m_debugger) - m_debugger->detach(this); + m_debugger->detach(this, Debugger::GlobalObjectIsDestructing); - Profiler** profiler = Profiler::enabledProfilerReference(); - if (UNLIKELY(*profiler != 0)) { - (*profiler)->stopProfiling(this); - } + if (LegacyProfiler* profiler = vm().enabledProfiler()) + profiler->stopProfiling(this); } void JSGlobalObject::destroy(JSCell* cell) { - jsCast(cell)->JSGlobalObject::~JSGlobalObject(); + static_cast(cell)->JSGlobalObject::~JSGlobalObject(); } -void JSGlobalObject::init(JSObject* thisValue) +void JSGlobalObject::setGlobalThis(VM& vm, JSObject* globalThis) { - ASSERT(globalData().apiLock().currentThreadIsHoldingLock()); - - structure()->disableSpecificFunctionTracking(); + m_globalThis.set(vm, this, globalThis); +} - m_globalScopeChain.set(globalData(), this, ScopeChainNode::create(0, this, &globalData(), this, thisValue)); +void JSGlobalObject::init(VM& vm) +{ + ASSERT(vm.currentThreadIsHoldingAPILock()); - JSGlobalObject::globalExec()->init(0, 0, m_globalScopeChain.get(), CallFrame::noCaller(), 0, 0); + JSGlobalObject::globalExec()->init(0, 0, CallFrame::noCaller(), 0, 0); m_debugger = 0; - reset(prototype()); -} +#if ENABLE(REMOTE_INSPECTOR) + m_inspectorController = std::make_unique(*this); + m_inspectorDebuggable = std::make_unique(*this); + m_inspectorDebuggable->init(); + m_consoleClient = m_inspectorController->consoleClient(); +#endif -void JSGlobalObject::put(JSCell* cell, ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) -{ - JSGlobalObject* thisObject = jsCast(cell); - ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject)); + ExecState* exec = JSGlobalObject::globalExec(); - if (thisObject->symbolTablePut(exec, propertyName, value, slot.isStrictMode())) - return; - JSVariableObject::put(thisObject, exec, propertyName, value, slot); + m_functionPrototype.set(vm, this, FunctionPrototype::create(vm, FunctionPrototype::createStructure(vm, this, jsNull()))); // The real prototype will be set once ObjectPrototype is created. + m_calleeStructure.set(vm, this, JSCallee::createStructure(vm, this, jsNull())); + + // Need to create the callee structure (above) before creating the callee. + m_globalCallee.set(vm, this, JSCallee::create(vm, this, this)); + exec->setCallee(m_globalCallee.get()); + + m_functionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get())); + m_boundFunctionStructure.set(vm, this, JSBoundFunction::createStructure(vm, this, m_functionPrototype.get())); + m_namedFunctionStructure.set(vm, this, Structure::addPropertyTransition(vm, m_functionStructure.get(), vm.propertyNames->name, DontDelete | ReadOnly | DontEnum, m_functionNameOffset)); + m_internalFunctionStructure.set(vm, this, InternalFunction::createStructure(vm, this, m_functionPrototype.get())); + JSFunction* callFunction = 0; + JSFunction* applyFunction = 0; + m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction); + m_callFunction.set(vm, this, callFunction); + m_applyFunction.set(vm, this, applyFunction); + m_arrayProtoValuesFunction.set(vm, this, JSFunction::create(vm, this, 0, vm.propertyNames->values.string(), arrayProtoFuncValues)); +#if ENABLE(PROMISES) + m_initializePromiseFunction.set(vm, this, JSFunction::createBuiltinFunction(vm, operationsPromiseInitializePromiseCodeGenerator(vm), this)); + m_newPromiseDeferredFunction.set(vm, this, JSFunction::createBuiltinFunction(vm, operationsPromiseNewPromiseDeferredCodeGenerator(vm), this)); +#endif // ENABLE(PROMISES) + m_nullGetterFunction.set(vm, this, NullGetterFunction::create(vm, NullGetterFunction::createStructure(vm, this, m_functionPrototype.get()))); + m_nullSetterFunction.set(vm, this, NullSetterFunction::create(vm, NullSetterFunction::createStructure(vm, this, m_functionPrototype.get()))); + m_objectPrototype.set(vm, this, ObjectPrototype::create(vm, this, ObjectPrototype::createStructure(vm, this, jsNull()))); + GetterSetter* protoAccessor = GetterSetter::create(vm, this); + protoAccessor->setGetter(vm, this, JSFunction::create(vm, this, 0, String(), globalFuncProtoGetter)); + protoAccessor->setSetter(vm, this, JSFunction::create(vm, this, 0, String(), globalFuncProtoSetter)); + m_objectPrototype->putDirectNonIndexAccessor(vm, vm.propertyNames->underscoreProto, protoAccessor, Accessor | DontEnum); + m_functionPrototype->structure()->setPrototypeWithoutTransition(vm, m_objectPrototype.get()); + + m_typedArrays[toIndex(TypeInt8)].prototype.set(vm, this, JSInt8ArrayPrototype::create(vm, this, JSInt8ArrayPrototype::createStructure(vm, this, m_objectPrototype.get()))); + m_typedArrays[toIndex(TypeInt16)].prototype.set(vm, this, JSInt16ArrayPrototype::create(vm, this, JSInt16ArrayPrototype::createStructure(vm, this, m_objectPrototype.get()))); + m_typedArrays[toIndex(TypeInt32)].prototype.set(vm, this, JSInt32ArrayPrototype::create(vm, this, JSInt32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get()))); + m_typedArrays[toIndex(TypeUint8)].prototype.set(vm, this, JSUint8ArrayPrototype::create(vm, this, JSUint8ArrayPrototype::createStructure(vm, this, m_objectPrototype.get()))); + m_typedArrays[toIndex(TypeUint8Clamped)].prototype.set(vm, this, JSUint8ClampedArrayPrototype::create(vm, this, JSUint8ClampedArrayPrototype::createStructure(vm, this, m_objectPrototype.get()))); + m_typedArrays[toIndex(TypeUint16)].prototype.set(vm, this, JSUint16ArrayPrototype::create(vm, this, JSUint16ArrayPrototype::createStructure(vm, this, m_objectPrototype.get()))); + m_typedArrays[toIndex(TypeUint32)].prototype.set(vm, this, JSUint32ArrayPrototype::create(vm, this, JSUint32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get()))); + m_typedArrays[toIndex(TypeFloat32)].prototype.set(vm, this, JSFloat32ArrayPrototype::create(vm, this, JSFloat32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get()))); + m_typedArrays[toIndex(TypeFloat64)].prototype.set(vm, this, JSFloat64ArrayPrototype::create(vm, this, JSFloat64ArrayPrototype::createStructure(vm, this, m_objectPrototype.get()))); + m_typedArrays[toIndex(TypeDataView)].prototype.set(vm, this, JSDataViewPrototype::create(vm, JSDataViewPrototype::createStructure(vm, this, m_objectPrototype.get()))); + + m_typedArrays[toIndex(TypeInt8)].structure.set(vm, this, JSInt8Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt8)].prototype.get())); + m_typedArrays[toIndex(TypeInt16)].structure.set(vm, this, JSInt16Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt16)].prototype.get())); + m_typedArrays[toIndex(TypeInt32)].structure.set(vm, this, JSInt32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt32)].prototype.get())); + m_typedArrays[toIndex(TypeUint8)].structure.set(vm, this, JSUint8Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint8)].prototype.get())); + m_typedArrays[toIndex(TypeUint8Clamped)].structure.set(vm, this, JSUint8ClampedArray::createStructure(vm, this, m_typedArrays[toIndex(TypeUint8Clamped)].prototype.get())); + m_typedArrays[toIndex(TypeUint16)].structure.set(vm, this, JSUint16Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint16)].prototype.get())); + m_typedArrays[toIndex(TypeUint32)].structure.set(vm, this, JSUint32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint32)].prototype.get())); + m_typedArrays[toIndex(TypeFloat32)].structure.set(vm, this, JSFloat32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeFloat32)].prototype.get())); + m_typedArrays[toIndex(TypeFloat64)].structure.set(vm, this, JSFloat64Array::createStructure(vm, this, m_typedArrays[toIndex(TypeFloat64)].prototype.get())); + m_typedArrays[toIndex(TypeDataView)].structure.set(vm, this, JSDataView::createStructure(vm, this, m_typedArrays[toIndex(TypeDataView)].prototype.get())); + + m_catchScopeStructure.set(vm, this, JSCatchScope::createStructure(vm, this, jsNull())); + m_functionNameScopeStructure.set(vm, this, JSFunctionNameScope::createStructure(vm, this, jsNull())); + m_lexicalEnvironmentStructure.set(vm, this, JSLexicalEnvironment::createStructure(vm, this)); + m_strictEvalActivationStructure.set(vm, this, StrictEvalActivation::createStructure(vm, this, jsNull())); + m_debuggerScopeStructure.set(m_vm, this, DebuggerScope::createStructure(m_vm, this)); + m_withScopeStructure.set(vm, this, JSWithScope::createStructure(vm, this, jsNull())); + + m_nullPrototypeObjectStructure.set(vm, this, JSFinalObject::createStructure(vm, this, jsNull(), JSFinalObject::defaultInlineCapacity())); + + m_callbackFunctionStructure.set(vm, this, JSCallbackFunction::createStructure(vm, this, m_functionPrototype.get())); + m_directArgumentsStructure.set(vm, this, DirectArguments::createStructure(vm, this, m_objectPrototype.get())); + m_scopedArgumentsStructure.set(vm, this, ScopedArguments::createStructure(vm, this, m_objectPrototype.get())); + m_outOfBandArgumentsStructure.set(vm, this, ClonedArguments::createStructure(vm, this, m_objectPrototype.get())); + m_callbackConstructorStructure.set(vm, this, JSCallbackConstructor::createStructure(vm, this, m_objectPrototype.get())); + m_callbackObjectStructure.set(vm, this, JSCallbackObject::createStructure(vm, this, m_objectPrototype.get())); +#if JSC_OBJC_API_ENABLED + m_objcCallbackFunctionStructure.set(vm, this, ObjCCallbackFunction::createStructure(vm, this, m_functionPrototype.get())); + m_objcWrapperObjectStructure.set(vm, this, JSCallbackObject::createStructure(vm, this, m_objectPrototype.get())); +#endif + + m_arrayPrototype.set(vm, this, ArrayPrototype::create(vm, this, ArrayPrototype::createStructure(vm, this, m_objectPrototype.get()))); + + m_originalArrayStructureForIndexingShape[UndecidedShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithUndecided)); + m_originalArrayStructureForIndexingShape[Int32Shape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithInt32)); + m_originalArrayStructureForIndexingShape[DoubleShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithDouble)); + m_originalArrayStructureForIndexingShape[ContiguousShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithContiguous)); + m_originalArrayStructureForIndexingShape[ArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithArrayStorage)); + m_originalArrayStructureForIndexingShape[SlowPutArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithSlowPutArrayStorage)); + for (unsigned i = 0; i < NumberOfIndexingShapes; ++i) + m_arrayStructureForIndexingShapeDuringAllocation[i] = m_originalArrayStructureForIndexingShape[i]; + + RegExp* emptyRegex = RegExp::create(vm, "", NoFlags); + + m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get()), emptyRegex)); + m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get())); + m_regExpMatchesArrayStructure.set(vm, this, createRegExpMatchesArrayStructure(vm, *this)); + +#if ENABLE(PROMISES) + m_promisePrototype.set(vm, this, JSPromisePrototype::create(exec, this, JSPromisePrototype::createStructure(vm, this, m_objectPrototype.get()))); + m_promiseStructure.set(vm, this, JSPromise::createStructure(vm, this, m_promisePrototype.get())); +#endif // ENABLE(PROMISES) + + m_parseIntFunction.set(vm, this, JSFunction::create(vm, this, 2, vm.propertyNames->parseInt.string(), globalFuncParseInt, NoIntrinsic)); + putDirectWithoutTransition(vm, vm.propertyNames->parseInt, m_parseIntFunction.get(), DontEnum | Function); + +#define CREATE_PROTOTYPE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \ +m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_objectPrototype.get()))); \ +m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get())); + + FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE) + +#undef CREATE_PROTOTYPE_FOR_SIMPLE_TYPE + + m_iteratorPrototype.set(vm, this, IteratorPrototype::create(vm, this, IteratorPrototype::createStructure(vm, this, m_objectPrototype.get()))); + +#define CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE(capitalName, lowerName, properName, instanceType, jsName) \ +m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_iteratorPrototype.get()))); \ +m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get())); + + FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE) + +#undef CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE + + // Constructors + + ObjectConstructor* objectConstructor = ObjectConstructor::create(vm, this, ObjectConstructor::createStructure(vm, this, m_functionPrototype.get()), m_objectPrototype.get()); + m_objectConstructor.set(vm, this, objectConstructor); + + JSFunction* definePropertyFunction = m_objectConstructor->addDefineProperty(exec, this); + m_definePropertyFunction.set(vm, this, definePropertyFunction); + + JSCell* functionConstructor = FunctionConstructor::create(vm, FunctionConstructor::createStructure(vm, this, m_functionPrototype.get()), m_functionPrototype.get()); + JSCell* arrayConstructor = ArrayConstructor::create(vm, ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayPrototype.get()); + + m_regExpConstructor.set(vm, this, RegExpConstructor::create(vm, RegExpConstructor::createStructure(vm, this, m_functionPrototype.get()), m_regExpPrototype.get())); + +#define CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \ +capitalName ## Constructor* lowerName ## Constructor = capitalName ## Constructor::create(vm, capitalName ## Constructor::createStructure(vm, this, m_functionPrototype.get()), m_ ## lowerName ## Prototype.get()); \ +m_ ## lowerName ## Prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, lowerName ## Constructor, DontEnum); \ + + FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE) + +#undef CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE + + m_errorConstructor.set(vm, this, errorConstructor); + + Structure* nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(vm, this, m_errorPrototype.get()); + Structure* nativeErrorStructure = NativeErrorConstructor::createStructure(vm, this, m_functionPrototype.get()); + m_evalErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("EvalError"))); + m_rangeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("RangeError"))); + m_referenceErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("ReferenceError"))); + m_syntaxErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("SyntaxError"))); + m_typeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("TypeError"))); + m_URIErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("URIError"))); +#if ENABLE(PROMISES) + m_promiseConstructor.set(vm, this, JSPromiseConstructor::create(vm, JSPromiseConstructor::createStructure(vm, this, m_functionPrototype.get()), m_promisePrototype.get())); +#endif + + m_objectPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, objectConstructor, DontEnum); + m_functionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, functionConstructor, DontEnum); + m_arrayPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayConstructor, DontEnum); + m_regExpPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_regExpConstructor.get(), DontEnum); +#if ENABLE(PROMISES) + m_promisePrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_promiseConstructor.get(), DontEnum); +#endif + + putDirectWithoutTransition(vm, vm.propertyNames->Object, objectConstructor, DontEnum); + putDirectWithoutTransition(vm, vm.propertyNames->Function, functionConstructor, DontEnum); + putDirectWithoutTransition(vm, vm.propertyNames->Array, arrayConstructor, DontEnum); + putDirectWithoutTransition(vm, vm.propertyNames->RegExp, m_regExpConstructor.get(), DontEnum); + putDirectWithoutTransition(vm, vm.propertyNames->EvalError, m_evalErrorConstructor.get(), DontEnum); + putDirectWithoutTransition(vm, vm.propertyNames->RangeError, m_rangeErrorConstructor.get(), DontEnum); + putDirectWithoutTransition(vm, vm.propertyNames->ReferenceError, m_referenceErrorConstructor.get(), DontEnum); + putDirectWithoutTransition(vm, vm.propertyNames->SyntaxError, m_syntaxErrorConstructor.get(), DontEnum); + putDirectWithoutTransition(vm, vm.propertyNames->TypeError, m_typeErrorConstructor.get(), DontEnum); + putDirectWithoutTransition(vm, vm.propertyNames->URIError, m_URIErrorConstructor.get(), DontEnum); +#if ENABLE(PROMISES) + if (!m_runtimeFlags.isPromiseDisabled()) + putDirectWithoutTransition(vm, vm.propertyNames->Promise, m_promiseConstructor.get(), DontEnum); +#endif + + +#define PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \ +putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Constructor, DontEnum); \ + + FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE) + + if (!m_runtimeFlags.isSymbolDisabled()) + putDirectWithoutTransition(vm, vm.propertyNames->Symbol, symbolConstructor, DontEnum); + +#undef PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE + PrototypeMap& prototypeMap = vm.prototypeMap; + Structure* iteratorResultStructure = prototypeMap.emptyObjectStructureForPrototype(m_objectPrototype.get(), JSFinalObject::defaultInlineCapacity()); + PropertyOffset offset; + iteratorResultStructure = Structure::addPropertyTransition(vm, iteratorResultStructure, vm.propertyNames->done, 0, offset); + iteratorResultStructure = Structure::addPropertyTransition(vm, iteratorResultStructure, vm.propertyNames->value, 0, offset); + m_iteratorResultStructure.set(vm, this, iteratorResultStructure); + + m_evalFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->eval.string(), globalFuncEval)); + putDirectWithoutTransition(vm, vm.propertyNames->eval, m_evalFunction.get(), DontEnum); + +#if ENABLE(INTL) + putDirectWithoutTransition(vm, vm.propertyNames->Intl, IntlObject::create(vm, IntlObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum); +#endif // ENABLE(INTL) + putDirectWithoutTransition(vm, vm.propertyNames->JSON, JSONObject::create(vm, JSONObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum); + putDirectWithoutTransition(vm, vm.propertyNames->Math, MathObject::create(vm, this, MathObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum); + + std::array typedArrayConstructors; + typedArrayConstructors[toIndex(TypeInt8)] = JSInt8ArrayConstructor::create(vm, JSInt8ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeInt8)].prototype.get(), ASCIILiteral("Int8Array")); + typedArrayConstructors[toIndex(TypeInt16)] = JSInt16ArrayConstructor::create(vm, JSInt16ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeInt16)].prototype.get(), ASCIILiteral("Int16Array")); + typedArrayConstructors[toIndex(TypeInt32)] = JSInt32ArrayConstructor::create(vm, JSInt32ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeInt32)].prototype.get(), ASCIILiteral("Int32Array")); + typedArrayConstructors[toIndex(TypeUint8)] = JSUint8ArrayConstructor::create(vm, JSUint8ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint8)].prototype.get(), ASCIILiteral("Uint8Array")); + typedArrayConstructors[toIndex(TypeUint8Clamped)] = JSUint8ClampedArrayConstructor::create(vm, JSUint8ClampedArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint8Clamped)].prototype.get(), ASCIILiteral("Uint8ClampedArray")); + typedArrayConstructors[toIndex(TypeUint16)] = JSUint16ArrayConstructor::create(vm, JSUint16ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint16)].prototype.get(), ASCIILiteral("Uint16Array")); + typedArrayConstructors[toIndex(TypeUint32)] = JSUint32ArrayConstructor::create(vm, JSUint32ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint32)].prototype.get(), ASCIILiteral("Uint32Array")); + typedArrayConstructors[toIndex(TypeFloat32)] = JSFloat32ArrayConstructor::create(vm, JSFloat32ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeFloat32)].prototype.get(), ASCIILiteral("Float32Array")); + typedArrayConstructors[toIndex(TypeFloat64)] = JSFloat64ArrayConstructor::create(vm, JSFloat64ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeFloat64)].prototype.get(), ASCIILiteral("Float64Array")); + typedArrayConstructors[toIndex(TypeDataView)] = JSDataViewConstructor::create(vm, JSDataViewConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeDataView)].prototype.get(), ASCIILiteral("DataView")); + + for (unsigned typedArrayIndex = NUMBER_OF_TYPED_ARRAY_TYPES; typedArrayIndex--;) { + m_typedArrays[typedArrayIndex].prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, typedArrayConstructors[typedArrayIndex], DontEnum); + putDirectWithoutTransition(vm, Identifier::fromString(exec, typedArrayConstructors[typedArrayIndex]->name(exec)), typedArrayConstructors[typedArrayIndex], DontEnum); + } + + JSFunction* builtinLog = JSFunction::create(vm, this, 1, vm.propertyNames->emptyIdentifier.string(), globalFuncBuiltinLog); + + JSFunction* privateFuncAbs = JSFunction::create(vm, this, 0, String(), mathProtoFuncAbs, AbsIntrinsic); + JSFunction* privateFuncFloor = JSFunction::create(vm, this, 0, String(), mathProtoFuncFloor, FloorIntrinsic); + JSFunction* privateFuncIsFinite = JSFunction::create(vm, this, 0, String(), globalFuncIsFinite); + + JSFunction* privateFuncObjectKeys = JSFunction::create(vm, this, 0, String(), objectConstructorKeys); + JSFunction* privateFuncObjectGetOwnPropertyDescriptor = JSFunction::create(vm, this, 0, String(), objectConstructorGetOwnPropertyDescriptor); + JSFunction* privateFuncObjectGetOwnPropertySymbols = JSFunction::create(vm, this, 0, String(), objectConstructorGetOwnPropertySymbols); + JSFunction* privateFuncGetTemplateObject = JSFunction::create(vm, this, 0, String(), getTemplateObject); + JSFunction* privateFuncToLength = JSFunction::createBuiltinFunction(vm, globalObjectToLengthCodeGenerator(vm), this); + JSFunction* privateFuncToInteger = JSFunction::createBuiltinFunction(vm, globalObjectToIntegerCodeGenerator(vm), this); + + GlobalPropertyInfo staticGlobals[] = { + GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits::infinity()), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->undefinedPrivateName, jsUndefined(), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->ObjectPrivateName, objectConstructor, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->objectKeysPrivateName, privateFuncObjectKeys, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->objectGetOwnPropertyDescriptorPrivateName, privateFuncObjectGetOwnPropertyDescriptor, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->objectGetOwnPropertySymbolsPrivateName, privateFuncObjectGetOwnPropertySymbols, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->getTemplateObjectPrivateName, privateFuncGetTemplateObject, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->enqueueJobPrivateName, JSFunction::create(vm, this, 0, String(), enqueueJob), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->TypeErrorPrivateName, m_typeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->BuiltinLogPrivateName, builtinLog, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->ArrayPrivateName, arrayConstructor, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->NumberPrivateName, numberConstructor, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->StringPrivateName, stringConstructor, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->absPrivateName, privateFuncAbs, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->floorPrivateName, privateFuncFloor, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->getPrototypeOfPrivateName, privateFuncFloor, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->getOwnPropertyNamesPrivateName, privateFuncFloor, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->isFinitePrivateName, privateFuncIsFinite, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->arrayIterationKindKeyPrivateName, jsNumber(ArrayIterateKey), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->arrayIterationKindValuePrivateName, jsNumber(ArrayIterateValue), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->arrayIterationKindKeyValuePrivateName, jsNumber(ArrayIterateKeyValue), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->symbolIteratorPrivateName, Symbol::create(vm, static_cast(*vm.propertyNames->iteratorSymbol.impl())), DontEnum | DontDelete | ReadOnly), +#if ENABLE(PROMISES) + GlobalPropertyInfo(vm.propertyNames->PromisePrivateName, m_promiseConstructor.get(), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->promisePendingPrivateName, jsNumber(static_cast(JSPromise::Status::Pending)), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->promiseFulfilledPrivateName, jsNumber(static_cast(JSPromise::Status::Fulfilled)), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->promiseRejectedPrivateName, jsNumber(static_cast(JSPromise::Status::Rejected)), DontEnum | DontDelete | ReadOnly), +#endif + GlobalPropertyInfo(vm.propertyNames->builtinNames().toLengthPrivateName(), privateFuncToLength, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->builtinNames().toIntegerPrivateName(), privateFuncToInteger, DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->builtinNames().isObjectPrivateName(), JSFunction::createBuiltinFunction(vm, globalObjectIsObjectCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->builtinNames().isPromisePrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromiseIsPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->builtinNames().newPromiseReactionPrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromiseNewPromiseReactionCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->builtinNames().newPromiseCapabilityPrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromiseNewPromiseCapabilityCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->builtinNames().triggerPromiseReactionsPrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromiseTriggerPromiseReactionsCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->builtinNames().rejectPromisePrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromiseRejectPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->builtinNames().fulfillPromisePrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromiseFulfillPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->builtinNames().createResolvingFunctionsPrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromiseCreateResolvingFunctionsCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->builtinNames().promiseReactionJobPrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromisePromiseReactionJobCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly), + GlobalPropertyInfo(vm.propertyNames->builtinNames().promiseResolveThenableJobPrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromisePromiseResolveThenableJobCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly), + }; + addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals)); + + m_specialPointers[Special::CallFunction] = m_callFunction.get(); + m_specialPointers[Special::ApplyFunction] = m_applyFunction.get(); + m_specialPointers[Special::ObjectConstructor] = objectConstructor; + m_specialPointers[Special::ArrayConstructor] = arrayConstructor; + + m_linkTimeConstants[static_cast(LinkTimeConstant::DefinePropertyFunction)] = m_definePropertyFunction.get(); + + ConsolePrototype* consolePrototype = ConsolePrototype::create(vm, this, ConsolePrototype::createStructure(vm, this, m_objectPrototype.get())); + m_consoleStructure.set(vm, this, JSConsole::createStructure(vm, this, consolePrototype)); + JSConsole* consoleObject = JSConsole::create(vm, m_consoleStructure.get()); + putDirectWithoutTransition(vm, Identifier::fromString(exec, "console"), consoleObject, DontEnum); + + if (UNLIKELY(Options::enableDollarVM())) { + JSDollarVMPrototype* dollarVMPrototype = JSDollarVMPrototype::create(vm, this, JSDollarVMPrototype::createStructure(vm, this, m_objectPrototype.get())); + m_dollarVMStructure.set(vm, this, JSDollarVM::createStructure(vm, this, dollarVMPrototype)); + JSDollarVM* dollarVM = JSDollarVM::create(vm, m_dollarVMStructure.get()); + putDirectWithoutTransition(vm, Identifier::fromString(exec, "$vm"), dollarVM, DontEnum); + } + + resetPrototype(vm, prototype()); } -void JSGlobalObject::putDirectVirtual(JSObject* object, ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes) +void JSGlobalObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot) { - JSGlobalObject* thisObject = jsCast(object); + JSGlobalObject* thisObject = jsCast(cell); ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject)); - if (thisObject->symbolTablePutWithAttributes(exec->globalData(), propertyName, value, attributes)) + if (symbolTablePut(thisObject, exec, propertyName, value, slot.isStrictMode())) return; - - JSValue valueBefore = thisObject->getDirect(exec->globalData(), propertyName); - PutPropertySlot slot; - JSVariableObject::put(thisObject, exec, propertyName, value, slot); - if (!valueBefore) { - JSValue valueAfter = thisObject->getDirect(exec->globalData(), propertyName); - if (valueAfter) - JSObject::putDirectVirtual(thisObject, exec, propertyName, valueAfter, attributes); - } + Base::put(thisObject, exec, propertyName, value, slot); } -bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, bool shouldThrow) +bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow) { JSGlobalObject* thisObject = jsCast(object); - PropertySlot slot; + PropertySlot slot(thisObject); // silently ignore attempts to add accessors aliasing vars. - if (descriptor.isAccessorDescriptor() && thisObject->symbolTableGet(propertyName, slot)) + if (descriptor.isAccessorDescriptor() && symbolTableGet(thisObject, propertyName, slot)) return false; return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow); } +void JSGlobalObject::addGlobalVar(const Identifier& ident, ConstantMode constantMode) +{ + ConcurrentJITLocker locker(symbolTable()->m_lock); + SymbolTableEntry entry = symbolTable()->get(locker, ident.impl()); + if (!entry.isNull()) + return; + + ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker); + SymbolTableEntry newEntry(VarOffset(offset), (constantMode == IsConstant) ? ReadOnly : 0); + if (constantMode == IsVariable) + newEntry.prepareToWatch(); + else + newEntry.disableWatching(); + symbolTable()->add(locker, ident.impl(), newEntry); + + ScopeOffset offsetForAssert = addVariables(1); + RELEASE_ASSERT(offsetForAssert == offset); +} + +void JSGlobalObject::addFunction(ExecState* exec, const Identifier& propertyName) +{ + VM& vm = exec->vm(); + removeDirect(vm, propertyName); // Newly declared functions overwrite existing properties. + addGlobalVar(propertyName, IsVariable); +} static inline JSObject* lastInPrototypeChain(JSObject* object) { @@ -189,292 +604,396 @@ static inline JSObject* lastInPrototypeChain(JSObject* object) return o; } -void JSGlobalObject::reset(JSValue prototype) -{ - ExecState* exec = JSGlobalObject::globalExec(); - - 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())); +// Private namespace for helpers for JSGlobalObject::haveABadTime() +namespace { - 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::createStructure(exec->globalData(), this, m_objectPrototype.get())); +class ObjectsWithBrokenIndexingFinder : public MarkedBlock::VoidFunctor { +public: + ObjectsWithBrokenIndexingFinder(MarkedArgumentBuffer&, JSGlobalObject*); + IterationStatus operator()(JSCell*); - 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())); +private: + void visit(JSCell*); - 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())); + MarkedArgumentBuffer& m_foundObjects; + JSGlobalObject* m_globalObject; +}; - 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())); +ObjectsWithBrokenIndexingFinder::ObjectsWithBrokenIndexingFinder( + MarkedArgumentBuffer& foundObjects, JSGlobalObject* globalObject) + : m_foundObjects(foundObjects) + , m_globalObject(globalObject) +{ +} - 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())); +inline bool hasBrokenIndexing(JSObject* object) +{ + // This will change if we have more indexing types. + IndexingType type = object->indexingType(); + // This could be made obviously more efficient, but isn't made so right now, because + // we expect this to be an unlikely slow path anyway. + return hasUndecided(type) || hasInt32(type) || hasDouble(type) || hasContiguous(type) || hasArrayStorage(type); +} - 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())); +inline void ObjectsWithBrokenIndexingFinder::visit(JSCell* cell) +{ + if (!cell->isObject()) + return; + + JSObject* object = asObject(cell); - RegExp* emptyRegex = RegExp::create(exec->globalData(), "", NoFlags); + // Run this filter first, since it's cheap, and ought to filter out a lot of objects. + if (!hasBrokenIndexing(object)) + return; + + // We only want to have a bad time in the affected global object, not in the entire + // VM. But we have to be careful, since there may be objects that claim to belong to + // a different global object that have prototypes from our global object. + bool foundGlobalObject = false; + for (JSObject* current = object; ;) { + if (current->globalObject() == m_globalObject) { + foundGlobalObject = true; + break; + } + + JSValue prototypeValue = current->prototype(); + if (prototypeValue.isNull()) + break; + current = asObject(prototypeValue); + } + if (!foundGlobalObject) + return; - 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())); + m_foundObjects.append(object); +} - m_methodCallDummy.set(exec->globalData(), this, constructEmptyObject(exec)); +IterationStatus ObjectsWithBrokenIndexingFinder::operator()(JSCell* cell) +{ + visit(cell); + return IterationStatus::Continue; +} - 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)); +} // end private namespace for helpers for JSGlobalObject::haveABadTime() - // Constructors +void JSGlobalObject::haveABadTime(VM& vm) +{ + ASSERT(&vm == &this->vm()); + + if (isHavingABadTime()) + return; + + // Make sure that all allocations or indexed storage transitions that are inlining + // the assumption that it's safe to transition to a non-SlowPut array storage don't + // do so anymore. + m_havingABadTimeWatchpoint->fireAll("Having a bad time"); + ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time. + + // Make sure that all JSArray allocations that load the appropriate structure from + // this object now load a structure that uses SlowPut. + for (unsigned i = 0; i < NumberOfIndexingShapes; ++i) + m_arrayStructureForIndexingShapeDuringAllocation[i].set(vm, this, originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage)); + + // Make sure that all objects that have indexed storage switch to the slow kind of + // indexed storage. + MarkedArgumentBuffer foundObjects; // Use MarkedArgumentBuffer because switchToSlowPutArrayStorage() may GC. + ObjectsWithBrokenIndexingFinder finder(foundObjects, this); + { + HeapIterationScope iterationScope(vm.heap); + vm.heap.objectSpace().forEachLiveCell(iterationScope, finder); + } + while (!foundObjects.isEmpty()) { + JSObject* object = asObject(foundObjects.last()); + foundObjects.removeLast(); + ASSERT(hasBrokenIndexing(object)); + object->switchToSlowPutArrayStorage(vm); + } +} - 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); +bool JSGlobalObject::objectPrototypeIsSane() +{ + return !hasIndexedProperties(m_objectPrototype->indexingType()) + && m_objectPrototype->prototype().isNull(); +} - GlobalPropertyInfo staticGlobals[] = { - 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::infinity()), DontEnum | DontDelete | ReadOnly), - GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete | ReadOnly) - }; - addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals)); +bool JSGlobalObject::arrayPrototypeChainIsSane() +{ + return !hasIndexedProperties(m_arrayPrototype->indexingType()) + && m_arrayPrototype->prototype() == m_objectPrototype.get() + && objectPrototypeIsSane(); +} - resetPrototype(exec->globalData(), prototype); +bool JSGlobalObject::stringPrototypeChainIsSane() +{ + return !hasIndexedProperties(m_stringPrototype->indexingType()) + && m_stringPrototype->prototype() == m_objectPrototype.get() + && objectPrototypeIsSane(); } -void JSGlobalObject::createThrowTypeError(ExecState* exec) +void JSGlobalObject::createThrowTypeError(VM& vm) { - 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); + JSFunction* thrower = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeError); + GetterSetter* getterSetter = GetterSetter::create(vm, this); + getterSetter->setGetter(vm, this, thrower); + getterSetter->setSetter(vm, this, thrower); + m_throwTypeErrorGetterSetter.set(vm, this, getterSetter); } // Set prototype, and also insert the object prototype at the end of the chain. -void JSGlobalObject::resetPrototype(JSGlobalData& globalData, JSValue prototype) +void JSGlobalObject::resetPrototype(VM& vm, JSValue prototype) { - setPrototype(globalData, prototype); + setPrototype(vm, prototype); JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this); JSObject* objectPrototype = m_objectPrototype.get(); if (oldLastInPrototypeChain != objectPrototype) - oldLastInPrototypeChain->setPrototype(globalData, objectPrototype); + oldLastInPrototypeChain->setPrototype(vm, objectPrototype); + + // Whenever we change the prototype of the global object, we need to create a new JSProxy with the correct prototype. + setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, prototype, PureForwardingProxyType), this)); } void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor) { JSGlobalObject* thisObject = jsCast(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()); + ASSERT_GC_OBJECT_INHERITS(thisObject, info()); + Base::visitChildren(thisObject, visitor); + + visitor.append(&thisObject->m_globalThis); + + visitor.append(&thisObject->m_globalCallee); + visitor.append(&thisObject->m_regExpConstructor); + visitor.append(&thisObject->m_errorConstructor); + visitor.append(&thisObject->m_evalErrorConstructor); + visitor.append(&thisObject->m_rangeErrorConstructor); + visitor.append(&thisObject->m_referenceErrorConstructor); + visitor.append(&thisObject->m_syntaxErrorConstructor); + visitor.append(&thisObject->m_typeErrorConstructor); + visitor.append(&thisObject->m_URIErrorConstructor); + visitor.append(&thisObject->m_objectConstructor); +#if ENABLE(PROMISES) + visitor.append(&thisObject->m_promiseConstructor); +#endif + + visitor.append(&thisObject->m_nullGetterFunction); + visitor.append(&thisObject->m_nullSetterFunction); + + visitor.append(&thisObject->m_parseIntFunction); + visitor.append(&thisObject->m_evalFunction); + visitor.append(&thisObject->m_callFunction); + visitor.append(&thisObject->m_applyFunction); + visitor.append(&thisObject->m_definePropertyFunction); + visitor.append(&thisObject->m_arrayProtoValuesFunction); +#if ENABLE(PROMISES) + visitor.append(&thisObject->m_initializePromiseFunction); + visitor.append(&thisObject->m_newPromiseDeferredFunction); +#endif + visitor.append(&thisObject->m_throwTypeErrorGetterSetter); + + visitor.append(&thisObject->m_objectPrototype); + visitor.append(&thisObject->m_functionPrototype); + visitor.append(&thisObject->m_arrayPrototype); + visitor.append(&thisObject->m_errorPrototype); + visitor.append(&thisObject->m_iteratorPrototype); +#if ENABLE(PROMISES) + visitor.append(&thisObject->m_promisePrototype); +#endif + + visitor.append(&thisObject->m_debuggerScopeStructure); + visitor.append(&thisObject->m_withScopeStructure); + visitor.append(&thisObject->m_strictEvalActivationStructure); + visitor.append(&thisObject->m_lexicalEnvironmentStructure); + visitor.append(&thisObject->m_catchScopeStructure); + visitor.append(&thisObject->m_functionNameScopeStructure); + visitor.append(&thisObject->m_directArgumentsStructure); + visitor.append(&thisObject->m_scopedArgumentsStructure); + visitor.append(&thisObject->m_outOfBandArgumentsStructure); + for (unsigned i = 0; i < NumberOfIndexingShapes; ++i) + visitor.append(&thisObject->m_originalArrayStructureForIndexingShape[i]); + for (unsigned i = 0; i < NumberOfIndexingShapes; ++i) + visitor.append(&thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]); + visitor.append(&thisObject->m_booleanObjectStructure); + visitor.append(&thisObject->m_callbackConstructorStructure); + visitor.append(&thisObject->m_callbackFunctionStructure); + visitor.append(&thisObject->m_callbackObjectStructure); +#if JSC_OBJC_API_ENABLED + visitor.append(&thisObject->m_objcCallbackFunctionStructure); + visitor.append(&thisObject->m_objcWrapperObjectStructure); +#endif + visitor.append(&thisObject->m_nullPrototypeObjectStructure); + visitor.append(&thisObject->m_errorStructure); + visitor.append(&thisObject->m_calleeStructure); + visitor.append(&thisObject->m_functionStructure); + visitor.append(&thisObject->m_boundFunctionStructure); + visitor.append(&thisObject->m_namedFunctionStructure); + visitor.append(&thisObject->m_symbolObjectStructure); + visitor.append(&thisObject->m_regExpStructure); + visitor.append(&thisObject->m_regExpMatchesArrayStructure); + visitor.append(&thisObject->m_consoleStructure); + visitor.append(&thisObject->m_dollarVMStructure); + visitor.append(&thisObject->m_internalFunctionStructure); + +#if ENABLE(PROMISES) + visitor.append(&thisObject->m_promiseStructure); +#endif // ENABLE(PROMISES) + +#define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName) \ + visitor.append(&thisObject->m_ ## lowerName ## Prototype); \ + visitor.append(&thisObject->m_ ## properName ## Structure); \ + + FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE) + FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(VISIT_SIMPLE_TYPE) + +#undef VISIT_SIMPLE_TYPE + + for (unsigned i = NUMBER_OF_TYPED_ARRAY_TYPES; i--;) { + visitor.append(&thisObject->m_typedArrays[i].prototype); + visitor.append(&thisObject->m_typedArrays[i].structure); } } -ExecState* JSGlobalObject::globalExec() +JSValue JSGlobalObject::toThis(JSCell*, ExecState* exec, ECMAMode ecmaMode) { - return CallFrame::create(m_globalCallFrame + RegisterFile::CallFrameHeaderSize); + if (ecmaMode == StrictMode) + return jsUndefined(); + return exec->globalThisValue(); } -void JSGlobalObject::resizeRegisters(size_t newSize) +ExecState* JSGlobalObject::globalExec() { - // Previous duplicate symbols may have created spare capacity in m_registerArray. - if (newSize <= m_registerArraySize) - return; - - size_t oldSize = m_registerArraySize; - OwnArrayPtr > registerArray = adoptArrayPtr(new WriteBarrier[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* registers = registerArray.get(); - setRegisters(registers, registerArray.release(), newSize); + return CallFrame::create(m_globalCallFrame); } void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count) { - resizeRegisters(symbolTable().size() + count); + ScopeOffset startOffset = addVariables(count); 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); + ScopeOffset offset; + { + ConcurrentJITLocker locker(symbolTable()->m_lock); + offset = symbolTable()->takeNextScopeOffset(locker); + RELEASE_ASSERT(offset = startOffset + i); + SymbolTableEntry newEntry(VarOffset(offset), global.attributes); + symbolTable()->add(locker, global.identifier.impl(), newEntry); + } + variableAt(offset).set(vm(), this, global.value); } } -bool JSGlobalObject::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +bool JSGlobalObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot) { - JSGlobalObject* thisObject = jsCast(cell); - if (getStaticFunctionSlot(exec, ExecState::globalObjectTable(exec), thisObject, propertyName, slot)) + JSGlobalObject* thisObject = jsCast(object); + if (getStaticFunctionSlot(exec, globalObjectTable, thisObject, propertyName, slot)) return true; - return thisObject->symbolTableGet(propertyName, slot); + return symbolTableGet(thisObject, propertyName, slot); } -bool JSGlobalObject::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +void JSGlobalObject::clearRareData(JSCell* cell) { - JSGlobalObject* thisObject = jsCast(object); - if (getStaticFunctionDescriptor(exec, ExecState::globalObjectTable(exec), thisObject, propertyName, descriptor)) - return true; - return thisObject->symbolTableGet(propertyName, descriptor); + jsCast(cell)->m_rareData = nullptr; } -void JSGlobalObject::clearRareData(JSCell* cell) +void slowValidateCell(JSGlobalObject* globalObject) +{ + RELEASE_ASSERT(globalObject->isGlobalObject()); + ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info()); +} + +UnlinkedProgramCodeBlock* JSGlobalObject::createProgramCodeBlock(CallFrame* callFrame, ProgramExecutable* executable, JSObject** exception) +{ + ParserError error; + JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict; + DebuggerMode debuggerMode = hasDebugger() ? DebuggerOn : DebuggerOff; + ProfilerMode profilerMode = hasProfiler() ? ProfilerOn : ProfilerOff; + UnlinkedProgramCodeBlock* unlinkedCodeBlock = vm().codeCache()->getProgramCodeBlock( + vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, strictMode, + debuggerMode, profilerMode, error); + + if (hasDebugger()) + debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message()); + + if (error.isValid()) { + *exception = error.toErrorObject(this, executable->source()); + return nullptr; + } + + return unlinkedCodeBlock; +} + +UnlinkedEvalCodeBlock* JSGlobalObject::createEvalCodeBlock(CallFrame* callFrame, EvalExecutable* executable, ThisTDZMode thisTDZMode) { - jsCast(cell)->m_rareData.clear(); + ParserError error; + JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict; + DebuggerMode debuggerMode = hasDebugger() ? DebuggerOn : DebuggerOff; + ProfilerMode profilerMode = hasProfiler() ? ProfilerOn : ProfilerOff; + UnlinkedEvalCodeBlock* unlinkedCodeBlock = vm().codeCache()->getEvalCodeBlock( + vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, strictMode, thisTDZMode, debuggerMode, profilerMode, error); + + if (hasDebugger()) + debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message()); + + if (error.isValid()) { + throwVMError(callFrame, error.toErrorObject(this, executable->source())); + return nullptr; + } + + return unlinkedCodeBlock; } -DynamicGlobalObjectScope::DynamicGlobalObjectScope(JSGlobalData& globalData, JSGlobalObject* dynamicGlobalObject) - : m_dynamicGlobalObjectSlot(globalData.dynamicGlobalObject) - , m_savedDynamicGlobalObject(m_dynamicGlobalObjectSlot) +void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled) { - if (!m_dynamicGlobalObjectSlot) { -#if ENABLE(ASSEMBLER) - if (ExecutableAllocator::underMemoryPressure()) - globalData.heap.discardAllCompiledCode(); +#if ENABLE(REMOTE_INSPECTOR) + m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled); +#else + UNUSED_PARAM(enabled); #endif +} - m_dynamicGlobalObjectSlot = dynamicGlobalObject; +bool JSGlobalObject::remoteDebuggingEnabled() const +{ +#if ENABLE(REMOTE_INSPECTOR) + return m_inspectorDebuggable->remoteDebuggingAllowed(); +#else + return false; +#endif +} - // Reset the date cache between JS invocations to force the VM - // to observe time zone changes. - globalData.resetDateCache(); +#if ENABLE(WEB_REPLAY) +void JSGlobalObject::setInputCursor(PassRefPtr prpCursor) +{ + m_inputCursor = prpCursor; + ASSERT(m_inputCursor); + + InputCursor& cursor = inputCursor(); + // Save or set the random seed. This performed here rather than the constructor + // to avoid threading the input cursor through all the abstraction layers. + if (cursor.isCapturing()) + cursor.appendInput(m_weakRandom.seedUnsafe()); + else if (cursor.isReplaying()) { + if (SetRandomSeed* input = cursor.fetchInput()) + m_weakRandom.initializeSeed(static_cast(input->randomSeed())); } } +#endif -void slowValidateCell(JSGlobalObject* globalObject) +void JSGlobalObject::setName(const String& name) +{ + m_name = name; + +#if ENABLE(REMOTE_INSPECTOR) + m_inspectorDebuggable->update(); +#endif +} + +void JSGlobalObject::queueMicrotask(PassRefPtr task) { - if (!globalObject->isGlobalObject()) - CRASH(); - ASSERT_GC_OBJECT_INHERITS(globalObject, &JSGlobalObject::s_info); + if (globalObjectMethodTable()->queueTaskToEventLoop) + globalObjectMethodTable()->queueTaskToEventLoop(this, task); + else + WTFLogAlways("ERROR: Event loop not supported."); } } // namespace JSC