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

isEmpty call on ProxyObject w/ size property throws '.get()' proxy assertion (3.1+) #17032

Closed
nickschot opened this issue Oct 3, 2018 · 5 comments · Fixed by #17570
Closed

Comments

@nickschot
Copy link
Contributor

nickschot commented Oct 3, 2018

Having an ObjectProxy (or any object using unknownProperty) with a property named 'size' of type String isEmpty(myChangeset) results in the Assertion Failed: You attempted to access the 'size' property (of changeset:[object Object]). Since Ember 3.1 , this is usually fine as you no longer need to use '.get()'... error.

This is caused at:

if (typeof obj.size === 'number') {
and only occurs in Ember 3.1+ (which is when the assertion was added) which also means that the assertion will trigger for any object with a "size" key that refers to a proxy.

Minimal reproduction: https://ember-twiddle.com/8e63470aa2e8ab8b07735334b169c96d?openFiles=controllers.application.js%2C

AFAIK .size is just used for Maps/Sets and the like? Might an extra check be necessary?

Somewhat similar to: #16259

cc @snewcomer

@nickschot nickschot changed the title isEmpty call on changeset w/ size property throws '.get()' proxy assertion isEmpty call on changeset w/ size property throws '.get()' proxy assertion (3.1+) Oct 3, 2018
@pixelhandler
Copy link
Contributor

@nickschot can you create an ember-twiddle as an example?

@nickschot
Copy link
Contributor Author

nickschot commented Oct 16, 2018

@pixelhandler I did some more debugging and the test case is pretty simple. I will update the main post with my new findings. Meanwhile a reproduction can be found: https://ember-twiddle.com/d3b2742a7156454f2ece80d6c26d2581?openFiles=controllers.application.js%2C . Press the "validate" button once and the error is thrown in the console.

@nickschot nickschot changed the title isEmpty call on changeset w/ size property throws '.get()' proxy assertion (3.1+) isEmpty call on ProxyObject w/ size property throws '.get()' proxy assertion (3.1+) Feb 6, 2019
@nickschot
Copy link
Contributor Author

nickschot commented Feb 6, 2019

I have created an updated test case which doesn't use changeset but a normal ObjectProxy in the example (as this is the more general case).

Updated minimal reproduction: https://ember-twiddle.com/8e63470aa2e8ab8b07735334b169c96d?openFiles=controllers.application.js%2C

The first post is also updated.

@nickschot
Copy link
Contributor Author

nickschot commented Feb 6, 2019

I think the solution can be as simple as adding an unknownProperty check so that it falls through to the branch where get(obj, 'size') is used. This still conforms to the description:

If the value is an object with a size property of type number, it is used
to check emptiness.

Proposed fix:

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

This uses the same check as the assertion:

if (DEBUG && HAS_NATIVE_PROXY && typeof self.unknownProperty === 'function') {

@nickschot
Copy link
Contributor Author

nickschot commented Feb 6, 2019

The same is true for an ObjectProxy with a property length. I think to conform with the description of isEmpty we need to apply the same fix to the branch testing for length.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants