In my NPAPI plugin I wish to determine if an NPObject is a function (ie, it is an instance of Function). Any suggestions how I can do this?
I can check with NPN_HasMethod() to see if there is a method called 'call', but I think a better way would be if I could perform the equivalent of javascript's "foo instanceof Function"
I have tried to call NPN_Evaluate, with my 'foo' NPObject as the scope, and a script of "this instanceof Function" but unfortunately the 'this' is the global scope, not my 'foo' object. Am I misunderstanding the intention of the scope parameter here? Any examples I've found are using the window. Being able to use the actual object (or at least the 'this' or a reference to the javascript object) would be preferable (for many other purposes) but any good way to determine if it's a function would be appreciated.
The only way I know of would be to use NPN_Evaluation to inject a function into the global javascript scope and then call it with the NPObject.
For example, inject the following function:
window.isFunction = window.isFunction || function(obj) {
return typeof obj === 'function';
};
Then you can use NPAPI to get the NPObject for the window, get the "isFunction" property, and then do an NPN_InvokeDefault on it with the function you want to check as the parameter.