Skip to content

Commit

Permalink
Ensure concatenated properties are frozen.
Browse files Browse the repository at this point in the history
Mutating objects on the prototype (which includes concatenated
properties) is not good. This changes the functionality of concatenated
properties to freeze the resulting array while in debug mode, to make it
clear that mutating them without slicing first is not good.
  • Loading branch information
Robert Jackson committed Sep 30, 2016
1 parent 09140df commit c800c18
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/ember-metal/lib/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,28 @@ function giveMethodSuper(obj, key, method, values, descs) {

function applyConcatenatedProperties(obj, key, value, values) {
let baseValue = values[key] || obj[key];
let ret;

if (baseValue) {
if ('function' === typeof baseValue.concat) {
if (value === null || value === undefined) {
return baseValue;
ret = baseValue;
} else {
return baseValue.concat(value);
ret = baseValue.concat(value);
}
} else {
return makeArray(baseValue).concat(value);
ret = makeArray(baseValue).concat(value);
}
} else {
return makeArray(value);
ret = makeArray(value);
}

runInDebug(() => {
// prevent mutating `concatenatedProperties` array after it is applied
Object.freeze(ret);
});

return ret;
}

function applyMergedProperties(obj, key, value, values) {
Expand Down

0 comments on commit c800c18

Please sign in to comment.