Skip to content

Conversation

@hiranya911
Copy link
Contributor

In newer JS specs like es2015, custom array types can have a constructor that is not Array.

class CustomArray extends Array { }

const arr = new CustomArray();
console.log(Array.isArray(arr), arr.constructor);

ES5 output: true [Function: Array]
ES2015 output: true [Function: CustomArray]

Our utils.deepCopy() method does not correctly copy such objects, which sometimes causes unusual behaviors. This fixes the issue for the FCM APIs affected by this problem.

Ideally, we should push this fix down into the deepCopy() method. But that would affect all the modules. I'd prefer to test this out with FCM first, and if all looks good move the fix to deepCopy() in the future.

Resolves #566

// for more context.
arrayLike.constructor = CustomArray;

return messaging.sendAll(arrayLike)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you validate the request arrayLike was property processed and converted to array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no way to validate it. But at least on non-ES5 targets, this test case fails if the SDK doesn't handle array-like objects correctly (it would throw the same error reported in #566).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks for clarifying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tokens type with MongooseArray conflict with android TTL

2 participants