Skip to content

Commit

Permalink
Merge pull request emberjs#15312 from rwjblue/avoid-refreezing
Browse files Browse the repository at this point in the history
[BUGFIX release] Avoid re-freezing already frozen objects.
  • Loading branch information
rwjblue authored Jun 1, 2017
2 parents 2e01276 + 567b1d7 commit e4f4b8f
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions packages/ember-glimmer/lib/utils/references.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ export const UPDATE = symbol('UPDATE');

export { NULL_REFERENCE, UNDEFINED_REFERENCE } from '@glimmer/runtime';

let maybeFreeze;
if (DEBUG) {
// gaurding this in a DEBUG gaurd (as well as all invocations)
// so that it is properly stripped during the minification's
// dead code elimination
maybeFreeze = (obj) => {
// re-freezing an already frozen object introduces a significant
// performance penalty on Chrome (tested through 59).
//
// See: https://bugs.chromium.org/p/v8/issues/detail?id=6450
if (!Object.isFrozen(obj) && HAS_NATIVE_WEAKMAP) {
Object.freeze(obj);
}
}
}

// @abstract
// @implements PathReference
class EmberPathReference {
Expand Down Expand Up @@ -296,10 +312,8 @@ export class SimpleHelperReference extends CachedReference {
let namedValue = named.value();

if (DEBUG) {
if (HAS_NATIVE_WEAKMAP) {
Object.freeze(positionalValue);
Object.freeze(namedValue);
}
maybeFreeze(positionalValue);
maybeFreeze(namedValue);
}

let result = helper(positionalValue, namedValue);
Expand Down Expand Up @@ -333,10 +347,8 @@ export class SimpleHelperReference extends CachedReference {
let namedValue = named.value();

if (DEBUG) {
if (HAS_NATIVE_WEAKMAP) {
Object.freeze(positionalValue);
Object.freeze(namedValue);
}
maybeFreeze(positionalValue);
maybeFreeze(namedValue);
}

return helper(positionalValue, namedValue);
Expand Down Expand Up @@ -365,10 +377,8 @@ export class ClassBasedHelperReference extends CachedReference {
let namedValue = named.value();

if (DEBUG) {
if (HAS_NATIVE_WEAKMAP) {
Object.freeze(positionalValue);
Object.freeze(namedValue);
}
maybeFreeze(positionalValue);
maybeFreeze(namedValue);
}

return instance.compute(positionalValue, namedValue);
Expand Down

0 comments on commit e4f4b8f

Please sign in to comment.