Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes #4853] use Object.create(null) directly #4854

Merged
merged 1 commit into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions addon/-private/system/clone-null.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import EmptyObject from "./empty-object";
export default function cloneNull(source) {
let clone = new EmptyObject();
let clone = Object.create(null);
for (let key in source) {
clone[key] = source[key];
}
Expand Down
33 changes: 16 additions & 17 deletions addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { assert, runInDebug } from "ember-data/-private/debug";
import RootState from "./states";
import Relationships from "../relationships/state/create";
import Snapshot from "../snapshot";
import EmptyObject from "../empty-object";
import isEnabled from '../../features';
import OrderedSet from "../ordered-set";

Expand Down Expand Up @@ -42,10 +41,10 @@ const assign = Ember.assign || Ember.merge;
and setups. It may also be faster to do a two level cache (from: { to }) instead of caching based
on a key that adds the two together.
*/
const TransitionChainMap = new EmptyObject();
const TransitionChainMap = Object.create(null);

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

function splitOnDot(name) {
return _splitOnDotCache[name] || (
Expand Down Expand Up @@ -180,7 +179,7 @@ export default class InternalModel {

get references() {
if (this._references === null) {
this._references = new EmptyObject();
this._references = Object.create(null);
}
return this._references;
}
Expand All @@ -194,7 +193,7 @@ export default class InternalModel {

get _attributes() {
if (this.__attributes === null) {
this.__attributes = new EmptyObject();
this.__attributes = Object.create(null);
}
return this.__attributes;
}
Expand All @@ -213,7 +212,7 @@ export default class InternalModel {

get _inFlightAttributes() {
if (this.__inFlightAttributes === null) {
this.__inFlightAttributes = new EmptyObject();
this.__inFlightAttributes = Object.create(null);
}
return this.__inFlightAttributes;
}
Expand All @@ -224,7 +223,7 @@ export default class InternalModel {

get _data() {
if (this.__data === null) {
this.__data = new EmptyObject();
this.__data = Object.create(null);
}
return this.__data;
}
Expand Down Expand Up @@ -262,7 +261,7 @@ export default class InternalModel {
*/
get _implicitRelationships() {
if (this.__implicitRelationships === null) {
this.__implicitRelationships = new EmptyObject();
this.__implicitRelationships = Object.create(null);
}
return this.__implicitRelationships;
}
Expand Down Expand Up @@ -598,7 +597,7 @@ export default class InternalModel {
flushChangedAttributes() {
heimdall.increment(flushChangedAttributes);
this._inFlightAttributes = this._attributes;
this._attributes = new EmptyObject();
this._attributes = Object.create(null);
}

hasChangedAttributes() {
Expand Down Expand Up @@ -647,7 +646,7 @@ export default class InternalModel {
let currentData = this._attributes;
let inFlightData = this._inFlightAttributes;
let newData = assign(copy(inFlightData), currentData);
let diffData = new EmptyObject();
let diffData = Object.create(null);
let newDataKeys = Object.keys(newData);

for (let i = 0, length = newDataKeys.length; i < length; i++) {
Expand Down Expand Up @@ -719,10 +718,10 @@ export default class InternalModel {
rollbackAttributes() {
let dirtyKeys = Object.keys(this._attributes);

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

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

Expand All @@ -739,7 +738,7 @@ export default class InternalModel {
}

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

this.send('rolledBack');
Expand Down Expand Up @@ -1005,7 +1004,7 @@ export default class InternalModel {
assign(this._data, data);
}

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

this.send('didCommit');
this.updateRecordArrays();
Expand Down Expand Up @@ -1071,7 +1070,7 @@ export default class InternalModel {
attrs[keys[i]] = this._inFlightAttributes[keys[i]];
}
}
this._inFlightAttributes = new EmptyObject();
this._inFlightAttributes = Object.create(null);
}

/*
Expand Down Expand Up @@ -1124,7 +1123,7 @@ export default class InternalModel {
let length = keys.length;
let attrs = this._attributes;

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

for (i = 0; i < length; i++) {
Expand Down
3 changes: 1 addition & 2 deletions addon/-private/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { PromiseObject } from "../promise-proxies";
import Errors from "../model/errors";
import isEnabled from '../../features';
import RootState from '../model/states';
import EmptyObject from "../empty-object";
import {
relationshipsByNameDescriptor,
relatedTypesDescriptor,
Expand Down Expand Up @@ -1272,7 +1271,7 @@ Model.reopenClass({
},

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

/**
Expand Down
3 changes: 1 addition & 2 deletions addon/-private/system/relationships/state/create.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Ember from 'ember';
import ManyRelationship from "./has-many";
import BelongsToRelationship from "./belongs-to";
import EmptyObject from "../../empty-object";
import { runInDebug } from 'ember-data/-private/debug';

const { get } = Ember;
Expand Down Expand Up @@ -37,7 +36,7 @@ function createRelationshipFor(internalModel, relationshipMeta, store) {
export default class Relationships {
constructor(internalModel) {
this.internalModel = internalModel;
this.initializedRelationships = new EmptyObject();
this.initializedRelationships = Object.create(null);
}

// TODO @runspired deprecate this as it was never truly a record instance
Expand Down
13 changes: 6 additions & 7 deletions addon/-private/system/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

import Ember from 'ember';
import EmptyObject from "./empty-object";

const {
get
Expand All @@ -18,11 +17,11 @@ const {
*/
export default class Snapshot {
constructor(internalModel, options = {}) {
this._attributes = new EmptyObject();
this._belongsToRelationships = new EmptyObject();
this._belongsToIds = new EmptyObject();
this._hasManyRelationships = new EmptyObject();
this._hasManyIds = new EmptyObject();
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._internalModel = internalModel;

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

for (let i=0, length = changedAttributeKeys.length; i < length; i++) {
Expand Down
9 changes: 4 additions & 5 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import coerceId from "./coerce-id";
import RecordArrayManager from "./record-array-manager";
import ContainerInstanceCache from './store/container-instance-cache';
import InternalModel from "./model/internal-model";
import EmptyObject from "./empty-object";
import isEnabled from '../features';

export let badIdFormatAssertion = '`id` passed to `findRecord()` has to be non-empty string or number';
Expand Down Expand Up @@ -219,7 +218,7 @@ Store = Service.extend({
this._identityMap = new IdentityMap();
this._pendingSave = [];
this._instanceCache = new ContainerInstanceCache(getOwner(this), this);
this._modelFactoryCache = new EmptyObject();
this._modelFactoryCache = Object.create(null);

/*
Ember Data uses several specialized micro-queues for organizing
Expand Down Expand Up @@ -349,7 +348,7 @@ Store = Service.extend({
assert(`You need to pass a model name to the store's createRecord method`, isPresent(modelName));
assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, typeof modelName === 'string');
let normalizedModelName = normalizeModelName(modelName);
let properties = copy(inputProperties) || new EmptyObject();
let properties = copy(inputProperties) || Object.create(null);

// If the passed properties do not include a primary key,
// give the adapter an opportunity to generate one. Typically,
Expand Down Expand Up @@ -860,7 +859,7 @@ Store = Service.extend({
let shouldCoalesce = !!adapter.findMany && adapter.coalesceFindRequests;
let totalItems = pendingFetchItems.length;
let internalModels = new Array(totalItems);
let seeking = new EmptyObject();
let seeking = Object.create(null);

for (let i = 0; i < totalItems; i++) {
let pendingItem = pendingFetchItems[i];
Expand All @@ -880,7 +879,7 @@ Store = Service.extend({

function handleFoundRecords(foundInternalModels, expectedInternalModels) {
// resolve found records
let found = new EmptyObject();
let found = Object.create(null);
for (let i = 0, l = foundInternalModels.length; i < l; i++) {
let internalModel = foundInternalModels[i];
let pair = seeking[internalModel.id];
Expand Down
5 changes: 2 additions & 3 deletions addon/-private/system/store/container-instance-cache.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* global heimdall */
import Ember from 'ember';
import EmptyObject from "../empty-object";
const { set } = Ember;

const {
Expand Down Expand Up @@ -37,8 +36,8 @@ export default class ContainerInstanceCache {
this._owner = owner;
this._store = store;
this._namespaces = {
adapter: new EmptyObject(),
serializer: new EmptyObject()
adapter: Object.create(null),
serializer: Object.create(null)
};
}

Expand Down
4 changes: 1 addition & 3 deletions addon/-private/utils/parse-response-headers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import EmptyObject from '../system/empty-object';

const CLRF = '\u000d\u000a';

export default function parseResponseHeaders(headersString) {
let headers = new EmptyObject();
let headers = Object.create(null);

if (!headersString) {
return headers;
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/utils/parse-response-headers-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import EmptyObject from 'ember-data/-private/system/empty-object';
import parseResponseHeaders from 'ember-data/-private/utils/parse-response-headers';
import { module, test } from 'qunit';

Expand All @@ -9,7 +8,7 @@ module('unit/adapters/parse-response-headers');
test('returns an EmptyObject when headersString is undefined', function(assert) {
let headers = parseResponseHeaders(undefined);

assert.deepEqual(headers, new EmptyObject(), 'EmptyObject is returned');
assert.deepEqual(headers, Object.create(null), 'EmptyObject is returned');
});

test('header parsing', function(assert) {
Expand Down