Skip to content

Commit

Permalink
Merge pull request #361 from mixonic/frozen-helper-args
Browse files Browse the repository at this point in the history
[BUGFIX] Only freeze empty array/dict with weakmap
  • Loading branch information
mixonic authored Jan 5, 2017
2 parents 4ca2684 + 6954ade commit 1b91f86
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/glimmer-runtime/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { Dict, dict } from 'glimmer-util';

export const EMPTY_ARRAY = Object.freeze([]);
export const EMPTY_DICT: Dict<any> = Object.freeze(dict<any>());
const HAS_NATIVE_WEAKMAP = (function() {
// detect if `WeakMap` is even present
let hasWeakMap = typeof WeakMap === 'function';
if (!hasWeakMap) { return false; }

let instance = new WeakMap();
// use `Object`'s `.toString` directly to prevent us from detecting
// polyfills as native weakmaps
return Object.prototype.toString.call(instance) === '[object WeakMap]';
})();

export const EMPTY_ARRAY = HAS_NATIVE_WEAKMAP ? Object.freeze([]) : [];
export const EMPTY_DICT: Dict<any> = HAS_NATIVE_WEAKMAP ? Object.freeze(dict<any>()) : dict<any>();

export interface EnumerableCallback<T> {
(item: T): void;
Expand Down

0 comments on commit 1b91f86

Please sign in to comment.