Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does my simple test NPObject not work?
    text
    copied!<p>I have this getValue method + NPclass methods: </p> <pre><code>static bool hasmethod(NPObject *npobj, NPIdentifier name) { return true; } static NPObject* allocate (NPP npp, NPClass *aClass) { return browser-&gt; createobject(npp, aClass); } static bool hasProperty(NPObject *npobj, NPIdentifier name) { return true; } static bool getProperty (NPObject *npobj, NPIdentifier name, NPVariant *result) { if (!result) return false; INT32_TO_NPVARIANT(50, *result); return true; } static void deallocate (NPObject *npobj) { browser -&gt; memfree(npobj); } static bool enumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count) { return false; } static bool defaultInvoke(NPObject* obj, const NPVariant *args, uint32_t argCount, NPVariant *result) { if (!result) return false; INT32_TO_NPVARIANT(42, *result); return true; } static bool setProperty (NPObject *npobj, NPIdentifier name, const NPVariant *value) { return false; } static void invalidate(NPObject *npobj) { } static bool removeProperty (NPObject *npobj,NPIdentifier name) { return false; } NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { if (! instance) { return NPERR_INVALID_INSTANCE_ERROR; } struct NPClass class; class.structVersion = NP_CLASS_STRUCT_VERSION; class.construct = NULL; class.deallocate = deallocate; class.hasMethod = hasmethod; class.getProperty= getProperty; class.enumerate= enumerate; class.removeProperty= removeProperty; class.hasProperty = hasProperty; class.invoke = pinvoke; class.invokeDefault = defaultInvoke; class.invalidate = invalidate; class.setProperty = setProperty; class.allocate = allocate; if (variable == NPPVpluginScriptableNPObject) { void **v = (void **)value; struct NPObject *object = NPN_CreateObject(instance, &amp;class); NPN_RetainObject(object); *v = object; return NPERR_NO_ERROR; } return NPERR_GENERIC_ERROR; } </code></pre> <p>Here are the two other methods the class points to:</p> <pre><code> bool hasmethod(NPObject *npobj, NPIdentifier name) { return true; } static bool pinvoke(NPObject* obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result) { if (!result) return false; INT32_TO_NPVARIANT(32, *result); return true; } </code></pre> <p>Basically, I wanted the object to return 32 when anything was called just to test.</p> <p>Here are my create &amp; retain methods:</p> <pre><code>NPObject *NPN_CreateObject(NPP npp, NPClass *aClass) { return browser-&gt;createobject(npp, aClass); } NPObject *NPN_RetainObject(NPObject *npobj) { return browser-&gt;retainobject(npobj); } </code></pre> <p>In my Javascript:</p> <pre><code> &lt;embed type="application/x-my-extension" id="pluginId"&gt; &lt;script&gt; var plugin = document.getElementById("pluginId"); console.log(plugin.something); </code></pre> <p>The window is drawn on the page, but the console outputs undefined. Help would be greatly appreciated. Thanks!</p> <p>UPDATE: Georg suggested that the browser was crashing due to infinite recursion with my allocate method. Here is the new one:</p> <pre><code> void* NPN_MemAlloc(uint32_t size) { return browser-&gt;memalloc(size); } static NPObject* allocate (NPP npp, NPClass *aClass) { NPObject* object = (NPObject*)NPN_MemAlloc(sizeof(NPObject)); if (!object) { return NULL; } memset(object, 0, sizeof(NPObject)); return object; } </code></pre> <p>The plugin still crashes.</p> <p>Update 2: I made the object Instance specific</p> <pre><code>typedef struct PluginInstance { NPP npp; NPWindow window; NPObject *object; }PluginInstance; </code></pre> <p>In my NPP_New method I have</p> <pre><code> PluginInstance *newInstance = (PluginInstance*)malloc(sizeof(PluginInstance)); bzero(newInstance, sizeof(PluginInstance)); newInstance -&gt; object = NPN_CreateObject(instance, &amp;class); newInstance-&gt;npp = instance; instance-&gt;pdata = newInstance; </code></pre> <p>In my getValue method:</p> <pre><code> NPObject* obj = ((PluginInstance *) (instance-&gt;pdata)) -&gt; object; void **v = (void **)value; NPN_RetainObject(obj); *v = obj; </code></pre> <p>still the same problem</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload