From 065a93290fb38b1739d29c764638b83a4e59c196 Mon Sep 17 00:00:00 2001 From: Jay Phelps Date: Wed, 27 May 2015 16:54:19 -0700 Subject: [PATCH] [WIP] detect props that aren't writable, fixes emberjs/ember.js#11221 --- packages/dom-helper/lib/prop.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/dom-helper/lib/prop.js b/packages/dom-helper/lib/prop.js index 8268cfad..be2e36dc 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 (isSettable(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 isSettable(element, attrName) { + var desc = getOwnPropertyDescriptor(element.constructor.prototype, attrName); + if (!desc) { return true; } + if (desc.writable === false || !desc.hasOwnProperty('value') && typeof desc.set !== 'function') { + return false; + } + + return true; }