Skip to content

Commit 1a8791f

Browse files
committed
Auto merge of #15002 - emberjs:empty-object, r=stefanpenner
[Fixes #15001] Remove internal EmptyObject usage - [x] confirm all are correctly removed - [x] confirm tests pass - [ ] do some tests ---- If this ends up good, we should likely consider deprecating `Ember.EmptyObject`. --- cc @bmeurer
2 parents 5a36a7d + c06d82d commit 1a8791f

File tree

20 files changed

+49
-86
lines changed

20 files changed

+49
-86
lines changed

packages/container/lib/registry.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dictionary, EmptyObject, assign, intern } from 'ember-utils';
1+
import { dictionary, assign, intern } from 'ember-utils';
22
import { assert, deprecate } from 'ember-metal';
33
import Container from './container';
44

@@ -35,7 +35,7 @@ export default function Registry(options) {
3535
this._factoryTypeInjections = dictionary(null);
3636
this._factoryInjections = dictionary(null);
3737

38-
this._localLookupCache = new EmptyObject();
38+
this._localLookupCache = Object.create(null);
3939
this._normalizeCache = dictionary(null);
4040
this._resolveCache = dictionary(null);
4141
this._failCache = dictionary(null);
@@ -205,7 +205,7 @@ Registry.prototype = {
205205

206206
let normalizedName = this.normalize(fullName);
207207

208-
this._localLookupCache = new EmptyObject();
208+
this._localLookupCache = Object.create(null);
209209

210210
delete this.registrations[normalizedName];
211211
delete this._resolveCache[normalizedName];
@@ -811,7 +811,7 @@ function expandLocalLookup(registry, normalizedName, normalizedSource) {
811811
let normalizedNameCache = cache[normalizedName];
812812

813813
if (!normalizedNameCache) {
814-
normalizedNameCache = cache[normalizedName] = new EmptyObject();
814+
normalizedNameCache = cache[normalizedName] = Object.create(null);
815815
}
816816

817817
let cached = normalizedNameCache[normalizedSource];

packages/ember-application/lib/system/engine.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@module ember
33
@submodule ember-application
44
*/
5-
import { canInvoke, EmptyObject } from 'ember-utils';
5+
import { canInvoke } from 'ember-utils';
66
import {
77
Namespace,
88
RegistryProxyMixin,
@@ -168,8 +168,8 @@ const Engine = Namespace.extend(RegistryProxyMixin, {
168168
});
169169

170170
Engine.reopenClass({
171-
initializers: new EmptyObject(),
172-
instanceInitializers: new EmptyObject(),
171+
initializers: Object.create(null),
172+
instanceInitializers: Object.create(null),
173173

174174
/**
175175
The goal of initializers should be to register dependencies and injections.

packages/ember-glimmer/lib/components/text_field.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
@module ember
33
@submodule ember-views
44
*/
5-
import { EmptyObject } from 'ember-utils';
65
import { computed } from 'ember-metal';
76
import { environment } from 'ember-environment';
87
import Component from '../component';
98
import layout from '../templates/empty';
109
import { TextSupport } from 'ember-views';
1110

1211
let inputTypeTestElement;
13-
const inputTypes = new EmptyObject();
12+
const inputTypes = Object.create(null);
1413
function canSetTypeOfInput(type) {
1514
if (type in inputTypes) {
1615
return inputTypes[type];

packages/ember-glimmer/lib/utils/iterable.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { guidFor, EmptyObject } from 'ember-utils';
1+
import { guidFor } from 'ember-utils';
22
import { get, tagForProperty, tagFor, isProxy } from 'ember-metal';
33
import {
44
objectAt,
@@ -84,7 +84,7 @@ class ArrayIterator {
8484
this.length = array.length;
8585
this.keyFor = keyFor;
8686
this.position = 0;
87-
this.seen = new EmptyObject();
87+
this.seen = Object.create(null);
8888
}
8989

9090
isEmpty() {
@@ -112,7 +112,7 @@ class EmberArrayIterator {
112112
this.length = get(array, 'length');
113113
this.keyFor = keyFor;
114114
this.position = 0;
115-
this.seen = new EmptyObject();
115+
this.seen = Object.create(null);
116116
}
117117

118118
isEmpty() {
@@ -140,7 +140,7 @@ class ObjectKeysIterator {
140140
this.values = values;
141141
this.keyFor = keyFor;
142142
this.position = 0;
143-
this.seen = new EmptyObject();
143+
this.seen = Object.create(null);
144144
}
145145

146146
isEmpty() {

packages/ember-glimmer/lib/utils/process-args.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
assign,
3-
symbol,
4-
EmptyObject
3+
symbol
54
} from 'ember-utils';
65
import {
76
CONSTANT_TAG
@@ -88,8 +87,8 @@ export class ComponentArgs {
8887
let { namedArgs } = this;
8988
let keys = namedArgs.keys;
9089
let attrs = namedArgs.value();
91-
let props = new EmptyObject();
92-
let args = new EmptyObject();
90+
let props = Object.create(null);
91+
let args = Object.create(null);
9392

9493
props[ARGS] = args;
9594

packages/ember-glimmer/lib/utils/references.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
HAS_NATIVE_WEAKMAP,
3-
symbol,
4-
EmptyObject
3+
symbol
54
} from 'ember-utils';
65
import {
76
get,
@@ -72,7 +71,7 @@ export class CachedReference extends EmberPathReference {
7271
export class RootReference extends ConstReference {
7372
constructor(value) {
7473
super(value);
75-
this.children = new EmptyObject();
74+
this.children = Object.create(null);
7675
}
7776

7877
get(propertyKey) {

packages/ember-glimmer/lib/views/outlet.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@module ember
33
@submodule ember-glimmer
44
*/
5-
import { assign, EmptyObject } from 'ember-utils';
5+
import { assign } from 'ember-utils';
66
import { DirtyableTag } from '@glimmer/reference';
77
import { environment } from 'ember-environment';
88
import { OWNER } from 'ember-utils';
@@ -56,7 +56,7 @@ class OrphanedOutletStateReference extends OutletStateReference {
5656
return null;
5757
}
5858

59-
let state = new EmptyObject();
59+
let state = Object.create(null);
6060
state[matched.render.outlet] = matched;
6161
matched.wasUsed = true;
6262
return { outlets: state };

packages/ember-glimmer/tests/unit/layout-cache-test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { EmptyObject } from 'ember-utils';
21
import { RenderingTest, moduleFor } from '../utils/test-case';
32
import { CompiledBlock } from '@glimmer/runtime';
43
import { OWNER } from 'ember-utils';
@@ -19,7 +18,7 @@ class Counter {
1918

2019
reset() {
2120
this.total = 0;
22-
this.counts = new EmptyObject();
21+
this.counts = Object.create(null);
2322
}
2423
}
2524

packages/ember-metal/lib/cache.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { EmptyObject } from 'ember-utils';
21
import { UNDEFINED } from './meta';
32

43
export default class Cache {
@@ -57,7 +56,7 @@ export default class Cache {
5756

5857
class DefaultStore {
5958
constructor() {
60-
this.data = new EmptyObject();
59+
this.data = Object.create(null);
6160
}
6261

6362
get(key) {
@@ -69,6 +68,6 @@ class DefaultStore {
6968
}
7069

7170
clear() {
72-
this.data = new EmptyObject();
71+
this.data = Object.create(null);
7372
}
7473
}

packages/ember-metal/lib/chains.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { EmptyObject } from 'ember-utils';
21
import { get } from './property_get';
32
import { meta as metaFor, peekMeta } from './meta';
43
import { watchKey, unwatchKey } from './watch_key';
@@ -23,7 +22,7 @@ class ChainWatchers {
2322
// chain nodes that reference a key in this obj by key
2423
// we only create ChainWatchers when we are going to add them
2524
// so create this upfront
26-
this.chains = new EmptyObject();
25+
this.chains = Object.create(null);
2726
}
2827

2928
add(key, node) {
@@ -231,7 +230,7 @@ class ChainNode {
231230
let chains = this._chains;
232231
let node;
233232
if (chains === undefined) {
234-
chains = this._chains = new EmptyObject();
233+
chains = this._chains = Object.create(null);
235234
} else {
236235
node = chains[key];
237236
}

packages/ember-metal/lib/map.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Map is mocked out to look like an Ember object, so you can do
2121
`Ember.Map.create()` for symmetry with other Ember classes.
2222
*/
23-
import { EmptyObject, guidFor } from 'ember-utils';
23+
import { guidFor } from 'ember-utils';
2424

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

3333
function copyNull(obj) {
34-
let output = new EmptyObject();
34+
let output = Object.create(null);
3535

3636
for (let prop in obj) {
37-
// hasOwnPropery is not needed because obj is new EmptyObject();
37+
// hasOwnPropery is not needed because obj is Object.create(null);
3838
output[prop] = obj[prop];
3939
}
4040

@@ -90,7 +90,7 @@ OrderedSet.prototype = {
9090
@private
9191
*/
9292
clear() {
93-
this.presenceSet = new EmptyObject();
93+
this.presenceSet = Object.create(null);
9494
this.list = [];
9595
this.size = 0;
9696
},
@@ -242,7 +242,7 @@ function Map() {
242242
if (this instanceof Map) {
243243
this._keys = OrderedSet.create();
244244
this._keys._silenceRemoveDeprecation = true;
245-
this._values = new EmptyObject();
245+
this._values = Object.create(null);
246246
this.size = 0;
247247
} else {
248248
missingNew('Map');
@@ -394,7 +394,7 @@ Map.prototype = {
394394
*/
395395
clear() {
396396
this._keys.clear();
397-
this._values = new EmptyObject();
397+
this._values = Object.create(null);
398398
this.size = 0;
399399
},
400400

packages/ember-metal/lib/meta.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
HAS_NATIVE_WEAKMAP,
3-
EmptyObject,
43
lookupDescriptor,
54
symbol
65
} from 'ember-utils';
@@ -202,7 +201,7 @@ export class Meta {
202201
}
203202

204203
_getOrCreateOwnMap(key) {
205-
return this[key] || (this[key] = new EmptyObject());
204+
return this[key] || (this[key] = Object.create(null));
206205
}
207206

208207
_getInherited(key) {
@@ -238,7 +237,7 @@ export class Meta {
238237
let outerMap = this._getOrCreateOwnMap('_deps');
239238
let innerMap = outerMap[subkey];
240239
if (!innerMap) {
241-
innerMap = outerMap[subkey] = new EmptyObject();
240+
innerMap = outerMap[subkey] = Object.create(null);
242241
}
243242
innerMap[itemkey] = value;
244243
}
@@ -282,7 +281,7 @@ export class Meta {
282281
while (pointer !== undefined) {
283282
let map = pointer[key];
284283
if (map) {
285-
seen = seen || new EmptyObject();
284+
seen = seen || Object.create(null);
286285
let innerMap = map[subkey];
287286
if (innerMap) {
288287
for (let innerKey in innerMap) {
@@ -372,7 +371,7 @@ function inheritedMap(name, Meta) {
372371

373372
Meta.prototype[`forEach${capitalized}`] = function(fn) {
374373
let pointer = this;
375-
let seen = new EmptyObject();
374+
let seen = Object.create(null);
376375
while (pointer !== undefined) {
377376
let map = pointer[key];
378377
if (map) {

packages/ember-routing/lib/system/cache.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { EmptyObject } from 'ember-utils';
21
import { Object as EmberObject } from 'ember-runtime';
32

43
/**
@@ -10,7 +9,7 @@ import { Object as EmberObject } from 'ember-runtime';
109
*/
1110
export default EmberObject.extend({
1211
init() {
13-
this.cache = new EmptyObject();
12+
this.cache = Object.create(null);
1413
},
1514

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

2322
if (!bucket) {
24-
bucket = this.cache[bucketKey] = new EmptyObject();
23+
bucket = this.cache[bucketKey] = Object.create(null);
2524
}
2625

2726
bucket[key] = value;

packages/ember-routing/lib/system/router.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
EmptyObject,
32
assign,
43
guidFor,
54
dictionary,
@@ -144,11 +143,11 @@ const EmberRouter = EmberObject.extend(Evented, {
144143
this.currentRouteName = null;
145144
this.currentPath = null;
146145

147-
this._qpCache = new EmptyObject();
146+
this._qpCache = Object.create(null);
148147
this._resetQueuedQueryParameterChanges();
149148
this._handledErrors = dictionary(null);
150-
this._engineInstances = new EmptyObject();
151-
this._engineInfoByRoute = new EmptyObject();
149+
this._engineInstances = Object.create(null);
150+
this._engineInfoByRoute = Object.create(null)
152151
},
153152

154153
/*
@@ -571,7 +570,7 @@ const EmberRouter = EmberObject.extend(Evented, {
571570
},
572571

573572
_getHandlerFunction() {
574-
let seen = new EmptyObject();
573+
let seen = Object.create(null);
575574
let owner = getOwner(this);
576575

577576
return name => {
@@ -1024,7 +1023,7 @@ const EmberRouter = EmberObject.extend(Evented, {
10241023
let engineInstances = this._engineInstances;
10251024

10261025
if (!engineInstances[name]) {
1027-
engineInstances[name] = new EmptyObject();
1026+
engineInstances[name] = Object.create(null);
10281027
}
10291028

10301029
let engineInstance = engineInstances[name][instanceId];
@@ -1483,7 +1482,7 @@ function appendLiveRoute(liveRoutes, defaultParentState, renderOptions) {
14831482
let target;
14841483
let myState = {
14851484
render: renderOptions,
1486-
outlets: new EmptyObject(),
1485+
outlets: Object.create(null),
14871486
wasUsed: false
14881487
};
14891488
if (renderOptions.into) {
@@ -1528,7 +1527,7 @@ function appendOrphan(liveRoutes, into, myState) {
15281527
render: {
15291528
name: '__ember_orphans__'
15301529
},
1531-
outlets: new EmptyObject()
1530+
outlets: Object.create(null)
15321531
};
15331532
}
15341533
liveRoutes.outlets.__ember_orphans__.outlets[into] = myState;

0 commit comments

Comments
 (0)