* Sets the value for a property on a node. * * @param {DOMElement} node * @param {string} name * @param {*} value
(node, name, value, isCustomComponentTag)
| 4971 | */ |
| 4972 | |
| 4973 | function setValueForProperty(node, name, value, isCustomComponentTag) { |
| 4974 | var propertyInfo = getPropertyInfo(name); |
| 4975 | |
| 4976 | if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) { |
| 4977 | return; |
| 4978 | } |
| 4979 | |
| 4980 | if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) { |
| 4981 | value = null; |
| 4982 | } // If the prop isn't in the special list, treat it as a simple attribute. |
| 4983 | |
| 4984 | |
| 4985 | if (isCustomComponentTag || propertyInfo === null) { |
| 4986 | if (isAttributeNameSafe(name)) { |
| 4987 | var _attributeName = name; |
| 4988 | |
| 4989 | if (value === null) { |
| 4990 | node.removeAttribute(_attributeName); |
| 4991 | } else { |
| 4992 | node.setAttribute(_attributeName, '' + value); |
| 4993 | } |
| 4994 | } |
| 4995 | |
| 4996 | return; |
| 4997 | } |
| 4998 | |
| 4999 | var mustUseProperty = propertyInfo.mustUseProperty; |
| 5000 | |
| 5001 | if (mustUseProperty) { |
| 5002 | var propertyName = propertyInfo.propertyName; |
| 5003 | |
| 5004 | if (value === null) { |
| 5005 | var type = propertyInfo.type; |
| 5006 | node[propertyName] = type === BOOLEAN ? false : ''; |
| 5007 | } else { |
| 5008 | // Contrary to `setAttribute`, object properties are properly |
| 5009 | // `toString`ed by IE8/9. |
| 5010 | node[propertyName] = value; |
| 5011 | } |
| 5012 | |
| 5013 | return; |
| 5014 | } // The rest are treated as attributes with special cases. |
| 5015 | |
| 5016 | |
| 5017 | var attributeName = propertyInfo.attributeName, |
| 5018 | attributeNamespace = propertyInfo.attributeNamespace; |
| 5019 | |
| 5020 | if (value === null) { |
| 5021 | node.removeAttribute(attributeName); |
| 5022 | } else { |
| 5023 | var _type = propertyInfo.type; |
| 5024 | var attributeValue; |
| 5025 | |
| 5026 | if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) { |
| 5027 | // If attribute type is boolean, we know for sure it won't be an execution sink |
| 5028 | // and we won't require Trusted Type here. |
| 5029 | attributeValue = ''; |
| 5030 | } else { |
no test coverage detected