Ticket #2959 (closed bug: fixed)

Opened 2 years ago

Last modified 22 months ago

instance of Array + GWT + Buttons + IFRAME = BUG in Panel.js

Reported by: grigoryevigor Owned by:
Priority: major Milestone: 2.11 Release
Component: Control.Panel Version: 2.10
Keywords: instanceof Array IFRAME GWT Panel Cc:
State: Pullup

Description

I'm using wrapper with OL API in GWT application. I found problem with Array type detection in OL. It just not works for array passed from other frame (see:  http://javascript.crockford.com/remedial.html).

As for me the problem resides in Panel.js addControls function

/*-------------------------------------------------------------*/

addControls: function(controls) {

if (!(controls instanceof Array)) {

controls = [controls];

} this.controls = this.controls.concat(controls);

/*-------------------------------------------------------------*/

failing to detect type correctly, it wraps array once more to the effect of nonsense. I also found 40 places using similar sintax around a project code. I'm suggesting to replace instanceof with a typeOf function usage from example (see URL above).

Attachments

OpenLayers-2959-Arrays.patch Download (31.6 KB) - added by mwootendev 2 years ago.
Patch that adds OpenLayers.Util.isArray() and utilizes it for Array tests.

Change History

Changed 2 years ago by grigoryevigor

  • type changed from feature to bug

Changed 2 years ago by grigoryevigor

Forgot to mention that GWT injects it's scripts in IFRAME, so that effect, described in article, of failing instanceof operation takes effect, when I'm trying to add controls array, created with GWT to Panel.

I'm loading OL from a host page.

Changed 2 years ago by grigoryevigor

Based on previous comment, I'm proposing to add this function to Util, and use it to detect arrays:

/**

OpenLayers.Util.typeOf = function (value) {

var s = typeof value; if (s === 'object') {

if (value) {

if (Object.prototype.toString.call(value) === '[object Array]') {

s = 'array';

}

} else {

s = 'null';

}

} return s;

};

Changed 2 years ago by mwootendev

Patch that adds OpenLayers.Util.isArray() and utilizes it for Array tests.

Changed 2 years ago by mwootendev

  • state set to Review

I have added a patch that should resolve the issue. The patch adds an OpenLayers.Util.isArray(a) function that utilizes the toString() method mentioned above. I though this might be cleaner than typeOf() === "array".

I replaced all "x instanceof Array" instances in the library code with "OpenLayers.Util.isArray(x)".

I added a test case for isArray() to Utils.html.

Changed 2 years ago by tschaub

  • state changed from Review to Commit

Thanks for the solid patch. Tests pass in Chrome 12, Safari 5, Firefox 4, and IE 6.

Changed 2 years ago by tschaub

  • status changed from new to closed
  • resolution set to fixed

(In [12095]) More robust array type check. p=mwootendev, r=me (closes #2959)

Changed 2 years ago by tschaub

  • status changed from closed to reopened
  • state changed from Commit to Pullup
  • resolution fixed deleted
  • milestone changed from 2.12 Release to 2.11 Release

Changed 2 years ago by tschaub

r12097 brings in an additional test.

Changed 22 months ago by ahocevar

  • status changed from reopened to closed
  • resolution set to fixed

in 2.11-rc2

Note: See TracTickets for help on using tickets.