WebKit custom Property Get function and property delete function implementation

Source: Internet
Author: User
Tags hasproperty

Overview: [Customenumerateproperty] when a given interface is enumerated, allows you to write your own implementation for the property fetch function for the specified interface. Similarly, when the properties of an interface are removed,[Customdeleteproperty] allows you to write your own implementation .

Customenumerateproperty] (i), [Customdeleteproperty] (i)


Usage: These two modifiers can be used in interface, as follows:

    [        customenumerateproperty,        customdeleteproperty    ] interface datatransferitemlist {    };
    • [Customenumerateproperty] in JavaScriptCore: You can write Datatransferitemlist Property Get function, specifically, you can write this function jsxxx:: Getownpropertynames (...), which comes from 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) prop     Ertynames.add (Identifier::from (exec, i)); Base::getownpropertynames (Thisobject, exec, propertynames, mode);}
    [        customdeleteproperty    ] interface Storage {    };
    • [Customdeleteproperty] : When the storage property is deleted, we can write our own property delete function, specifically, that is, like this write jsstorage::d eleteproperty (... ) function, which is located in Webcore/bindings/js/jsStorageCustom.cpp:
BOOL Jsstorage::d eleteproperty (jscell* cell, execstate* exec, PropertyName PropertyName) {    jsstorage* Thisobject = jscast<jsstorage*> (cell);   //Only perform the custom delete if the object doesn ' t has a n Ative-name.   //Since Hasproperty () would end up calling Cangetitemsforname () and is fooled, We need to check   //The native property slots manually.    Propertyslot slot;    if (GetS Taticvalueslot<jsstorage, base> (exec, s_info.prophashtable (exec), Thisobject, PropertyName, slot))         return false;            Jsvalue prototype = Thisobject->protot Ype ();    if (Prototype.isobject () && Asobject (prototype)->hasproperty (exec, PropertyName))         return false;    Thisobject->m_impl->removeitem (propertynametostring ( PropertyName));    return true;}
Reference: 1 http://trac.webkit.org/wiki/WebKitIDL#CustomEnumerateProperty2 souce Code of WebKit

WebKit custom Property Get function and property delete function implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.