Uploaded image for project: 'Keikai'
  1. Keikai
  2. KEIKAI-228

an extra property in Array causes Keikai crashed


    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 5.2.0
    • 5.1.1
    • None
    • None

      Steps to Reproduce

      1. open chrome developer tool / console tab
      2. load the attached jsp

      Current Result

      zss.wpd:11857 Uncaught TypeError: action.replace is not a function
      at new KMenuitem (zss.wpd:11857)
      at new KMenupopup (zss.wpd:11807)
      at init.paste (zss.wpd:17128)
      at init.paste (zss.wpd:17595)
      at init.build (zss.wpd:17524)
      at init.showToolbar (zss.wpd:12926)
      at init.setShowToolbar (zk.wpd:11275)
      at Function._set2 (zk.wpd:12250)
      at init.setter.func (zk.wpd:20665)
      at init.zk.Widget.zk.$extends.set (zk.wpd:20693)

      Expected Result

      no error

      Debug Information

      1. the root cause is the script

          if (!('unique' in Array.prototype)) {
              Array.prototype.unique = function() {
                  return this.filter(function (value, index, self) {
                      return self.indexOf(value) === index;

      In Keikai, the code here causes the error

      for (let i in data) {
      	let item = new zss.KMenuitem(wgt, data[i], prefix, action);
      	item.parent = self;

      using for...in will iterate the key unique in prototype.

      Proposed solution

      Although adding a property to Array's prototype is a bad practice, for...in is also not a good way to iterate an Array.

      According to the suggestion in MDN , don't iterate an Array with for ... in. Please replace all such loop in KToolbar.js with alternative syntax.

      Note: for...in should not be used to iterate over an Array where the index order is important.

      Array indexes are just enumerable properties with integer names and are otherwise identical to general object properties. There is no guarantee that for...in will return the indexes in any particular order. The for...in loop statement will return all enumerable properties, including those with non–integer names and those that are inherited.

      			for (const subAction of data) {
      				let item = new zss.KMenuitem(wgt, subAction, prefix, action);
      				item.parent = self;



        1. index.jsp
          1 kB
        2. KToolbar.js
          30 kB

            wenninghsu wenninghsu
            hawk hawk
            0 Vote for this issue
            1 Start watching this issue