Opened 9 years ago

Closed 3 years ago

#11700 closed defect (patchwelcome)

dojox.json.query collects properties and methods from the object's prototype along with the instance properties

Reported by: MaxMotovilov Owned by: Kris Zyp
Priority: high Milestone: 1.13
Component: Dojox Version: 1.5
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by Adam Peller)

var cls = dojo.extend( 
  function(bag) {dojo.mixin( this, bag );},

  { aMethod: function() {}, aPrototypeProperty: 12345 }

),

    o = new cls( { anInstanceProperty: 54321 } ),

    q = dojox.json.query( "[*]", o );

At this point, 'q' will contain not only 54321, but also 12345 and an empty function collected from the prototype.

It appears that JSON Query has only been targeted to work on objects deserialized from JSON in a straightforward manner (i.e. with eval()) without a view towards the objects with non-default constructors. This is a serious handicap in my use case where the objects are actually instantiated by an intelligent cache/virtual memory layer that injects additional metadata and functionality into the prototypes without affecting the deserialized representations. It would be nice to either restrict [*] to instance properties only (by adding a check for hasOwnProperty() to the generated code) or to have an alternative syntax for such an operation. Note that property enumeration seems to be the only query operation logically affected by this oversight.

Change History (2)

comment:1 Changed 9 years ago by Adam Peller

Description: modified (diff)
Owner: changed from Adam Peller to Kris Zyp

comment:2 Changed 3 years ago by dylan

Milestone: tbd1.12
Resolution: patchwelcome
Status: newclosed

Given that no one has shown interest in creating a patch in the past 5+ years, I'm closing this as patchwelcome.

Note: See TracTickets for help on using tickets.