📄 jsglobalobject.cpp
字号:
/* * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. * Copyright (C) 2008 Cameron Zwarich (cwzwarich@uwaterloo.ca) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * 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 * its contributors may be used to endorse or promote products derived * 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 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */#include "config.h"#include "JSGlobalObject.h"#include "JSCallbackConstructor.h"#include "JSCallbackFunction.h"#include "JSCallbackObject.h"#include "Arguments.h"#include "ArrayConstructor.h"#include "ArrayPrototype.h"#include "BooleanConstructor.h"#include "BooleanPrototype.h"#include "CodeBlock.h"#include "DateConstructor.h"#include "DatePrototype.h"#include "ErrorConstructor.h"#include "ErrorPrototype.h"#include "FunctionConstructor.h"#include "FunctionPrototype.h"#include "GlobalEvalFunction.h"#include "JSGlobalObjectFunctions.h"#include "JSLock.h"#include "Interpreter.h"#include "MathObject.h"#include "NativeErrorConstructor.h"#include "NativeErrorPrototype.h"#include "NumberConstructor.h"#include "NumberPrototype.h"#include "ObjectConstructor.h"#include "ObjectPrototype.h"#include "Profiler.h"#include "PrototypeFunction.h"#include "RegExpConstructor.h"#include "RegExpMatchesArray.h"#include "RegExpObject.h"#include "RegExpPrototype.h"#include "ScopeChainMark.h"#include "StringConstructor.h"#include "StringPrototype.h"#include "Debugger.h"namespace JSC {ASSERT_CLASS_FITS_IN_CELL(JSGlobalObject);// Default number of ticks before a timeout check should be done.static const int initialTickCountThreshold = 255;// Preferred number of milliseconds between each timeout checkstatic const int preferredScriptCheckTimeInterval = 1000;static inline void markIfNeeded(JSValuePtr v){ if (v && !v.marked()) v.mark();}static inline void markIfNeeded(const RefPtr<Structure>& s){ if (s) s->mark();}JSGlobalObject::~JSGlobalObject(){ ASSERT(JSLock::currentThreadIsHoldingLock()); if (d()->debugger) d()->debugger->detach(this); Profiler** profiler = Profiler::enabledProfilerReference(); if (UNLIKELY(*profiler != 0)) { (*profiler)->stopProfiling(globalExec(), UString()); } 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<ProgramCodeBlock*>::const_iterator end = codeBlocks().end(); for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it) (*it)->clearGlobalObject(); RegisterFile& registerFile = globalData()->interpreter->registerFile(); if (registerFile.globalObject() == this) { registerFile.setGlobalObject(0); registerFile.setNumGlobals(0); } delete d();}void JSGlobalObject::init(JSObject* thisValue){ ASSERT(JSLock::currentThreadIsHoldingLock()); d()->globalData = Heap::heap(this)->globalData(); d()->globalScopeChain = ScopeChain(this, d()->globalData.get(), thisValue); JSGlobalObject::globalExec()->init(0, 0, d()->globalScopeChain.node(), CallFrame::noCaller(), 0, 0, 0); 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; d()->recursion = 0; d()->debugger = 0; d()->profileGroup = 0; reset(prototype());}void JSGlobalObject::put(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot){ ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this)); if (symbolTablePut(propertyName, value)) return; JSVariableObject::put(exec, propertyName, value, slot);}void JSGlobalObject::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValuePtr value, unsigned attributes){ ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this)); if (symbolTablePutWithAttributes(propertyName, value, attributes)) return; JSValuePtr valueBefore = getDirect(propertyName); PutPropertySlot slot; JSVariableObject::put(exec, propertyName, value, slot); if (!valueBefore) { JSValuePtr valueAfter = getDirect(propertyName); if (valueAfter) putDirect(propertyName, valueAfter, attributes); }}void JSGlobalObject::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunc){ PropertySlot slot; if (!symbolTableGet(propertyName, slot)) JSVariableObject::defineGetter(exec, propertyName, getterFunc);}void JSGlobalObject::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunc){ PropertySlot slot; if (!symbolTableGet(propertyName, slot)) JSVariableObject::defineSetter(exec, propertyName, setterFunc);}static inline JSObject* lastInPrototypeChain(JSObject* object){ JSObject* o = object; while (o->prototype().isObject()) o = asObject(o->prototype()); return o;}void JSGlobalObject::reset(JSValuePtr prototype){ 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); d()->functionPrototype->addFunctionProperties(exec, d()->prototypeFunctionStructure.get()); 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -