⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsobject.h

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 H
📖 第 1 页 / 共 2 页
字号:
    if (JSValuePtr* location = getDirectLocation(propertyName)) {        if (m_structure->hasGetterSetterProperties() && location[0].isGetterSetter())            fillGetterPropertySlot(slot, location);        else            slot.setValueSlot(this, location, offsetForLocation(location));        return true;    }    // non-standard Netscape extension    if (propertyName == exec->propertyNames().underscoreProto) {        slot.setValue(prototype());        return true;    }    return false;}ALWAYS_INLINE bool JSObject::getOwnPropertySlotForWrite(ExecState* exec, const Identifier& propertyName, PropertySlot& slot, bool& slotIsWriteable){    unsigned attributes;    if (JSValuePtr* location = getDirectLocation(propertyName, attributes)) {        if (m_structure->hasGetterSetterProperties() && location[0].isGetterSetter()) {            slotIsWriteable = false;            fillGetterPropertySlot(slot, location);        } else {            slotIsWriteable = !(attributes & ReadOnly);            slot.setValueSlot(this, location, offsetForLocation(location));        }        return true;    }    // non-standard Netscape extension    if (propertyName == exec->propertyNames().underscoreProto) {        slot.setValue(prototype());        slotIsWriteable = false;        return true;    }    return false;}// It may seem crazy to inline a function this large, especially a virtual function,// but it makes a big difference to property lookup that derived classes can inline their// base class call to this.ALWAYS_INLINE bool JSObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot){    return inlineGetOwnPropertySlot(exec, propertyName, slot);}ALWAYS_INLINE bool JSCell::fastGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot){    if (structure()->typeInfo().hasStandardGetOwnPropertySlot())        return asObject(this)->inlineGetOwnPropertySlot(exec, propertyName, slot);    return getOwnPropertySlot(exec, propertyName, slot);}// It may seem crazy to inline a function this large but it makes a big difference// since this is function very hot in variable lookupinline bool JSObject::getPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot){    JSObject* object = this;    while (true) {        if (object->fastGetOwnPropertySlot(exec, propertyName, slot))            return true;        JSValuePtr prototype = object->prototype();        if (!prototype.isObject())            return false;        object = asObject(prototype);    }}inline bool JSObject::getPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot){    JSObject* object = this;    while (true) {        if (object->getOwnPropertySlot(exec, propertyName, slot))            return true;        JSValuePtr prototype = object->prototype();        if (!prototype.isObject())            return false;        object = asObject(prototype);    }}inline JSValuePtr JSObject::get(ExecState* exec, const Identifier& propertyName) const{    PropertySlot slot(this);    if (const_cast<JSObject*>(this)->getPropertySlot(exec, propertyName, slot))        return slot.getValue(exec, propertyName);        return jsUndefined();}inline JSValuePtr JSObject::get(ExecState* exec, unsigned propertyName) const{    PropertySlot slot(this);    if (const_cast<JSObject*>(this)->getPropertySlot(exec, propertyName, slot))        return slot.getValue(exec, propertyName);    return jsUndefined();}inline void JSObject::putDirect(const Identifier& propertyName, JSValuePtr value, unsigned attr){    PutPropertySlot slot;    putDirect(propertyName, value, attr, false, slot);}inline void JSObject::putDirect(const Identifier& propertyName, JSValuePtr value, unsigned attributes, bool checkReadOnly, PutPropertySlot& slot){    ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));    if (m_structure->isDictionary()) {        unsigned currentAttributes;        size_t offset = m_structure->get(propertyName, currentAttributes);        if (offset != WTF::notFound) {            if (checkReadOnly && currentAttributes & ReadOnly)                return;            m_propertyStorage[offset] = value;            slot.setExistingProperty(this, offset);            return;        }        size_t currentCapacity = m_structure->propertyStorageCapacity();        offset = m_structure->addPropertyWithoutTransition(propertyName, attributes);        if (currentCapacity != m_structure->propertyStorageCapacity())            allocatePropertyStorage(currentCapacity, m_structure->propertyStorageCapacity());        ASSERT(offset < m_structure->propertyStorageCapacity());        m_propertyStorage[offset] = value;        slot.setNewProperty(this, offset);        return;    }    size_t offset;    size_t currentCapacity = m_structure->propertyStorageCapacity();    if (RefPtr<Structure> structure = Structure::addPropertyTransitionToExistingStructure(m_structure, propertyName, attributes, offset)) {        if (currentCapacity != structure->propertyStorageCapacity())            allocatePropertyStorage(currentCapacity, structure->propertyStorageCapacity());        ASSERT(offset < structure->propertyStorageCapacity());        m_propertyStorage[offset] = value;        slot.setNewProperty(this, offset);        slot.setWasTransition(true);        setStructure(structure.release());        return;    }    unsigned currentAttributes;    offset = m_structure->get(propertyName, currentAttributes);    if (offset != WTF::notFound) {        if (checkReadOnly && currentAttributes & ReadOnly)            return;        m_propertyStorage[offset] = value;        slot.setExistingProperty(this, offset);        return;    }    RefPtr<Structure> structure = Structure::addPropertyTransition(m_structure, propertyName, attributes, offset);    if (currentCapacity != structure->propertyStorageCapacity())        allocatePropertyStorage(currentCapacity, structure->propertyStorageCapacity());    ASSERT(offset < structure->propertyStorageCapacity());    m_propertyStorage[offset] = value;    slot.setNewProperty(this, offset);    slot.setWasTransition(true);    setStructure(structure.release());}inline void JSObject::putDirectWithoutTransition(const Identifier& propertyName, JSValuePtr value, unsigned attributes){    size_t currentCapacity = m_structure->propertyStorageCapacity();    size_t offset = m_structure->addPropertyWithoutTransition(propertyName, attributes);    if (currentCapacity != m_structure->propertyStorageCapacity())        allocatePropertyStorage(currentCapacity, m_structure->propertyStorageCapacity());    m_propertyStorage[offset] = value;}inline void JSObject::transitionTo(Structure* newStructure){    if (m_structure->propertyStorageCapacity() != newStructure->propertyStorageCapacity())        allocatePropertyStorage(m_structure->propertyStorageCapacity(), newStructure->propertyStorageCapacity());    setStructure(newStructure);}inline JSValuePtr JSObject::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const{    return defaultValue(exec, preferredType);}inline JSValuePtr JSValuePtr::get(ExecState* exec, const Identifier& propertyName) const{    PropertySlot slot(asValue());    return get(exec, propertyName, slot);}inline JSValuePtr JSValuePtr::get(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) const{    if (UNLIKELY(!isCell())) {        JSObject* prototype = JSImmediate::prototype(asValue(), exec);        if (!prototype->getPropertySlot(exec, propertyName, slot))            return jsUndefined();        return slot.getValue(exec, propertyName);    }    JSCell* cell = asCell();    while (true) {        if (cell->fastGetOwnPropertySlot(exec, propertyName, slot))            return slot.getValue(exec, propertyName);        ASSERT(cell->isObject());        JSValuePtr prototype = static_cast<JSObject*>(cell)->prototype();        if (!prototype.isObject())            return jsUndefined();        cell = asObject(prototype);    }}inline JSValuePtr JSValuePtr::get(ExecState* exec, unsigned propertyName) const{    PropertySlot slot(asValue());    return get(exec, propertyName, slot);}inline JSValuePtr JSValuePtr::get(ExecState* exec, unsigned propertyName, PropertySlot& slot) const{    if (UNLIKELY(!isCell())) {        JSObject* prototype = JSImmediate::prototype(asValue(), exec);        if (!prototype->getPropertySlot(exec, propertyName, slot))            return jsUndefined();        return slot.getValue(exec, propertyName);    }    JSCell* cell = const_cast<JSCell*>(asCell());    while (true) {        if (cell->getOwnPropertySlot(exec, propertyName, slot))            return slot.getValue(exec, propertyName);        ASSERT(cell->isObject());        JSValuePtr prototype = static_cast<JSObject*>(cell)->prototype();        if (!prototype.isObject())            return jsUndefined();        cell = prototype.asCell();    }}inline void JSValuePtr::put(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot){    if (UNLIKELY(!isCell())) {        JSImmediate::toObject(asValue(), exec)->put(exec, propertyName, value, slot);        return;    }    asCell()->put(exec, propertyName, value, slot);}inline void JSValuePtr::put(ExecState* exec, unsigned propertyName, JSValuePtr value){    if (UNLIKELY(!isCell())) {        JSImmediate::toObject(asValue(), exec)->put(exec, propertyName, value);        return;    }    asCell()->put(exec, propertyName, value);}ALWAYS_INLINE void JSObject::allocatePropertyStorageInline(size_t oldSize, size_t newSize){    ASSERT(newSize > oldSize);    JSValuePtr* oldPropertyStorage = m_propertyStorage;    m_propertyStorage = new JSValuePtr[newSize];    for (unsigned i = 0; i < oldSize; ++i)        m_propertyStorage[i] = oldPropertyStorage[i];    if (oldPropertyStorage != m_inlineStorage)        delete [] oldPropertyStorage;}} // namespace JSC#endif // JSObject_h

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -