Skip to content

Commit

Permalink
Replace instances of Object.create(null) with new EmptyObject(). Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
karanjthakkar committed Aug 12, 2015
1 parent 1f866da commit 4b644fa
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ correctly will need a shim for Object.create.
* Refactor JSON serializer to use _getMappedKey
* Don't normalize the key if not present in the hash
* Add serializeIntoHash to the JSON Serializer
* prefer Object.create(null) for typeMap backing stores. Cache misses are faster, and won’t collide with prototype pollution
* prefer new EmptyObject() for typeMap backing stores. Cache misses are faster, and won’t collide with prototype pollution
* since the recordArrayManager already maintains the uniq index, we can use that to simply push the record onto the record array without needing the safety of addRecords dupe guard. This prevents another O(n) operation
* the string splitting in transitionTo is wasteful and for large payloads can be surprisingly costly. As they never actually change, we should simply cache and forget about them.
* Coalesce find requests, add support for preloading data
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-data/lib/adapters/rest-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
});

function parseResponseHeaders(headerStr) {
var headers = Object.create(null);
var headers = new EmptyObject();
if (!headerStr) { return headers; }

var headerPairs = headerStr.split('\u000d\u000a');
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-data/lib/system/clone-null.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default function cloneNull(source) {
var clone = Object.create(null);
var clone = new EmptyObject();
for (var key in source) {
clone[key] = source[key];
}
Expand Down
26 changes: 13 additions & 13 deletions packages/ember-data/lib/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ var Promise = Ember.RSVP.Promise;
var get = Ember.get;
var set = Ember.set;

var _extractPivotNameCache = Object.create(null);
var _splitOnDotCache = Object.create(null);
var _extractPivotNameCache = new EmptyObject();
var _splitOnDotCache = new EmptyObject();

function splitOnDot(name) {
return _splitOnDotCache[name] || (
Expand Down Expand Up @@ -48,13 +48,13 @@ export default function InternalModel(type, id, store, container, data) {
this.id = id;
this.store = store;
this.container = container;
this._data = data || Object.create(null);
this._data = data || new EmptyObject();
this.modelName = type.modelName;
this.dataHasInitialized = false;
//Look into making this lazy
this._deferredTriggers = [];
this._attributes = Object.create(null);
this._inFlightAttributes = Object.create(null);
this._attributes = new EmptyObject();
this._inFlightAttributes = new EmptyObject();
this._relationships = new Relationships(this);
this.currentState = RootState.empty;
this.isReloading = false;
Expand Down Expand Up @@ -87,7 +87,7 @@ export default function InternalModel(type, id, store, container, data) {
would have a implicit post relationship in order to be do things like remove ourselves from the post
when we are deleted
*/
this._implicitRelationships = Object.create(null);
this._implicitRelationships = new EmptyObject();
}

InternalModel.prototype = {
Expand Down Expand Up @@ -263,7 +263,7 @@ InternalModel.prototype = {

flushChangedAttributes: function() {
this._inFlightAttributes = this._attributes;
this._attributes = Object.create(null);
this._attributes = new EmptyObject();
},

/**
Expand Down Expand Up @@ -326,10 +326,10 @@ InternalModel.prototype = {
rollbackAttributes: function() {
var dirtyKeys = Object.keys(this._attributes);

this._attributes = Object.create(null);
this._attributes = new EmptyObject();

if (get(this, 'isError')) {
this._inFlightAttributes = Object.create(null);
this._inFlightAttributes = new EmptyObject();
this.didCleanError();
}

Expand All @@ -346,7 +346,7 @@ InternalModel.prototype = {
}

if (this.isValid()) {
this._inFlightAttributes = Object.create(null);
this._inFlightAttributes = new EmptyObject();
}

this.send('rolledBack');
Expand Down Expand Up @@ -585,7 +585,7 @@ InternalModel.prototype = {
merge(this._data, data);
}

this._inFlightAttributes = Object.create(null);
this._inFlightAttributes = new EmptyObject();

this.send('didCommit');
this.updateRecordArraysLater();
Expand Down Expand Up @@ -656,7 +656,7 @@ InternalModel.prototype = {
this._attributes[keys[i]] = this._inFlightAttributes[keys[i]];
}
}
this._inFlightAttributes = Object.create(null);
this._inFlightAttributes = new EmptyObject();
},

/**
Expand Down Expand Up @@ -708,7 +708,7 @@ InternalModel.prototype = {
var keys = Object.keys(updates);
var length = keys.length;

original = merge(Object.create(null), this._data);
original = merge(new EmptyObject(), this._data);
original = merge(original, this._inFlightAttributes);

for (i = 0; i < length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-data/lib/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ var Model = Ember.Object.extend(Ember.Evented, {
var currentData = get(this._internalModel, '_attributes');
var inFlightData = get(this._internalModel, '_inFlightAttributes');
var newData = merge(copy(inFlightData), currentData);
var diffData = Object.create(null);
var diffData = new EmptyObject();

var newDataKeys = Object.keys(newData);

Expand Down
2 changes: 1 addition & 1 deletion packages/ember-data/lib/system/model/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ var DirtyState = {
},

exit: function(internalModel) {
internalModel._inFlightAttributes = Object.create(null);
internalModel._inFlightAttributes = new EmptyObject();
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-data/lib/system/relationships/ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Model.reopenClass({
},

inverseMap: Ember.computed(function() {
return Object.create(null);
return new EmptyObject();
}),

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function createRelationshipFor(record, relationshipMeta, store) {

export default function Relationships(record) {
this.record = record;
this.initializedRelationships = Object.create(null);
this.initializedRelationships = new EmptyObject();
}

Relationships.prototype.has = function(key) {
Expand Down
12 changes: 6 additions & 6 deletions packages/ember-data/lib/system/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ var get = Ember.get;
@param {DS.Model} internalModel The model to create a snapshot from
*/
export default function Snapshot(internalModel) {
this._attributes = Object.create(null);
this._belongsToRelationships = Object.create(null);
this._belongsToIds = Object.create(null);
this._hasManyRelationships = Object.create(null);
this._hasManyIds = Object.create(null);
this._attributes = new EmptyObject();
this._belongsToRelationships = new EmptyObject();
this._belongsToIds = new EmptyObject();
this._hasManyRelationships = new EmptyObject();
this._hasManyIds = new EmptyObject();

var record = internalModel.getRecord();
this.record = record;
Expand Down Expand Up @@ -135,7 +135,7 @@ Snapshot.prototype = {
@return {Object} All changed attributes of the current snapshot
*/
changedAttributes: function() {
let changedAttributes = Object.create(null);
let changedAttributes = new EmptyObject();
let changedAttributeKeys = Object.keys(this._changedAttributes);

for (let i=0, length = changedAttributeKeys.length; i < length; i++) {
Expand Down
8 changes: 4 additions & 4 deletions packages/ember-data/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ Store = Service.extend({
createRecord: function(modelName, inputProperties) {
Ember.assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${Ember.inspect(modelName)}`, typeof modelName === 'string');
var typeClass = this.modelFor(modelName);
var properties = copy(inputProperties) || Object.create(null);
var properties = copy(inputProperties) || new EmptyObject();

// If the passed properties do not include a primary key,
// give the adapter an opportunity to generate one. Typically,
Expand Down Expand Up @@ -1105,7 +1105,7 @@ Store = Service.extend({
record.destroy(); // maybe within unloadRecord
}

typeMap.metadata = Object.create(null);
typeMap.metadata = new EmptyObject();
}

function byType(entry) {
Expand Down Expand Up @@ -1421,9 +1421,9 @@ Store = Service.extend({
if (typeMap) { return typeMap; }

typeMap = {
idToRecord: Object.create(null),
idToRecord: new EmptyObject(),
records: [],
metadata: Object.create(null),
metadata: new EmptyObject(),
type: typeClass
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import Ember from 'ember';
*/
export default function ContainerInstanceCache(container) {
this._container = container;
this._cache = Object.create(null);
this._cache = new EmptyObject();
}

ContainerInstanceCache.prototype = Object.create(null);
ContainerInstanceCache.prototype = new EmptyObject();

Ember.merge(ContainerInstanceCache.prototype, {
get: function(type, preferredKey, fallbacks) {
Expand Down

0 comments on commit 4b644fa

Please sign in to comment.