Skip to content

Commit

Permalink
remove usage of Ember.EXTEND_PROTOTYPES (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
bekzod authored and RobbieTheWagner committed May 29, 2018
1 parent 7b6f622 commit bda1280
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
36 changes: 9 additions & 27 deletions ember_debug/adapters/web-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ export default BasicAdapter.extend({
}, null, 'ember-inspector');
},

sendMessage(options) {
options = options || {};
sendMessage(options = {}) {
// If prototype extensions are disabled, `Ember.A()` arrays
// would not be considered native arrays, so it's not possible to
// "clone" them through postMessage unless they are converted to a
// native array.
if (!Ember.EXTEND_PROTOTYPES || Ember.EXTEND_PROTOTYPES.Array === false) {
options = deepCloneArrays(deepClone(options));
}
options = deepClone(options);
this.get('_chromePort').postMessage(options);
},

Expand Down Expand Up @@ -78,33 +75,18 @@ export default BasicAdapter.extend({
* @param {Mixed} item The item to clone
* @return {Mixed}
*/
function deepCloneArrays(item) {
function deepClone(item) {
let clone = item;
if (isArray(item)) {
item = item.slice();
clone = new Array(item.length);
item.forEach((child, key) => {
item[key] = deepCloneArrays(child);
clone[key] = deepClone(child);
});
} else if (item && typeOf(item) === 'object') {
clone = {};
keys(item).forEach(key => {
item[key] = deepCloneArrays(item[key]);
clone[key] = deepClone(item[key]);
});
}
return item;
}

/**
* Recursive function that performs a deep clone on an object.
*
* @param {Any} obj
* @return {Any} Deep cloned object
*/
function deepClone(obj) {
if (obj && typeOf(obj) === 'object') {
let item = {};
keys(obj).forEach(key => {
item[key] = deepClone(obj[key]);
});
return item;
}
return obj;
return clone;
}
3 changes: 1 addition & 2 deletions ember_debug/adapters/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { onReady } from '../utils/on-ready';

export default BasicAdapter.extend({

sendMessage(options) {
options = options || {};
sendMessage(options = {}) {
this.get('socket').emit('emberInspectorMessage', options);
},

Expand Down

0 comments on commit bda1280

Please sign in to comment.