Skip to content

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

Open
sebasbaumh wants to merge 1 commit intobrody2consult:devfrom
sebasbaumh:arrayCheckFix
Open

use Array.isArray() function to check for arrays#844
sebasbaumh wants to merge 1 commit intobrody2consult:devfrom
sebasbaumh:arrayCheckFix

Conversation

@sebasbaumh
Copy link
Copy Markdown

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).

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

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