Skip to content

Commit

Permalink
[Fixes #15001] Remove internal EmptyObject usage
Browse files Browse the repository at this point in the history
(cherry picked from commit c06d82d)
  • Loading branch information
stefanpenner authored and chancancode committed Mar 14, 2017
1 parent daefda7 commit 09c1218
Show file tree
Hide file tree
Showing 20 changed files with 48 additions and 85 deletions.
8 changes: 4 additions & 4 deletions packages/container/lib/registry.js
@@ -1,4 +1,4 @@
import { dictionary, EmptyObject, assign, intern } from 'ember-utils';
import { dictionary, assign, intern } from 'ember-utils';
import { assert, deprecate } from 'ember-metal';
import Container from './container';

Expand Down Expand Up @@ -35,7 +35,7 @@ export default function Registry(options) {
this._factoryTypeInjections = dictionary(null);
this._factoryInjections = dictionary(null);

this._localLookupCache = new EmptyObject();
this._localLookupCache = Object.create(null);
this._normalizeCache = dictionary(null);
this._resolveCache = dictionary(null);
this._failCache = dictionary(null);
Expand Down Expand Up @@ -205,7 +205,7 @@ Registry.prototype = {

let normalizedName = this.normalize(fullName);

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

delete this.registrations[normalizedName];
delete this._resolveCache[normalizedName];
Expand Down Expand Up @@ -813,7 +813,7 @@ function expandLocalLookup(registry, normalizedName, normalizedSource) {
let normalizedNameCache = cache[normalizedName];

if (!normalizedNameCache) {
normalizedNameCache = cache[normalizedName] = new EmptyObject();
normalizedNameCache = cache[normalizedName] = Object.create(null);
}

let cached = normalizedNameCache[normalizedSource];
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-application/lib/system/engine.js
Expand Up @@ -2,7 +2,7 @@
@module ember
@submodule ember-application
*/
import { canInvoke, EmptyObject } from 'ember-utils';
import { canInvoke } from 'ember-utils';
import {
Namespace,
RegistryProxyMixin,
Expand Down Expand Up @@ -168,8 +168,8 @@ const Engine = Namespace.extend(RegistryProxyMixin, {
});

Engine.reopenClass({
initializers: new EmptyObject(),
instanceInitializers: new EmptyObject(),
initializers: Object.create(null),
instanceInitializers: Object.create(null),

/**
The goal of initializers should be to register dependencies and injections.
Expand Down
3 changes: 1 addition & 2 deletions packages/ember-glimmer/lib/components/text_field.js
Expand Up @@ -2,15 +2,14 @@
@module ember
@submodule ember-views
*/
import { EmptyObject } from 'ember-utils';
import { computed } from 'ember-metal';
import { environment } from 'ember-environment';
import Component from '../component';
import layout from '../templates/empty';
import { TextSupport } from 'ember-views';

let inputTypeTestElement;
const inputTypes = new EmptyObject();
const inputTypes = Object.create(null);
function canSetTypeOfInput(type) {
if (type in inputTypes) {
return inputTypes[type];
Expand Down
8 changes: 4 additions & 4 deletions packages/ember-glimmer/lib/utils/iterable.js
@@ -1,4 +1,4 @@
import { guidFor, EmptyObject } from 'ember-utils';
import { guidFor } from 'ember-utils';
import { get, tagForProperty, tagFor, isProxy } from 'ember-metal';
import {
objectAt,
Expand Down Expand Up @@ -84,7 +84,7 @@ class ArrayIterator {
this.length = array.length;
this.keyFor = keyFor;
this.position = 0;
this.seen = new EmptyObject();
this.seen = Object.create(null);
}

isEmpty() {
Expand Down Expand Up @@ -112,7 +112,7 @@ class EmberArrayIterator {
this.length = get(array, 'length');
this.keyFor = keyFor;
this.position = 0;
this.seen = new EmptyObject();
this.seen = Object.create(null);
}

isEmpty() {
Expand Down Expand Up @@ -140,7 +140,7 @@ class ObjectKeysIterator {
this.values = values;
this.keyFor = keyFor;
this.position = 0;
this.seen = new EmptyObject();
this.seen = Object.create(null);
}

isEmpty() {
Expand Down
7 changes: 3 additions & 4 deletions packages/ember-glimmer/lib/utils/process-args.js
@@ -1,7 +1,6 @@
import {
assign,
symbol,
EmptyObject
symbol
} from 'ember-utils';
import {
CONSTANT_TAG
Expand Down Expand Up @@ -88,8 +87,8 @@ export class ComponentArgs {
let { namedArgs } = this;
let keys = namedArgs.keys;
let attrs = namedArgs.value();
let props = new EmptyObject();
let args = new EmptyObject();
let props = Object.create(null);
let args = Object.create(null);

props[ARGS] = args;

Expand Down
5 changes: 2 additions & 3 deletions packages/ember-glimmer/lib/utils/references.js
@@ -1,7 +1,6 @@
import {
HAS_NATIVE_WEAKMAP,
symbol,
EmptyObject
symbol
} from 'ember-utils';
import {
get,
Expand Down Expand Up @@ -72,7 +71,7 @@ export class CachedReference extends EmberPathReference {
export class RootReference extends ConstReference {
constructor(value) {
super(value);
this.children = new EmptyObject();
this.children = Object.create(null);
}

get(propertyKey) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/views/outlet.js
Expand Up @@ -56,7 +56,7 @@ class OrphanedOutletStateReference extends OutletStateReference {
return null;
}

let state = new EmptyObject();
let state = Object.create(null);
state[matched.render.outlet] = matched;
matched.wasUsed = true;
return { outlets: state };
Expand Down
3 changes: 1 addition & 2 deletions packages/ember-glimmer/tests/unit/layout-cache-test.js
@@ -1,4 +1,3 @@
import { EmptyObject } from 'ember-utils';
import { RenderingTest, moduleFor } from '../utils/test-case';
import { CompiledBlock } from 'glimmer-runtime';
import { OWNER } from 'ember-utils';
Expand All @@ -19,7 +18,7 @@ class Counter {

reset() {
this.total = 0;
this.counts = new EmptyObject();
this.counts = Object.create(null);
}
}

Expand Down
5 changes: 2 additions & 3 deletions packages/ember-metal/lib/cache.js
@@ -1,4 +1,3 @@
import { EmptyObject } from 'ember-utils';
import { UNDEFINED } from './meta';

export default class Cache {
Expand Down Expand Up @@ -57,7 +56,7 @@ export default class Cache {

class DefaultStore {
constructor() {
this.data = new EmptyObject();
this.data = Object.create(null);
}

get(key) {
Expand All @@ -69,6 +68,6 @@ class DefaultStore {
}

clear() {
this.data = new EmptyObject();
this.data = Object.create(null);
}
}
5 changes: 2 additions & 3 deletions packages/ember-metal/lib/chains.js
@@ -1,4 +1,3 @@
import { EmptyObject } from 'ember-utils';
import { get } from './property_get';
import { meta as metaFor, peekMeta } from './meta';
import { watchKey, unwatchKey } from './watch_key';
Expand All @@ -23,7 +22,7 @@ class ChainWatchers {
// chain nodes that reference a key in this obj by key
// we only create ChainWatchers when we are going to add them
// so create this upfront
this.chains = new EmptyObject();
this.chains = Object.create(null);
}

add(key, node) {
Expand Down Expand Up @@ -231,7 +230,7 @@ class ChainNode {
let chains = this._chains;
let node;
if (chains === undefined) {
chains = this._chains = new EmptyObject();
chains = this._chains = Object.create(null);
} else {
node = chains[key];
}
Expand Down
12 changes: 6 additions & 6 deletions packages/ember-metal/lib/map.js
Expand Up @@ -20,7 +20,7 @@
Map is mocked out to look like an Ember object, so you can do
`Ember.Map.create()` for symmetry with other Ember classes.
*/
import { EmptyObject, guidFor } from 'ember-utils';
import { guidFor } from 'ember-utils';

function missingFunction(fn) {
throw new TypeError(`${Object.prototype.toString.call(fn)} is not a function`);
Expand All @@ -31,10 +31,10 @@ function missingNew(name) {
}

function copyNull(obj) {
let output = new EmptyObject();
let output = Object.create(null);

for (let prop in obj) {
// hasOwnPropery is not needed because obj is new EmptyObject();
// hasOwnPropery is not needed because obj is Object.create(null);
output[prop] = obj[prop];
}

Expand Down Expand Up @@ -90,7 +90,7 @@ OrderedSet.prototype = {
@private
*/
clear() {
this.presenceSet = new EmptyObject();
this.presenceSet = Object.create(null);
this.list = [];
this.size = 0;
},
Expand Down Expand Up @@ -242,7 +242,7 @@ function Map() {
if (this instanceof Map) {
this._keys = OrderedSet.create();
this._keys._silenceRemoveDeprecation = true;
this._values = new EmptyObject();
this._values = Object.create(null);
this.size = 0;
} else {
missingNew('Map');
Expand Down Expand Up @@ -394,7 +394,7 @@ Map.prototype = {
*/
clear() {
this._keys.clear();
this._values = new EmptyObject();
this._values = Object.create(null);
this.size = 0;
},

Expand Down
9 changes: 4 additions & 5 deletions packages/ember-metal/lib/meta.js
Expand Up @@ -4,7 +4,6 @@

import {
HAS_NATIVE_WEAKMAP,
EmptyObject,
lookupDescriptor,
symbol
} from 'ember-utils';
Expand Down Expand Up @@ -206,7 +205,7 @@ export class Meta {
}

_getOrCreateOwnMap(key) {
return this[key] || (this[key] = new EmptyObject());
return this[key] || (this[key] = Object.create(null));
}

_getInherited(key) {
Expand Down Expand Up @@ -242,7 +241,7 @@ export class Meta {
let outerMap = this._getOrCreateOwnMap('_deps');
let innerMap = outerMap[subkey];
if (!innerMap) {
innerMap = outerMap[subkey] = new EmptyObject();
innerMap = outerMap[subkey] = Object.create(null);
}
innerMap[itemkey] = value;
}
Expand Down Expand Up @@ -286,7 +285,7 @@ export class Meta {
while (pointer !== undefined) {
let map = pointer[key];
if (map) {
seen = seen || new EmptyObject();
seen = seen || Object.create(null);
let innerMap = map[subkey];
if (innerMap) {
for (let innerKey in innerMap) {
Expand Down Expand Up @@ -376,7 +375,7 @@ function inheritedMap(name, Meta) {

Meta.prototype[`forEach${capitalized}`] = function(fn) {
let pointer = this;
let seen = new EmptyObject();
let seen = Object.create(null);
while (pointer !== undefined) {
let map = pointer[key];
if (map) {
Expand Down
5 changes: 2 additions & 3 deletions packages/ember-routing/lib/system/cache.js
@@ -1,4 +1,3 @@
import { EmptyObject } from 'ember-utils';
import { Object as EmberObject } from 'ember-runtime';

/**
Expand All @@ -10,7 +9,7 @@ import { Object as EmberObject } from 'ember-runtime';
*/
export default EmberObject.extend({
init() {
this.cache = new EmptyObject();
this.cache = Object.create(null);
},

has(bucketKey) {
Expand All @@ -21,7 +20,7 @@ export default EmberObject.extend({
let bucket = this.cache[bucketKey];

if (!bucket) {
bucket = this.cache[bucketKey] = new EmptyObject();
bucket = this.cache[bucketKey] = Object.create(null);
}

bucket[key] = value;
Expand Down
15 changes: 7 additions & 8 deletions packages/ember-routing/lib/system/router.js
@@ -1,5 +1,4 @@
import {
EmptyObject,
assign,
guidFor,
dictionary,
Expand Down Expand Up @@ -136,11 +135,11 @@ const EmberRouter = EmberObject.extend(Evented, {
init() {
this._super(...arguments);

this._qpCache = new EmptyObject();
this._qpCache = Object.create(null);
this._resetQueuedQueryParameterChanges();
this._handledErrors = dictionary(null);
this._engineInstances = new EmptyObject();
this._engineInfoByRoute = new EmptyObject();
this._engineInstances = Object.create(null);
this._engineInfoByRoute = Object.create(null)
},

/*
Expand Down Expand Up @@ -559,7 +558,7 @@ const EmberRouter = EmberObject.extend(Evented, {
},

_getHandlerFunction() {
let seen = new EmptyObject();
let seen = Object.create(null);
let owner = getOwner(this);

return name => {
Expand Down Expand Up @@ -1008,7 +1007,7 @@ const EmberRouter = EmberObject.extend(Evented, {
let engineInstances = this._engineInstances;

if (!engineInstances[name]) {
engineInstances[name] = new EmptyObject();
engineInstances[name] = Object.create(null);
}

let engineInstance = engineInstances[name][instanceId];
Expand Down Expand Up @@ -1465,7 +1464,7 @@ function appendLiveRoute(liveRoutes, defaultParentState, renderOptions) {
let target;
let myState = {
render: renderOptions,
outlets: new EmptyObject(),
outlets: Object.create(null),
wasUsed: false
};
if (renderOptions.into) {
Expand Down Expand Up @@ -1510,7 +1509,7 @@ function appendOrphan(liveRoutes, into, myState) {
render: {
name: '__ember_orphans__'
},
outlets: new EmptyObject()
outlets: Object.create(null)
};
}
liveRoutes.outlets.__ember_orphans__.outlets[into] = myState;
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-runtime/lib/computed/reduce_computed_macros.js
Expand Up @@ -3,7 +3,7 @@
@submodule ember-runtime
*/

import { EmptyObject, guidFor } from 'ember-utils';
import { guidFor } from 'ember-utils';
import {
assert,
get,
Expand Down Expand Up @@ -411,7 +411,7 @@ export function uniq(...args) {
export function uniqBy(dependentKey, propertyKey) {
return computed(`${dependentKey}.[]`, function() {
let uniq = emberA();
let seen = new EmptyObject();
let seen = Object.create(null);
let list = get(this, dependentKey);
if (isArray(list)) {
list.forEach(item => {
Expand Down

0 comments on commit 09c1218

Please sign in to comment.