New Client: stable (#8426)

* try to freeze content object

* deep freeze the content object, start to implement stable

* freeze at the /common level

* go back to freezing content only on the client

* use deep-frezze-strict to support phantomjs

* use own version of deepFreeze

* update comment about deepFreeze
This commit is contained in:
Matteo Pagliazzi
2017-02-15 12:49:57 +01:00
committed by GitHub
parent 6fd509df13
commit 20792f5455
5 changed files with 98 additions and 2 deletions

View File

@@ -0,0 +1,20 @@
// Code taken from https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
// and adapted
export default function deepFreeze (obj) {
// Retrieve the property names defined on obj
const propNames = Object.getOwnPropertyNames(obj);
const propNamesLength = propNames.length;
// Freeze properties before freezing self
for (let i = 0; i < propNamesLength; i++) {
const prop = obj[propNames[i]];
// Freeze prop if it is an object
if (typeof prop === 'object' && prop !== null) {
deepFreeze(prop);
}
}
// Freeze self (no-op if already frozen)
return Object.freeze(obj);
}