Skip to content

Commit

Permalink
[WIP] detect props that aren't writable, fixes emberjs/ember.js#11221
Browse files Browse the repository at this point in the history
  • Loading branch information
jayphelps committed May 27, 2015
1 parent 325de7c commit df03728
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/dom-helper/lib/prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand All @@ -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;
}
Empty file.

0 comments on commit df03728

Please sign in to comment.