OLD | NEW |
1 # Blink IDL Extended Attributes | 1 # Blink IDL Extended Attributes |
2 | 2 |
3 [TOC] | 3 [TOC] |
4 | 4 |
5 ## Introduction | 5 ## Introduction |
6 | 6 |
7 The main interest in extended attributes are their _semantics_: Blink implements
many more extended attributes than the Web IDL standard, to specify various beh
avior. | 7 The main interest in extended attributes are their _semantics_: Blink implements
many more extended attributes than the Web IDL standard, to specify various beh
avior. |
8 | 8 |
9 The authoritative list of allowed extended attributes and values is [bindings/ID
LExtendedAttributes.txt](https://code.google.com/p/chromium/codesearch#chromium/
src/third_party/WebKit/Source/bindings/IDLExtendedAttributes.txt). This is compl
ete but not necessarily precise (there may be unused extended attributes or valu
es), since validation is run on build, but coverage isn't checked. | 9 The authoritative list of allowed extended attributes and values is [bindings/ID
LExtendedAttributes.txt](https://code.google.com/p/chromium/codesearch#chromium/
src/third_party/WebKit/Source/bindings/IDLExtendedAttributes.txt). This is compl
ete but not necessarily precise (there may be unused extended attributes or valu
es), since validation is run on build, but coverage isn't checked. |
10 | 10 |
(...skipping 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 Summary: Caches the resulting object and always returns the same object. | 1218 Summary: Caches the resulting object and always returns the same object. |
1219 | 1219 |
1220 When specified, caches the resulting object and returns it in later calls so tha
t the attribute always returns the same object. Must be accompanied with `[SameO
bject]`. | 1220 When specified, caches the resulting object and returns it in later calls so tha
t the attribute always returns the same object. Must be accompanied with `[SameO
bject]`. |
1221 | 1221 |
1222 ## Rare Blink-specific IDL Extended Attributes | 1222 ## Rare Blink-specific IDL Extended Attributes |
1223 | 1223 |
1224 These extended attributes are rarely used, generally only in one or two places.
These are often replacements for `[Custom]` bindings, and may be candidates for
deprecation and removal. | 1224 These extended attributes are rarely used, generally only in one or two places.
These are often replacements for `[Custom]` bindings, and may be candidates for
deprecation and removal. |
1225 | 1225 |
1226 ### [CachedAttribute] _(a)_ | 1226 ### [CachedAttribute] _(a)_ |
1227 | 1227 |
1228 Summary: For performance optimization, `[CachedAttribute]` indicates that a wrap
ped object should be cached on a DOM object. Rarely used (only by IndexDB). | 1228 Summary: For performance optimization, `[CachedAttribute]` indicates that a wrap
ped object should be cached on a DOM object. Rarely used. |
1229 | 1229 |
1230 Usage: `[CachedAttribute]` can be specified on attributes, and takes a required
value, generally called is*Dirty (esp. isValueDirty): | 1230 Usage: `[CachedAttribute]` can be specified on attributes, and takes a required
value, generally called is*Dirty (e.g. isValueDirty): |
1231 | 1231 |
1232 ```webidl | 1232 ```webidl |
1233 interface HTMLFoo { | 1233 interface HTMLFoo { |
1234 [CachedAttribute=isKeyDirty] attribute DOMString key; | 1234 [CachedAttribute=isKeyDirty] attribute DOMString key; |
1235 [CachedAttribute=isValueDirty] attribute SerializedScriptValue serializedVal
ue; | 1235 [CachedAttribute=isValueDirty] attribute SerializedScriptValue serializedVal
ue; |
1236 }; | 1236 }; |
1237 ``` | 1237 ``` |
1238 | 1238 |
1239 Without `[CachedAttribute]`, the key getter works in the following way: | 1239 Without `[CachedAttribute]`, the key getter works in the following way: |
1240 | 1240 |
(...skipping 22 matching lines...) Expand all Loading... |
1263 2. Otherwise, `HTMLFoo::serializedValue()` is called in Blink. | 1263 2. Otherwise, `HTMLFoo::serializedValue()` is called in Blink. |
1264 3. The result of `HTMLFoo::serializedValue()` is deserialized. | 1264 3. The result of `HTMLFoo::serializedValue()` is deserialized. |
1265 4. The deserialized result is passed to `toJS()` or `ToV8()`, and is converted t
o a wrapped object. | 1265 4. The deserialized result is passed to `toJS()` or `ToV8()`, and is converted t
o a wrapped object. |
1266 5. The wrapped object is cached. | 1266 5. The wrapped object is cached. |
1267 6. The wrapped object is returned. | 1267 6. The wrapped object is returned. |
1268 | 1268 |
1269 *** note | 1269 *** note |
1270 You should cache attributes if and only if it is really important for performanc
e. Not only does caching increase the DOM object size, but also it increases the
overhead of "cache-miss"ed getters. In addition, setters always need to invalid
ate the cache. | 1270 You should cache attributes if and only if it is really important for performanc
e. Not only does caching increase the DOM object size, but also it increases the
overhead of "cache-miss"ed getters. In addition, setters always need to invalid
ate the cache. |
1271 *** | 1271 *** |
1272 | 1272 |
1273 `[CachedAttribute]` takes a required parameter which the name of a method to cal
l on the implementation object. The method should take void and return bool. Bef
ore the cached attribute is used, the method will be called. If the method retur
ns true the cached value is not used, which will result in the accessor being ca
lled again. This allows the implementation to both gain the performance benefit
of caching (when the conversion to a script value can be done lazily) while allo
wing the value to be updated. The typical use pattern is: | 1273 `[CachedAttribute]` takes a required parameter which the name of a method to cal
l on the implementation object. The method should be const, take void and return
bool. Before the cached attribute is used, the method will be called. If the me
thod returns true the cached value is not used, which will result in the accesso
r being called again. This allows the implementation to both gain the performanc
e benefit of caching (when the conversion to a script value can be done lazily)
while allowing the value to be updated. The typical use pattern is: |
1274 | 1274 |
1275 ```c++ | 1275 ```c++ |
1276 // Called internally to update value | 1276 // Called internally to update value |
1277 void Object::setValue(Type data) | 1277 void Object::setValue(Type data) |
1278 { | 1278 { |
1279 m_data = data; | 1279 m_data = data; |
1280 m_attributeDirty = true; | 1280 m_attributeDirty = true; |
1281 } | 1281 } |
1282 | 1282 |
1283 // Called by generated binding code | 1283 // Called by generated binding code |
1284 bool Object::isAttributeDirty() | 1284 bool Object::isAttributeDirty() const |
1285 { | 1285 { |
1286 return m_attributeDirty; | 1286 return m_attributeDirty; |
1287 } | 1287 } |
1288 | 1288 |
1289 // Called by generated binding code if no value cached or isAttributeDirty() ret
urns true | 1289 // Called by generated binding code if no value cached or isAttributeDirty() ret
urns true |
1290 ScriptValue Object::attribute(ExecutionContext* context) | 1290 ScriptValue Object::attribute(ExecutionContext* context) |
1291 { | 1291 { |
1292 m_attributeDirty = false; | 1292 m_attributeDirty = false; |
1293 return convertDataToScriptValue(m_data); | 1293 return convertDataToScriptValue(m_data); |
1294 } | 1294 } |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met: | 1577 Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met: |
1578 | 1578 |
1579 1. Redistributions of source code must retain the above copyright notice, this l
ist of conditions and the following disclaimer. | 1579 1. Redistributions of source code must retain the above copyright notice, this l
ist of conditions and the following disclaimer. |
1580 | 1580 |
1581 2. Redistributions in binary form must reproduce the above copyright notice, thi
s list of conditions and the following disclaimer in the documentation and/or ot
her materials provided with the distribution. | 1581 2. Redistributions in binary form must reproduce the above copyright notice, thi
s list of conditions and the following disclaimer in the documentation and/or ot
her materials provided with the distribution. |
1582 | 1582 |
1583 THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS “AS IS” AND ANY EXP
RESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIE
S OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, I
NCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMI
TED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFI
TS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHE
THER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
BILITY OF SUCH DAMAGE. | 1583 THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS “AS IS” AND ANY EXP
RESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIE
S OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, I
NCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMI
TED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFI
TS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHE
THER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
BILITY OF SUCH DAMAGE. |
1584 *** | 1584 *** |
1585 | 1585 |
1586 [CrossOriginProperties]: https://html.spec.whatwg.org/multipage/browsers.html#cr
ossoriginproperties-(-o-) | 1586 [CrossOriginProperties]: https://html.spec.whatwg.org/multipage/browsers.html#cr
ossoriginproperties-(-o-) |
OLD | NEW |