📄 jsglobalobject.cpp
字号:
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); ErrorPrototype* errorPrototype = new (exec) ErrorPrototype(exec, ErrorPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get()); d()->errorStructure = ErrorInstance::createStructure(errorPrototype); RefPtr<Structure> nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(errorPrototype); NativeErrorPrototype* evalErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "EvalError", "EvalError"); NativeErrorPrototype* rangeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "RangeError", "RangeError"); NativeErrorPrototype* referenceErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "ReferenceError", "ReferenceError"); NativeErrorPrototype* syntaxErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "SyntaxError", "SyntaxError"); NativeErrorPrototype* typeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "TypeError", "TypeError"); NativeErrorPrototype* URIErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "URIError", "URIError"); // Constructors JSValuePtr objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructure(d()->functionPrototype), d()->objectPrototype); JSValuePtr functionConstructor = new (exec) FunctionConstructor(exec, FunctionConstructor::createStructure(d()->functionPrototype), d()->functionPrototype); JSValuePtr arrayConstructor = new (exec) ArrayConstructor(exec, ArrayConstructor::createStructure(d()->functionPrototype), d()->arrayPrototype); JSValuePtr stringConstructor = new (exec) StringConstructor(exec, StringConstructor::createStructure(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->stringPrototype); JSValuePtr booleanConstructor = new (exec) BooleanConstructor(exec, BooleanConstructor::createStructure(d()->functionPrototype), d()->booleanPrototype); JSValuePtr numberConstructor = new (exec) NumberConstructor(exec, NumberConstructor::createStructure(d()->functionPrototype), d()->numberPrototype); JSValuePtr 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> nativeErrorStructure = NativeErrorConstructor::createStructure(d()->functionPrototype); d()->evalErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, evalErrorPrototype); d()->rangeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, rangeErrorPrototype); d()->referenceErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, referenceErrorPrototype); d()->syntaxErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, syntaxErrorPrototype); d()->typeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, typeErrorPrototype); d()->URIErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, URIErrorPrototype); d()->objectPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, objectConstructor, DontEnum); d()->functionPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, functionConstructor, DontEnum); d()->arrayPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, arrayConstructor, DontEnum); d()->booleanPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, booleanConstructor, DontEnum); d()->stringPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, stringConstructor, DontEnum); d()->numberPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, numberConstructor, DontEnum); d()->datePrototype->putDirectWithoutTransition(exec->propertyNames().constructor, dateConstructor, DontEnum); d()->regExpPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, d()->regExpConstructor, DontEnum); errorPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, d()->errorConstructor, DontEnum); evalErrorPrototype->putDirect(exec->propertyNames().constructor, d()->evalErrorConstructor, DontEnum); rangeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->rangeErrorConstructor, DontEnum); referenceErrorPrototype->putDirect(exec->propertyNames().constructor, d()->referenceErrorConstructor, DontEnum); syntaxErrorPrototype->putDirect(exec->propertyNames().constructor, d()->syntaxErrorConstructor, DontEnum); typeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->typeErrorConstructor, DontEnum); URIErrorPrototype->putDirect(exec->propertyNames().constructor, d()->URIErrorConstructor, DontEnum); // Set global constructors // FIXME: These properties could be handled by a static hash table. putDirectWithoutTransition(Identifier(exec, "Object"), objectConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "Function"), functionConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "Array"), arrayConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "Boolean"), booleanConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "String"), stringConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "Number"), numberConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "Date"), dateConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "RegExp"), d()->regExpConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "Error"), d()->errorConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "EvalError"), d()->evalErrorConstructor); putDirectWithoutTransition(Identifier(exec, "RangeError"), d()->rangeErrorConstructor); putDirectWithoutTransition(Identifier(exec, "ReferenceError"), d()->referenceErrorConstructor); putDirectWithoutTransition(Identifier(exec, "SyntaxError"), d()->syntaxErrorConstructor); putDirectWithoutTransition(Identifier(exec, "TypeError"), d()->typeErrorConstructor); putDirectWithoutTransition(Identifier(exec, "URIError"), d()->URIErrorConstructor); // Set global values. GlobalPropertyInfo staticGlobals[] = { GlobalPropertyInfo(Identifier(exec, "Math"), new (exec) MathObject(exec, MathObject::createStructure(d()->objectPrototype)), DontEnum | DontDelete), GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(exec), DontEnum | DontDelete), GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(exec, Inf), DontEnum | DontDelete), GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete) }; 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) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 2, Identifier(exec, "parseInt"), globalFuncParseInt), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "parseFloat"), globalFuncParseFloat), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isNaN"), globalFuncIsNaN), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isFinite"), globalFuncIsFinite), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "escape"), globalFuncEscape), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "unescape"), globalFuncUnescape), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURI"), globalFuncDecodeURI), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURIComponent"), globalFuncDecodeURIComponent), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURI"), globalFuncEncodeURI), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURIComponent"), globalFuncEncodeURIComponent), DontEnum);#ifndef NDEBUG putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "jscprint"), globalFuncJSCPrint), DontEnum);#endif resetPrototype(prototype);}// Set prototype, and also insert the object prototype at the end of the chain.void JSGlobalObject::resetPrototype(JSValuePtr prototype){ setPrototype(prototype); lastInPrototypeChain(this)->setPrototype(d()->objectPrototype);}void JSGlobalObject::mark(){ JSVariableObject::mark(); HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end(); for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it) (*it)->mark(); RegisterFile& registerFile = globalData()->interpreter->registerFile(); if (registerFile.globalObject() == this) registerFile.markGlobals(&globalData()->heap); markIfNeeded(d()->regExpConstructor); markIfNeeded(d()->errorConstructor); markIfNeeded(d()->evalErrorConstructor); markIfNeeded(d()->rangeErrorConstructor); markIfNeeded(d()->referenceErrorConstructor); markIfNeeded(d()->syntaxErrorConstructor); markIfNeeded(d()->typeErrorConstructor); markIfNeeded(d()->URIErrorConstructor); markIfNeeded(d()->evalFunction); markIfNeeded(d()->objectPrototype); markIfNeeded(d()->functionPrototype); markIfNeeded(d()->arrayPrototype); markIfNeeded(d()->booleanPrototype); markIfNeeded(d()->stringPrototype); markIfNeeded(d()->numberPrototype); markIfNeeded(d()->datePrototype); markIfNeeded(d()->regExpPrototype); markIfNeeded(d()->errorStructure); // 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; for (size_t i = 0; i < size; ++i) { Register& r = registerArray[i]; if (!r.marked()) r.mark(); }}ExecState* JSGlobalObject::globalExec(){ return CallFrame::create(d()->globalCallFrame + RegisterFile::CallFrameHeaderSize);}bool JSGlobalObject::isDynamicScope() const{ return true;}void JSGlobalObject::copyGlobalsFrom(RegisterFile& registerFile){ ASSERT(!d()->registerArray); ASSERT(!d()->registerArraySize); int numGlobals = registerFile.numGlobals(); if (!numGlobals) { d()->registers = 0; return; } Register* registerArray = copyRegisterArray(registerFile.lastGlobal(), numGlobals); setRegisters(registerArray + numGlobals, registerArray, numGlobals);}void JSGlobalObject::copyGlobalsTo(RegisterFile& registerFile){ 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); }}void* JSGlobalObject::operator new(size_t size, JSGlobalData* globalData){#ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE return globalData->heap.inlineAllocate(size);#else return globalData->heap.allocate(size);#endif}} // namespace JSC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -