Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove function prototype extensions #19663

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions packages/@ember/-internals/environment/lib/env.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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.

Loading