Skip to content

Commit

Permalink
[BUGFIX] bring back isObject guard for ember-utils/is_proxy
Browse files Browse the repository at this point in the history
`WeakSet.has` throws `TypeError` if argument is not an object:
https://www.ecma-international.org/ecma-262/6.0/#sec-weakset.prototype.has

While recent Chrome versions just returns `false`.
  • Loading branch information
ampatspell committed Jun 15, 2018
1 parent 9ba382d commit 6346e82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/ember-utils/lib/is_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import WeakSet from './weak_set';
const PROXIES = new WeakSet();

export function isProxy(object: any | undefined | null) {
return PROXIES.has(object);
if (isObject(object)) {
return PROXIES.has(object);
}
return false;
}

export function setProxy(object: object) {
Expand Down
18 changes: 18 additions & 0 deletions packages/ember-utils/tests/is_proxy_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isProxy, setProxy } from '..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

moduleFor(
'ember-utils isProxy',
class extends AbstractTestCase {
['@test basic'](assert) {
let proxy = {};
setProxy(proxy);

assert.equal(isProxy(proxy), true);

assert.equal(isProxy({}), false);
assert.equal(isProxy(undefined), false);
assert.equal(isProxy(null), false);
}
}
);

0 comments on commit 6346e82

Please sign in to comment.