language
stringclasses
1 value
owner
stringlengths
2
15
repo
stringlengths
2
21
sha
stringlengths
45
45
message
stringlengths
7
36.3k
path
stringlengths
1
199
patch
stringlengths
15
102k
is_multipart
bool
2 classes
Other
emberjs
ember.js
cfaa47e48b0d6badb5e84419f117a46fd2f2ae8e.json
Introduce source to injections Ember templates use a `source` argument to the container. This hints where to look for "local lookup", and also what namespace to look in for a partial specifier. For example a template in an addon's `src` tree can invoke components and helpers in that tree becuase it has a `source` argument passed to lookups. This introduces the same functionality for service injections. A service can now accept a `source` argument and its lookup will apply to the namespace of that file. Additionally, refactor away from using a `source` argument to the `resolve` API of resolvers. Instead leveral the `expandLocalLookup` API to pass the source and get an identifier that can be treated as canonical for that factory.
packages/container/tests/container_test.js
@@ -388,15 +388,18 @@ moduleFor('Container', class extends AbstractTestCase { assert.deepEqual(resolveWasCalled, ['foo:post']); } - ['@test A factory\'s lazy injections are validated when first instantiated'](assert) { + [`@test A factory's lazy injections are validated when first instantiated`](assert) { let registry = new Registry(); let container = registry.container(); let Apple = factory(); let Orange = factory(); Apple.reopenClass({ _lazyInjections() { - return ['orange:main', 'banana:main']; + return [ + {specifier: 'orange:main'}, + {specifier: 'banana:main'} + ]; } }); @@ -419,7 +422,9 @@ moduleFor('Container', class extends AbstractTestCase { Apple.reopenClass({ _lazyInjections: () => { assert.ok(true, 'should call lazy injection method'); - return ['orange:main']; + return [ + {specifier: 'orange:main'} + ]; } }); @@ -637,18 +642,20 @@ moduleFor('Container', class extends AbstractTestCase { }); if (EMBER_MODULE_UNIFICATION) { - QUnit.module('Container module unification'); - moduleFor('Container module unification', class extends AbstractTestCase { - ['@test The container can pass a source to factoryFor'](assert) { + ['@test The container can expand and resolve a source to factoryFor'](assert) { let PrivateComponent = factory(); let lookup = 'component:my-input'; let expectedSource = 'template:routes/application'; let registry = new Registry(); let resolveCount = 0; - registry.resolve = function(fullName, { source }) { + let expandedKey = 'boom, special expanded key'; + registry.expandLocalLookup = function() { + return expandedKey; + }; + registry.resolve = function(fullName) { resolveCount++; - if (fullName === lookup && source === expectedSource) { + if (fullName === expandedKey) { return PrivateComponent; } }; @@ -660,13 +667,17 @@ if (EMBER_MODULE_UNIFICATION) { assert.equal(resolveCount, 1, 'resolve called only once and a cached factory was returned the second time'); } - ['@test The container can pass a source to lookup']() { + ['@test The container can expand and resolve a source to lookup']() { let PrivateComponent = factory(); let lookup = 'component:my-input'; let expectedSource = 'template:routes/application'; let registry = new Registry(); - registry.resolve = function(fullName, { source }) { - if (fullName === lookup && source === expectedSource) { + let expandedKey = 'boom, special expanded key'; + registry.expandLocalLookup = function() { + return expandedKey; + }; + registry.resolve = function(fullName) { + if (fullName === expandedKey) { return PrivateComponent; } }; @@ -676,7 +687,7 @@ if (EMBER_MODULE_UNIFICATION) { let result = container.lookup(lookup, { source: expectedSource }); this.assert.ok(result instanceof PrivateComponent, 'The correct factory was provided'); - this.assert.ok(container.cache[`template:routes/application:component:my-input`] instanceof PrivateComponent, + this.assert.ok(container.cache[expandedKey] instanceof PrivateComponent, 'The correct factory was stored in the cache with the correct key which includes the source.'); } });
true
Other
emberjs
ember.js
cfaa47e48b0d6badb5e84419f117a46fd2f2ae8e.json
Introduce source to injections Ember templates use a `source` argument to the container. This hints where to look for "local lookup", and also what namespace to look in for a partial specifier. For example a template in an addon's `src` tree can invoke components and helpers in that tree becuase it has a `source` argument passed to lookups. This introduces the same functionality for service injections. A service can now accept a `source` argument and its lookup will apply to the namespace of that file. Additionally, refactor away from using a `source` argument to the `resolve` API of resolvers. Instead leveral the `expandLocalLookup` API to pass the source and get an identifier that can be treated as canonical for that factory.
packages/ember-application/tests/system/application_instance_test.js
@@ -121,6 +121,29 @@ moduleFor('ApplicationInstance', class extends TestCase { assert.notStrictEqual(postController1, postController2, 'lookup creates a brand new instance, because the previous one was reset'); } + ['@skip unregistering a factory clears caches with source of that factory'](assert) { + assert.expect(1); + + appInstance = run(() => ApplicationInstance.create({ application })); + + let PostController1 = factory(); + let PostController2 = factory(); + + appInstance.register('controller:post', PostController1); + + appInstance.lookup('controller:post'); + let postControllerLookupWithSource = appInstance.lookup('controller:post', {source: 'doesnt-even-matter'}); + + appInstance.unregister('controller:post'); + appInstance.register('controller:post', PostController2); + + // The cache that is source-specific is not cleared + assert.ok( + postControllerLookupWithSource !== appInstance.lookup('controller:post', {source: 'doesnt-even-matter'}), + 'lookup with source creates a new instance' + ); + } + ['@test can build and boot a registered engine'](assert) { assert.expect(11);
true
Other
emberjs
ember.js
cfaa47e48b0d6badb5e84419f117a46fd2f2ae8e.json
Introduce source to injections Ember templates use a `source` argument to the container. This hints where to look for "local lookup", and also what namespace to look in for a partial specifier. For example a template in an addon's `src` tree can invoke components and helpers in that tree becuase it has a `source` argument passed to lookups. This introduces the same functionality for service injections. A service can now accept a `source` argument and its lookup will apply to the namespace of that file. Additionally, refactor away from using a `source` argument to the `resolve` API of resolvers. Instead leveral the `expandLocalLookup` API to pass the source and get an identifier that can be treated as canonical for that factory.
packages/ember-application/tests/test-helpers/registry-check.js
@@ -18,7 +18,7 @@ export function verifyInjection(assert, owner, fullName, property, injectionName for (let i = 0, l = injections.length; i < l; i++) { injection = injections[i]; - if (injection.property === property && injection.fullName === normalizedName) { + if (injection.property === property && injection.specifier === normalizedName) { hasInjection = true; break; }
true
Other
emberjs
ember.js
cfaa47e48b0d6badb5e84419f117a46fd2f2ae8e.json
Introduce source to injections Ember templates use a `source` argument to the container. This hints where to look for "local lookup", and also what namespace to look in for a partial specifier. For example a template in an addon's `src` tree can invoke components and helpers in that tree becuase it has a `source` argument passed to lookups. This introduces the same functionality for service injections. A service can now accept a `source` argument and its lookup will apply to the namespace of that file. Additionally, refactor away from using a `source` argument to the `resolve` API of resolvers. Instead leveral the `expandLocalLookup` API to pass the source and get an identifier that can be treated as canonical for that factory.
packages/ember-glimmer/tests/integration/components/local-lookup-test.js
@@ -1,5 +1,7 @@ import { moduleFor, RenderingTest } from '../../utils/test-case'; +import { compile } from 'ember-template-compiler'; import { ModuleBasedTestResolver } from 'internal-test-helpers'; +import { moduleFor as applicationModuleFor, ApplicationTestCase } from 'internal-test-helpers'; import { Component } from '../../utils/helpers'; import { EMBER_MODULE_UNIFICATION } from 'ember/features'; import { helper, Helper } from 'ember-glimmer'; @@ -218,7 +220,6 @@ function buildResolver() { sourceName = sourceName.replace('.hbs', ''); let result = `${type}:${sourceName}/${name}`; - return result; } }; @@ -234,23 +235,17 @@ moduleFor('Components test: local lookup with expandLocalLookup feature', class if (EMBER_MODULE_UNIFICATION) { class LocalLookupTestResolver extends ModuleBasedTestResolver { - resolve(specifier, referrer) { - let [type, name ] = specifier.split(':'); - let fullSpecifier = specifier; + expandLocalLookup(specifier, source) { + if (source && source.indexOf('components/') !== -1) { + let namespace = source.split('components/')[1]; + let [type, name] = specifier.split(':'); + name = name.replace('components/', ''); - if (referrer) { - let namespace = referrer.split('components/')[1] || ''; namespace = namespace.replace('.hbs', ''); - if (specifier.indexOf('template:components/') !== -1) { - name = name.replace('components/', ''); - fullSpecifier = `${type}:components/${namespace}/${name}`; - } else if (specifier.indexOf(':') !== -1) { - let [type, name] = specifier.split(':'); - fullSpecifier = `${type}:${namespace}/${name}`; - } + return `${type}:${type === 'template' ? 'components/' : ''}${namespace}/${name}`; } - return super.resolve(fullSpecifier); + return super.expandLocalLookup(specifier, source); } } @@ -310,3 +305,33 @@ if (EMBER_MODULE_UNIFICATION) { } }); } + +if (EMBER_MODULE_UNIFICATION) { + applicationModuleFor('Components test: local lookup with resolution referrer (MU)', class extends ApplicationTestCase { + ['@test Ensure that the same specifier with two sources does not share a cache key'](assert) { + this.add({ + specifier: 'template:components/x-not-shared', + source: 'template:my-app/templates/components/x-top.hbs' + }, compile('child-x-not-shared')); + + this.add({ + specifier: 'template:components/x-top', + source: 'template:my-app/templates/application.hbs' + }, compile('top-level-x-top ({{x-not-shared}})', { moduleName: 'my-app/templates/components/x-top.hbs' })); + + this.add({ + specifier: 'template:components/x-not-shared', + source: 'template:my-app/templates/application.hbs' + }, compile('top-level-x-not-shared')); + + this.addTemplate('application', '{{x-not-shared}} {{x-top}} {{x-not-shared}} {{x-top}}'); + + return this.visit('/').then(() => { + assert.equal( + this.element.textContent, + 'top-level-x-not-shared top-level-x-top (child-x-not-shared) top-level-x-not-shared top-level-x-top (child-x-not-shared)' + ); + }); + } + }); +}
true
Other
emberjs
ember.js
cfaa47e48b0d6badb5e84419f117a46fd2f2ae8e.json
Introduce source to injections Ember templates use a `source` argument to the container. This hints where to look for "local lookup", and also what namespace to look in for a partial specifier. For example a template in an addon's `src` tree can invoke components and helpers in that tree becuase it has a `source` argument passed to lookups. This introduces the same functionality for service injections. A service can now accept a `source` argument and its lookup will apply to the namespace of that file. Additionally, refactor away from using a `source` argument to the `resolve` API of resolvers. Instead leveral the `expandLocalLookup` API to pass the source and get an identifier that can be treated as canonical for that factory.
packages/ember-metal/lib/injected_property.js
@@ -20,11 +20,12 @@ import { descriptorFor } from './meta'; @private */ export default class InjectedProperty extends ComputedProperty { - constructor(type, name) { + constructor(type, name, options) { super(injectedPropertyGet); this.type = type; this.name = name; + this.source = options ? options.source : undefined; } } @@ -35,5 +36,6 @@ function injectedPropertyGet(keyName) { assert(`InjectedProperties should be defined with the inject computed property macros.`, desc && desc.type); assert(`Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container.`, owner); - return owner.lookup(`${desc.type}:${desc.name || keyName}`); + let specifier = `${desc.type}:${desc.name || keyName}`; + return owner.lookup(specifier, {source: desc.source}); }
true
Other
emberjs
ember.js
cfaa47e48b0d6badb5e84419f117a46fd2f2ae8e.json
Introduce source to injections Ember templates use a `source` argument to the container. This hints where to look for "local lookup", and also what namespace to look in for a partial specifier. For example a template in an addon's `src` tree can invoke components and helpers in that tree becuase it has a `source` argument passed to lookups. This introduces the same functionality for service injections. A service can now accept a `source` argument and its lookup will apply to the namespace of that file. Additionally, refactor away from using a `source` argument to the `resolve` API of resolvers. Instead leveral the `expandLocalLookup` API to pass the source and get an identifier that can be treated as canonical for that factory.
packages/ember-runtime/lib/inject.js
@@ -1,5 +1,7 @@ import { InjectedProperty, descriptorFor } from 'ember-metal'; import { assert } from 'ember-debug'; +import { EMBER_MODULE_UNIFICATION } from 'ember/features'; + /** @module ember */ @@ -35,7 +37,11 @@ const typeValidators = {}; export function createInjectionHelper(type, validator) { typeValidators[type] = validator; - inject[type] = name => new InjectedProperty(type, name); + if (EMBER_MODULE_UNIFICATION) { + inject[type] = (name, options) => new InjectedProperty(type, name, options); + } else { + inject[type] = name => new InjectedProperty(type, name); + } } /**
true
Other
emberjs
ember.js
cfaa47e48b0d6badb5e84419f117a46fd2f2ae8e.json
Introduce source to injections Ember templates use a `source` argument to the container. This hints where to look for "local lookup", and also what namespace to look in for a partial specifier. For example a template in an addon's `src` tree can invoke components and helpers in that tree becuase it has a `source` argument passed to lookups. This introduces the same functionality for service injections. A service can now accept a `source` argument and its lookup will apply to the namespace of that file. Additionally, refactor away from using a `source` argument to the `resolve` API of resolvers. Instead leveral the `expandLocalLookup` API to pass the source and get an identifier that can be treated as canonical for that factory.
packages/ember-runtime/lib/mixins/registry_proxy.js
@@ -2,6 +2,7 @@ @module ember */ +import { assert } from 'ember-debug'; import { Mixin } from 'ember-metal'; @@ -24,7 +25,10 @@ export default Mixin.create({ @param {String} fullName @return {Function} fullName's factory */ - resolveRegistration: registryAlias('resolve'), + resolveRegistration(fullName, options) { + assert('fullName must be a proper full name', this.__registry__.isValidFullName(fullName)); + return this.__registry__.resolve(fullName, options); + }, /** Registers a factory that can be used for dependency injection (with
true
Other
emberjs
ember.js
cfaa47e48b0d6badb5e84419f117a46fd2f2ae8e.json
Introduce source to injections Ember templates use a `source` argument to the container. This hints where to look for "local lookup", and also what namespace to look in for a partial specifier. For example a template in an addon's `src` tree can invoke components and helpers in that tree becuase it has a `source` argument passed to lookups. This introduces the same functionality for service injections. A service can now accept a `source` argument and its lookup will apply to the namespace of that file. Additionally, refactor away from using a `source` argument to the `resolve` API of resolvers. Instead leveral the `expandLocalLookup` API to pass the source and get an identifier that can be treated as canonical for that factory.
packages/ember-runtime/lib/system/core_object.js
@@ -1020,7 +1020,10 @@ if (DEBUG) { for (key in proto) { desc = descriptorFor(proto, key); if (desc instanceof InjectedProperty) { - injections[key] = `${desc.type}:${desc.name || key}`; + injections[key] = { + specifier: `${desc.type}:${desc.name || key}`, + source: desc.source + }; } }
true
Other
emberjs
ember.js
cfaa47e48b0d6badb5e84419f117a46fd2f2ae8e.json
Introduce source to injections Ember templates use a `source` argument to the container. This hints where to look for "local lookup", and also what namespace to look in for a partial specifier. For example a template in an addon's `src` tree can invoke components and helpers in that tree becuase it has a `source` argument passed to lookups. This introduces the same functionality for service injections. A service can now accept a `source` argument and its lookup will apply to the namespace of that file. Additionally, refactor away from using a `source` argument to the `resolve` API of resolvers. Instead leveral the `expandLocalLookup` API to pass the source and get an identifier that can be treated as canonical for that factory.
packages/ember-runtime/tests/inject_test.js
@@ -61,6 +61,11 @@ if (DEBUG) { bar: new InjectedProperty('quux') }); - assert.deepEqual(AnObject._lazyInjections(), { 'foo': 'foo:bar', 'bar': 'quux:bar' }, 'should return injected container keys'); + assert.deepEqual( + AnObject._lazyInjections(), + { + 'foo': { specifier: 'foo:bar', source: undefined }, + 'bar': { specifier: 'quux:bar', source: undefined } + }, 'should return injected container keys'); }); }
true
Other
emberjs
ember.js
cfaa47e48b0d6badb5e84419f117a46fd2f2ae8e.json
Introduce source to injections Ember templates use a `source` argument to the container. This hints where to look for "local lookup", and also what namespace to look in for a partial specifier. For example a template in an addon's `src` tree can invoke components and helpers in that tree becuase it has a `source` argument passed to lookups. This introduces the same functionality for service injections. A service can now accept a `source` argument and its lookup will apply to the namespace of that file. Additionally, refactor away from using a `source` argument to the `resolve` API of resolvers. Instead leveral the `expandLocalLookup` API to pass the source and get an identifier that can be treated as canonical for that factory.
packages/ember/tests/service_injection_test.js
@@ -2,7 +2,7 @@ import { Controller } from 'ember-runtime'; import { moduleFor, ApplicationTestCase } from 'internal-test-helpers'; import { inject, Service } from 'ember-runtime'; import { computed } from 'ember-metal'; -import { EMBER_METAL_ES5_GETTERS } from 'ember/features'; +import { EMBER_METAL_ES5_GETTERS, EMBER_MODULE_UNIFICATION } from 'ember/features'; moduleFor('Service Injection', class extends ApplicationTestCase { @@ -43,3 +43,131 @@ if (EMBER_METAL_ES5_GETTERS) { } }); } + +if (EMBER_MODULE_UNIFICATION) { + moduleFor('Service Injection (MU)', class extends ApplicationTestCase { + ['@test Service can be injected with source and is resolved'](assert) { + let source = 'controller:src/ui/routes/application/controller'; + this.add('controller:application', Controller.extend({ + myService: inject.service('my-service', { source }) + })); + let MyService = Service.extend(); + this.add({ + specifier: 'service:my-service', + source + }, MyService); + + return this.visit('/').then(() => { + let controller = this.applicationInstance.lookup('controller:application'); + + assert.ok(controller.get('myService') instanceof MyService); + }); + } + + ['@test Services can be injected with same name, different source, and resolve different instances'](assert) { + // This test implies that there is a file src/ui/routes/route-a/-services/my-service + let routeASource = 'controller:src/ui/routes/route-a/controller'; + // This test implies that there is a file src/ui/routes/route-b/-services/my-service + let routeBSource = 'controller:src/ui/routes/route-b/controller'; + + this.add('controller:route-a', Controller.extend({ + myService: inject.service('my-service', { source: routeASource }) + })); + + this.add('controller:route-b', Controller.extend({ + myService: inject.service('my-service', { source: routeBSource }) + })); + + let LocalLookupService = Service.extend(); + this.add({ + specifier: 'service:my-service', + source: routeASource + }, LocalLookupService); + + let MyService = Service.extend(); + this.add({ + specifier: 'service:my-service', + source: routeBSource + }, MyService); + + return this.visit('/').then(() => { + let controllerA = this.applicationInstance.lookup('controller:route-a'); + let serviceFromControllerA = controllerA.get('myService'); + assert.ok(serviceFromControllerA instanceof LocalLookupService, 'local lookup service is returned'); + + let controllerB = this.applicationInstance.lookup('controller:route-b'); + let serviceFromControllerB = controllerB.get('myService'); + assert.ok(serviceFromControllerB instanceof MyService, 'global service is returned'); + + assert.notStrictEqual(serviceFromControllerA, serviceFromControllerB); + }); + } + + ['@test Services can be injected with same name, different source, but same resolution result, and share an instance'](assert) { + let routeASource = 'controller:src/ui/routes/route-a/controller'; + let routeBSource = 'controller:src/ui/routes/route-b/controller'; + + this.add('controller:route-a', Controller.extend({ + myService: inject.service('my-service', { source: routeASource }) + })); + + this.add('controller:route-b', Controller.extend({ + myService: inject.service('my-service', { source: routeBSource }) + })); + + let MyService = Service.extend(); + this.add({ + specifier: 'service:my-service' + }, MyService); + + return this.visit('/').then(() => { + let controllerA = this.applicationInstance.lookup('controller:route-a'); + let serviceFromControllerA = controllerA.get('myService'); + assert.ok(serviceFromControllerA instanceof MyService); + + let controllerB = this.applicationInstance.lookup('controller:route-b'); + assert.strictEqual(serviceFromControllerA, controllerB.get('myService')); + }); + } + + /* + * This test demonstrates a failure in the caching system of ember's + * container around singletons and and local lookup. The local lookup + * is cached and the global injection is then looked up incorrectly. + * + * The paractical rules of Ember's module unification config are such + * that services cannot be locally looked up, thus this case is really + * just a demonstration of what could go wrong if we permit arbitrary + * configuration (such as a singleton type that has local lookup). + */ + ['@test Services can be injected with same name, one with source one without, and share an instance'](assert) { + let routeASource = 'controller:src/ui/routes/route-a/controller'; + this.add('controller:route-a', Controller.extend({ + myService: inject.service('my-service', { source: routeASource }) + })); + + this.add('controller:route-b', Controller.extend({ + myService: inject.service('my-service') + })); + + let MyService = Service.extend(); + this.add({ + specifier: 'service:my-service' + }, MyService); + + return this.visit('/').then(() => { + let controllerA = this.applicationInstance.lookup('controller:route-a'); + let serviceFromControllerA = controllerA.get('myService'); + assert.ok(serviceFromControllerA instanceof MyService, 'global service is returned'); + + let controllerB = this.applicationInstance.lookup('controller:route-b'); + let serviceFromControllerB = controllerB.get('myService'); + assert.ok(serviceFromControllerB instanceof MyService, 'global service is returned'); + + assert.strictEqual(serviceFromControllerA, serviceFromControllerB); + }); + } + + }); + +}
true
Other
emberjs
ember.js
cfaa47e48b0d6badb5e84419f117a46fd2f2ae8e.json
Introduce source to injections Ember templates use a `source` argument to the container. This hints where to look for "local lookup", and also what namespace to look in for a partial specifier. For example a template in an addon's `src` tree can invoke components and helpers in that tree becuase it has a `source` argument passed to lookups. This introduces the same functionality for service injections. A service can now accept a `source` argument and its lookup will apply to the namespace of that file. Additionally, refactor away from using a `source` argument to the `resolve` API of resolvers. Instead leveral the `expandLocalLookup` API to pass the source and get an identifier that can be treated as canonical for that factory.
packages/internal-test-helpers/lib/test-resolver.js
@@ -1,6 +1,6 @@ import { compile } from 'ember-template-compiler'; -const DELIMITER = '\0'; +const DELIMITER = '%'; function serializeKey(specifier, source) { return [specifier, source].join(DELIMITER); @@ -11,8 +11,19 @@ class Resolver { this._registered = {}; this.constructor.lastInstance = this; } - resolve(specifier, source) { - return this._registered[serializeKey(specifier, source)]; + resolve(specifier) { + return this._registered[specifier] || this._registered[serializeKey(specifier)]; + } + expandLocalLookup(specifier, source) { + let key = serializeKey(specifier, source); + if (this._registered[key]) { + return key; + } + + /* + * For a top-level resolution or no resolution, return null + */ + return null; } add(lookup, factory) { let key;
true
Other
emberjs
ember.js
8b8ae79a1f78b3be1b39ae500cb9f85f65cfc3f7.json
Set proper moduleName values
packages/ember-glimmer/tests/integration/application/rendering-test.js
@@ -407,7 +407,7 @@ moduleFor('Application test: rendering', class extends ApplicationTest { template: 'Hi {{person.name}} from component' }); - let expectedBacktrackingMessage = /modified "model\.name" twice on \[object Object\] in a single render\. It was rendered in "template:routeWithError" and modified in "component:x-foo"/; + let expectedBacktrackingMessage = /modified "model\.name" twice on \[object Object\] in a single render\. It was rendered in "template:my-app\/templates\/routeWithError.hbs" and modified in "component:x-foo"/; return this.visit('/').then(() => { expectAssertion(() => {
true
Other
emberjs
ember.js
8b8ae79a1f78b3be1b39ae500cb9f85f65cfc3f7.json
Set proper moduleName values
packages/ember-glimmer/tests/integration/components/local-lookup-test.js
@@ -202,14 +202,20 @@ function buildResolver() { let [sourceType, sourceName ] = sourceFullName.split(':'); let [type, name ] = fullName.split(':'); - if (type !== 'template' && sourceType === 'template' && sourceName.slice(0, 11) === 'components/') { - sourceName = sourceName.slice(11); + sourceName = sourceName.replace('my-app/', ''); + + if (sourceType === 'template' && sourceName.slice(0, 21) === 'templates/components/') { + sourceName = sourceName.slice(21); } - if (type === 'template' && sourceType === 'template' && name.slice(0, 11) === 'components/') { + name = name.replace('my-app/', ''); + + if (type === 'template' && name.slice(0, 11) === 'components/') { name = name.slice(11); + sourceName = `components/${sourceName}`; } + sourceName = sourceName.replace('.hbs', ''); let result = `${type}:${sourceName}/${name}`; @@ -229,13 +235,15 @@ moduleFor('Components test: local lookup with expandLocalLookup feature', class if (EMBER_MODULE_UNIFICATION) { class LocalLookupTestResolver extends ModuleBasedTestResolver { resolve(specifier, referrer) { + let [type, name ] = specifier.split(':'); let fullSpecifier = specifier; if (referrer) { - let namespace = referrer.split('template:components/')[1]; + let namespace = referrer.split('components/')[1] || ''; + namespace = namespace.replace('.hbs', ''); if (specifier.indexOf('template:components/') !== -1) { - let name = specifier.split('template:components/')[1]; - fullSpecifier = `template:components/${namespace}/${name}`; + name = name.replace('components/', ''); + fullSpecifier = `${type}:components/${namespace}/${name}`; } else if (specifier.indexOf(':') !== -1) { let [type, name] = specifier.split(':'); fullSpecifier = `${type}:${namespace}/${name}`; @@ -272,7 +280,7 @@ if (EMBER_MODULE_UNIFICATION) { if (typeof template === 'string') { resolver.add(`template:components/${name}`, this.compile(template, { - moduleName: `components/${name}` + moduleName: `my-name/templates/components/${name}.hbs` })); } } @@ -281,7 +289,7 @@ if (EMBER_MODULE_UNIFICATION) { let { resolver } = this; if (typeof template === 'string') { resolver.add(`template:${name}`, this.compile(template, { - moduleName: name + moduleName: `my-name/templates/${name}.hbs` })); } else { throw new Error(`Registered template "${name}" must be a string`);
true
Other
emberjs
ember.js
8b8ae79a1f78b3be1b39ae500cb9f85f65cfc3f7.json
Set proper moduleName values
packages/ember-glimmer/tests/integration/mount-test.js
@@ -64,7 +64,7 @@ moduleFor('{{mount}} test', class extends ApplicationTest { } ['@test it boots an engine, instantiates its application controller, and renders its application template'](assert) { - this.engineRegistrations['template:application'] = compile('<h2>Chat here, {{username}}</h2>', { moduleName: 'application' }); + this.engineRegistrations['template:application'] = compile('<h2>Chat here, {{username}}</h2>', { moduleName: 'my-app/templates/application.hbs' }); let controller; @@ -103,20 +103,20 @@ moduleFor('{{mount}} test', class extends ApplicationTest { this.addTemplate('index', ''); this.addTemplate('route-with-mount', '{{mount "chat"}}'); - this.engineRegistrations['template:application'] = compile('hi {{person.name}} [{{component-with-backtracking-set person=person}}]', { moduleName: 'application' }); + this.engineRegistrations['template:application'] = compile('hi {{person.name}} [{{component-with-backtracking-set person=person}}]', { moduleName: 'my-app/templates/application.hbs' }); this.engineRegistrations['controller:application'] = Controller.extend({ person: { name: 'Alex' } }); - this.engineRegistrations['template:components/component-with-backtracking-set'] = compile('[component {{person.name}}]', { moduleName: 'components/component-with-backtracking-set' }); + this.engineRegistrations['template:components/component-with-backtracking-set'] = compile('[component {{person.name}}]', { moduleName: 'my-app/templates/components/component-with-backtracking-set.hbs' }); this.engineRegistrations['component:component-with-backtracking-set'] = Component.extend({ init() { this._super(...arguments); this.set('person.name', 'Ben'); } }); - let expectedBacktrackingMessage = /modified "person\.name" twice on \[object Object\] in a single render\. It was rendered in "template:route-with-mount" \(in "engine:chat"\) and modified in "component:component-with-backtracking-set" \(in "engine:chat"\)/; + let expectedBacktrackingMessage = /modified "person\.name" twice on \[object Object\] in a single render\. It was rendered in "template:my-app\/templates\/route-with-mount.hbs" \(in "engine:chat"\) and modified in "component:component-with-backtracking-set" \(in "engine:chat"\)/; return this.visit('/').then(() => { expectAssertion(() => { @@ -143,14 +143,14 @@ moduleFor('{{mount}} test', class extends ApplicationTest { router: null, init() { this._super(...arguments); - this.register('template:application', compile('<h2>Foo Engine</h2>', { moduleName: 'application' })); + this.register('template:application', compile('<h2>Foo Engine</h2>', { moduleName: 'my-app/templates/application.hbs' })); } })); this.add('engine:bar', Engine.extend({ router: null, init() { this._super(...arguments); - this.register('template:application', compile('<h2>Bar Engine</h2>', { moduleName: 'application' })); + this.register('template:application', compile('<h2>Bar Engine</h2>', { moduleName: 'my-app/templates/application.hbs' })); } })); @@ -203,15 +203,15 @@ moduleFor('{{mount}} test', class extends ApplicationTest { router: null, init() { this._super(...arguments); - this.register('template:application', compile('<h2>Foo Engine: {{tagless-component}}</h2>', { moduleName: 'application' })); + this.register('template:application', compile('<h2>Foo Engine: {{tagless-component}}</h2>', { moduleName: 'my-app/templates/application.hbs' })); this.register('component:tagless-component', Component.extend({ tagName: "", init() { this._super(...arguments); component = this; } })); - this.register('template:components/tagless-component', compile('Tagless Component', { moduleName: 'components/tagless-component' })); + this.register('template:components/tagless-component', compile('Tagless Component', { moduleName: 'my-app/templates/components/tagless-component.hbs' })); } })); @@ -236,7 +236,7 @@ if (EMBER_ENGINES_MOUNT_PARAMS) { router: null, init() { this._super(...arguments); - this.register('template:application', compile('<h2>Param Engine: {{model.foo}}</h2>', { moduleName: 'application' })); + this.register('template:application', compile('<h2>Param Engine: {{model.foo}}</h2>', { moduleName: 'my-app/templates/application.hbs' })); } })); } @@ -311,7 +311,7 @@ if (EMBER_ENGINES_MOUNT_PARAMS) { router: null, init() { this._super(...arguments); - this.register('template:application', compile('{{model.foo}}', { moduleName: 'application' })); + this.register('template:application', compile('{{model.foo}}', { moduleName: 'my-app/templates/application.hbs' })); } })); this.addTemplate('engine-params-contextual-component', '{{mount "componentParamEngine" model=(hash foo=(component "foo-component"))}}');
true
Other
emberjs
ember.js
8b8ae79a1f78b3be1b39ae500cb9f85f65cfc3f7.json
Set proper moduleName values
packages/ember-glimmer/tests/unit/template-factory-test.js
@@ -9,7 +9,7 @@ moduleFor('Template factory test', class extends RenderingTest { let { runtimeResolver } = this; let templateStr = 'Hello {{name}}'; - let options = { moduleName: 'some-module' }; + let options = { moduleName: 'my-app/templates/some-module.hbs' }; let spec = precompile(templateStr, options); let body = `exports.default = template(${spec});`;
true
Other
emberjs
ember.js
8b8ae79a1f78b3be1b39ae500cb9f85f65cfc3f7.json
Set proper moduleName values
packages/ember/tests/integration/multiple-app-test.js
@@ -61,15 +61,15 @@ moduleFor('View Integration', class extends ApplicationTestCase { this.compile(` <h1>Node 1</h1>{{special-button}} `, { - moduleName: 'index' + moduleName: 'my-app/templates/index.hbs' }) ); resolver.add( 'template:components/special-button', this.compile(` <button class='do-stuff' {{action 'doStuff'}}>Button</button> `, { - moduleName: 'components/special-button' + moduleName: 'my-app/templates/components/special-button.hbs' }) ); }
true
Other
emberjs
ember.js
8b8ae79a1f78b3be1b39ae500cb9f85f65cfc3f7.json
Set proper moduleName values
packages/internal-test-helpers/lib/test-cases/abstract-rendering.js
@@ -98,8 +98,7 @@ export default class AbstractRenderingTestCase extends AbstractTestCase { registerPartial(name, template) { let owner = this.env.owner || this.owner; if (typeof template === 'string') { - let moduleName = `template:${name}`; - owner.register(moduleName, this.compile(template, { moduleName })); + owner.register(`template:${name}`, this.compile(template, { moduleName: `my-app/templates/-${name}.hbs` })); } } @@ -112,7 +111,7 @@ export default class AbstractRenderingTestCase extends AbstractTestCase { if (typeof template === 'string') { owner.register(`template:components/${name}`, this.compile(template, { - moduleName: `components/${name}` + moduleName: `my-app/templates/components/${name}.hbs` })); } } @@ -121,7 +120,7 @@ export default class AbstractRenderingTestCase extends AbstractTestCase { let { owner } = this; if (typeof template === 'string') { owner.register(`template:${name}`, this.compile(template, { - moduleName: name + moduleName: `my-app/templates/${name}.hbs` })); } else { throw new Error(`Registered template "${name}" must be a string`);
true
Other
emberjs
ember.js
8b8ae79a1f78b3be1b39ae500cb9f85f65cfc3f7.json
Set proper moduleName values
packages/internal-test-helpers/lib/test-cases/test-resolver-application.js
@@ -17,7 +17,7 @@ export default class TestResolverApplicationTestCase extends AbstractApplication addTemplate(templateName, templateString) { this.resolver.add(`template:${templateName}`, this.compile(templateString, { - moduleName: templateName + moduleName: `my-app/templates/${templateName}.hbs` })); } @@ -28,7 +28,7 @@ export default class TestResolverApplicationTestCase extends AbstractApplication if (typeof template === 'string') { this.resolver.add(`template:components/${name}`, this.compile(template, { - moduleName: `components/${name}` + moduleName: `my-app/templates/components/${name}.hbs` })); } }
true
Other
emberjs
ember.js
8b8ae79a1f78b3be1b39ae500cb9f85f65cfc3f7.json
Set proper moduleName values
packages/internal-test-helpers/lib/test-resolver.js
@@ -38,7 +38,7 @@ class Resolver { throw new Error(`You called addTemplate for "${templateName}" with a template argument of type of '${templateType}'. addTemplate expects an argument of an uncompiled template as a string.`); } return this._registered[serializeKey(`template:${templateName}`)] = compile(template, { - moduleName: templateName + moduleName: `my-app/templates/${templateName}.hbs` }); } static create() {
true
Other
emberjs
ember.js
9c2c2eaf256077203e242d0b3a31b6f27e3962ec.json
Add code sample to `trySet`
packages/ember-metal/lib/property_set.js
@@ -136,6 +136,13 @@ function setPath(root, path, value, tolerant) { This is primarily used when syncing bindings, which may try to update after an object has been destroyed. + + ```javascript + import { trySet } from '@ember/object'; + + let obj = { name: "Zoey" }; + trySet(obj, "contacts.twitter", "@emberjs"); + ``` @method trySet @static
false
Other
emberjs
ember.js
25c2ec05bb9364ad2a489864d4ac80015feb2630.json
Add v3.1.0-beta.3 to CHANGELOG [ci skip] (cherry picked from commit 7662c8a700448ed34f4bf7d726cc04b6a2765505)
CHANGELOG.md
@@ -1,5 +1,14 @@ # Ember Changelog +### v3.1.0-beta.3 (February 26, 2018) +- [#16271](https://github.com/emberjs/ember.js/pull/16271) [BUGFIX] Fix ChainNode unchaining +- [#16274](https://github.com/emberjs/ember.js/pull/16274) [BUGFIX] Ensure accessing a "proxy" itself does not error. +- [#16282](https://github.com/emberjs/ember.js/pull/16282) [BUGFIX] Fix nested ObserverSet flushes +- [#16285](https://github.com/emberjs/ember.js/pull/16285) [BUGFIX] Fix version with many special chars. +- [#16286](https://github.com/emberjs/ember.js/pull/16286) [BUGFIX] Update to [email protected]. +- [#16287](https://github.com/emberjs/ember.js/pull/16287) [BUGFIX] Update to [email protected]. +- [#16288](https://github.com/emberjs/ember.js/pull/16288) [BUGFIX] Ensure all "internal symbols" avoid the proxy assertion + ### v3.1.0-beta.2 (February 19, 2018) - [#13355](https://github.com/emberjs/ember.js/pull/13355) [BUGFIX] Fix issue with `Ember.trySet` on destroyed objects.
false
Other
emberjs
ember.js
5c6eef38fd59b58e1bf39ef3b8e1fc4e4064ab8f.json
Add failing tests for -addon blueprints with --pod * helper-addon * initializer-addon * instance-initializer-addon
node-tests/blueprints/helper-addon-test.js
@@ -24,5 +24,12 @@ describe('Blueprint: helper-addon', function() { .to.equal(fixture('helper-addon.js')); }); }); + + it('helper-addon foo/bar-baz --pod', function() { + return emberGenerateDestroy(['helper-addon', 'foo/bar-baz', '--pod'], _file => { + expect(_file('app/helpers/foo/bar-baz.js')) + .to.equal(fixture('helper-addon.js')); + }); + }); }); });
true
Other
emberjs
ember.js
5c6eef38fd59b58e1bf39ef3b8e1fc4e4064ab8f.json
Add failing tests for -addon blueprints with --pod * helper-addon * initializer-addon * instance-initializer-addon
node-tests/blueprints/initializer-addon-test.js
@@ -22,5 +22,12 @@ describe('Blueprint: initializer-addon', function() { .to.contain("export { default, initialize } from 'my-addon/initializers/foo';"); }); }); + + it('initializer-addon foo --pod', function() { + return emberGenerateDestroy(['initializer-addon', 'foo', '--pod'], _file => { + expect(_file('app/initializers/foo.js')) + .to.contain("export { default, initialize } from 'my-addon/initializers/foo';"); + }); + }); }); });
true
Other
emberjs
ember.js
5c6eef38fd59b58e1bf39ef3b8e1fc4e4064ab8f.json
Add failing tests for -addon blueprints with --pod * helper-addon * initializer-addon * instance-initializer-addon
node-tests/blueprints/instance-initializer-addon-test.js
@@ -22,5 +22,12 @@ describe('Blueprint: instance-initializer-addon', function() { .to.contain("export { default, initialize } from 'my-addon/instance-initializers/foo';"); }); }); + + it('instance-initializer-addon foo --pod', function() { + return emberGenerateDestroy(['instance-initializer-addon', 'foo', '--pod'], _file => { + expect(_file('app/instance-initializers/foo.js')) + .to.contain("export { default, initialize } from 'my-addon/instance-initializers/foo';"); + }); + }); }); });
true
Other
emberjs
ember.js
3509c99d6de5201cdb29dc4c267c60ed13f9801c.json
fix(link-to): add id to "inactive loading state" warning Without an ID, this triggers an assertion with the message "When calling warn you must provide an options hash as the third parameter. options should include an id property."
packages/ember-glimmer/lib/components/link-to.ts
@@ -628,7 +628,9 @@ const LinkComponent = EmberComponent.extend({ if (get(this, 'loading')) { // tslint:disable-next-line:max-line-length - warn('This link-to is in an inactive loading state because at least one of its parameters presently has a null/undefined value, or the provided route name is invalid.', false); + warn('This link-to is in an inactive loading state because at least one of its parameters presently has a null/undefined value, or the provided route name is invalid.', false, { + id: 'ember-glimmer.link-to.inactive-loading-state' + }); return false; }
false
Other
emberjs
ember.js
810c2c6a82ce797a6a9f3e397f4796c890e28b6b.json
Improve eachComputedProperty implementation
packages/ember-metal/lib/descriptor.js
@@ -16,6 +16,7 @@ class Descriptor extends EmberDescriptor { constructor(desc) { super(); this.desc = desc; + this.enumerable = desc.enumerable; } setup(obj, key) {
true
Other
emberjs
ember.js
810c2c6a82ce797a6a9f3e397f4796c890e28b6b.json
Improve eachComputedProperty implementation
packages/ember-metal/lib/index.js
@@ -72,8 +72,7 @@ export { } from './property_events'; export { defineProperty, - Descriptor, - _hasCachedComputedProperties + Descriptor } from './properties'; export { watchKey,
true
Other
emberjs
ember.js
810c2c6a82ce797a6a9f3e397f4796c890e28b6b.json
Improve eachComputedProperty implementation
packages/ember-metal/lib/meta.js
@@ -446,6 +446,27 @@ if (EMBER_METAL_ES5_GETTERS) { Meta.prototype.removeDescriptors = function(subkey) { this.writeDescriptors(subkey, UNDEFINED); }; + + Meta.prototype.forEachDescriptors = function(fn) { + let pointer = this; + let seen; + while (pointer !== undefined) { + let map = pointer._descriptors; + if (map !== undefined) { + for (let key in map) { + seen = seen === undefined ? new Set() : seen; + if (!seen.has(key)) { + seen.add(key); + let value = map[key]; + if (value !== UNDEFINED) { + fn(key, value); + } + } + } + } + pointer = pointer.parent; + } + }; } const getPrototypeOf = Object.getPrototypeOf;
true
Other
emberjs
ember.js
810c2c6a82ce797a6a9f3e397f4796c890e28b6b.json
Improve eachComputedProperty implementation
packages/ember-metal/lib/properties.js
@@ -7,7 +7,6 @@ import { HAS_NATIVE_PROXY } from 'ember-utils'; import { descriptorFor, meta as metaFor, peekMeta, DESCRIPTOR, UNDEFINED } from './meta'; import { overrideChains } from './property_events'; import { DESCRIPTOR_TRAP, EMBER_METAL_ES5_GETTERS, MANDATORY_SETTER } from 'ember/features'; -import { peekCacheFor } from './computed'; // .......................................................... // DESCRIPTOR // @@ -22,6 +21,7 @@ import { peekCacheFor } from './computed'; export class Descriptor { constructor() { this.isDescriptor = true; + this.enumerable = true; } } @@ -282,8 +282,6 @@ export function defineProperty(obj, keyName, desc, data, meta) { meta.writeDescriptors(keyName, value); } - didDefineComputedProperty(obj.constructor); - if (typeof desc.setup === 'function') { desc.setup(obj, keyName); } } else if (desc === undefined || desc === null) { value = data; @@ -333,17 +331,3 @@ export function defineProperty(obj, keyName, desc, data, meta) { return this; } - -let hasCachedComputedProperties = false; -export function _hasCachedComputedProperties() { - hasCachedComputedProperties = true; -} - -function didDefineComputedProperty(constructor) { - if (hasCachedComputedProperties === false) { return; } - - let cache = peekCacheFor(constructor); - if (cache !== undefined) { - cache.delete('_computedProperties'); - } -}
true
Other
emberjs
ember.js
810c2c6a82ce797a6a9f3e397f4796c890e28b6b.json
Improve eachComputedProperty implementation
packages/ember-runtime/lib/system/core_object.js
@@ -18,7 +18,6 @@ import { import { PROXY_CONTENT, descriptorFor, - get, meta, peekMeta, finishChains, @@ -27,12 +26,10 @@ import { REQUIRED, defineProperty, ComputedProperty, - computed, InjectedProperty, run, deleteMeta, - descriptor, - _hasCachedComputedProperties + descriptor } from 'ember-metal'; import ActionHandler from '../mixins/action_handler'; import { validatePropertyInjections } from '../inject'; @@ -917,35 +914,17 @@ let ClassMixinProps = { @private */ metaForProperty(key) { - let proto = this.proto(); + let proto = this.proto(); // ensure prototype is initialized let possibleDesc = descriptorFor(proto, key); assert( `metaForProperty() could not find a computed property with key '${key}'.`, possibleDesc !== undefined ); + return possibleDesc._meta || {}; }, - _computedProperties: computed(function() { - _hasCachedComputedProperties(); - let proto = this.proto(); - let possibleDesc; - let properties = []; - - for (let name in proto) { - possibleDesc = descriptorFor(proto, name); - - if (possibleDesc !== undefined) { - properties.push({ - name, - meta: possibleDesc._meta - }); - } - } - return properties; - }).readOnly(), - /** Iterate over each computed property for the class, passing its name and any associated metadata (see `metaForProperty`) to the callback. @@ -956,16 +935,16 @@ let ClassMixinProps = { @param {Object} binding @private */ - eachComputedProperty(callback, binding) { - let property; + eachComputedProperty(callback, binding = this) { + this.proto(); // ensure prototype is initialized let empty = {}; - let properties = get(this, '_computedProperties'); - - for (let i = 0; i < properties.length; i++) { - property = properties[i]; - callback.call(binding || this, property.name, property.meta || empty); - } + meta(this.prototype).forEachDescriptors((name, descriptor) => { + if (descriptor.enumerable) { + let meta = descriptor._meta || empty; + callback.call(binding, name, meta); + } + }); } };
true
Other
emberjs
ember.js
810c2c6a82ce797a6a9f3e397f4796c890e28b6b.json
Improve eachComputedProperty implementation
packages/ember-runtime/tests/system/object/computed_test.js
@@ -2,7 +2,8 @@ import { alias, computed, get as emberGet, - observer + observer, + defineProperty } from 'ember-metal'; import { testWithDefault } from 'internal-test-helpers'; import EmberObject from '../../../system/object'; @@ -149,6 +150,26 @@ QUnit.test('can retrieve metadata for a computed property', function(assert) { }, 'metaForProperty() could not find a computed property with key \'staticProperty\'.'); }); +QUnit.test('overriding a computed property with null removes it from eachComputedProperty iteration', function(assert) { + let MyClass = EmberObject.extend({ + foo: computed(function() {}), + + fooDidChange: observer('foo', function() {}), + + bar: computed(function() {}), + }); + + let SubClass = MyClass.extend({ + foo: null + }); + + let list = []; + + SubClass.eachComputedProperty(name => list.push(name)); + + assert.deepEqual(list.sort(), ['bar'], 'overridding with null removes from eachComputedProperty listing'); +}); + QUnit.test('can iterate over a list of computed properties for a class', function(assert) { let MyClass = EmberObject.extend({ foo: computed(function() {}), @@ -221,6 +242,16 @@ QUnit.test('list of properties updates when an additional property is added (suc }); assert.deepEqual(list.sort(), ['bar', 'foo', 'baz'].sort(), 'expected three computed properties'); + + defineProperty(MyClass.prototype, 'qux', computed(K)); + + list = []; + + MyClass.eachComputedProperty(function(name) { + list.push(name); + }); + + assert.deepEqual(list.sort(), ['bar', 'foo', 'baz', 'qux'].sort(), 'expected four computed properties'); }); QUnit.test('Calling _super in call outside the immediate function of a CP getter works', function(assert) {
true
Other
emberjs
ember.js
c6386c043f1c8aafc858f1990da51b1b041c1ff1.json
Remove unnecessary runTask
packages/ember-application/tests/system/visit_test.js
@@ -68,34 +68,32 @@ moduleFor('Application - visit()', class extends ApplicationTestCase { ENV._APPLICATION_TEMPLATE_WRAPPER = false; - return this.runTask(() => { - return this.visit('/', bootOptions) - .then((instance) => { + return this.visit('/', bootOptions) + .then((instance) => { + assert.equal( + instance.rootElement.firstChild.nodeValue, + '%+b:0%', + 'glimmer-vm comment node was not found' + ); + }).then(() =>{ + return this.runTask(()=>{ + this.applicationInstance.destroy(); + this.applicationInstance = null; + }); + }).then(() => { + bootOptions = { + isBrowser: false, + rootElement, + _renderMode: 'rehydrate' + }; + this.application.visit('/', bootOptions).then(instance => { assert.equal( - instance.rootElement.firstChild.nodeValue, - '%+b:0%', - 'glimmer-vm comment node was not found' + instance.rootElement.innerHTML, + indexTemplate, + 'was not properly rehydrated' ); }); - }).then(() =>{ - return this.runTask(()=>{ - this.applicationInstance.destroy(); - this.applicationInstance = null; }); - }).then(() => { - bootOptions = { - isBrowser: false, - rootElement, - _renderMode: 'rehydrate' - }; - this.application.visit('/', bootOptions).then(instance => { - assert.equal( - instance.rootElement.innerHTML, - indexTemplate, - 'was not properly rehydrated' - ); - }); - }); } // This tests whether the application is "autobooted" by registering an
false
Other
emberjs
ember.js
0627ae68cbbfbc7179f39ad0ed7eee670d5f371a.json
update serialized format to new glimmer-vm output This is meant to be a temporary test. Want a more robust test that doesn't rely on the actual serialization format of glimmer's serializer builder
packages/ember-application/tests/system/visit_test.js
@@ -55,7 +55,7 @@ moduleFor('Application - visit()', class extends ApplicationTestCase { [`@test _renderMode: rehydrate`](assert) { - let initialHTML = `<!--%+block:0%--><!--%+block:1%--><!--%+block:2%--><!--%+block:3%--><!--%+block:4%--><!--%+block:5%--><!--%+block:6%--><div class=\"foo\">Hi, Mom!</div><!--%-block:6%--><!--%-block:5%--><!--%-block:4%--><!--%-block:3%--><!--%-block:2%--><!--%-block:1%--><!--%-block:0%-->`; + let initialHTML = `<!--%+b:0%--><!--%+b:1%--><!--%+b:2%--><!--%+b:3%--><!--%+b:4%--><!--%+b:5%--><!--%+b:6%--><div class=\"foo\">Hi, Mom!</div><!--%-b:6%--><!--%-b:5%--><!--%-b:4%--><!--%-b:3%--><!--%-b:2%--><!--%-b:1%--><!--%-b:0%-->`; this.addTemplate('index', '<div class="foo">Hi, Mom!</div>'); let rootElement = document.createElement('div'); @@ -89,7 +89,7 @@ moduleFor('Application - visit()', class extends ApplicationTestCase { return this.visit('/', bootOptions).then(()=> { // The exact contents of this may change when the underlying // implementation changes in the glimmer vm - let expectedTemplate = `<!--%+block:0%--><!--%+block:1%--><!--%+block:2%--><!--%+block:3%--><!--%+block:4%--><!--%+block:5%--><!--%+block:6%--><div class=\"foo\">Hi, Mom!</div><!--%-block:6%--><!--%-block:5%--><!--%-block:4%--><!--%-block:3%--><!--%-block:2%--><!--%-block:1%--><!--%-block:0%-->`; + let expectedTemplate = `<!--%+b:0%--><!--%+b:1%--><!--%+b:2%--><!--%+b:3%--><!--%+b:4%--><!--%+b:5%--><!--%+b:6%--><div class=\"foo\">Hi, Mom!</div><!--%-b:6%--><!--%-b:5%--><!--%-b:4%--><!--%-b:3%--><!--%-b:2%--><!--%-b:1%--><!--%-b:0%-->`; assert.equal(rootElement.innerHTML, expectedTemplate, 'precond - without serialize flag renders as expected'); }); }
false
Other
emberjs
ember.js
882bbdd5df177fa4c9690679d91774e80bfbc269.json
Ensure correct signature for renderMain
packages/ember-glimmer/lib/renderer.ts
@@ -105,7 +105,7 @@ class RootState { env, self, dynamicScope, - builder: builder(env, { element: parentElement, nextSibling: null}), + builder(env, { element: parentElement, nextSibling: null }), handle ); let iteratorResult: IteratorResult<RenderResult>;
false
Other
emberjs
ember.js
45b9f15b874068f2e8d6c8789602e697942c0f40.json
Convert Descriptor and Alias to native classes
packages/ember-metal/lib/mixin.js
@@ -656,13 +656,13 @@ export function required() { return REQUIRED; } -function Alias(methodName) { - this.isDescriptor = true; - this.methodName = methodName; +class Alias extends Descriptor { + constructor(methodName) { + super(); + this.methodName = methodName; + } } -Alias.prototype = new Descriptor(); - /** Makes a method available via an additional name.
true
Other
emberjs
ember.js
45b9f15b874068f2e8d6c8789602e697942c0f40.json
Convert Descriptor and Alias to native classes
packages/ember-metal/lib/properties.js
@@ -19,8 +19,10 @@ import { peekCacheFor } from './computed'; @class Descriptor @private */ -export function Descriptor() { - this.isDescriptor = true; +export class Descriptor { + constructor() { + this.isDescriptor = true; + } } // ..........................................................
true
Other
emberjs
ember.js
455c4c44410f55c2d77258934d903dcd3328782e.json
Add v3.1.0-beta.2 to CHANGELOG [ci skip] (cherry picked from commit 0f8e2f4d823c590a76e0158960a8b05aeb5f64e1)
CHANGELOG.md
@@ -1,5 +1,11 @@ # Ember Changelog +### v3.1.0-beta.2 (February 19, 2018) + +- [#13355](https://github.com/emberjs/ember.js/pull/13355) [BUGFIX] Fix issue with `Ember.trySet` on destroyed objects. +- [#16245](https://github.com/emberjs/ember.js/pull/16245) [BUGFIX] Ensure errors in deferred component hooks can be recovered. +- [#16246](https://github.com/emberjs/ember.js/pull/16246) [BUGFIX] computed.sort should not sort if sortProperties is empty + ### v3.1.0-beta.1 (February 14, 2018) - [emberjs/rfcs#276](https://github.com/emberjs/rfcs/blob/master/text/0276-named-args.md) [FEATURE named-args] enabled by default.
false
Other
emberjs
ember.js
6e01000e4002910ddc966de07714323c101b95af.json
Remove Ember global from ember-glimmer loc tests
packages/ember-glimmer/tests/integration/helpers/loc-test.js
@@ -1,21 +1,20 @@ import { RenderingTest, moduleFor } from '../../utils/test-case'; import { set } from 'ember-metal'; -import Ember from 'ember'; +import { setStrings } from 'ember-runtime'; moduleFor('Helpers test: {{loc}}', class extends RenderingTest { constructor() { super(); - this.oldString = Ember.STRINGS; - Ember.STRINGS = { + setStrings({ 'Hello Friend': 'Hallo Freund', 'Hello': 'Hallo, %@' - }; + }); } teardown() { super.teardown(); - Ember.STRINGS = this.oldString; + setStrings({}); } ['@test it lets the original value through by default']() { @@ -91,6 +90,6 @@ moduleFor('Helpers test: {{loc}}', class extends RenderingTest { this.render(`{{loc greeting}}`, { greeting: 'Hello Friend' }); - this.assertText('Yup', 'the localized string is correct'); + this.assertText('Yup', 'the localized string is correct'); } });
false
Other
emberjs
ember.js
52c48d08158857329e8bdd52873fefca32780057.json
Remove custom manager test
packages/ember-glimmer/tests/integration/custom-component-manager-test.js
@@ -1,41 +0,0 @@ -import { moduleFor, RenderingTest } from '../utils/test-case'; -import { - GLIMMER_CUSTOM_COMPONENT_MANAGER -} from 'ember/features'; -import { AbstractComponentManager } from 'ember-glimmer'; - -if (GLIMMER_CUSTOM_COMPONENT_MANAGER) { - /* - Implementation of custom component manager, `ComponentManager` interface - */ - class TestComponentManager extends AbstractComponentManager { - create(env, definition) { - return definition.ComponentClass.create(); - } - - getDestructor(component) { - return component; - } - - getSelf() { - return null; - } - } - - moduleFor('Components test: curly components with custom manager', class extends RenderingTest { - ['@skip it can render a basic component with custom component manager'](assert) { - let managerId = 'test'; - this.owner.register(`component-manager:${managerId}`, new TestComponentManager()); - this.registerComponent('foo-bar', { - template: `{{use-component-manager "${managerId}"}}hello`, - managerId - }); - - this.render('{{foo-bar}}'); - - assert.equal(this.firstChild.className, 'hey-oh-lets-go', 'class name was set correctly'); - assert.equal(this.firstChild.tagName, 'P', 'tag name was set correctly'); - assert.equal(this.firstChild.getAttribute('manager-id'), managerId, 'custom attribute was set correctly'); - } - }); -}
false
Other
emberjs
ember.js
b3786610acdad73be20092876bf60f0b17af83c3.json
Add v3.1.0-beta.1 to CHANGELOG.md.
CHANGELOG.md
@@ -1,5 +1,14 @@ # Ember Changelog +### v3.1.0-beta.1 (February 14, 2018) + +- [emberjs/rfcs#276](https://github.com/emberjs/rfcs/blob/master/text/0276-named-args.md) [FEATURE named-args] enabled by default. +- [emberjs/rfcs#278](https://github.com/emberjs/rfcs/blob/master/text/0278-template-only-components.md) [FEATURE template-only-glimmer-components] Enable-able via `@ember/optional-features` addon. +- [emberjs/rfcs#280](https://github.com/emberjs/rfcs/blob/master/text/0280-remove-application-wrapper.md) [FEATURE application-template-wrapper] Enable-able via `@ember/optional-features` addon. +- [emberjs/rfcs#281](https://github.com/emberjs/rfcs/blob/master/text/0281-es5-getters.md) [FEATURE native-es5-getters] Enabled by default. +- [#15828](https://github.com/emberjs/ember.js/pull/15828) Upgrade glimmer-vm to latest version. +- [#16212](https://github.com/emberjs/ember.js/pull/16212) Update to [email protected]. + ### v3.0.0 (February 13, 2018) - [#16218](https://github.com/emberjs/ember.js/pull/16218) [BUGFIX beta] Prevent errors when using const `(get arr 1)`.
false
Other
emberjs
ember.js
080ba6643251209dd7f88974955aae5848bdc8e2.json
Add v3.0.0 to CHANGELOG.md.
CHANGELOG.md
@@ -1,16 +1,12 @@ # Ember Changelog -### 3.0.0-beta.6 (February 5, 2018) +### v3.0.0 (February 13, 2018) +- [#16218](https://github.com/emberjs/ember.js/pull/16218) [BUGFIX beta] Prevent errors when using const `(get arr 1)`. +- [#16241](https://github.com/emberjs/ember.js/pull/16241) [BUGFIX lts] Avoid excessively calling Glimmer AST transforms. - [#16199](https://github.com/emberjs/ember.js/pull/16199) [BUGFIX] Mention "computed properties" in the assertion message - [#16200](https://github.com/emberjs/ember.js/pull/16200) [BUGFIX] Prevent test error by converting illegal characters - -### 3.0.0-beta.5 (January 29, 2018) - - [#16179](https://github.com/emberjs/ember.js/pull/16179) [BUGFIX] Fix a few bugs in the caching ArrayProxy implementation - -### 3.0.0-beta.4 (January 25, 2018) - - [#16160](https://github.com/emberjs/ember.js/pull/16160) [BUGFIX] Remove humanize() call from generated test descriptions - [#16101](https://github.com/emberjs/ember.js/pull/16101) [CLEANUP] Remove legacy ArrayProxy features - [#16116](https://github.com/emberjs/ember.js/pull/16116) [CLEANUP] Remove private enumerable observers @@ -22,28 +18,17 @@ - [#16163](https://github.com/emberjs/ember.js/pull/16163) [CLEANUP] Remove unused path caches - [#16169](https://github.com/emberjs/ember.js/pull/16169) [BUGFIX] Fix various issues with descriptor trap. - [#16174](https://github.com/emberjs/ember.js/pull/16174) [BUGFIX] Enable _some_ recovery of errors thrown during render. - - -### 3.0.0-beta.3 (January 15, 2018) - - [#16095](https://github.com/emberjs/ember.js/pull/16095) [CLEANUP] Fix ember-2-legacy support for Ember.Binding. - [#16117](https://github.com/emberjs/ember.js/pull/16117) [BUGFIX] link-to active class applied when params change - [#16097](https://github.com/emberjs/ember.js/pull/16097) / [#16110](https://github.com/emberjs/ember.js/pull/16110) [CLEANUP] Remove `sync` runloop queue. - [#16099](https://github.com/emberjs/ember.js/pull/16099) [CLEANUP] Remove custom eventManager support. - -### 3.0.0-beta.2 (January 8, 2018) - - [#16067](https://github.com/emberjs/ember.js/pull/16067) [BUGFIX] Fix issues with `run.debounce` with only method and wait. - [#16045](https://github.com/emberjs/ember.js/pull/16045) [BUGFIX] Fix double debug output - [#16050](https://github.com/emberjs/ember.js/pull/16050) [BUGFIX] Add inspect and constructor to list of descriptor exceptions - [#16080](https://github.com/emberjs/ember.js/pull/16080) [BUGFIX] Add missing modules docs for tryInvoke, compare, isEqual #16079 - [#16084](https://github.com/emberjs/ember.js/pull/16084) [BUGFIX] Update `computed.sort` docs to avoid state leakage - [#16087](https://github.com/emberjs/ember.js/pull/16087) [BUGFIX] Ensure `App.visit` resolves when rendering completed. - [#16090](https://github.com/emberjs/ember.js/pull/16090) [CLEANUP] Remove Ember.Binding support - - -### 3.0.0-beta.1 (January 1, 2018) - - [#15901](https://github.com/emberjs/ember.js/pull/15901) [CLEANUP] Remove Ember.Handlebars.SafeString - [#15894](https://github.com/emberjs/ember.js/pull/15894) [CLEANUP] removed `immediateObserver` - [#15897](https://github.com/emberjs/ember.js/pull/15897) [CLEANUP] Remove controller wrapped param deprecation
false
Other
emberjs
ember.js
8222f4eafd2a1ff305cb1e465b359badb77097fb.json
Add v2.18.1 to CHANGELOG.md.
CHANGELOG.md
@@ -77,6 +77,11 @@ - [#16036](https://github.com/emberjs/ember.js/pull/16036) [CLEANUP] Convert ember-metal accessors tests to new style - [#16023](https://github.com/emberjs/ember.js/pull/16023) Make event dispatcher work without jQuery +### 2.18.1 (February 13, 2018) + +- [#16174](https://github.com/emberjs/ember.js/pull/16174) [BUGFIX] Enable _some_ recovery of errors thrown during render. +- [#16241](https://github.com/emberjs/ember.js/pull/16241) [BUGFIX] Avoid excessively calling Glimmer AST transforms. + ### 2.18.0 (January 1, 2018) - [95b449](https://github.com/emberjs/ember.js/commit/95b4499b3667712a202bef834268e23867fc8842) [BUGFIX] Ensure `Ember.run.cancel` while the run loop is flushing works properly.
false
Other
emberjs
ember.js
5112d7a4443670dbf965432540a468dc59b4e850.json
Add v2.17.1 to CHANGELOG.md (cherry picked from commit 6e0b9fdec1b500050e117744e3d7216d21833833)
CHANGELOG.md
@@ -91,6 +91,11 @@ - [#14590](https://github.com/emberjs/ember.js/pull/14590) [DEPRECATION] Deprecate using `targetObject`. - [#15754](https://github.com/emberjs/ember.js/pull/15754) [CLEANUP] Remove `router.router` deprecation. +### 2.17.1 (February 13, 2018) + +- [#16174](https://github.com/emberjs/ember.js/pull/16174) [BUGFIX] Enable _some_ recovery of errors thrown during render. +- [#16241](https://github.com/emberjs/ember.js/pull/16241) [BUGFIX] Avoid excessively calling Glimmer AST transforms. + ### 2.17.0 (November 29, 2017) - [#15855](https://github.com/emberjs/ember.js/pull/15855) [BUGFIX] fix regression with computed `filter/map/sort`
false
Other
emberjs
ember.js
85c78893f5ae84a8587755faa9f8c2d9073298c9.json
Add v2.16.2 to CHANGELOG.md.
CHANGELOG.md
@@ -114,6 +114,13 @@ - [#15265](https://github.com/emberjs/ember.js/pull/15265) [BUGFIX] fixed issue when passing `false` to `activeClass` for `{{link-to}}` - [#15672](https://github.com/emberjs/ember.js/pull/15672) Update router_js to 2.0.0. +### 2.16.3 (February 13, 2018) + +- [#15927](https://github.com/emberjs/ember.js/pull/15927) blueprints: Extend test framework detection to `ember-qunit` and `ember-mocha` +- [#15935](https://github.com/emberjs/ember.js/pull/15935) [BUGFIX] blueprints: fix framework detection to work with prerelease versions of ember-cli-mocha +- [#16174](https://github.com/emberjs/ember.js/pull/16174) [BUGFIX] Enable _some_ recovery of errors thrown during render. +- [#16241](https://github.com/emberjs/ember.js/pull/16241) [BUGFIX] Avoid excessively calling Glimmer AST transforms. + ### 2.16.2 (November 1, 2017) - [#15797](https://github.com/emberjs/ember.js/pull/15797) [BUGFIX] Fix issues with using partials nested within other partials.
false
Other
emberjs
ember.js
35889593cb05d8934413be96efa31a375fd0b4e3.json
Add referrer capability to the test resolver
packages/container/tests/registry_test.js
@@ -1,5 +1,10 @@ import { Registry, privatize } from '..'; -import { factory, moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { + factory, + moduleFor, + AbstractTestCase, + ModuleBasedTestResolver +} from 'internal-test-helpers'; import { EMBER_MODULE_UNIFICATION } from 'ember/features'; import { ENV } from 'ember-environment'; @@ -746,25 +751,25 @@ if (EMBER_MODULE_UNIFICATION) { moduleFor('Registry module unification', class extends AbstractTestCase { ['@test The registry can pass a source to the resolver'](assert) { let PrivateComponent = factory(); - let lookup = 'component:my-input'; + let type = 'component'; + let name = 'my-input'; + let specifier = `${type}:${name}`; let source = 'template:routes/application'; - let resolveCount = 0; - let resolver = { - resolve(fullName, src) { - resolveCount++; - if (fullName === lookup && src === source) { - return PrivateComponent; - } - } - }; + + let resolver = new ModuleBasedTestResolver(); + resolver.add({specifier, source}, PrivateComponent); let registry = new Registry({ resolver }); - registry.normalize = function(name) { - return name; - }; - assert.strictEqual(registry.resolve(lookup, { source }), PrivateComponent, 'The correct factory was provided'); - assert.strictEqual(registry.resolve(lookup, { source }), PrivateComponent, 'The correct factory was provided again'); - assert.equal(resolveCount, 1, 'resolve called only once and a cached factory was returned the second time'); + assert.strictEqual( + registry.resolve(specifier, { source }), + PrivateComponent, + 'The correct factory was provided' + ); + assert.strictEqual( + registry.resolve(specifier, { source }), + PrivateComponent, + 'The correct factory was provided again' + ); } }); }
true
Other
emberjs
ember.js
35889593cb05d8934413be96efa31a375fd0b4e3.json
Add referrer capability to the test resolver
packages/internal-test-helpers/lib/test-resolver.js
@@ -1,25 +1,43 @@ import { compile } from 'ember-template-compiler'; +const DELIMITER = '\0'; + +function serializeKey(specifier, source) { + return [specifier, source].join(DELIMITER); +} + class Resolver { constructor() { this._registered = {}; this.constructor.lastInstance = this; } - resolve(specifier) { - return this._registered[specifier]; + resolve(specifier, source) { + return this._registered[serializeKey(specifier, source)]; } - add(specifier, factory) { - if (specifier.indexOf(':') === -1) { - throw new Error('Specifiers added to the resolver must be in the format of type:name'); + add(lookup, factory) { + let key; + switch (typeof lookup) { + case 'string': + if (lookup.indexOf(':') === -1) { + throw new Error('Specifiers added to the resolver must be in the format of type:name'); + } + key = serializeKey(lookup); + break; + case 'object': + key = serializeKey(lookup.specifier, lookup.source); + break; + default: + throw new Error('Specifier string has an unknown type'); } - return this._registered[specifier] = factory; + + return this._registered[key] = factory; } addTemplate(templateName, template) { let templateType = typeof template; if (templateType !== 'string') { throw new Error(`You called addTemplate for "${templateName}" with a template argument of type of '${templateType}'. addTemplate expects an argument of an uncompiled template as a string.`); } - return this._registered[`template:${templateName}`] = compile(template, { + return this._registered[serializeKey(`template:${templateName}`)] = compile(template, { moduleName: templateName }); }
true
Other
emberjs
ember.js
7c4e925553ac3a0bdfcc14ba44d19c5719ab6c95.json
Fix failing tests
packages/ember-runtime/tests/helpers/array.js
@@ -49,9 +49,8 @@ const ArrayTestsObserverClass = EmberObject.extend({ return this; }, - observe(obj) { + observe(obj, ...keys) { if (obj.addObserver) { - let keys = Array.prototype.slice.call(arguments, 1); let loc = keys.length; while (--loc >= 0) {
true
Other
emberjs
ember.js
7c4e925553ac3a0bdfcc14ba44d19c5719ab6c95.json
Fix failing tests
packages/ember-runtime/tests/mutable-array/unshiftObjects-test.js
@@ -70,7 +70,7 @@ class UnshiftObjectsTests extends AbstractTestCase { this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once'); - this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); + this.assert.equal(observer.validate('firstObject'), true, 'should NOT have notified firstObject'); this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); } }
true
Other
emberjs
ember.js
30702be41b358b5cb8e65f3c66bb484342003d56.json
Kill Array Suites
packages/ember-runtime/tests/mixins/array_test.js
@@ -7,7 +7,6 @@ import { computed } from 'ember-metal'; import { testBoth } from 'internal-test-helpers'; -import { ArrayTests } from '../suites/array'; import EmberObject from '../../system/object'; import EmberArray, { addArrayObserver, @@ -53,26 +52,7 @@ const TestArray = EmberObject.extend(EmberArray, { }) }); - -ArrayTests.extend({ - - name: 'Basic Ember Array', - - newObject(ary) { - ary = ary ? ary.slice() : this.newFixture(3); - return new TestArray({ _content: ary }); - }, - - // allows for testing of the basic enumerable after an internal mutation - mutate(obj) { - obj.addObject(this.getFixture(1)[0]); - }, - - toArray(obj) { - return obj.slice(); - } - -}).run(); +QUnit.module('Ember.Array'); QUnit.test('the return value of slice has Ember.Array applied', function(assert) { let x = EmberObject.extend(EmberArray).create({
true
Other
emberjs
ember.js
30702be41b358b5cb8e65f3c66bb484342003d56.json
Kill Array Suites
packages/ember-runtime/tests/mixins/copyable_test.js
@@ -1,39 +0,0 @@ -import { generateGuid } from 'ember-utils'; -import CopyableTests from '../suites/copyable'; -import Copyable from '../../mixins/copyable'; -import EmberObject from '../../system/object'; -import { set, get } from 'ember-metal'; - -QUnit.module('Ember.Copyable'); - -const CopyableObject = EmberObject.extend(Copyable, { - id: null, - - init() { - this._super(...arguments); - set(this, 'id', generateGuid()); - }, - - copy() { - let ret = new CopyableObject(); - set(ret, 'id', get(this, 'id')); - return ret; - } -}); - -CopyableTests.extend({ - - name: 'Copyable Basic Test', - - newObject() { - return new CopyableObject(); - }, - - isEqual(a, b) { - if (!(a instanceof CopyableObject) || !(b instanceof CopyableObject)) { - return false; - } - - return get(a, 'id') === get(b, 'id'); - } -}).run();
true
Other
emberjs
ember.js
30702be41b358b5cb8e65f3c66bb484342003d56.json
Kill Array Suites
packages/ember-runtime/tests/mixins/mutable_array_test.js
@@ -1,69 +0,0 @@ -import { computed } from 'ember-metal'; -import MutableArrayTests from '../suites/mutable_array'; -import EmberObject from '../../system/object'; -import { A as emberA, MutableArray } from '../../mixins/array'; -import { - arrayContentDidChange, - arrayContentWillChange -} from '../../mixins/array'; - -/* - Implement a basic fake mutable array. This validates that any non-native - enumerable can impl this API. -*/ -const TestMutableArray = EmberObject.extend(MutableArray, { - - _content: null, - - init(ary = []) { - this._content = emberA(ary); - }, - - replace(idx, amt, objects) { - let args = objects ? objects.slice() : []; - let removeAmt = amt; - let addAmt = args.length; - - arrayContentWillChange(this, idx, removeAmt, addAmt); - - args.unshift(amt); - args.unshift(idx); - this._content.splice.apply(this._content, args); - arrayContentDidChange(this, idx, removeAmt, addAmt); - return this; - }, - - objectAt(idx) { - return this._content[idx]; - }, - - length: computed(function() { - return this._content.length; - }), - - slice() { - return this._content.slice(); - } - -}); - - -MutableArrayTests.extend({ - - name: 'Basic Mutable Array', - - newObject(ary) { - ary = ary ? ary.slice() : this.newFixture(3); - return new TestMutableArray(ary); - }, - - // allows for testing of the basic enumerable after an internal mutation - mutate(obj) { - obj.addObject(this.getFixture(1)[0]); - }, - - toArray(obj) { - return obj.slice(); - } - -}).run();
true
Other
emberjs
ember.js
30702be41b358b5cb8e65f3c66bb484342003d56.json
Kill Array Suites
packages/ember-runtime/tests/suites/array.js
@@ -1,204 +0,0 @@ -import { guidFor, generateGuid } from 'ember-utils'; -import { Suite } from './suite'; -import { computed, get } from 'ember-metal'; -import { - addArrayObserver, - removeArrayObserver -} from '../../mixins/array'; -import EmberObject from '../../system/object'; - -const ArrayTestsObserverClass = EmberObject.extend({ - init() { - this._super(...arguments); - this.isEnabled = true; - this.reset(); - }, - - reset() { - this._keys = {}; - this._values = {}; - this._before = null; - this._after = null; - return this; - }, - - observe(obj) { - if (obj.addObserver) { - let keys = Array.prototype.slice.call(arguments, 1); - let loc = keys.length; - - while (--loc >= 0) { - obj.addObserver(keys[loc], this, 'propertyDidChange'); - } - } else { - this.isEnabled = false; - } - return this; - }, - - observeArray(obj) { - addArrayObserver(obj, this); - return this; - }, - - stopObserveArray(obj) { - removeArrayObserver(obj, this); - return this; - }, - - propertyDidChange(target, key, value) { - if (this._keys[key] === undefined) { this._keys[key] = 0; } - this._keys[key]++; - this._values[key] = value; - }, - - arrayWillChange() { - QUnit.config.current.assert.equal(this._before, null, 'should only call once'); - this._before = Array.prototype.slice.call(arguments); - }, - - arrayDidChange() { - QUnit.config.current.assert.equal(this._after, null, 'should only call once'); - this._after = Array.prototype.slice.call(arguments); - }, - - validate(key, value) { - if (!this.isEnabled) { - return true; - } - - if (!this._keys[key]) { - return false; - } - - if (arguments.length > 1) { - return this._values[key] === value; - } else { - return true; - } - }, - - timesCalled(key) { - return this._keys[key] || 0; - } -}); - -const ArrayTests = Suite.extend({ - /* - __Required.__ You must implement this method to apply this mixin. - - Implement to return a new enumerable object for testing. Should accept - either no parameters, a single number (indicating the desired length of - the collection) or an array of objects. - - @param {Array} content - An array of items to include in the enumerable optionally. - - @returns {Ember.Enumerable} a new enumerable - */ - newObject: null, - - /* - Implement to return a set of new fixture strings that can be applied to - the enumerable. This may be passed into the newObject method. - - @param {Number} count - The number of items required. - - @returns {Array} array of strings - */ - newFixture(cnt) { - let ret = []; - while (--cnt >= 0) { - ret.push(generateGuid()); - } - - return ret; - }, - - /* - Implement to return a set of new fixture objects that can be applied to - the enumerable. This may be passed into the newObject method. - - @param {Number} cnt - The number of items required. - - @returns {Array} array of objects - */ - newObjectsFixture(cnt) { - let ret = []; - let item; - while (--cnt >= 0) { - item = {}; - guidFor(item); - ret.push(item); - } - return ret; - }, - - /* - __Required.__ You must implement this method to apply this mixin. - - Implement accept an instance of the enumerable and return an array - containing the objects in the enumerable. This is used only for testing - so performance is not important. - - @param {Ember.Enumerable} enumerable - The enumerable to convert. - - @returns {Array} array of items - */ - toArray: null, - - /* - Implement this method if your object can mutate internally (even if it - does not support the MutableEnumerable API). The method should accept - an object of your desired type and modify it somehow. Suite tests will - use this to ensure that all appropriate caches, etc. clear when the - mutation occurs. - - If you do not define this optional method, then mutation-related tests - will be skipped. - - @param {Ember.Enumerable} enumerable - The enumerable to mutate - - @returns {void} - */ - mutate() {}, - - /* - Becomes true when you define a new mutate() method, indicating that - mutation tests should run. This is calculated automatically. - - @type Boolean - */ - canTestMutation: computed(function() { - return this.mutate !== ArrayTests.prototype.mutate; - }), - - /* - Invoked to actually run the test - overridden by mixins - */ - run() {}, - - /* - Creates a new observer object for testing. You can add this object as an - observer on an array and it will record results anytime it is invoked. - After running the test, call the validate() method on the observer to - validate the results. - */ - newObserver(/* obj */) { - let ret = get(this, 'observerClass').create(); - - if (arguments.length > 0) { - ret.observe.apply(ret, arguments); - } - - return ret; - }, - - observerClass: ArrayTestsObserverClass -}); - -export { ArrayTests };
true
Other
emberjs
ember.js
30702be41b358b5cb8e65f3c66bb484342003d56.json
Kill Array Suites
packages/ember-runtime/tests/suites/copyable.js
@@ -1,32 +0,0 @@ -import { Suite } from './suite'; - -const CopyableTests = Suite.extend({ - - /* - __Required.__ You must implement this method to apply this mixin. - - Must be able to create a new object for testing. - - @returns {Object} object - */ - newObject: null, - - /* - __Required.__ You must implement this method to apply this mixin. - - Compares the two passed in objects. Returns true if the two objects - are logically equivalent. - - @param {Object} a - First object - - @param {Object} b - Second object - - @returns {Boolean} - */ - isEqual: null - -}); - -export default CopyableTests;
true
Other
emberjs
ember.js
30702be41b358b5cb8e65f3c66bb484342003d56.json
Kill Array Suites
packages/ember-runtime/tests/suites/mutable_array.js
@@ -1,5 +0,0 @@ -import { ArrayTests } from './array'; - -const MutableArrayTests = ArrayTests.extend(); - -export default MutableArrayTests;
true
Other
emberjs
ember.js
30702be41b358b5cb8e65f3c66bb484342003d56.json
Kill Array Suites
packages/ember-runtime/tests/suites/suite.js
@@ -1,143 +0,0 @@ -import { guidFor } from 'ember-utils'; -import EmberObject from '../../system/object'; -import { get } from 'ember-metal'; - -/* - @class - A Suite can be used to define a reusable set of unit tests that can be - applied to any object. Suites are most useful for defining tests that - work against a mixin or plugin API. Developers implementing objects that - use the mixin or support the API can then run these tests against their - own code to verify compliance. - - To define a suite, you need to define the tests themselves as well as a - callback API implementers can use to tie your tests to their specific class. - - ## Defining a Callback API - - To define the callback API, just extend this class and add your properties - or methods that must be provided. - - ## Defining Unit Tests - - To add unit tests, use the suite.module() or suite.test() methods instead - of a regular module() or test() method when defining your tests. This will - add the tests to the suite. - - ## Using a Suite - - To use a Suite to test your own objects, extend the suite subclass and - define any required methods. Then call run() on the new subclass. This - will create an instance of your class and then defining the unit tests. - - @extends Ember.Object - @private -*/ -const Suite = EmberObject.extend({ - - /* - __Required.__ You must implement this method to apply this mixin. - - Define a name for these tests - all modules are prefixed w/ it. - - @type String - */ - name: null, - - /* - Invoked to actually run the test - overridden by mixins - */ - run() {} - -}); - -Suite.reopenClass({ - - plan: null, - - run() { - let C = this; - return new C().run(); - }, - - module(desc, opts) { - if (!opts) { - opts = {}; - } - - let setup = opts.setup || opts.beforeEach; - let teardown = opts.teardown || opts.afterEach; - this.reopen({ - run() { - this._super(...arguments); - let title = get(this, 'name') + ': ' + desc; - let ctx = this; - QUnit.module(title, { - beforeEach(assert) { - if (setup) { - setup.call(ctx, assert); - } - }, - - afterEach(assert) { - if (teardown) { - teardown.call(ctx, assert); - } - } - }); - } - }); - }, - - test(name, func) { - this.reopen({ - run() { - this._super(...arguments); - let ctx = this; - - if (!func) { - QUnit.test(name); // output warning - } else { - QUnit.test(name, (assert) => func.call(ctx, assert)); - } - } - }); - }, - - // convert to guids to minimize logging. - same(actual, exp, message) { - actual = (actual && actual.map) ? actual.map(x => guidFor(x)) : actual; - exp = (exp && exp.map) ? exp.map(x => guidFor(x)) : exp; - return deepEqual(actual, exp, message); - }, - - // easy way to disable tests - notest() {}, - - importModuleTests(builder) { - this.module(builder._module); - - builder._tests.forEach((descAndFunc) => { - this.test.apply(this, descAndFunc); - }); - } -}); - -const SuiteModuleBuilder = EmberObject.extend({ - _module: null, - _tests: null, - - init() { - this._tests = []; - }, - - module(name) { this._module = name; }, - - test(name, func) { - this._tests.push([name, func]); - } -}); - -export { SuiteModuleBuilder, Suite }; - -export default Suite;
true
Other
emberjs
ember.js
30702be41b358b5cb8e65f3c66bb484342003d56.json
Kill Array Suites
packages/ember-runtime/tests/system/array_proxy/suite_test.js
@@ -1,21 +0,0 @@ -import MutableArrayTests from '../../suites/mutable_array'; -import ArrayProxy from '../../../system/array_proxy'; -import { get } from 'ember-metal'; -import { A as emberA } from '../../../mixins/array'; - -MutableArrayTests.extend({ - name: 'Ember.ArrayProxy', - - newObject(ary) { - let ret = ary ? ary.slice() : this.newFixture(3); - return ArrayProxy.create({ content: emberA(ret) }); - }, - - mutate(obj) { - obj.pushObject(get(obj, 'length') + 1); - }, - - toArray(obj) { - return obj.toArray ? obj.toArray() : obj.slice(); - } -}).run();
true
Other
emberjs
ember.js
30702be41b358b5cb8e65f3c66bb484342003d56.json
Kill Array Suites
packages/ember-runtime/tests/system/native_array/copyable_suite_test.js
@@ -1,31 +1,4 @@ -import { generateGuid } from 'ember-utils'; import { A as emberA } from '../../../mixins/array'; -import CopyableTests from '../../suites/copyable'; - -CopyableTests.extend({ - name: 'NativeArray Copyable', - - newObject() { - return emberA([generateGuid()]); - }, - - isEqual(a, b) { - if (!(a instanceof Array)) { - return false; - } - - if (!(b instanceof Array)) { - return false; - } - - if (a.length !== b.length) { - return false; - } - - return a[0] === b[0]; - } - -}).run(); QUnit.module('NativeArray Copyable');
true
Other
emberjs
ember.js
30702be41b358b5cb8e65f3c66bb484342003d56.json
Kill Array Suites
packages/ember-runtime/tests/system/native_array/suite_test.js
@@ -1,18 +0,0 @@ -import { A as emberA } from '../../../mixins/array'; -import MutableArrayTests from '../../suites/mutable_array'; - -MutableArrayTests.extend({ - name: 'Native Array', - - newObject(ary) { - return emberA(ary ? ary.slice() : this.newFixture(3)); - }, - - mutate(obj) { - obj.pushObject(obj.length + 1); - }, - - toArray(obj) { - return obj.slice(); // make a copy. - } -}).run();
true
Other
emberjs
ember.js
235193ef315cf2351e942da277b3d3ace245a400.json
Get new infra in place
packages/ember-runtime/tests/mixins/array_test.js
@@ -56,7 +56,7 @@ const TestArray = EmberObject.extend(EmberArray, { ArrayTests.extend({ - name: 'Basic Mutable Array', + name: 'Basic Ember Array', newObject(ary) { ary = ary ? ary.slice() : this.newFixture(3);
true
Other
emberjs
ember.js
235193ef315cf2351e942da277b3d3ace245a400.json
Get new infra in place
packages/ember-runtime/tests/suites/array.js
@@ -201,7 +201,7 @@ const ArrayTests = Suite.extend({ observerClass: ArrayTestsObserverClass }); -import anyTests from './array/any'; +// import './array/any'; import compactTests from './array/compact'; import everyTests from './array/every'; import filterTests from './array/filter'; @@ -225,7 +225,7 @@ import uniqByTests from './array/uniqBy'; import uniqTests from './array/uniq'; import withoutTests from './array/without'; -ArrayTests.importModuleTests(anyTests); +// ArrayTests.importModuleTests(anyTests); ArrayTests.importModuleTests(compactTests); ArrayTests.importModuleTests(everyTests); ArrayTests.importModuleTests(filterTests);
true
Other
emberjs
ember.js
235193ef315cf2351e942da277b3d3ace245a400.json
Get new infra in place
packages/ember-runtime/tests/suites/array/any.js
@@ -1,67 +1,167 @@ -import { SuiteModuleBuilder } from '../suite'; +// import { SuiteModuleBuilder } from '../suite'; import { A as emberA } from '../../../mixins/array'; +import { get } from 'ember-metal'; +import { AbstractTestCase, moduleFor } from 'internal-test-helpers'; +import { generateGuid } from 'ember-utils'; +import ArrayProxy from '../../../system/array_proxy'; -const suite = SuiteModuleBuilder.create(); +// const suite = SuiteModuleBuilder.create(); // .......................................................... // any() // -suite.module('any'); - -suite.test('any should should invoke callback on each item as long as you return false', function(assert) { - let obj = this.newObject(); - let ary = this.toArray(obj); - let found = []; - let result; - - result = obj.any(function(i) { - found.push(i); - return false; - }); - assert.equal(result, false, 'return value of obj.any'); - assert.deepEqual(found, ary, 'items passed during any() should match'); -}); - -suite.test('any should stop invoking when you return true', function(assert) { - let obj = this.newObject(); - let ary = this.toArray(obj); - let cnt = ary.length - 2; - let exp = cnt; - let found = []; - let result; - - result = obj.any(function(i) { - found.push(i); - return --cnt <= 0; - }); - assert.equal(result, true, 'return value of obj.any'); - assert.equal(found.length, exp, 'should invoke proper number of times'); - assert.deepEqual(found, ary.slice(0, -2), 'items passed during any() should match'); -}); - -suite.test('any should return true if any object matches the callback', function(assert) { - let obj = emberA([0, 1, 2]); - let result; - - result = obj.any(i => !!i); - assert.equal(result, true, 'return value of obj.any'); -}); - -suite.test('any should return false if no object matches the callback', function(assert) { - let obj = emberA([0, null, false]); - let result; - - result = obj.any(i => !!i); - assert.equal(result, false, 'return value of obj.any'); -}); - -suite.test('any should produce correct results even if the matching element is undefined', function(assert) { - let obj = emberA([undefined]); - let result; - - result = obj.any(() => true); - assert.equal(result, true, 'return value of obj.any'); -}); - -export default suite; +// class AbstractArrayHelpers { +// newObject() { +// throw new Error('Must implement'); +// } + +// toArray() { +// throw new Error('Must implement'); +// } +// } + +// class AbstractArrayTests extends AbstractTestCase { +// constructor(ArrayHelpers) { +// super(); +// this.ArrayHelpers = ArrayHelpers; +// } + +// newObject() { +// return new this.ArrayHelpers().newObject(...arguments); +// } + +// toArray() { +// return new this.ArrayHelpers().toArray(...arguments); +// } +// } + +class NativeArrayHelpers { + newObject(ary) { + return emberA(ary ? ary.slice() : this.newFixture(3)); + } + + newFixture(cnt) { + let ret = []; + while (--cnt >= 0) { + ret.push(generateGuid()); + } + + return ret; + } + + mutate(obj) { + obj.pushObject(obj.length + 1); + } + + toArray(obj) { + return obj.slice(); + } +} + +class AbstractArrayHelper { + newFixture(cnt) { + let ret = []; + while (--cnt >= 0) { + ret.push(generateGuid()); + } + + return ret; + } +} + +class ArrayProxyHelpers extends AbstractArrayHelper { + newObject(ary) { + let ret = ary ? ary.slice() : this.newFixture(3); + return ArrayProxy.create({ content: emberA(ret) }); + } + + mutate(obj) { + obj.pushObject(get(obj, 'length') + 1); + } + + toArray(obj) { + return obj.toArray ? obj.toArray() : obj.slice(); + } +} + +// class ArrayProxyTests extends AbstractArrayTests { +// newObject(ary) { +// let ret = ary ? ary.slice() : this.newFixture(3); +// return ArrayProxy.create({ content: emberA(ret) }); +// } + +// mutate(obj) { +// obj.pushObject(get(obj, 'length') + 1); +// } + +// toArray(obj) { +// return obj.toArray ? obj.toArray() : obj.slice(); +// } +// } + + +// function f(K, S) { +// return class K extends S { + +// }; +// } + +// moduleFor('any', f(class { +// d() { +// this.newObject(); +// } +// }, ArrayProxyTests)); + +class AnyTests extends AbstractTestCase { + '@test any should should invoke callback on each item as long as you return false'() { + let obj = this.newObject(); + let ary = this.toArray(obj); + let found = []; + let result; + + result = obj.any(function(i) { + found.push(i); + return false; + }); + + this.assert.equal(result, false, 'return value of obj.any'); + this.assert.deepEqual(found, ary, 'items passed during any() should match'); + } + + '@test any should stop invoking when you return true'() { + let obj = this.newObject(); + let ary = this.toArray(obj); + let cnt = ary.length - 2; + let exp = cnt; + let found = []; + let result; + + result = obj.any(function(i) { + found.push(i); + return --cnt <= 0; + }); + this.assert.equal(result, true, 'return value of obj.any'); + this.assert.equal(found.length, exp, 'should invoke proper number of times'); + this.assert.deepEqual(found, ary.slice(0, -2), 'items passed during any() should match'); + } + + '@test any should return true if any object matches the callback'() { + let obj = emberA([0, 1, 2]); + let result; + + result = obj.any(i => !!i); + this.assert.equal(result, true, 'return value of obj.any'); + } + + '@test any should produce correct results even if the matching element is undefined'(assert) { + let obj = emberA([undefined]); + let result; + + result = obj.any(() => true); + assert.equal(result, true, 'return value of obj.any'); + } +} + +moduleFor('[NEW] NativeArray: any', AnyTests, NativeArrayHelpers); +moduleFor('[NEW] ArrayProxy: any', AnyTests, ArrayProxyHelpers); \ No newline at end of file
true
Other
emberjs
ember.js
235193ef315cf2351e942da277b3d3ace245a400.json
Get new infra in place
packages/internal-test-helpers/lib/apply-mixins.js
@@ -15,11 +15,17 @@ export default function applyMixins(TestClass, ...mixins) { generator.cases.forEach((value, idx) => { assign(mixin, generator.generate(value, idx)); }); + + assign(TestClass.prototype, mixin); + } else if (typeof mixinOrGenerator === 'function') { + mixin = new mixinOrGenerator(); + assign(TestClass.prototype, mixin.__proto__); } else { mixin = mixinOrGenerator; + assign(TestClass.prototype, mixin); } - assign(TestClass.prototype, mixin); + }); return TestClass;
true
Other
emberjs
ember.js
235193ef315cf2351e942da277b3d3ace245a400.json
Get new infra in place
packages/internal-test-helpers/lib/module-for.js
@@ -38,7 +38,9 @@ export default function moduleFor(description, TestClass, ...mixins) { } }); - applyMixins(TestClass, mixins); + if (mixins.length > 0) { + applyMixins(TestClass, ...mixins); + } let proto = TestClass.prototype;
true
Other
emberjs
ember.js
93080b5879d02412b737eacaaf25e0f0d8e7db9e.json
Update semver regex to support uppercase branches Having an uppercase character within your git branch name would cause the regex to fail. Updating the regex to support this use case.
packages/ember-metal/tests/main_test.js
@@ -1,7 +1,7 @@ import Ember from '..'; // testing reexports -// From sindresourhus/semver-regex https://github.com/sindresorhus/semver-regex/blob/795b05628d96597ebcbe6d31ef4a432858365582/index.js#L3 -const SEMVER_REGEX = /^\bv?(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?\b$/; +// From https://github.com/semver/semver.org/issues/59 & https://regex101.com/r/vW1jA8/6 +const SEMVER_REGEX = /^((?:0|(?:[1-9]\d*)))\.((?:0|(?:[1-9]\d*)))\.((?:0|(?:[1-9]\d*)))(?:-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$/; QUnit.module('ember-metal/core/main'); @@ -26,6 +26,7 @@ QUnit.test('SEMVER_REGEX properly validates and invalidates version numbers', fu validateVersionString('1.0.0-beta.16.1', true); validateVersionString('1.12.1+canary.aba1412', true); validateVersionString('2.0.0-beta.1+canary.bb344775', true); + validateVersionString('3.1.0-foobarBaz+30d70bd3', true); // Negative test cases validateVersionString('1.11.3.aba18a', false);
false
Other
emberjs
ember.js
bb506f48135df05450e97fe34ce04a627dd3004c.json
Move TestAdapter tests into ember-testing
packages/ember-testing/lib/index.js
@@ -1,6 +1,5 @@ export { default as Test } from './test'; export { default as Adapter } from './adapters/adapter'; -export { setAdapter, getAdapter } from './test/adapter'; export { default as setupForTesting } from './setup_for_testing'; export { default as QUnitAdapter } from './adapters/qunit';
true
Other
emberjs
ember.js
bb506f48135df05450e97fe34ce04a627dd3004c.json
Move TestAdapter tests into ember-testing
packages/ember-testing/tests/adapters_test.js
@@ -1,13 +1,26 @@ -import { run } from 'ember-metal'; +import { run, setOnerror } from 'ember-metal'; import Test from '../test'; import Adapter from '../adapters/adapter'; import QUnitAdapter from '../adapters/qunit'; import { Application as EmberApplication } from 'ember-application'; import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { RSVP } from 'ember-runtime'; var App, originalAdapter, originalQUnit, originalWindowOnerror; -moduleFor('ember-testing Adapters', class extends AbstractTestCase { +function runThatThrowsSync(message = 'Error for testing error handling') { + return run(() => { + throw new Error(message); + }); +} + +function runThatThrowsAsync(message = 'Error for testing error handling') { + return run.next(() => { + throw new Error(message); + }); +} + +class AdapterSetupAndTearDown extends AbstractTestCase { constructor() { super(); originalAdapter = Test.adapter; @@ -25,8 +38,11 @@ moduleFor('ember-testing Adapters', class extends AbstractTestCase { Test.adapter = originalAdapter; window.QUnit = originalQUnit; window.onerror = originalWindowOnerror; + setOnerror(undefined); } +} +moduleFor('ember-testing Adapters', class extends AdapterSetupAndTearDown { ['@test Setting a test adapter manually'](assert) { assert.expect(1); var CustomAdapter; @@ -94,4 +110,228 @@ moduleFor('ember-testing Adapters', class extends AbstractTestCase { assert.equal(caughtInAdapter, undefined, 'test adapter should never receive synchronous errors'); assert.equal(caughtInCatch, thrown, 'a "normal" try/catch should catch errors in sync run'); } + + ['@test when both Ember.onerror (which rethrows) and TestAdapter are registered - sync run'](assert) { + assert.expect(2); + + Test.adapter = { + exception() { + assert.notOk(true, 'adapter is not called for errors thrown in sync run loops'); + } + }; + + setOnerror(function(error) { + assert.ok(true, 'onerror is called for sync errors even if TestAdapter is setup'); + throw error; + }); + + assert.throws(runThatThrowsSync, Error, 'error is thrown'); + } + + ['@test when both Ember.onerror (which does not rethrow) and TestAdapter are registered - sync run'](assert) { + assert.expect(2); + + Test.adapter = { + exception() { + assert.notOk(true, 'adapter is not called for errors thrown in sync run loops'); + } + }; + + setOnerror(function() { + assert.ok(true, 'onerror is called for sync errors even if TestAdapter is setup'); + }); + + runThatThrowsSync(); + assert.ok(true, 'no error was thrown, Ember.onerror can intercept errors'); + } + + ['@test when TestAdapter is registered and error is thrown - async run'](assert) { + assert.expect(3); + let done = assert.async(); + + let caughtInAdapter, caughtInCatch, caughtByWindowOnerror; + Test.adapter = { + exception(error) { + caughtInAdapter = error; + } + }; + + window.onerror = function(message) { + caughtByWindowOnerror = message; + // prevent "bubbling" and therefore failing the test + return true; + }; + + try { + runThatThrowsAsync(); + } catch(e) { + caughtInCatch = e; + } + + setTimeout(() => { + assert.equal(caughtInAdapter, undefined, 'test adapter should never catch errors in run loops'); + assert.equal(caughtInCatch, undefined, 'a "normal" try/catch should never catch errors in an async run'); + + assert.pushResult({ + result: /Error for testing error handling/.test(caughtByWindowOnerror), + actual: caughtByWindowOnerror, + expected: 'to include `Error for testing error handling`', + message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)' + }); + + done(); + }, 20); + } + + ['@test when both Ember.onerror and TestAdapter are registered - async run'](assert) { + assert.expect(1); + let done = assert.async(); + + Test.adapter ={ + exception() { + assert.notOk(true, 'Adapter.exception is not called for errors thrown in run.next'); + } + }; + + setOnerror(function() { + assert.ok(true, 'onerror is invoked for errors thrown in run.next/run.later'); + }); + + runThatThrowsAsync(); + setTimeout(done, 10); + } }); + + +function testAdapter(message, generatePromise, timeout = 10) { + return class PromiseFailureTests extends AdapterSetupAndTearDown { + [`@test ${message} when TestAdapter without \`exception\` method is present - rsvp`](assert) { + assert.expect(1); + + let thrown = new Error('the error'); + Test.adapter = QUnitAdapter.create({ + exception: undefined + }); + + window.onerror = function(message) { + assert.pushResult({ + result: /the error/.test(message), + actual: message, + expected: 'to include `the error`', + message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)' + }); + + // prevent "bubbling" and therefore failing the test + return true; + }; + + generatePromise(thrown); + + // RSVP.Promise's are configured to settle within the run loop, this + // ensures that run loop has completed + return new RSVP.Promise((resolve) => setTimeout(resolve, timeout)); + } + + [`@test ${message} when both Ember.onerror and TestAdapter without \`exception\` method are present - rsvp`](assert) { + assert.expect(1); + + let thrown = new Error('the error'); + Test.adapter = QUnitAdapter.create({ + exception: undefined + }); + + setOnerror(function(error) { + assert.pushResult({ + result: /the error/.test(error.message), + actual: error.message, + expected: 'to include `the error`', + message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)' + }); + }); + + generatePromise(thrown); + + // RSVP.Promise's are configured to settle within the run loop, this + // ensures that run loop has completed + return new RSVP.Promise((resolve) => setTimeout(resolve, timeout)); + } + + [`@test ${message} when TestAdapter is present - rsvp`](assert) { + assert.expect(1); + + let thrown = new Error('the error'); + Test.adapter = QUnitAdapter.create({ + exception(error) { + assert.strictEqual(error, thrown, 'Adapter.exception is called for errors thrown in RSVP promises'); + } + }); + + generatePromise(thrown); + + // RSVP.Promise's are configured to settle within the run loop, this + // ensures that run loop has completed + return new RSVP.Promise((resolve) => setTimeout(resolve, timeout)); + } + + [`@test ${message} when both Ember.onerror and TestAdapter are present - rsvp`](assert) { + assert.expect(1); + + let thrown = new Error('the error'); + Test.adapter = QUnitAdapter.create({ + exception(error) { + assert.strictEqual(error, thrown, 'Adapter.exception is called for errors thrown in RSVP promises'); + } + }); + + setOnerror(function() { + assert.notOk(true, 'Ember.onerror is not called if Test.adapter does not rethrow'); + }); + + generatePromise(thrown); + + // RSVP.Promise's are configured to settle within the run loop, this + // ensures that run loop has completed + return new RSVP.Promise((resolve) => setTimeout(resolve, timeout)); + } + + [`@test ${message} when both Ember.onerror and TestAdapter are present - rsvp`](assert) { + assert.expect(2); + + let thrown = new Error('the error'); + Test.adapter = QUnitAdapter.create({ + exception(error) { + assert.strictEqual(error, thrown, 'Adapter.exception is called for errors thrown in RSVP promises'); + throw error; + } + }); + + setOnerror(function(error) { + assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises if Test.adapter rethrows'); + }); + + generatePromise(thrown); + + // RSVP.Promise's are configured to settle within the run loop, this + // ensures that run loop has completed + return new RSVP.Promise((resolve) => setTimeout(resolve, timeout)); + } + }; +} + +moduleFor('Adapter Errors: .then callback', testAdapter('errors in promise constructor', (error) => { + new RSVP.Promise(() => { + throw error; + }); +})); + +moduleFor('Adapter Errors: Promise Contructor', testAdapter('errors in promise constructor', (error) => { + RSVP.resolve().then(() => { + throw error; + }); +})); + +moduleFor('Adapter Errors: Promise chain .then callback', testAdapter('errors in promise constructor', (error) => { + new RSVP.Promise((resolve) => setTimeout(resolve, 10)).then(() => { + throw error; + }); +}, 20)); \ No newline at end of file
true
Other
emberjs
ember.js
bb506f48135df05450e97fe34ce04a627dd3004c.json
Move TestAdapter tests into ember-testing
packages/ember/tests/error_handler_test.js
@@ -1,21 +1,12 @@ import { isTesting, setTesting } from 'ember-debug'; import { run, getOnerror, setOnerror } from 'ember-metal'; -import { DEBUG } from 'ember-env-flags'; import RSVP from 'rsvp'; -import require, { has } from 'require'; let WINDOW_ONERROR; -let setAdapter; -let QUnitAdapter; QUnit.module('error_handler', { beforeEach() { - if (has('ember-testing')) { - let testing = require('ember-testing'); - setAdapter = testing.setAdapter; - QUnitAdapter = testing.QUnitAdapter; - } // capturing this outside of module scope to ensure we grab // the test frameworks own window.onerror to reset it WINDOW_ONERROR = window.onerror; @@ -25,12 +16,7 @@ QUnit.module('error_handler', { setTesting(isTesting); window.onerror = WINDOW_ONERROR; - if (setAdapter) { - setAdapter(); - } - setOnerror(undefined); - } }); @@ -40,12 +26,6 @@ function runThatThrowsSync(message = 'Error for testing error handling') { }); } -function runThatThrowsAsync(message = 'Error for testing error handling') { - return run.next(() => { - throw new Error(message); - }); -} - QUnit.test('by default there is no onerror - sync run', function(assert) { assert.strictEqual(getOnerror(), undefined, 'precond - there should be no Ember.onerror set by default'); assert.throws(runThatThrowsSync, Error, 'errors thrown sync are catchable'); @@ -69,110 +49,6 @@ QUnit.test('when Ember.onerror (which does not rethrow) is registered - sync run assert.ok(true, 'no error was thrown, Ember.onerror can intercept errors'); }); -if (DEBUG) { - QUnit.test('when TestAdapter is registered and error is thrown - sync run', function(assert) { - assert.expect(1); - - setAdapter({ - exception() { - assert.notOk(true, 'adapter is not called for errors thrown in sync run loops'); - } - }); - - assert.throws(runThatThrowsSync, Error); - }); - - QUnit.test('when both Ember.onerror (which rethrows) and TestAdapter are registered - sync run', function(assert) { - assert.expect(2); - - setAdapter({ - exception() { - assert.notOk(true, 'adapter is not called for errors thrown in sync run loops'); - } - }); - - setOnerror(function(error) { - assert.ok(true, 'onerror is called for sync errors even if TestAdapter is setup'); - throw error; - }); - - assert.throws(runThatThrowsSync, Error, 'error is thrown'); - }); - - QUnit.test('when both Ember.onerror (which does not rethrow) and TestAdapter are registered - sync run', function(assert) { - assert.expect(2); - - setAdapter({ - exception() { - assert.notOk(true, 'adapter is not called for errors thrown in sync run loops'); - } - }); - - setOnerror(function() { - assert.ok(true, 'onerror is called for sync errors even if TestAdapter is setup'); - }); - - runThatThrowsSync(); - assert.ok(true, 'no error was thrown, Ember.onerror can intercept errors'); - }); - - QUnit.test('when TestAdapter is registered and error is thrown - async run', function(assert) { - assert.expect(3); - let done = assert.async(); - - let caughtInAdapter, caughtInCatch, caughtByWindowOnerror; - setAdapter({ - exception(error) { - caughtInAdapter = error; - } - }); - - window.onerror = function(message) { - caughtByWindowOnerror = message; - // prevent "bubbling" and therefore failing the test - return true; - }; - - try { - runThatThrowsAsync(); - } catch(e) { - caughtInCatch = e; - } - - setTimeout(() => { - assert.equal(caughtInAdapter, undefined, 'test adapter should never catch errors in run loops'); - assert.equal(caughtInCatch, undefined, 'a "normal" try/catch should never catch errors in an async run'); - - assert.pushResult({ - result: /Error for testing error handling/.test(caughtByWindowOnerror), - actual: caughtByWindowOnerror, - expected: 'to include `Error for testing error handling`', - message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)' - }); - - done(); - }, 20); - }); - - QUnit.test('when both Ember.onerror and TestAdapter are registered - async run', function(assert) { - assert.expect(1); - let done = assert.async(); - - setAdapter({ - exception() { - assert.notOk(true, 'Adapter.exception is not called for errors thrown in run.next'); - } - }); - - setOnerror(function() { - assert.ok(true, 'onerror is invoked for errors thrown in run.next/run.later'); - }); - - runThatThrowsAsync(); - setTimeout(done, 10); - }); -} - QUnit.test('does not swallow exceptions by default (Ember.testing = true, no Ember.onerror) - sync run', function(assert) { setTesting(true); @@ -397,119 +273,6 @@ function generateRSVPErrorHandlingTests(message, generatePromise, timeout = 10) // ensures that run loop has completed return new RSVP.Promise((resolve) => setTimeout(resolve, timeout)); }); - - if (DEBUG) { - QUnit.test(`${message} when TestAdapter without \`exception\` method is present - rsvp`, function(assert) { - assert.expect(1); - - let thrown = new Error('the error'); - setAdapter(QUnitAdapter.create({ - exception: undefined - })); - - window.onerror = function(message) { - assert.pushResult({ - result: /the error/.test(message), - actual: message, - expected: 'to include `the error`', - message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)' - }); - - // prevent "bubbling" and therefore failing the test - return true; - }; - - generatePromise(thrown); - - // RSVP.Promise's are configured to settle within the run loop, this - // ensures that run loop has completed - return new RSVP.Promise((resolve) => setTimeout(resolve, timeout)); - }); - - QUnit.test(`${message} when both Ember.onerror and TestAdapter without \`exception\` method are present - rsvp`, function(assert) { - assert.expect(1); - - let thrown = new Error('the error'); - setAdapter(QUnitAdapter.create({ - exception: undefined - })); - - setOnerror(function(error) { - assert.pushResult({ - result: /the error/.test(error.message), - actual: error.message, - expected: 'to include `the error`', - message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)' - }); - }); - - generatePromise(thrown); - - // RSVP.Promise's are configured to settle within the run loop, this - // ensures that run loop has completed - return new RSVP.Promise((resolve) => setTimeout(resolve, timeout)); - }); - - QUnit.test(`${message} when TestAdapter is present - rsvp`, function(assert) { - assert.expect(1); - - let thrown = new Error('the error'); - setAdapter(QUnitAdapter.create({ - exception(error) { - assert.strictEqual(error, thrown, 'Adapter.exception is called for errors thrown in RSVP promises'); - } - })); - - generatePromise(thrown); - - // RSVP.Promise's are configured to settle within the run loop, this - // ensures that run loop has completed - return new RSVP.Promise((resolve) => setTimeout(resolve, timeout)); - }); - - QUnit.test(`${message} when both Ember.onerror and TestAdapter are present - rsvp`, function(assert) { - assert.expect(1); - - let thrown = new Error('the error'); - setAdapter(QUnitAdapter.create({ - exception(error) { - assert.strictEqual(error, thrown, 'Adapter.exception is called for errors thrown in RSVP promises'); - } - })); - - setOnerror(function() { - assert.notOk(true, 'Ember.onerror is not called if Test.adapter does not rethrow'); - }); - - generatePromise(thrown); - - // RSVP.Promise's are configured to settle within the run loop, this - // ensures that run loop has completed - return new RSVP.Promise((resolve) => setTimeout(resolve, timeout)); - }); - - QUnit.test(`${message} when both Ember.onerror and TestAdapter are present - rsvp`, function(assert) { - assert.expect(2); - - let thrown = new Error('the error'); - setAdapter(QUnitAdapter.create({ - exception(error) { - assert.strictEqual(error, thrown, 'Adapter.exception is called for errors thrown in RSVP promises'); - throw error; - } - })); - - setOnerror(function(error) { - assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises if Test.adapter rethrows'); - }); - - generatePromise(thrown); - - // RSVP.Promise's are configured to settle within the run loop, this - // ensures that run loop has completed - return new RSVP.Promise((resolve) => setTimeout(resolve, timeout)); - }); - } } generateRSVPErrorHandlingTests('errors in promise constructor', (error) => {
true
Other
emberjs
ember.js
253556651d74fd0bd5c5a50d0abb6bcd20bf9028.json
Remove Ember global usage when testing onError
packages/ember-testing/lib/index.js
@@ -1,5 +1,6 @@ export { default as Test } from './test'; export { default as Adapter } from './adapters/adapter'; +export { setAdapter, getAdapter } from './test/adapter'; export { default as setupForTesting } from './setup_for_testing'; export { default as QUnitAdapter } from './adapters/qunit';
true
Other
emberjs
ember.js
253556651d74fd0bd5c5a50d0abb6bcd20bf9028.json
Remove Ember global usage when testing onError
packages/ember/tests/error_handler_test.js
@@ -1,28 +1,36 @@ -import Ember from 'ember'; -import { run } from 'ember-metal'; +import { isTesting, setTesting } from 'ember-debug'; +import { run, getOnerror, setOnerror } from 'ember-metal'; import { DEBUG } from 'ember-env-flags'; import RSVP from 'rsvp'; - -const ONERROR = Ember.onerror; -const ADAPTER = Ember.Test && Ember.Test.adapter; -const TESTING = Ember.testing; +import require, { has } from 'require'; let WINDOW_ONERROR; +let setAdapter; +let QUnitAdapter; + QUnit.module('error_handler', { beforeEach() { + if (has('ember-testing')) { + let testing = require('ember-testing'); + setAdapter = testing.setAdapter; + QUnitAdapter = testing.QUnitAdapter; + } // capturing this outside of module scope to ensure we grab // the test frameworks own window.onerror to reset it WINDOW_ONERROR = window.onerror; }, afterEach() { - Ember.onerror = ONERROR; - Ember.testing = TESTING; + setTesting(isTesting); window.onerror = WINDOW_ONERROR; - if (Ember.Test) { - Ember.Test.adapter = ADAPTER; + + if (setAdapter) { + setAdapter(); } + + setOnerror(undefined); + } }); @@ -39,24 +47,24 @@ function runThatThrowsAsync(message = 'Error for testing error handling') { } QUnit.test('by default there is no onerror - sync run', function(assert) { - assert.strictEqual(Ember.onerror, undefined, 'precond - there should be no Ember.onerror set by default'); + assert.strictEqual(getOnerror(), undefined, 'precond - there should be no Ember.onerror set by default'); assert.throws(runThatThrowsSync, Error, 'errors thrown sync are catchable'); }); QUnit.test('when Ember.onerror (which rethrows) is registered - sync run', function(assert) { assert.expect(2); - Ember.onerror = function(error) { + setOnerror(function(error) { assert.ok(true, 'onerror called'); throw error; - }; + }); assert.throws(runThatThrowsSync, Error, 'error is thrown'); }); QUnit.test('when Ember.onerror (which does not rethrow) is registered - sync run', function(assert) { assert.expect(2); - Ember.onerror = function() { + setOnerror(function() { assert.ok(true, 'onerror called'); - }; + }); runThatThrowsSync(); assert.ok(true, 'no error was thrown, Ember.onerror can intercept errors'); }); @@ -65,44 +73,44 @@ if (DEBUG) { QUnit.test('when TestAdapter is registered and error is thrown - sync run', function(assert) { assert.expect(1); - Ember.Test.adapter = { + setAdapter({ exception() { assert.notOk(true, 'adapter is not called for errors thrown in sync run loops'); } - }; + }); assert.throws(runThatThrowsSync, Error); }); QUnit.test('when both Ember.onerror (which rethrows) and TestAdapter are registered - sync run', function(assert) { assert.expect(2); - Ember.Test.adapter = { + setAdapter({ exception() { assert.notOk(true, 'adapter is not called for errors thrown in sync run loops'); } - }; + }); - Ember.onerror = function(error) { + setOnerror(function(error) { assert.ok(true, 'onerror is called for sync errors even if TestAdapter is setup'); throw error; - }; + }); assert.throws(runThatThrowsSync, Error, 'error is thrown'); }); QUnit.test('when both Ember.onerror (which does not rethrow) and TestAdapter are registered - sync run', function(assert) { assert.expect(2); - Ember.Test.adapter = { + setAdapter({ exception() { assert.notOk(true, 'adapter is not called for errors thrown in sync run loops'); } - }; + }); - Ember.onerror = function() { + setOnerror(function() { assert.ok(true, 'onerror is called for sync errors even if TestAdapter is setup'); - }; + }); runThatThrowsSync(); assert.ok(true, 'no error was thrown, Ember.onerror can intercept errors'); @@ -113,11 +121,11 @@ if (DEBUG) { let done = assert.async(); let caughtInAdapter, caughtInCatch, caughtByWindowOnerror; - Ember.Test.adapter = { + setAdapter({ exception(error) { caughtInAdapter = error; } - }; + }); window.onerror = function(message) { caughtByWindowOnerror = message; @@ -150,70 +158,70 @@ if (DEBUG) { assert.expect(1); let done = assert.async(); - Ember.Test.adapter = { + setAdapter({ exception() { assert.notOk(true, 'Adapter.exception is not called for errors thrown in run.next'); } - }; + }); - Ember.onerror = function() { + setOnerror(function() { assert.ok(true, 'onerror is invoked for errors thrown in run.next/run.later'); - }; + }); runThatThrowsAsync(); setTimeout(done, 10); }); } QUnit.test('does not swallow exceptions by default (Ember.testing = true, no Ember.onerror) - sync run', function(assert) { - Ember.testing = true; + setTesting(true); let error = new Error('the error'); assert.throws(() => { - Ember.run(() => { + run(() => { throw error; }); }, error); }); QUnit.test('does not swallow exceptions by default (Ember.testing = false, no Ember.onerror) - sync run', function(assert) { - Ember.testing = false; + setTesting(false); let error = new Error('the error'); assert.throws(() => { - Ember.run(() => { + run(() => { throw error; }); }, error); }); QUnit.test('does not swallow exceptions (Ember.testing = false, Ember.onerror which rethrows) - sync run', function(assert) { assert.expect(2); - Ember.testing = false; + setTesting(false); - Ember.onerror = function(error) { + setOnerror(function(error) { assert.ok(true, 'Ember.onerror was called'); throw error; - }; + }); let error = new Error('the error'); assert.throws(() => { - Ember.run(() => { + run(() => { throw error; }); }, error); }); QUnit.test('Ember.onerror can intercept errors (aka swallow) by not rethrowing (Ember.testing = false) - sync run', function(assert) { assert.expect(1); - Ember.testing = false; + setTesting(false); - Ember.onerror = function() { + setOnerror(function() { assert.ok(true, 'Ember.onerror was called'); - }; + }); let error = new Error('the error'); try { - Ember.run(() => { + run(() => { throw error; }); } catch(e) { @@ -226,15 +234,15 @@ QUnit.test('does not swallow exceptions by default (Ember.testing = true, no Emb let done = assert.async(); let caughtByWindowOnerror; - Ember.testing = true; + setTesting(true); window.onerror = function(message) { caughtByWindowOnerror = message; // prevent "bubbling" and therefore failing the test return true; }; - Ember.run.later(() => { + run.later(() => { throw new Error('the error'); }, 10); @@ -254,15 +262,15 @@ QUnit.test('does not swallow exceptions by default (Ember.testing = false, no Em let done = assert.async(); let caughtByWindowOnerror; - Ember.testing = false; + setTesting(false); window.onerror = function(message) { caughtByWindowOnerror = message; // prevent "bubbling" and therefore failing the test return true; }; - Ember.run.later(() => { + run.later(() => { throw new Error('the error'); }, 10); @@ -281,7 +289,7 @@ QUnit.test('does not swallow exceptions by default (Ember.testing = false, no Em QUnit.test('Ember.onerror can intercept errors (aka swallow) by not rethrowing (Ember.testing = false) - async run', function(assert) { let done = assert.async(); - Ember.testing = false; + setTesting(false); window.onerror = function() { assert.notOk(true, 'window.onerror is never invoked when Ember.onerror intentionally swallows errors'); @@ -290,11 +298,11 @@ QUnit.test('Ember.onerror can intercept errors (aka swallow) by not rethrowing ( }; let thrown = new Error('the error'); - Ember.onerror = function(error) { + setOnerror(function(error) { assert.strictEqual(error, thrown, 'Ember.onerror is called with the error'); - }; + }); - Ember.run.later(() => { + run.later(() => { throw thrown; }, 10); @@ -306,9 +314,9 @@ function generateRSVPErrorHandlingTests(message, generatePromise, timeout = 10) assert.expect(1); let thrown = new Error('the error'); - Ember.onerror = function(error) { + setOnerror(function(error) { assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises'); - }; + }); generatePromise(thrown); @@ -321,10 +329,10 @@ function generateRSVPErrorHandlingTests(message, generatePromise, timeout = 10) assert.expect(2); let thrown = new Error('the error'); - Ember.onerror = function(error) { + setOnerror(function(error) { assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises'); throw error; - }; + }); window.onerror = function(message) { assert.pushResult({ @@ -348,11 +356,11 @@ function generateRSVPErrorHandlingTests(message, generatePromise, timeout = 10) QUnit.test(`${message} when Ember.onerror which does not rethrow is present (Ember.testing = false) - rsvp`, function(assert) { assert.expect(1); - Ember.testing = false; + setTesting(false); let thrown = new Error('the error'); - Ember.onerror = function(error) { + setOnerror(function(error) { assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises'); - }; + }); generatePromise(thrown); @@ -364,12 +372,12 @@ function generateRSVPErrorHandlingTests(message, generatePromise, timeout = 10) QUnit.test(`${message} when Ember.onerror which does rethrow is present (Ember.testing = false) - rsvp`, function(assert) { assert.expect(2); - Ember.testing = false; + setTesting(false); let thrown = new Error('the error'); - Ember.onerror = function(error) { + setOnerror(function(error) { assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises'); throw error; - }; + }); window.onerror = function(message) { assert.pushResult({ @@ -395,9 +403,9 @@ function generateRSVPErrorHandlingTests(message, generatePromise, timeout = 10) assert.expect(1); let thrown = new Error('the error'); - Ember.Test.adapter = Ember.Test.QUnitAdapter.create({ + setAdapter(QUnitAdapter.create({ exception: undefined - }); + })); window.onerror = function(message) { assert.pushResult({ @@ -422,18 +430,18 @@ function generateRSVPErrorHandlingTests(message, generatePromise, timeout = 10) assert.expect(1); let thrown = new Error('the error'); - Ember.Test.adapter = Ember.Test.QUnitAdapter.create({ + setAdapter(QUnitAdapter.create({ exception: undefined - }); + })); - Ember.onerror = function(error) { + setOnerror(function(error) { assert.pushResult({ result: /the error/.test(error.message), actual: error.message, expected: 'to include `the error`', message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)' }); - }; + }); generatePromise(thrown); @@ -446,11 +454,11 @@ function generateRSVPErrorHandlingTests(message, generatePromise, timeout = 10) assert.expect(1); let thrown = new Error('the error'); - Ember.Test.adapter = Ember.Test.QUnitAdapter.create({ + setAdapter(QUnitAdapter.create({ exception(error) { assert.strictEqual(error, thrown, 'Adapter.exception is called for errors thrown in RSVP promises'); } - }); + })); generatePromise(thrown); @@ -463,15 +471,15 @@ function generateRSVPErrorHandlingTests(message, generatePromise, timeout = 10) assert.expect(1); let thrown = new Error('the error'); - Ember.Test.adapter = Ember.Test.QUnitAdapter.create({ + setAdapter(QUnitAdapter.create({ exception(error) { assert.strictEqual(error, thrown, 'Adapter.exception is called for errors thrown in RSVP promises'); } - }); + })); - Ember.onerror = function() { + setOnerror(function() { assert.notOk(true, 'Ember.onerror is not called if Test.adapter does not rethrow'); - }; + }); generatePromise(thrown); @@ -484,16 +492,16 @@ function generateRSVPErrorHandlingTests(message, generatePromise, timeout = 10) assert.expect(2); let thrown = new Error('the error'); - Ember.Test.adapter = Ember.Test.QUnitAdapter.create({ + setAdapter(QUnitAdapter.create({ exception(error) { assert.strictEqual(error, thrown, 'Adapter.exception is called for errors thrown in RSVP promises'); throw error; } - }); + })); - Ember.onerror = function(error) { + setOnerror(function(error) { assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises if Test.adapter rethrows'); - }; + }); generatePromise(thrown);
true
Other
emberjs
ember.js
507196da7be456628202e93525a30e13a2cc9a1d.json
Remove Ember from NameSpace list
packages/ember-extension-support/lib/container_debug_adapter.js
@@ -87,14 +87,12 @@ export default EmberObject.extend({ let typeSuffixRegex = new RegExp(`${StringUtils.classify(type)}$`); namespaces.forEach(namespace => { - if (namespace.toString() !== 'Ember') { - for (let key in namespace) { - if (!namespace.hasOwnProperty(key)) { continue; } - if (typeSuffixRegex.test(key)) { - let klass = namespace[key]; - if (typeOf(klass) === 'class') { - types.push(StringUtils.dasherize(key.replace(typeSuffixRegex, ''))); - } + for (let key in namespace) { + if (!namespace.hasOwnProperty(key)) { continue; } + if (typeSuffixRegex.test(key)) { + let klass = namespace[key]; + if (typeOf(klass) === 'class') { + types.push(StringUtils.dasherize(key.replace(typeSuffixRegex, ''))); } } }
true
Other
emberjs
ember.js
507196da7be456628202e93525a30e13a2cc9a1d.json
Remove Ember from NameSpace list
packages/ember-runtime/lib/system/namespace.js
@@ -2,7 +2,7 @@ @module ember */ import { guidFor } from 'ember-utils'; -import Ember, { +import { get, Mixin, hasUnprocessedMixins, @@ -74,10 +74,8 @@ const Namespace = EmberObject.extend({ }); Namespace.reopenClass({ - NAMESPACES: [Ember], - NAMESPACES_BY_ID: { - Ember - }, + NAMESPACES: [], + NAMESPACES_BY_ID: {}, PROCESSED: false, processAll: processAllNamespaces, byName(name) {
true
Other
emberjs
ember.js
6eb4b1d0d330d75a3f72f6253cacad4a82259a11.json
Expose meta counters (privately). Various counters are being tracked around meta usage (how many instantiated, how many prototype walks, etc) but this data is not exposed (even privately) at the moment. This PR updates `Ember.meta` to tack on `Ember.meta._counters` which exposes the counters object in debug builds only...
packages/ember-metal/lib/meta.js
@@ -563,6 +563,10 @@ export function meta(obj) { return newMeta; } +if (DEBUG) { + meta._counters = counters; +} + // Using `symbol()` here causes some node test to fail, presumably // because we define the CP with one copy of Ember and boot the app // with a different copy, so the random key we generate do not line
false
Other
emberjs
ember.js
7f3f3872f23871f134006836bf1c531a94186f86.json
Move computed property caches into a weak map
packages/ember-metal/lib/alias.js
@@ -6,7 +6,7 @@ import { Descriptor, defineProperty } from './properties'; -import { ComputedProperty } from './computed'; +import { ComputedProperty, getCacheFor } from './computed'; import { meta as metaFor } from './meta'; import { addDependentKeys, @@ -52,9 +52,9 @@ export class AliasedProperty extends Descriptor { get(obj, keyName) { let ret = get(obj, this.altKey); let meta = metaFor(obj); - let cache = meta.writableCache(); - if (cache[keyName] !== CONSUMED) { - cache[keyName] = CONSUMED; + let cache = getCacheFor(obj); + if (cache.get(keyName) !== CONSUMED) { + cache.set(keyName, CONSUMED); addDependentKeys(this, obj, keyName, meta); } return ret;
true
Other
emberjs
ember.js
7f3f3872f23871f134006836bf1c531a94186f86.json
Move computed property caches into a weak map
packages/ember-metal/lib/chains.js
@@ -1,7 +1,7 @@ import { get } from './property_get'; import { descriptorFor, meta as metaFor, peekMeta } from './meta'; import { watchKey, unwatchKey } from './watch_key'; -import { cacheFor } from './computed'; +import { getCachedValueFor } from './computed'; import { eachProxyFor } from './each_proxy'; const FIRST_KEY = /^([^\.]+)/; @@ -333,10 +333,7 @@ function lazyGet(obj, key) { return get(obj, key); // Otherwise attempt to get the cached value of the computed property } else { - let cache = meta.readableCache(); - if (cache !== undefined) { - return cacheFor.get(cache, key); - } + return getCachedValueFor(obj, key); } }
true
Other
emberjs
ember.js
7f3f3872f23871f134006836bf1c531a94186f86.json
Move computed property caches into a weak map
packages/ember-metal/lib/computed.js
@@ -1,7 +1,7 @@ import { inspect } from 'ember-utils'; import { assert, warn, Error as EmberError } from 'ember-debug'; import { set } from './property_set'; -import { meta as metaFor, peekMeta, UNDEFINED } from './meta'; +import { meta as metaFor, peekMeta } from './meta'; import expandProperties from './expand_properties'; import { Descriptor, @@ -317,9 +317,8 @@ ComputedPropertyPrototype.didChange = function(obj, keyName) { return; } - let cache = meta.readableCache(); - if (cache !== undefined && cache[keyName] !== undefined) { - cache[keyName] = undefined; + let cache = peekCacheFor(obj); + if (cache !== undefined && cache.delete(keyName)) { removeDependentKeys(this, obj, keyName, meta); } }; @@ -329,20 +328,17 @@ ComputedPropertyPrototype.get = function(obj, keyName) { return this._getter.call(obj, keyName); } - let meta = metaFor(obj); - let cache = meta.writableCache(); + let cache = getCacheFor(obj); - let result = cache[keyName]; - if (result === UNDEFINED) { - return undefined; - } else if (result !== undefined) { - return result; + if (cache.has(keyName)) { + return cache.get(keyName); } let ret = this._getter.call(obj, keyName); - cache[keyName] = ret === undefined ? UNDEFINED : ret; + cache.set(keyName, ret); + let meta = metaFor(obj); let chainWatchers = meta.readableChainWatchers(); if (chainWatchers !== undefined) { chainWatchers.revalidate(keyName); @@ -373,7 +369,7 @@ ComputedPropertyPrototype._throwReadOnlyError = function computedPropertyThrowRe }; ComputedPropertyPrototype.clobberSet = function computedPropertyClobberSet(obj, keyName, value) { - let cachedValue = cacheFor(obj, keyName); + let cachedValue = getCachedValueFor(obj, keyName); defineProperty(obj, keyName, null, cachedValue); set(obj, keyName, value); return value; @@ -395,15 +391,9 @@ ComputedPropertyPrototype.setWithSuspend = function computedPropertySetWithSuspe ComputedPropertyPrototype._set = function computedPropertySet(obj, keyName, value) { let meta = metaFor(obj); - let cache = meta.writableCache(); - - let val = cache[keyName]; - let hadCachedValue = val !== undefined; - - let cachedValue; - if (hadCachedValue && val !== UNDEFINED) { - cachedValue = val; - } + let cache = getCacheFor(obj); + let hadCachedValue = cache.has(keyName); + let cachedValue = cache.get(keyName); let ret = this._setter.call(obj, keyName, value, cachedValue); @@ -416,7 +406,7 @@ ComputedPropertyPrototype._set = function computedPropertySet(obj, keyName, valu addDependentKeys(this, obj, keyName, meta); } - cache[keyName] = ret === undefined ? UNDEFINED : ret; + cache.set(keyName, ret); notifyPropertyChange(obj, keyName, meta); @@ -428,10 +418,9 @@ ComputedPropertyPrototype.teardown = function(obj, keyName, meta) { if (this._volatile) { return; } - let cache = meta.readableCache(); - if (cache !== undefined && cache[keyName] !== undefined) { + let cache = peekCacheFor(obj); + if (cache !== undefined && cache.delete(keyName)) { removeDependentKeys(this, obj, keyName, meta); - cache[keyName] = undefined; } }; @@ -535,6 +524,8 @@ export default function computed(...args) { return cp; } +const COMPUTED_PROPERTY_CACHED_VALUES = new WeakMap(); + /** Returns the cached value for a property, if one exists. This can be useful for peeking at the value of a computed @@ -550,39 +541,27 @@ export default function computed(...args) { @return {Object} the cached value @public */ -function cacheFor(obj, key) { - let meta = peekMeta(obj); - let cache = meta !== undefined ? meta.source === obj && meta.readableCache() : undefined; - let ret = cache !== undefined ? cache[key] : undefined; - - if (ret === UNDEFINED) { - return undefined; +export function getCacheFor(obj) { + let cache = COMPUTED_PROPERTY_CACHED_VALUES.get(obj); + if (cache === undefined) { + cache = new Map(); + COMPUTED_PROPERTY_CACHED_VALUES.set(obj, cache); } - return ret; + return cache; } -cacheFor.set = function(cache, key, value) { - if (value === undefined) { - cache[key] = UNDEFINED; - } else { - cache[key] = value; +export function getCachedValueFor(obj, key) { + let cache = COMPUTED_PROPERTY_CACHED_VALUES.get(obj); + if (cache !== undefined) { + return cache.get(key); } -}; - -cacheFor.get = function(cache, key) { - let ret = cache[key]; - if (ret === UNDEFINED) { - return undefined; - } - return ret; -}; +} -cacheFor.remove = function(cache, key) { - cache[key] = undefined; -}; +export function peekCacheFor(obj) { + return COMPUTED_PROPERTY_CACHED_VALUES.get(obj); +} export { ComputedProperty, - computed, - cacheFor + computed };
true
Other
emberjs
ember.js
7f3f3872f23871f134006836bf1c531a94186f86.json
Move computed property caches into a weak map
packages/ember-metal/lib/index.js
@@ -2,7 +2,9 @@ export { default } from './core'; // reexports export { default as computed, - cacheFor, + getCacheFor, + getCachedValueFor, + peekCacheFor, ComputedProperty } from './computed'; export { default as alias } from './alias';
true
Other
emberjs
ember.js
7f3f3872f23871f134006836bf1c531a94186f86.json
Move computed property caches into a weak map
packages/ember-metal/lib/meta.js
@@ -45,8 +45,6 @@ export class Meta { counters.metaInstantiated++; } - this._cache = undefined; - if (EMBER_METAL_ES5_GETTERS) { this._descriptors = undefined; } @@ -266,9 +264,6 @@ export class Meta { } } - writableCache() { return this._getOrCreateOwnMap('_cache'); } - readableCache() { return this._cache; } - writableTags() { return this._getOrCreateOwnMap('_tags'); } readableTags() { return this._tags; }
true
Other
emberjs
ember.js
7f3f3872f23871f134006836bf1c531a94186f86.json
Move computed property caches into a weak map
packages/ember-metal/lib/properties.js
@@ -7,6 +7,7 @@ import { HAS_NATIVE_PROXY } from 'ember-utils'; import { descriptorFor, meta as metaFor, peekMeta, DESCRIPTOR, UNDEFINED } from './meta'; import { overrideChains } from './property_events'; import { DESCRIPTOR_TRAP, EMBER_METAL_ES5_GETTERS, MANDATORY_SETTER } from 'ember/features'; +import { peekCacheFor } from './computed'; // .......................................................... // DESCRIPTOR // @@ -338,9 +339,9 @@ export function _hasCachedComputedProperties() { function didDefineComputedProperty(constructor) { if (hasCachedComputedProperties === false) { return; } - let cache = metaFor(constructor).readableCache(); - if (cache && cache._computedProperties !== undefined) { - cache._computedProperties = undefined; + let cache = peekCacheFor(constructor); + if (cache !== undefined) { + cache.delete('_computedProperties'); } }
true
Other
emberjs
ember.js
7f3f3872f23871f134006836bf1c531a94186f86.json
Move computed property caches into a weak map
packages/ember-metal/tests/computed_test.js
@@ -4,7 +4,7 @@ import { testBoth } from 'internal-test-helpers'; import { ComputedProperty, computed, - cacheFor, + getCachedValueFor, Descriptor, defineProperty, get, @@ -316,24 +316,24 @@ testBoth('inherited property should not pick up cache', function(get, set, asser assert.equal(get(objB, 'foo'), 'bar 2', 'objB third get'); }); -testBoth('cacheFor should return the cached value', function(get, set, assert) { - assert.equal(cacheFor(obj, 'foo'), undefined, 'should not yet be a cached value'); +testBoth('getCachedValueFor should return the cached value', function(get, set, assert) { + assert.equal(getCachedValueFor(obj, 'foo'), undefined, 'should not yet be a cached value'); get(obj, 'foo'); - assert.equal(cacheFor(obj, 'foo'), 'bar 1', 'should retrieve cached value'); + assert.equal(getCachedValueFor(obj, 'foo'), 'bar 1', 'should retrieve cached value'); }); -testBoth('cacheFor should return falsy cached values', function(get, set, assert) { +testBoth('getCachedValueFor should return falsy cached values', function(get, set, assert) { defineProperty(obj, 'falsy', computed(function() { return false; })); - assert.equal(cacheFor(obj, 'falsy'), undefined, 'should not yet be a cached value'); + assert.equal(getCachedValueFor(obj, 'falsy'), undefined, 'should not yet be a cached value'); get(obj, 'falsy'); - assert.equal(cacheFor(obj, 'falsy'), false, 'should retrieve cached value'); + assert.equal(getCachedValueFor(obj, 'falsy'), false, 'should retrieve cached value'); }); testBoth('setting a cached computed property passes the old value as the third argument', function(get, set, assert) {
true
Other
emberjs
ember.js
7f3f3872f23871f134006836bf1c531a94186f86.json
Move computed property caches into a weak map
packages/ember-metal/tests/observer_test.js
@@ -6,7 +6,7 @@ import { notifyPropertyChange, defineProperty, computed, - cacheFor, + getCachedValueFor, Mixin, mixin, observer, @@ -484,7 +484,7 @@ testBoth('depending on a chain with a computed property', function(get, set, ass changed++; }); - assert.equal(cacheFor(obj, 'computed'), undefined, 'addObserver should not compute CP'); + assert.equal(getCachedValueFor(obj, 'computed'), undefined, 'addObserver should not compute CP'); set(obj, 'computed.foo', 'baz');
true
Other
emberjs
ember.js
7f3f3872f23871f134006836bf1c531a94186f86.json
Move computed property caches into a weak map
packages/ember-runtime/lib/mixins/array.js
@@ -22,7 +22,8 @@ import { eachProxyArrayWillChange, eachProxyArrayDidChange, beginPropertyChanges, - endPropertyChanges + endPropertyChanges, + peekCacheFor } from 'ember-metal'; import { assert, deprecate } from 'ember-debug'; import Enumerable from './enumerable'; @@ -105,7 +106,7 @@ export function arrayContentDidChange(array, startIdx, removeAmt, addAmt) { sendEvent(array, '@array:change', [array, startIdx, removeAmt, addAmt]); let meta = peekMeta(array); - let cache = meta !== undefined ? meta.readableCache() : undefined; + let cache = peekCacheFor(array); if (cache !== undefined) { let length = get(array, 'length'); let addedAmount = (addAmt === -1 ? 0 : addAmt); @@ -114,17 +115,17 @@ export function arrayContentDidChange(array, startIdx, removeAmt, addAmt) { let previousLength = length - delta; let normalStartIdx = startIdx < 0 ? previousLength + startIdx : startIdx; - if (cache.firstObject !== undefined && normalStartIdx === 0) { + if (cache.has('firstObject') && normalStartIdx === 0) { notifyPropertyChange(array, 'firstObject', meta); } - if (cache.lastObject !== undefined) { + if (cache.has('lastObject')) { let previousLastIndex = previousLength - 1; let lastAffectedIndex = normalStartIdx + removedAmount; if (previousLastIndex < lastAffectedIndex) { notifyPropertyChange(array, 'lastObject', meta); } - } + } } return array;
true
Other
emberjs
ember.js
7f3f3872f23871f134006836bf1c531a94186f86.json
Move computed property caches into a weak map
packages/ember-runtime/lib/mixins/observable.js
@@ -17,7 +17,7 @@ import { endPropertyChanges, addObserver, removeObserver, - cacheFor, + getCachedValueFor, isNone } from 'ember-metal'; import { assert } from 'ember-debug'; @@ -476,6 +476,6 @@ export default Mixin.create({ @public */ cacheFor(keyName) { - return cacheFor(this, keyName); + return getCachedValueFor(this, keyName); }, });
true
Other
emberjs
ember.js
7f3f3872f23871f134006836bf1c531a94186f86.json
Move computed property caches into a weak map
packages/ember/lib/index.js
@@ -40,7 +40,7 @@ const computed = metal.computed; computed.alias = metal.alias; Ember.computed = computed; Ember.ComputedProperty = metal.ComputedProperty; -Ember.cacheFor = metal.cacheFor; +Ember.cacheFor = metal.getCachedValueFor; Ember.assert = EmberDebug.assert; Ember.warn = EmberDebug.warn;
true
Other
emberjs
ember.js
7f3f3872f23871f134006836bf1c531a94186f86.json
Move computed property caches into a weak map
packages/ember/tests/reexports_test.js
@@ -40,7 +40,7 @@ let allExports =[ ['computed', 'ember-metal'], ['computed.alias', 'ember-metal', 'alias'], ['ComputedProperty', 'ember-metal'], - ['cacheFor', 'ember-metal'], + ['cacheFor', 'ember-metal', 'getCachedValueFor'], ['merge', 'ember-metal'], ['instrument', 'ember-metal'], ['Instrumentation.instrument', 'ember-metal', 'instrument'],
true
Other
emberjs
ember.js
00a74888f7776f3808534d6a2a3af5dc9c6d5b98.json
Move each proxies into a weak map
packages/ember-metal/lib/chains.js
@@ -2,6 +2,7 @@ import { get } from './property_get'; import { descriptorFor, meta as metaFor, peekMeta } from './meta'; import { watchKey, unwatchKey } from './watch_key'; import { cacheFor } from './computed'; +import { eachProxyFor } from './each_proxy'; const FIRST_KEY = /^([^\.]+)/; @@ -326,7 +327,9 @@ function lazyGet(obj, key) { } // Use `get` if the return value is an EachProxy or an uncacheable value. - if (isVolatile(obj, key, meta)) { + if (key === '@each') { + return eachProxyFor(obj); + } else if (isVolatile(obj, key, meta)) { return get(obj, key); // Otherwise attempt to get the cached value of the computed property } else {
true
Other
emberjs
ember.js
00a74888f7776f3808534d6a2a3af5dc9c6d5b98.json
Move each proxies into a weak map
packages/ember-metal/lib/each_proxy.js
@@ -0,0 +1,131 @@ +import { assert } from 'ember-debug'; +import { get } from './property_get'; +import { notifyPropertyChange } from './property_events'; +import { addObserver, removeObserver } from './observer'; +import { meta, peekMeta } from './meta'; +import { objectAt } from './array'; + +const EACH_PROXIES = new WeakMap(); + +export function eachProxyFor(array) { + let eachProxy = EACH_PROXIES.get(array); + if (eachProxy === undefined) { + eachProxy = new EachProxy(array); + EACH_PROXIES.set(array, eachProxy); + } + return eachProxy; +} + +export function eachProxyArrayWillChange(array, idx, removedCnt, addedCnt) { + let eachProxy = EACH_PROXIES.get(array); + if (eachProxy !== undefined) { + eachProxy.arrayWillChange(array, idx, removedCnt, addedCnt); + } +} + +export function eachProxyArrayDidChange(array, idx, removedCnt, addedCnt) { + let eachProxy = EACH_PROXIES.get(array); + if (eachProxy !== undefined) { + eachProxy.arrayDidChange(array, idx, removedCnt, addedCnt); + } +} + +class EachProxy { + constructor(content) { + this._content = content; + this._keys = undefined; + meta(this); + } + + // .......................................................... + // ARRAY CHANGES + // Invokes whenever the content array itself changes. + + arrayWillChange(content, idx, removedCnt, addedCnt) { // eslint-disable-line no-unused-vars + let keys = this._keys; + let lim = removedCnt > 0 ? idx + removedCnt : -1; + for (let key in keys) { + if (lim > 0) { + removeObserverForContentKey(content, key, this, idx, lim); + } + } + } + + arrayDidChange(content, idx, removedCnt, addedCnt) { + let keys = this._keys; + let lim = addedCnt > 0 ? idx + addedCnt : -1; + let meta = peekMeta(this); + for (let key in keys) { + if (lim > 0) { + addObserverForContentKey(content, key, this, idx, lim); + } + notifyPropertyChange(this, key, meta); + } + } + + // .......................................................... + // LISTEN FOR NEW OBSERVERS AND OTHER EVENT LISTENERS + // Start monitoring keys based on who is listening... + + willWatchProperty(property) { + this.beginObservingContentKey(property); + } + + didUnwatchProperty(property) { + this.stopObservingContentKey(property); + } + + // .......................................................... + // CONTENT KEY OBSERVING + // Actual watch keys on the source content. + + beginObservingContentKey(keyName) { + let keys = this._keys; + if (!keys) { + keys = this._keys = Object.create(null); + } + + if (!keys[keyName]) { + keys[keyName] = 1; + let content = this._content; + let len = get(content, 'length'); + + addObserverForContentKey(content, keyName, this, 0, len); + } else { + keys[keyName]++; + } + } + + stopObservingContentKey(keyName) { + let keys = this._keys; + if (keys && (keys[keyName] > 0) && (--keys[keyName] <= 0)) { + let content = this._content; + let len = get(content, 'length'); + + removeObserverForContentKey(content, keyName, this, 0, len); + } + } + + contentKeyDidChange(obj, keyName) { + notifyPropertyChange(this, keyName); + } +} + +function addObserverForContentKey(content, keyName, proxy, idx, loc) { + while (--loc >= idx) { + let item = objectAt(content, loc); + if (item) { + assert(`When using @each to observe the array \`${toString(content)}\`, the array must return an object`, typeof item === 'object'); + addObserver(item, keyName, proxy, 'contentKeyDidChange'); + } + } +} + +function removeObserverForContentKey(content, keyName, proxy, idx, loc) { + while (--loc >= idx) { + let item = objectAt(content, loc); + if (item) { + removeObserver(item, keyName, proxy, 'contentKeyDidChange'); + } + } +}
true
Other
emberjs
ember.js
00a74888f7776f3808534d6a2a3af5dc9c6d5b98.json
Move each proxies into a weak map
packages/ember-metal/lib/index.js
@@ -40,6 +40,11 @@ export { trySet } from './property_set'; export { objectAt } from './array'; +export { + eachProxyFor, + eachProxyArrayWillChange, + eachProxyArrayDidChange +} from './each_proxy'; export { addListener, hasListeners,
true
Other
emberjs
ember.js
00a74888f7776f3808534d6a2a3af5dc9c6d5b98.json
Move each proxies into a weak map
packages/ember-runtime/lib/mixins/array.js
@@ -17,14 +17,14 @@ import { removeListener, sendEvent, hasListeners, - addObserver, - removeObserver, - meta, peekMeta, + eachProxyFor, + eachProxyArrayWillChange, + eachProxyArrayDidChange, beginPropertyChanges, endPropertyChanges } from 'ember-metal'; -import { assert } from 'ember-debug'; +import { assert, deprecate } from 'ember-debug'; import Enumerable from './enumerable'; import compare from '../compare'; import { ENV } from 'ember-environment'; @@ -72,9 +72,7 @@ export function arrayContentWillChange(array, startIdx, removeAmt, addAmt) { } } - if (array.__each) { - array.__each.arrayWillChange(array, startIdx, removeAmt, addAmt); - } + eachProxyArrayWillChange(array, startIdx, removeAmt, addAmt); sendEvent(array, '@array:before', [array, startIdx, removeAmt, addAmt]); @@ -102,9 +100,7 @@ export function arrayContentDidChange(array, startIdx, removeAmt, addAmt) { notifyPropertyChange(array, '[]'); - if (array.__each) { - array.__each.arrayDidChange(array, startIdx, removeAmt, addAmt); - } + eachProxyArrayDidChange(array, startIdx, removeAmt, addAmt); sendEvent(array, '@array:change', [array, startIdx, removeAmt, addAmt]); @@ -1232,125 +1228,19 @@ const ArrayMixin = Mixin.create(Enumerable, { @public */ '@each': computed(function() { - // TODO use Symbol or add to meta - if (!this.__each) { - this.__each = new EachProxy(this); - } - - return this.__each; - }).volatile().readOnly() -}); - -/** - This is the object instance returned when you get the `@each` property on an - array. It uses the unknownProperty handler to automatically create - EachArray instances for property names. - @class EachProxy - @private -*/ -function EachProxy(content) { - this._content = content; - this._keys = undefined; - meta(this); -} - -EachProxy.prototype = { - __defineNonEnumerable(property) { - this[property.name] = property.descriptor.value; - }, - - // .......................................................... - // ARRAY CHANGES - // Invokes whenever the content array itself changes. - - arrayWillChange(content, idx, removedCnt, addedCnt) { // eslint-disable-line no-unused-vars - let keys = this._keys; - let lim = removedCnt > 0 ? idx + removedCnt : -1; - for (let key in keys) { - if (lim > 0) { - removeObserverForContentKey(content, key, this, idx, lim); + deprecate( + `Getting the '@each' property on object ${toString(this)} is deprecated`, + false, + { + id: 'ember-metal.getting-each', + until: '3.5.0', + url: 'https://emberjs.com/deprecations/v3.x#toc_getting-the-each-property' } - } - }, - - arrayDidChange(content, idx, removedCnt, addedCnt) { - let keys = this._keys; - let lim = addedCnt > 0 ? idx + addedCnt : -1; - let meta = peekMeta(this); - for (let key in keys) { - if (lim > 0) { - addObserverForContentKey(content, key, this, idx, lim); - } - notifyPropertyChange(this, key, meta); - } - }, - - // .......................................................... - // LISTEN FOR NEW OBSERVERS AND OTHER EVENT LISTENERS - // Start monitoring keys based on who is listening... - - willWatchProperty(property) { - this.beginObservingContentKey(property); - }, - - didUnwatchProperty(property) { - this.stopObservingContentKey(property); - }, + ); - // .......................................................... - // CONTENT KEY OBSERVING - // Actual watch keys on the source content. - - beginObservingContentKey(keyName) { - let keys = this._keys; - if (!keys) { - keys = this._keys = Object.create(null); - } - - if (!keys[keyName]) { - keys[keyName] = 1; - let content = this._content; - let len = get(content, 'length'); - - addObserverForContentKey(content, keyName, this, 0, len); - } else { - keys[keyName]++; - } - }, - - stopObservingContentKey(keyName) { - let keys = this._keys; - if (keys && (keys[keyName] > 0) && (--keys[keyName] <= 0)) { - let content = this._content; - let len = get(content, 'length'); - - removeObserverForContentKey(content, keyName, this, 0, len); - } - }, - - contentKeyDidChange(obj, keyName) { - notifyPropertyChange(this, keyName); - } -}; - -function addObserverForContentKey(content, keyName, proxy, idx, loc) { - while (--loc >= idx) { - let item = objectAt(content, loc); - if (item) { - assert(`When using @each to observe the array \`${toString(content)}\`, the array must return an object`, typeof item === 'object'); - addObserver(item, keyName, proxy, 'contentKeyDidChange'); - } - } -} - -function removeObserverForContentKey(content, keyName, proxy, idx, loc) { - while (--loc >= idx) { - let item = objectAt(content, loc); - if (item) { - removeObserver(item, keyName, proxy, 'contentKeyDidChange'); - } - } -} + return eachProxyFor(this); + }).readOnly() +}); const OUT_OF_RANGE_EXCEPTION = 'Index out of range';
true
Other
emberjs
ember.js
00a74888f7776f3808534d6a2a3af5dc9c6d5b98.json
Move each proxies into a weak map
packages/ember-runtime/lib/system/core_object.js
@@ -101,7 +101,6 @@ function makeCtor() { property === 'willWatchProperty' || property === 'didUnwatchProperty' || property === 'didAddListener' || - property === '__each' || property in target ) { return Reflect.get(target, property, receiver);
true
Other
emberjs
ember.js
00a74888f7776f3808534d6a2a3af5dc9c6d5b98.json
Move each proxies into a weak map
packages/ember-runtime/tests/mixins/array_test.js
@@ -288,6 +288,14 @@ QUnit.test('adding an object should notify (@each.isDone)', function(assert) { assert.equal(called, 1, 'calls observer when object is pushed'); }); +QUnit.test('getting @each is deprecated', function(assert) { + assert.expect(1); + + expectDeprecation(() => { + get(ary, '@each'); + }, /Getting the '@each' property on object .* is deprecated/); +}); + QUnit.test('@each is readOnly', function(assert) { assert.expect(1); @@ -328,8 +336,10 @@ QUnit.test('modifying the array should also indicate the isDone prop itself has // important because it tests the case where we don't have an isDone // EachArray materialized but just want to know when the property has // changed. - - let each = get(ary, '@each'); + let each; + expectDeprecation(() => { + each = get(ary, '@each'); + }); let count = 0; addObserver(each, 'isDone', () => count++);
true
Other
emberjs
ember.js
daa39359c2b3811d7053e2162a5717dcf40b04a1.json
Move objectAt to ember-metal ... and fix some tests that should ahve been testing the method version of objectAt.
packages/ember-extension-support/lib/data_adapter.js
@@ -1,13 +1,12 @@ import { getOwner } from 'ember-utils'; -import { get, run } from 'ember-metal'; +import { get, run, objectAt } from 'ember-metal'; import { String as StringUtils, Namespace, Object as EmberObject, A as emberA, addArrayObserver, - removeArrayObserver, - objectAt + removeArrayObserver } from 'ember-runtime'; /**
true
Other
emberjs
ember.js
daa39359c2b3811d7053e2162a5717dcf40b04a1.json
Move objectAt to ember-metal ... and fix some tests that should ahve been testing the method version of objectAt.
packages/ember-glimmer/lib/utils/iterable.ts
@@ -6,11 +6,16 @@ import { UpdatableTag, } from '@glimmer/reference'; import { Opaque } from '@glimmer/util'; -import { get, isProxy, tagFor, tagForProperty } from 'ember-metal'; import { - _contentFor, - isEmberArray, + get, + isProxy, objectAt, + tagFor, + tagForProperty +} from 'ember-metal'; +import { + _contentFor, + isEmberArray } from 'ember-runtime'; import { guidFor } from 'ember-utils'; import { isEachIn } from '../helpers/each-in';
true
Other
emberjs
ember.js
daa39359c2b3811d7053e2162a5717dcf40b04a1.json
Move objectAt to ember-metal ... and fix some tests that should ahve been testing the method version of objectAt.
packages/ember-metal/lib/array.js
@@ -0,0 +1,7 @@ +export function objectAt(content, idx) { + if (typeof content.objectAt === 'function') { + return content.objectAt(idx); + } else { + return content[idx]; + } +}
true
Other
emberjs
ember.js
daa39359c2b3811d7053e2162a5717dcf40b04a1.json
Move objectAt to ember-metal ... and fix some tests that should ahve been testing the method version of objectAt.
packages/ember-metal/lib/index.d.ts
@@ -33,6 +33,8 @@ export function get(obj: any, keyName: string): any; export function set(obj: any, keyName: string, value: any, tolerant?: boolean): void; +export function objectAt(arr: any, i: number): any; + export function computed(...args: Array<any>): any; export function didRender(object: any, key: string, reference: any): boolean;
true
Other
emberjs
ember.js
daa39359c2b3811d7053e2162a5717dcf40b04a1.json
Move objectAt to ember-metal ... and fix some tests that should ahve been testing the method version of objectAt.
packages/ember-metal/lib/index.js
@@ -39,6 +39,7 @@ export { set, trySet } from './property_set'; +export { objectAt } from './array'; export { addListener, hasListeners,
true
Other
emberjs
ember.js
daa39359c2b3811d7053e2162a5717dcf40b04a1.json
Move objectAt to ember-metal ... and fix some tests that should ahve been testing the method version of objectAt.
packages/ember-runtime/lib/index.d.ts
@@ -18,8 +18,6 @@ export const String: { loc(s: string, ...args: string[]): string; }; -export function objectAt(arr: any, i: number): any; - export function isEmberArray(arr: any): boolean; export function _contentFor(proxy: any): any;
true
Other
emberjs
ember.js
daa39359c2b3811d7053e2162a5717dcf40b04a1.json
Move objectAt to ember-metal ... and fix some tests that should ahve been testing the method version of objectAt.
packages/ember-runtime/lib/index.js
@@ -12,7 +12,6 @@ export { default as compare } from './compare'; export { default as isEqual } from './is-equal'; export { default as Array, - objectAt, isEmberArray, addArrayObserver, removeArrayObserver,
true
Other
emberjs
ember.js
daa39359c2b3811d7053e2162a5717dcf40b04a1.json
Move objectAt to ember-metal ... and fix some tests that should ahve been testing the method version of objectAt.
packages/ember-runtime/lib/mixins/array.js
@@ -6,6 +6,8 @@ import { symbol, toString } from 'ember-utils'; import { get, set, + objectAt, + replace, computed, isNone, aliasMethod, @@ -25,9 +27,6 @@ import { import { assert } from 'ember-debug'; import Enumerable from './enumerable'; import compare from '../compare'; -import { - replace -} from 'ember-metal'; import { ENV } from 'ember-environment'; import Observable from '../mixins/observable'; import Copyable from '../mixins/copyable'; @@ -58,10 +57,6 @@ export function removeArrayObserver(array, target, opts) { return arrayObserversHelper(array, target, opts, removeListener, true); } -export function objectAt(content, idx) { - return typeof content.objectAt === 'function' ? content.objectAt(idx) : content[idx]; -} - export function arrayContentWillChange(array, startIdx, removeAmt, addAmt) { // if no args are passed assume everything changes if (startIdx === undefined) {
true
Other
emberjs
ember.js
daa39359c2b3811d7053e2162a5717dcf40b04a1.json
Move objectAt to ember-metal ... and fix some tests that should ahve been testing the method version of objectAt.
packages/ember-runtime/lib/system/array_proxy.js
@@ -4,6 +4,7 @@ import { get, + objectAt, computed, alias, PROPERTY_DID_CHANGE @@ -15,8 +16,7 @@ import EmberObject from './object'; import { MutableArray } from '../mixins/array'; import { addArrayObserver, - removeArrayObserver, - objectAt + removeArrayObserver } from '../mixins/array'; import { assert } from 'ember-debug';
true
Other
emberjs
ember.js
daa39359c2b3811d7053e2162a5717dcf40b04a1.json
Move objectAt to ember-metal ... and fix some tests that should ahve been testing the method version of objectAt.
packages/ember-runtime/tests/mixins/array_test.js
@@ -1,6 +1,7 @@ import { get, set, + objectAt, addObserver, observer as emberObserver, computed @@ -12,8 +13,7 @@ import EmberArray, { addArrayObserver, removeArrayObserver, arrayContentDidChange, - arrayContentWillChange, - objectAt + arrayContentWillChange } from '../../mixins/array'; import { A as emberA } from '../../mixins/array';
true