Skip to content

Commit

Permalink
Merge pull request #19663 from nlfurniss/remove-function-prototype-ex…
Browse files Browse the repository at this point in the history
…tensions

Remove function prototype extensions
  • Loading branch information
mixonic committed Jul 20, 2021
2 parents 8acff3d + 8ae02f2 commit 7222c5e
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 441 deletions.
9 changes: 1 addition & 8 deletions packages/@ember/-internals/environment/lib/env.ts
@@ -1,4 +1,3 @@
import { FUNCTION_PROTOTYPE_EXTENSIONS } from '@ember/deprecated-features';
import { DEBUG } from '@glimmer/env';
import global from './global';

Expand Down Expand Up @@ -220,16 +219,10 @@ export const ENV = {
if (EXTEND_PROTOTYPES !== undefined) {
if (typeof EXTEND_PROTOTYPES === 'object' && EXTEND_PROTOTYPES !== null) {
ENV.EXTEND_PROTOTYPES.String = EXTEND_PROTOTYPES.String !== false;
if (FUNCTION_PROTOTYPE_EXTENSIONS) {
ENV.EXTEND_PROTOTYPES.Function = EXTEND_PROTOTYPES.Function !== false;
}
ENV.EXTEND_PROTOTYPES.Array = EXTEND_PROTOTYPES.Array !== false;
} else {
let isEnabled = EXTEND_PROTOTYPES !== false;
ENV.EXTEND_PROTOTYPES.String = isEnabled;
if (FUNCTION_PROTOTYPE_EXTENSIONS) {
ENV.EXTEND_PROTOTYPES.Function = isEnabled;
}
ENV.EXTEND_PROTOTYPES.Array = isEnabled;
}
}
Expand Down Expand Up @@ -259,6 +252,6 @@ export const ENV = {
}
})(global.EmberENV);

export function getENV() {
export function getENV(): object {
return ENV;
}
87 changes: 0 additions & 87 deletions packages/@ember/-internals/metal/tests/observer_test.js
@@ -1,4 +1,3 @@
import { ENV } from '@ember/-internals/environment';
import {
changeProperties,
addObserver,
Expand All @@ -15,7 +14,6 @@ import {
set,
} from '..';
import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
import { FUNCTION_PROTOTYPE_EXTENSIONS } from '@ember/deprecated-features';
import { destroy } from '@glimmer/destroyable';
import { meta as metaFor } from '@ember/-internals/meta';

Expand Down Expand Up @@ -192,91 +190,6 @@ moduleFor(
assert.equal(observerCount, 10, 'should continue to fire indefinitely');
}

async ['@test observer added via Function.prototype extensions and brace expansion should fire when property changes'](
assert
) {
if (!FUNCTION_PROTOTYPE_EXTENSIONS && ENV.EXTEND_PROTOTYPES.Function) {
obj = {};
let count = 0;

expectDeprecation(() => {
mixin(obj, {
observeFooAndBar: function () {
count++;
}.observes('{foo,bar}'),
});
}, /Function prototype extensions have been deprecated, please migrate from function\(\){}.observes\('foo'\) to observer\('foo', function\(\) {}\)/);

set(obj, 'foo', 'foo');
await runLoopSettled();

assert.equal(count, 1, 'observer specified via brace expansion invoked on property change');

set(obj, 'bar', 'bar');
await runLoopSettled();

assert.equal(count, 2, 'observer specified via brace expansion invoked on property change');

set(obj, 'baz', 'baz');
await runLoopSettled();

assert.equal(count, 2, 'observer not invoked on unspecified property');
} else {
assert.expect(0);
}
}

async ['@test observer specified via Function.prototype extensions via brace expansion should fire when dependent property changes'](
assert
) {
if (!FUNCTION_PROTOTYPE_EXTENSIONS && ENV.EXTEND_PROTOTYPES.Function) {
obj = { baz: 'Initial' };
let count = 0;

defineProperty(
obj,
'foo',
computed('bar', function () {
return get(this, 'bar').toLowerCase();
})
);

defineProperty(
obj,
'bar',
computed('baz', function () {
return get(this, 'baz').toUpperCase();
})
);

expectDeprecation(() => {
mixin(obj, {
fooAndBarWatcher: function () {
count++;
}.observes('{foo,bar}'),
});
}, /Function prototype extensions have been deprecated, please migrate from function\(\){}.observes\('foo'\) to observer\('foo', function\(\) {}\)/);

get(obj, 'foo');
set(obj, 'baz', 'Baz');
await runLoopSettled();

// fire once for foo, once for bar
assert.equal(
count,
2,
'observer specified via brace expansion invoked on dependent property change'
);

set(obj, 'quux', 'Quux');
await runLoopSettled();

assert.equal(count, 2, 'observer not fired on unspecified property');
} else {
assert.expect(0);
}
}

async ['@test observers watching multiple properties via brace expansion should fire when the properties change'](
assert
) {
Expand Down
2 changes: 0 additions & 2 deletions packages/@ember/-internals/runtime/index.js
Expand Up @@ -30,5 +30,3 @@ export { default as PromiseProxyMixin } from './lib/mixins/promise_proxy';

export { default as RSVP, onerrorDefault } from './lib/ext/rsvp'; // just for side effect of extending Ember.RSVP
export { typeOf } from './lib/type-of';

import './lib/ext/function'; // just for side effect of extending Function.prototype
197 changes: 0 additions & 197 deletions packages/@ember/-internals/runtime/lib/ext/function.js

This file was deleted.

0 comments on commit 7222c5e

Please sign in to comment.