Skip to content Skip to sidebar Skip to footer

Unable To Pass Integer From Javascript To Npapi Plugin

I am writing a simple napapi plugin where I have to print the value passed from javascript function in html page. But I am facing problem while doing it. It works properly on firef

Solution 1:

When providing a number argument to a NPAPI method, it is undefined whether you will receive a Int32 or Double variant, so you have to handle both cases in your code. Furthermore, the NPVARIANT_TO_* macros only extract the respective value - they don't do any conversion.

To extract an integer from any numeric argument, you have to write your own code, e.g. something like:

bool convertToInt(const NPVariant& v, int32_t& out) {
  if (NPVARIANT_IS_INT32(v)) {
    out = NPVARIANT_TO_INT32(v);
    returntrue;
  }

  if (NPVARIANT_IS_DOUBLE(v)) {
    out = NPVARIANT_TO_DOUBLE(v);
    returntrue;
  }

  // not a numeric variantreturnfalse;
}

Solution 2:

From here http://code.google.com/p/chromium/issues/detail?id=68175 and here https://bugs.webkit.org/show_bug.cgi?id=49036 I understand that it is bug in WEB kit, so I add next in "npruntime.h":

#define FIX_WEB_KIT_INT32_BUG#ifdef FIX_WEB_KIT_INT32_BUG#define NPVARIANT_IS_INT32(_v)   ((_v).type == NPVariantType_Int32 || (_v).type == NPVariantType_Double)#define NPVARIANT_TO_INT32(_v)   ((_v).type == NPVariantType_Double ? (_v).value.doubleValue : (_v).value.intValue)#else#define NPVARIANT_IS_INT32(_v)   ((_v).type == NPVariantType_Int32)#define NPVARIANT_TO_INT32(_v)  (_v).value.intValue)#endif

on web(from javascript) I use parseInt(myVal,10) for all int values that passed to plugin. Check it on Google Chrome and Safari.

Post a Comment for "Unable To Pass Integer From Javascript To Npapi Plugin"