标签:
总结: [CustomNamedGetter] 或者 [CustomNamedSetter] 允许你为命名属性的getter或者setter编写自己的绑定函数.
用法如下:
[
CustomNamedGetter,
CustomNamedSetter
] interface MichaelNamedGetter {
};
当Michael.foooooo被执行时,命名的getters定义了它的行为, 这里的foooooooo不是Michael的属性. 当语句"XXX.foooooooo = ..." 执行时,命名的setter定义了它的行为。[CustomNamedGetter] 和 [CustomNamedSetter] 允许你按照如下方式编写自己的绑定:
bool JSXXX::canGetItemsForName(ExecState* exec, XXX* impl, const Identifier& propertyName)
{
...;
}
JSValue JSXXX::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
{
...;
}
bool JSXXX::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
{
...;
}
总结: 他们允许你这样编写绑定代码。
用法: [Custom] 可用于函数和属性. [CustomGetter], [CustomSetter]只能用于属性:
[Custom] void func();
[CustomGetter, JSCustomSetter] attribute DOMString str;
我们应该尽可能少的使用自定义的绑定代码,因为他们可能有问题。在考虑使用他们之前,你应该慎重思考:我真的需要自定义绑定代码吗?推荐你修改代码生成器而不是自定义绑定代码。
在解释细节之前,让我澄清这些IDL属性之间的关系。
举例:
interface XXX {
[Custom] void func(int a, int b);
};
你可以编写绑定代码:WebCore/bindings/js/JSXXXCustom.cpp:
JSValue JSXXX::func(ExecState* exec)
{
...;
}
参考更多例子:WebCore/bindings/js/JSXXXCustom.cpp
interface XXX {
[CustomGetter] attribute DOMString str;
};
编写绑定代码: WebCore/bindings/js/JSXXXCustom.cpp:
JSValue JSXXX::str(ExecState* exec) const
{
...;
}
参考更多例子:WebCore/bindings/js/JSXXXCustom.cpp
interface XXX {
[CustomSetter] attribute DOMString str;
};
编写绑定代码: WebCore/bindings/js/JSXXXCustom.cpp:
void JSXXX::setStr(ExecState*, JSValue value)
{
...;
}
注意: ObjC, GObject,CPP 绑定bindings 不支持自己定义的绑定代码.
Webkit IDL中自定义[命名]属性的获取(Getter)以及设置(Setter)函数
标签:
原文地址:http://blog.csdn.net/lichwei1983/article/details/43888717