2
votes

I am trying to fetch properties of javascript objects from within my NPAPI plugin, but am having some trouble with NPN_HasProperty(), NPN_HasMethod() and NPN_Enumerate() and what they return, and don't return.

As an example, if I create an array with x=new Array; the Javascript x.hasOwnProperty('length') returns true, and NPN_HasProperty() for 'length' returns true, but NPN_Enumerate does not list this property, as I would expect.

In a related issue, I want to detect if an object is a Function. Any suggestions on how to do this in a NPAPI plugin? I am trying to call NPN_HasMethod('call') but this is returning false (as 'call' is defined on a prototype?) Is there any way for the plugin to follow inheritance, or execute the equivalent of "x instanceof Function".. ?

Any further info on how to enumerate over properties, and especially, how to follow the inheritance graph would be really welcome, thanks.

1

1 Answers

1
votes

NPN_Enumerate is a funny thing; it was introduced at the same time as NPN_Construct, and at least on many browsers they don't work on native javascript objects. They are mostly provided to allow you to make enumerating or constructing NPObjects possible.

I already answered your other question on the thread where you actually ask that specific question; best to limit yourself to one question at a time here to avoid confusion.

I would recommend if you need to do this injecting a javascript function into the page with NPN_Evaluate that will enumerate the properties and return either an array or a comma separated string (which would be slightly more efficient, since the array you'd have to iterate through making NPN_GetProperty calls on).