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

feat(breaking): replace polyfills assign with Object.assign #795

Merged
merged 1 commit into from
Apr 21, 2023
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
12 changes: 5 additions & 7 deletions packages/ember-cookies/src/services/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { get } from '@ember/object';
import { assert } from '@ember/debug';
import { getOwner } from '@ember/application';
import Service from '@ember/service';
import { assign as emberAssign } from '@ember/polyfills';
import { serializeCookie } from '../utils/serialize-cookie';
const { keys } = Object;
const assign = Object.assign || emberAssign;
const DEFAULTS = { raw: false };
const MAX_COOKIE_BYTE_LENGTH = 4096;

Expand Down Expand Up @@ -44,14 +42,14 @@ export default class CookiesService extends Service {
}, {});

let fastBootCookiesCache = this._fastBootCookiesCache || {};
fastBootCookies = assign({}, fastBootCookies, fastBootCookiesCache);
fastBootCookies = Object.assign({}, fastBootCookies, fastBootCookiesCache);
this._fastBootCookiesCache = fastBootCookies;

return this._filterCachedFastBootCookies(fastBootCookies);
}

read(name, options = {}) {
options = assign({}, DEFAULTS, options || {});
options = Object.assign({}, DEFAULTS, options || {});
assert(
'Domain, Expires, Max-Age, and Path options cannot be set when reading cookies',
isEmpty(options.domain) &&
Expand All @@ -76,7 +74,7 @@ export default class CookiesService extends Service {
}

write(name, value, options = {}) {
options = assign({}, DEFAULTS, options || {});
options = Object.assign({}, DEFAULTS, options || {});
assert(
"Cookies cannot be set as signed as signed cookies would not be modifyable in the browser as it has no knowledge of the express server's signing key!",
!options.signed
Expand Down Expand Up @@ -104,7 +102,7 @@ export default class CookiesService extends Service {
}

clear(name, options = {}) {
options = assign({}, options || {});
options = Object.assign({}, options || {});
assert(
'Expires, Max-Age, and raw options cannot be set when clearing cookies',
isEmpty(options.expires) && isEmpty(options.maxAge) && isEmpty(options.raw)
Expand Down Expand Up @@ -159,7 +157,7 @@ export default class CookiesService extends Service {

_cacheFastBootCookie(name, value, options = {}) {
let fastBootCache = this._fastBootCookiesCache || {};
let cachedOptions = assign({}, options);
let cachedOptions = Object.assign({}, options);

if (cachedOptions.maxAge) {
let expires = new Date();
Expand Down
5 changes: 1 addition & 4 deletions packages/ember-cookies/src/test-support/clear-all-cookies.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { assert } from '@ember/debug';
import { assign as emberAssign } from '@ember/polyfills';
import { isEmpty } from '@ember/utils';
import { serializeCookie } from '../utils/serialize-cookie';

const assign = Object.assign || emberAssign;

export default function clearAllCookies(options = {}) {
assert('Cookies cannot be set to be HTTP-only from a browser!', !options.httpOnly);
assert(
'Expires, Max-Age, and raw options cannot be set when clearing cookies',
isEmpty(options.expires) && isEmpty(options.maxAge) && isEmpty(options.raw)
);
options = assign({}, options, {
options = Object.assign({}, options, {
expires: new Date(0),
});

Expand Down