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

use Array.isArray() function to check for arrays #844

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

sebasbaumh
Copy link

Currently the plugin is checking for arrays by comparing the constructor to the Array class.
There are cases where a JavaScript function running in another iframe or window is calling a Cordova-sqlite-storage function (like GWT compiled JavaScript code).
In that case there are different array prototypes (one per window object), which nevertheless are functionally identical.
But as the check returns false, the given array is not processed any further.

The function to be used to detect an array even in these cases is Array.isArray().
It ensures correct array detection also for iframes.

See also http://web.mit.edu/jwalden/www/isArray.html :

Multiple globals, however, are fundamental to the browser; each window object is the global object for the scripts its page contains or references. What about arrays in different windows? The shared-mutation hazard of having arrays in two coordinating windows be instances of the same Array constructor, sharing the same Array.prototype, is enormous when either page augments Array.prototype (not to mention the security problems when one page is malicious!), so Array and Array.prototype in each window must be different. Therefore, by the semantics of instanceof, o instanceof Array works correctly only if o is an array created by that page's original Array constructor (or, equivalently, by use of an array literal in that page).

@brodycj brodycj changed the base branch from storage-master to dev February 18, 2019 21:15
@brodycj
Copy link
Contributor

brodycj commented Mar 13, 2019

Thanks for the contribution. I hope to give my response in the near future.

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

Successfully merging this pull request may close these issues.

2 participants