diff --git a/packages/dom-helper/lib/prop.js b/packages/dom-helper/lib/prop.js index 8268cfad..e01bf3bf 100644 --- a/packages/dom-helper/lib/prop.js +++ b/packages/dom-helper/lib/prop.js @@ -2,6 +2,9 @@ export function isAttrRemovalValue(value) { return value === null || value === undefined; } +var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; +function UNDEFINED() {} + // TODO should this be an o_create kind of thing? export var propertyCaches = {}; @@ -13,11 +16,26 @@ export function normalizeProperty(element, attrName) { // TODO should this be an o_create kind of thing? cache = {}; for (key in element) { - cache[key.toLowerCase()] = key; + if (isWritable(element, key)) { + cache[key.toLowerCase()] = key; + } else { + cache[key] = UNDEFINED; + } } propertyCaches[tagName] = cache; } // presumes that the attrName has been lowercased. - return cache[attrName]; + var value = cache[attrName]; + return value === UNDEFINED ? undefined : value; +} + +function isWritable(element, attrName) { + var desc = getOwnPropertyDescriptor(element.constructor.prototype, attrName); + if (!desc) { return true; } + if (!desc.writable || !desc.hasOwnProperty('value') && typeof desc.set !== 'function') { + return false; + } + + return true; } diff --git a/packages/dom-helper/tests/prop-test.js b/packages/dom-helper/tests/prop-test.js new file mode 100644 index 00000000..e69de29b