Skip to content

Commit

Permalink
Merge pull request #19667 from simonihmig/ie-cleanup2
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic authored Jul 20, 2021
2 parents 9149433 + bdb32d9 commit 3ce13ce
Show file tree
Hide file tree
Showing 29 changed files with 107 additions and 244 deletions.
46 changes: 21 additions & 25 deletions packages/@ember/-internals/container/lib/container.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Factory, LookupOptions, Owner, setOwner } from '@ember/-internals/owner';
import { dictionary, HAS_NATIVE_PROXY, HAS_NATIVE_SYMBOL, symbol } from '@ember/-internals/utils';
import { dictionary, symbol } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import Registry, { DebugRegistry, Injection } from './registry';
Expand Down Expand Up @@ -234,30 +234,26 @@ if (DEBUG) {
* set on the manager.
*/
function wrapManagerInDeprecationProxy<T, C>(manager: FactoryManager<T, C>): FactoryManager<T, C> {
if (HAS_NATIVE_PROXY) {
let validator = {
set(_obj: T, prop: keyof T) {
throw new Error(
`You attempted to set "${prop}" on a factory manager created by container#factoryFor. A factory manager is a read-only construct.`
);
},
};

// Note:
// We have to proxy access to the manager here so that private property
// access doesn't cause the above errors to occur.
let m = manager;
let proxiedManager = {
class: m.class,
create(props?: { [prop: string]: any }) {
return m.create(props);
},
};

return new Proxy(proxiedManager, validator as any) as any;
}
let validator = {
set(_obj: T, prop: keyof T) {
throw new Error(
`You attempted to set "${prop}" on a factory manager created by container#factoryFor. A factory manager is a read-only construct.`
);
},
};

return manager;
// Note:
// We have to proxy access to the manager here so that private property
// access doesn't cause the above errors to occur.
let m = manager;
let proxiedManager = {
class: m.class,
create(props?: { [prop: string]: any }) {
return m.create(props);
},
};

return new Proxy(proxiedManager, validator as any) as any;
}

function isSingleton(container: Container, fullName: string) {
Expand Down Expand Up @@ -551,7 +547,7 @@ class FactoryManager<T, C> {
this.injections = undefined;
setFactoryFor(this, this);

if (factory && (HAS_NATIVE_SYMBOL || INIT_FACTORY in factory)) {
if (factory) {
setFactoryFor(factory, this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { getOwner } from '@ember/-internals/owner';
import { _backburner } from '@ember/runloop';
import { get } from '@ember/-internals/metal';
import { dasherize } from '@ember/string';
import { HAS_NATIVE_SYMBOL } from '@ember/-internals/utils';
import { Namespace, Object as EmberObject, A as emberA } from '@ember/-internals/runtime';
import { consumeTag, createCache, getValue, tagFor, untrack } from '@glimmer/validator';

function iterate(arr, fn) {
if (HAS_NATIVE_SYMBOL && Symbol.iterator in arr) {
if (Symbol.iterator in arr) {
for (let item of arr) {
fn(item);
}
Expand Down
8 changes: 3 additions & 5 deletions packages/@ember/-internals/glimmer/lib/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ import {
} from './component-managers/curly';

// Keep track of which component classes have already been processed for lazy event setup.
// Using a WeakSet would be more appropriate here, but this can only be used when IE11 support is dropped.
// Thus the workaround using a WeakMap<object, true>
let lazyEventsProcessed = new WeakMap<EventDispatcher, WeakMap<object, true>>();
let lazyEventsProcessed = new WeakMap<EventDispatcher, WeakSet<object>>();

/**
@module @ember/component
Expand Down Expand Up @@ -671,7 +669,7 @@ const Component = CoreView.extend(
if (eventDispatcher) {
let lazyEventsProcessedForComponentClass = lazyEventsProcessed.get(eventDispatcher);
if (!lazyEventsProcessedForComponentClass) {
lazyEventsProcessedForComponentClass = new WeakMap<object, true>();
lazyEventsProcessedForComponentClass = new WeakSet<object>();
lazyEventsProcessed.set(eventDispatcher, lazyEventsProcessedForComponentClass);
}

Expand All @@ -685,7 +683,7 @@ const Component = CoreView.extend(
}
});

lazyEventsProcessedForComponentClass.set(proto, true);
lazyEventsProcessedForComponentClass.add(proto);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import InternalComponent, {
handleDeprecatedEventArguments,
InternalComponentConstructor,
jQueryEventShim,
ObjectEntries,
ObjectValues,
} from './internal';

const UNINITIALIZED: unknown = Object.freeze({});
Expand Down Expand Up @@ -304,7 +302,7 @@ export function handleDeprecatedFeatures(

handleDeprecatedAttributeArguments(target, attributeBindings);

handleDeprecatedEventArguments(target, ObjectEntries(virtualEvents));
handleDeprecatedEventArguments(target, Object.entries(virtualEvents));

{
let superIsVirtualEventListener = prototype['isVirtualEventListener'];
Expand All @@ -318,7 +316,7 @@ export function handleDeprecatedFeatures(
listener: Function
): listener is VirtualEventListener {
return (
ObjectValues(virtualEvents).indexOf(name) !== -1 ||
Object.values(virtualEvents).indexOf(name) !== -1 ||
superIsVirtualEventListener.call(this, name, listener)
);
},
Expand Down
24 changes: 3 additions & 21 deletions packages/@ember/-internals/glimmer/lib/components/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,6 @@ import InternalModifier, { InternalModifierManager } from '../modifiers/internal

function NOOP(): void {}

// TODO: remove me when IE11 support is EOL
export let ObjectEntries = ((): typeof Object['entries'] => {
if (typeof Object.entries === 'function') {
return Object.entries;
} else {
return (obj: {}) => Object.keys(obj).map((key) => [key, obj[key]] as [string, unknown]);
}
})();

// TODO: remove me when IE11 support is EOL
export let ObjectValues = ((): typeof Object['values'] => {
if (typeof Object.values === 'function') {
return Object.values;
} else {
return (obj: {}) => Object.keys(obj).map((key) => obj[key]);
}
})();

export type EventListener = (event: Event) => void;

export default class InternalComponent {
Expand Down Expand Up @@ -444,7 +426,7 @@ if (EMBER_MODERNIZED_BUILT_IN_COMPONENTS) {
name: string
): boolean {
let events = [
...ObjectValues(getEventsMap(this.owner)),
...Object.values(getEventsMap(this.owner)),
'focus-in',
'focus-out',
'key-press',
Expand All @@ -470,7 +452,7 @@ if (EMBER_MODERNIZED_BUILT_IN_COMPONENTS) {
let { element, component, listenerFor, listeners } = this;

let entries: [event: string, argument: string][] = [
...ObjectEntries(getEventsMap(this.owner)),
...Object.entries(getEventsMap(this.owner)),
...extraEvents,
];

Expand All @@ -489,7 +471,7 @@ if (EMBER_MODERNIZED_BUILT_IN_COMPONENTS) {
remove(): void {
let { element, listeners } = this;

for (let [event, listener] of ObjectEntries(listeners)) {
for (let [event, listener] of Object.entries(listeners)) {
element.removeEventListener(event, listener);
}

Expand Down
7 changes: 3 additions & 4 deletions packages/@ember/-internals/glimmer/lib/utils/iterator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { objectAt } from '@ember/-internals/metal';
import { _contentFor } from '@ember/-internals/runtime';
import { EmberArray, HAS_NATIVE_SYMBOL, isEmberArray, isObject } from '@ember/-internals/utils';
import { EmberArray, isEmberArray, isObject } from '@ember/-internals/utils';
import { Option } from '@glimmer/interfaces';
import { IteratorDelegate } from '@glimmer/reference';
import { consumeTag, isTracking, tagFor } from '@glimmer/validator';
Expand All @@ -21,7 +20,7 @@ function toEachInIterator(iterable: unknown) {

if (Array.isArray(iterable) || isEmberArray(iterable)) {
return ObjectIterator.fromIndexable(iterable);
} else if (HAS_NATIVE_SYMBOL && isNativeIterable<[unknown, unknown]>(iterable)) {
} else if (isNativeIterable<[unknown, unknown]>(iterable)) {
return MapLikeNativeIterator.from(iterable);
} else if (hasForEach(iterable)) {
return ObjectIterator.fromForEachable(iterable);
Expand All @@ -39,7 +38,7 @@ function toEachIterator(iterable: unknown) {
return ArrayIterator.from(iterable);
} else if (isEmberArray(iterable)) {
return EmberArrayIterator.from(iterable);
} else if (HAS_NATIVE_SYMBOL && isNativeIterable(iterable)) {
} else if (isNativeIterable(iterable)) {
return ArrayLikeNativeIterator.from(iterable);
} else if (hasForEach(iterable)) {
return ArrayIterator.fromForEachable(iterable);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { DEBUG } from '@glimmer/env';
import { moduleFor, RenderingTestCase, runTask } from 'internal-test-helpers';

import { HAS_NATIVE_SYMBOL } from '@ember/-internals/utils';

import { setComponentTemplate, getComponentTemplate } from '@glimmer/manager';
import { Component, compile } from '../../utils/helpers';

Expand Down Expand Up @@ -68,11 +66,9 @@ moduleFor(
setComponentTemplate(compile('foo'), 'foo');
}, /Cannot call `setComponentTemplate` on `foo`/);

if (HAS_NATIVE_SYMBOL) {
assert.throws(() => {
setComponentTemplate(compile('foo'), Symbol('foo'));
}, /Cannot call `setComponentTemplate` on `Symbol\(foo\)`/);
}
assert.throws(() => {
setComponentTemplate(compile('foo'), Symbol('foo'));
}, /Cannot call `setComponentTemplate` on `Symbol\(foo\)`/);
}

'@test calling it twice on the same object asserts'(assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { set, computed } from '@ember/-internals/metal';
import { getDebugFunction, setDebugFunction } from '@ember/debug';
import { readOnly } from '@ember/object/computed';
import { Object as EmberObject, ObjectProxy } from '@ember/-internals/runtime';
import { HAS_NATIVE_SYMBOL } from '@ember/-internals/utils';
import { constructStyleDeprecationMessage } from '@ember/-internals/views';
import { Component, SafeString, htmlSafe } from '../utils/helpers';

Expand Down Expand Up @@ -768,12 +767,9 @@ const SharedContentTestCases = new DynamicContentTestGenerator([

let GlimmerContentTestCases = new DynamicContentTestGenerator([
[Object.create(null), EMPTY, 'an object with no toString'],
[Symbol('debug'), 'Symbol(debug)', 'a symbol'],
]);

if (HAS_NATIVE_SYMBOL) {
GlimmerContentTestCases.cases.push([Symbol('debug'), 'Symbol(debug)', 'a symbol']);
}

applyMixins(DynamicContentTest, SharedContentTestCases, GlimmerContentTestCases);

moduleFor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '@ember/instrumentation';
import { EMBER_IMPROVED_INSTRUMENTATION } from '@ember/canary-features';
import { jQueryDisabled, jQuery } from '@ember/-internals/views';
import { HAS_NATIVE_PROXY } from '@ember/-internals/utils';
import { DEBUG } from '@glimmer/env';

let canDataTransfer = Boolean(document.createEvent('HTMLEvents').dataTransfer);
Expand Down Expand Up @@ -749,9 +748,7 @@ if (jQueryDisabled) {
assert.ok(receivedEvent instanceof jQuery.Event, 'event is a jQuery.Event');
}

[`@${HAS_NATIVE_PROXY ? 'test' : 'skip'} accessing jQuery.Event#originalEvent is deprecated`](
assert
) {
['@test accessing jQuery.Event#originalEvent is deprecated'](assert) {
let receivedEvent;

this.registerComponent('x-foo', {
Expand Down Expand Up @@ -823,7 +820,7 @@ if (jQueryDisabled) {
}

[`@${
HAS_NATIVE_PROXY && DEBUG ? 'test' : 'skip'
DEBUG ? 'test' : 'skip'
} accessing jQuery.Event#__originalEvent does not trigger deprecations to support ember-jquery-legacy`](
assert
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { set } from '@ember/-internals/metal';
import { HAS_NATIVE_PROXY } from '@ember/-internals/utils';
import { DEBUG } from '@glimmer/env';
import { RenderingTestCase, moduleFor, runTask } from 'internal-test-helpers';
import { Component } from '../../utils/helpers';
Expand Down Expand Up @@ -121,7 +120,7 @@ moduleFor(
}

'@test there is no `this` context within the callback'(assert) {
if (DEBUG && HAS_NATIVE_PROXY) {
if (DEBUG) {
assert.expect(0);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { RenderingTestCase, moduleFor, runTask } from 'internal-test-helpers';
import { Component } from '../../utils/helpers';

import { set, computed } from '@ember/-internals/metal';
import { HAS_NATIVE_PROXY } from '@ember/-internals/utils';

moduleFor(
'Helpers test: {{hash}}',
Expand Down Expand Up @@ -226,13 +225,9 @@ moduleFor(
init() {
this._super(...arguments);

if (HAS_NATIVE_PROXY) {
expectDeprecation(() => {
set(this.hash, 'lastName', 'Hietala');
}, /You set the '.*' property on a {{hash}} object/);
} else {
expectDeprecation(() => {
set(this.hash, 'lastName', 'Hietala');
}
}, /You set the '.*' property on a {{hash}} object/);

instance = this;
},
Expand Down Expand Up @@ -261,13 +256,9 @@ moduleFor(
runTask(() => {
set(this.context, 'firstName', 'Godfrey');

if (HAS_NATIVE_PROXY) {
expectDeprecation(() => {
set(instance.hash, 'lastName', 'Chan');
}, /You set the '.*' property on a {{hash}} object/);
} else {
expectDeprecation(() => {
set(instance.hash, 'lastName', 'Chan');
}
}, /You set the '.*' property on a {{hash}} object/);
});

this.assertText('Godfrey Chan');
Expand All @@ -294,13 +285,9 @@ moduleFor(
this.assertText('Chad ');

runTask(() => {
if (HAS_NATIVE_PROXY) {
expectDeprecation(() => {
set(fooBarInstance.hash, 'lastName', 'Hietala');
}, /You set the '.*' property on a {{hash}} object/);
} else {
expectDeprecation(() => {
set(fooBarInstance.hash, 'lastName', 'Hietala');
}
}, /You set the '.*' property on a {{hash}} object/);
});

this.assertText('Chad Hietala');
Expand Down
Loading

0 comments on commit 3ce13ce

Please sign in to comment.