* Sets the value for a property on a node. * * @param {DOMElement} node * @param {string} name * @param {*} value
(node, name, value, isCustomComponentTag)
| 1294 | */ |
| 1295 | |
| 1296 | function setValueForProperty(node, name, value, isCustomComponentTag) { |
| 1297 | var propertyInfo = getPropertyInfo(name); |
| 1298 | |
| 1299 | if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) { |
| 1300 | return; |
| 1301 | } |
| 1302 | |
| 1303 | if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) { |
| 1304 | value = null; |
| 1305 | } // If the prop isn't in the special list, treat it as a simple attribute. |
| 1306 | |
| 1307 | |
| 1308 | if (isCustomComponentTag || propertyInfo === null) { |
| 1309 | if (isAttributeNameSafe(name)) { |
| 1310 | var _attributeName = name; |
| 1311 | |
| 1312 | if (value === null) { |
| 1313 | node.removeAttribute(_attributeName); |
| 1314 | } else { |
| 1315 | node.setAttribute(_attributeName, '' + value); |
| 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | return; |
| 1320 | } |
| 1321 | |
| 1322 | var mustUseProperty = propertyInfo.mustUseProperty; |
| 1323 | |
| 1324 | if (mustUseProperty) { |
| 1325 | var propertyName = propertyInfo.propertyName; |
| 1326 | |
| 1327 | if (value === null) { |
| 1328 | var type = propertyInfo.type; |
| 1329 | node[propertyName] = type === BOOLEAN ? false : ''; |
| 1330 | } else { |
| 1331 | // Contrary to `setAttribute`, object properties are properly |
| 1332 | // `toString`ed by IE8/9. |
| 1333 | node[propertyName] = value; |
| 1334 | } |
| 1335 | |
| 1336 | return; |
| 1337 | } // The rest are treated as attributes with special cases. |
| 1338 | |
| 1339 | |
| 1340 | var attributeName = propertyInfo.attributeName, |
| 1341 | attributeNamespace = propertyInfo.attributeNamespace; |
| 1342 | |
| 1343 | if (value === null) { |
| 1344 | node.removeAttribute(attributeName); |
| 1345 | } else { |
| 1346 | var _type = propertyInfo.type; |
| 1347 | var attributeValue; |
| 1348 | |
| 1349 | if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) { |
| 1350 | // If attribute type is boolean, we know for sure it won't be an execution sink |
| 1351 | // and we won't require Trusted Type here. |
| 1352 | attributeValue = ''; |
| 1353 | } else { |
no test coverage detected