Webkit的自訂屬性擷取函數以及屬性刪除函數實現

來源:互聯網
上載者:User

標籤:

概述: [CustomEnumerateProperty] 當給定的介面被枚舉時,允許你為指定介面的屬性擷取函數編寫自己的實現. 同樣,當介面的屬性被刪除時,[CustomDeleteProperty]允許你編寫自己的實現.

customEnumerateProperty](i), [CustomDeleteProperty](i)


用法: 這兩個修飾可作用在interface,用法如下:

    [        CustomEnumerateProperty,        CustomDeleteProperty    ] interface DataTransferItemList {    };
  • [CustomEnumerateProperty] in JavaScriptCore: 你能編寫DataTransferItemList的屬性擷取函數,具體來說,你可以編寫這個函數JSXXX::getOwnPropertyNames(...), 它來自於WebCore/bindings/js/JSDataTransferItemListCustom.cpp:
 void JSDataTransferItemList::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode){    JSDataTransferItemList* thisObject = jsCast<JSDataTransferItemList*>(object);    ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);    for (unsigned i = 0; i < static_cast<DataTransferItemList*>(thisObject->impl())->length(); ++i)        propertyNames.add(Identifier::from(exec, i));     Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);}
    [        CustomDeleteProperty    ] interface Storage {    };
  • [CustomDeleteProperty] : 當Storage的屬性被刪除時,我們可以編寫自己的屬性刪除函數,具體點說,就是像這樣子編寫JSStorage::deleteProperty(...) 函數,它位於WebCore/bindings/js/JSStorageCustom.cpp:
bool JSStorage::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName){    JSStorage* thisObject = jsCast<JSStorage*>(cell);    // Only perform the custom delete if the object doesn‘t have a native property by this name.    // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check    // the native property slots manually.    PropertySlot slot;    if (getStaticValueSlot<JSStorage, Base>(exec, s_info.propHashTable(exec), thisObject, propertyName, slot))        return false;            JSValue prototype = thisObject->prototype();    if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName))        return false;    thisObject->m_impl->removeItem(propertyNameToString(propertyName));    return true;}
參考:1 http://trac.webkit.org/wiki/WebKitIDL#CustomEnumerateProperty2 souce code of webkit

Webkit的自訂屬性擷取函數以及屬性刪除函數實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.