Skip to content

Commit

Permalink
Remove meta.descs
Browse files Browse the repository at this point in the history
  • Loading branch information
ebryn committed Jan 31, 2015
1 parent ac07b27 commit c3f13e8
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 57 deletions.
4 changes: 2 additions & 2 deletions packages/ember-application/lib/ext/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Ember from "ember-metal/core"; // Ember.assert
import { get } from "ember-metal/property_get";
import EmberError from "ember-metal/error";
import { inspect, meta } from "ember-metal/utils";
import { inspect } from "ember-metal/utils";
import { computed } from "ember-metal/computed";
import ControllerMixin from "ember-runtime/mixins/controller";
import controllerFor from "ember-routing/system/controller_for";
Expand Down Expand Up @@ -131,7 +131,7 @@ ControllerMixin.reopen({
Ember.assert(' `' + inspect(this) + ' specifies `needs`, but does ' +
"not have a container. Please ensure this controller was " +
"instantiated with a container.",
this.container || meta(this, false).descs.controllers !== defaultControllersComputedProperty);
this.container || this.controllers !== defaultControllersComputedProperty);

if (this.container) {
verifyNeedsDependencies(this, this.container, needs);
Expand Down
5 changes: 4 additions & 1 deletion packages/ember-htmlbars/lib/system/append-templated-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export default function appendTemplatedView(parentView, morph, viewClassOrInstan

// We only want to override the `_context` computed property if there is
// no specified controller. See View#_context for more information.
if (!viewProto.controller &&

var noControllerInProto = !viewProto.controller;
if (viewProto.controller.isDescriptor) { noControllerInProto = true; }
if (noControllerInProto &&
!viewProto.controllerBinding &&
!props.controller &&
!props.controllerBinding) {
Expand Down
1 change: 1 addition & 0 deletions packages/ember-metal/lib/alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function alias(altKey) {
}

export function AliasedProperty(altKey) {
this.isDescriptor = true;
this.altKey = altKey;
this._dependentKeys = [altKey];
}
Expand Down
3 changes: 2 additions & 1 deletion packages/ember-metal/lib/chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ function lazyGet(obj, key) {
}

// if a CP only return cached value
var desc = meta && meta.descs[key];
var possibleDesc = obj[key];
var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined;
if (desc && desc._cacheable) {
if (key in meta.cache) {
return meta.cache[key];
Expand Down
1 change: 1 addition & 0 deletions packages/ember-metal/lib/computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function UNDEFINED() { }
@constructor
*/
function ComputedProperty(config, opts) {
this.isDescriptor = true;
if (Ember.FEATURES.isEnabled("new-computed-syntax")) {
if (typeof config === "function") {
config.__ember_arity = config.length;
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-metal/lib/injected_property.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ComputedProperty } from "ember-metal/computed";
import { AliasedProperty } from "ember-metal/alias";
import { Descriptor } from "ember-metal/properties";
import create from "ember-metal/platform/create";
import { meta } from "ember-metal/utils";

/**
Read-only property that returns the result of a container lookup.
Expand All @@ -25,7 +24,8 @@ function InjectedProperty(type, name) {
}

function injectedPropertyGet(keyName) {
var desc = meta(this).descs[keyName];
var possibleDesc = this[keyName];
var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined;

Ember.assert("Attempting to lookup an injected property on an object " +
"without a container, ensure that the object was " +
Expand Down
17 changes: 12 additions & 5 deletions packages/ember-metal/lib/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function concatenatedMixinProperties(concatProp, props, values, base) {
return concats;
}

function giveDescriptorSuper(meta, key, property, values, descs) {
function giveDescriptorSuper(meta, key, property, values, descs, base) {
var superProperty;

// Computed properties override methods, and do not call super to them
Expand All @@ -139,7 +139,12 @@ function giveDescriptorSuper(meta, key, property, values, descs) {

// If we didn't find the original descriptor in a parent mixin, find
// it on the original object.
superProperty = superProperty || meta.descs[key];
if (!superProperty) {
var possibleDesc = base[key];
var superDesc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined;

superProperty = superDesc;
}

if (superProperty === undefined || !(superProperty instanceof ComputedProperty)) {
return property;
Expand Down Expand Up @@ -256,7 +261,7 @@ function addNormalizedProperty(base, key, value, meta, descs, values, concats, m
// Wrap descriptor function to implement
// __nextSuper() if needed
if (value._getter) {
value = giveDescriptorSuper(meta, key, value, values, descs);
value = giveDescriptorSuper(meta, key, value, values, descs, base);
}

descs[key] = value;
Expand Down Expand Up @@ -388,11 +393,12 @@ function finishPartial(obj, m) {
function followAlias(obj, desc, m, descs, values) {
var altKey = desc.methodName;
var value;
var possibleDesc;
if (descs[altKey] || values[altKey]) {
value = values[altKey];
desc = descs[altKey];
} else if (m.descs[altKey]) {
desc = m.descs[altKey];
} else if ((possibleDesc = obj[altKey]) && possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) {
desc = possibleDesc;
value = undefined;
} else {
desc = undefined;
Expand Down Expand Up @@ -743,6 +749,7 @@ export function required() {
}

function Alias(methodName) {
this.isDescriptor = true;
this.methodName = methodName;
}

Expand Down
20 changes: 10 additions & 10 deletions packages/ember-metal/lib/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import { overrideChains } from "ember-metal/property_events";
@private
@constructor
*/
export function Descriptor() {}
export function Descriptor() {
this.isDescriptor = true;
}

// ..........................................................
// DEFINING PROPERTIES API
Expand Down Expand Up @@ -89,42 +91,40 @@ export function DEFAULT_GETTER_FUNCTION(name) {
become the explicit value of this property.
*/
export function defineProperty(obj, keyName, desc, data, meta) {
var descs, existingDesc, watching, value;
var possibleDesc, existingDesc, watching, value;

if (!meta) {
meta = metaFor(obj);
}
descs = meta.descs;
existingDesc = meta.descs[keyName];
var watchEntry = meta.watching[keyName];
possibleDesc = obj[keyName];
existingDesc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined;

watching = watchEntry !== undefined && watchEntry > 0;

if (existingDesc instanceof Descriptor) {
if (existingDesc) {
existingDesc.teardown(obj, keyName);
}

if (desc instanceof Descriptor) {
value = desc;

descs[keyName] = desc;
if (Ember.FEATURES.isEnabled('mandatory-setter')) {
if (watching && hasPropertyAccessors) {
objectDefineProperty(obj, keyName, {
configurable: true,
enumerable: true,
writable: true,
value: undefined // make enumerable
value: value
});
} else {
obj[keyName] = undefined; // make enumerable
obj[keyName] = value;
}
} else {
obj[keyName] = undefined; // make enumerable
obj[keyName] = value;
}
if (desc.setup) { desc.setup(obj, keyName); }
} else {
descs[keyName] = undefined; // shadow descriptor in proto
if (desc == null) {
value = data;

Expand Down
12 changes: 7 additions & 5 deletions packages/ember-metal/lib/property_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function propertyWillChange(obj, keyName) {
var m = obj['__ember_meta__'];
var watching = (m && m.watching[keyName] > 0) || keyName === 'length';
var proto = m && m.proto;
var desc = m && m.descs[keyName];
var possibleDesc = obj[keyName];
var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined;

if (!watching) {
return;
Expand Down Expand Up @@ -73,7 +74,8 @@ function propertyDidChange(obj, keyName) {
var m = obj['__ember_meta__'];
var watching = (m && m.watching[keyName] > 0) || keyName === 'length';
var proto = m && m.proto;
var desc = m && m.descs[keyName];
var possibleDesc = obj[keyName];
var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined;

if (proto === obj) {
return;
Expand Down Expand Up @@ -150,7 +152,7 @@ function keysOf(obj) {
}

function iterDeps(method, obj, deps, depKey, seen, meta) {
var keys, key, i, desc;
var keys, key, i, possibleDesc, desc;
var guid = guidFor(obj);
var current = seen[guid];

Expand All @@ -166,10 +168,10 @@ function iterDeps(method, obj, deps, depKey, seen, meta) {

if (deps) {
keys = keysOf(deps);
var descs = meta.descs;
for (i=0; i<keys.length; i++) {
key = keys[i];
desc = descs[key];
possibleDesc = obj[key];
desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined;

if (desc && desc._suspended === obj) {
continue;
Expand Down
3 changes: 2 additions & 1 deletion packages/ember-metal/lib/property_get.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export function get(obj, keyName) {
}

var meta = obj['__ember_meta__'];
var desc = meta && meta.descs[keyName];
var possibleDesc = obj[keyName];
var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined;
var ret;

if (desc === undefined && isPath(keyName)) {
Expand Down
6 changes: 4 additions & 2 deletions packages/ember-metal/lib/property_set.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export function set(obj, keyName, value, tolerant) {
}

var meta = obj['__ember_meta__'];
var desc = meta && meta.descs[keyName];
var possibleDesc = obj[keyName];
var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined;

var isUnknown, currentValue;

if (desc === undefined && isPath(keyName)) {
Expand All @@ -51,7 +53,7 @@ export function set(obj, keyName, value, tolerant) {
Ember.assert("You need to provide an object and key to `set`.", !!obj && keyName !== undefined);
Ember.assert('calling set on destroyed object', !obj.isDestroyed);

if (desc !== undefined) {
if (desc) {
desc.set(obj, keyName, value);
} else {

Expand Down
12 changes: 3 additions & 9 deletions packages/ember-metal/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ export function guidFor(obj) {
// META
//
function Meta(obj) {
this.descs = {};
this.watching = {};
this.cache = {};
this.cacheMeta = {};
Expand All @@ -303,7 +302,7 @@ function Meta(obj) {
}

Meta.prototype = {
chainWatchers: null
chainWatchers: null // FIXME
};

if (!canDefineNonEnumerableProperties) {
Expand Down Expand Up @@ -346,7 +345,7 @@ if (Ember.FEATURES.isEnabled('mandatory-setter')) {
@return {Object} the meta hash for an object
*/
function meta(obj, writable) {
var ret = obj['__ember_meta__'];
var ret = obj.__ember_meta__;
if (writable===false) {
return ret || EMPTY_META;
}
Expand All @@ -368,11 +367,7 @@ function meta(obj, writable) {
}
}

obj['__ember_meta__'] = ret;

// make sure we don't accidentally try to create constructor like desc
ret.descs.constructor = null;

obj.__ember_meta__ = ret;
} else if (ret.source !== obj) {
if (obj.__defineNonEnumerable) {
obj.__defineNonEnumerable(EMBER_META_PROPERTY);
Expand All @@ -381,7 +376,6 @@ function meta(obj, writable) {
}

ret = o_create(ret);
ret.descs = o_create(ret.descs);
ret.watching = o_create(ret.watching);
ret.cache = {};
ret.cacheMeta = {};
Expand Down
12 changes: 9 additions & 3 deletions packages/ember-metal/lib/watch_key.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export function watchKey(obj, keyName, meta) {
if (!watching[keyName]) {
watching[keyName] = 1;

var desc = m.descs[keyName];
var possibleDesc = obj[keyName];
var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined;
if (desc && desc.willWatch) { desc.willWatch(obj, keyName); }

if ('function' === typeof obj.willWatchProperty) {
Expand All @@ -47,6 +48,10 @@ if (Ember.FEATURES.isEnabled('mandatory-setter')) {
var configurable = descriptor ? descriptor.configurable : true;
var isWritable = descriptor ? descriptor.writable : true;
var hasValue = descriptor ? 'value' in descriptor : true;
var possibleDesc = descriptor && descriptor.value;
var isDescriptor = possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor;

if (isDescriptor) { return; }

// this x in Y deopts, so keeping it in this function is better;
if (configurable && isWritable && hasValue && keyName in obj) {
Expand All @@ -68,15 +73,16 @@ export function unwatchKey(obj, keyName, meta) {
if (watching[keyName] === 1) {
watching[keyName] = 0;

var desc = m.descs[keyName];
var possibleDesc = obj[keyName];
var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined;
if (desc && desc.didUnwatch) { desc.didUnwatch(obj, keyName); }

if ('function' === typeof obj.didUnwatchProperty) {
obj.didUnwatchProperty(keyName);
}

if (Ember.FEATURES.isEnabled('mandatory-setter')) {
if (hasPropertyAccessors && keyName in obj) {
if (!desc && hasPropertyAccessors && keyName in obj) {
o_defineProperty(obj, keyName, {
configurable: true,
enumerable: Object.prototype.propertyIsEnumerable.call(obj, keyName),
Expand Down
3 changes: 1 addition & 2 deletions packages/ember-metal/tests/computed_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
} from "ember-metal/properties";
import { get } from 'ember-metal/property_get';
import { set } from 'ember-metal/property_set';
import { meta } from 'ember-metal/utils';
import { isWatching } from "ember-metal/watching";
import {
addObserver,
Expand Down Expand Up @@ -861,7 +860,7 @@ testBoth("when setting a value on a computed property that doesn't handle sets",
set(obj, 'foo', 'bar');

equal(get(obj, 'foo'), 'bar', 'The set value is properly returned');
ok(!meta(obj).descs.foo, 'The computed property was removed');
ok(typeof obj.foo === 'string', 'The computed property was removed');
ok(observerFired, 'The observer was still notified');
});

Expand Down
6 changes: 2 additions & 4 deletions packages/ember-runtime/lib/inject.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Ember from "ember-metal/core"; // Ember.assert
import { indexOf } from "ember-metal/enumerable_utils";
import { meta } from "ember-metal/utils";
import InjectedProperty from "ember-metal/injected_property";
import keys from "ember-metal/keys";

Expand Down Expand Up @@ -48,12 +47,11 @@ export function createInjectionHelper(type, validator) {
*/
export function validatePropertyInjections(factory) {
var proto = factory.proto();
var descs = meta(proto).descs;
var types = [];
var key, desc, validator, i, l;

for (key in descs) {
desc = descs[key];
for (key in proto) {
desc = proto[key];
if (desc instanceof InjectedProperty && indexOf(types, desc.type) === -1) {
types.push(desc.type);
}
Expand Down
Loading

0 comments on commit c3f13e8

Please sign in to comment.