Skip to content

Commit

Permalink
Merge pull request #17570 from nickschot/fix-objectproxy-is-empty
Browse files Browse the repository at this point in the history
[BUGFIX] passing ObjectProxy with a property size to `isEmpty` would throw assertion
  • Loading branch information
locks authored Oct 16, 2021
2 parents 7b9584b + 8c5147f commit b838c80
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@ember/-internals/metal/lib/is_empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function isEmpty(obj: any): boolean {
return none;
}

if (typeof obj.size === 'number') {
if (typeof obj.unknownProperty !== 'function' && typeof obj.size === 'number') {
return !obj.size;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/@ember/-internals/metal/tests/is_empty_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isEmpty } from '..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
import ObjectProxy from '../../runtime/lib/system/object_proxy';

moduleFor(
'isEmpty',
Expand All @@ -8,6 +9,7 @@ moduleFor(
let string = 'string';
let fn = function () {};
let object = { length: 0 };
let proxy = ObjectProxy.create({ content: { size: 0 } });

assert.equal(true, isEmpty(null), 'for null');
assert.equal(true, isEmpty(undefined), 'for undefined');
Expand All @@ -22,6 +24,7 @@ moduleFor(
assert.equal(true, isEmpty([]), 'for an empty Array');
assert.equal(false, isEmpty({}), 'for an empty Object');
assert.equal(true, isEmpty(object), "for an Object that has zero 'length'");
assert.equal(true, isEmpty(proxy), "for a proxy that has zero 'size'");
}
}
);

0 comments on commit b838c80

Please sign in to comment.