脚本插件:在NPObject上调用方法时出错 [英] Scriptable plugin: Error calling method on NPObject

查看:763
本文介绍了脚本插件:在NPObject上调用方法时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个JavaScript错误:在NPObject 上调用方法时,在Chrome& Firefox上的XP。使用相同的浏览器在Windows 7上运行相同的代码是成功的。

我已经使用NPAPI构建了一个脚本化的插件,到目前为止我可以调试到调用我的可脚本化对象的方法但是,我不相信我完成后有任何控制。

有没有人有任何想法?这只是在Windows XP中的问题?

  bool MY_ScriptableObject :: Invoke(NPObject * npobj,
NPIdentifier name,
const NPVariant * args,
uint32_t argCount,
NPVariant * result)
{
bool rc = true;
char * wptr = NULL;

rc = false;
wptr = NULL;

if(name == NPN_GetStringIdentifier(getVersion))
{
wptr =(NPUTF8 *)NPN_MemAlloc(strlen(version:1.0.1)+ 1) ; //如果(wptr!= NULL)
应该被浏览器释放
{
rc = true;
memset(wptr,
0x00,
strlen(version:1.0.1)+ 1);
memcpy(wptr,
version:1.0.1,
strlen(version:1.0.1));
STRINGZ_TO_NPVARIANT(wptr,
* result);
}
}
return(rc);

$ / code $


这是我正在执行的HTML函数:

  function Version()
{
var plugin = document.getElementById(plugin);
if(plugin == undefined)
{
alert(plugin failed);
return;
}
var text = plugin.getVersion(); //错误发生在这一行
alert(text); (讽刺)真棒(讽刺)真棒(讽刺)真棒(讽刺)真棒(讽刺)真棒(讽刺)真棒(嘘) / sarcasm)在当前版本的浏览器中关于NPAPI的一点是,如果调用出现错误,那么即使插件以其他方式尝试使用NPN_SetException设置异常,也会自动获得该错误消息。 / p>

我的第一个猜测是你编译的代码针对Windows以后的版本而不是Windows XP;我不确定是否会产生这个问题。我从来没有见过你正在描述的问题,并且我已经在xp,vista和7上运行了插件,没有任何问题。您也可以尝试使用 FireBreath 插件,并查看问题是否存在。



我建议你附加一个调试器并设置一些断点。从NPN_GetValue开始,确保它实例化你的NPObject,然后在NPObject的HasMethod和Invoke方法中设置断点并查看命中。有可能在那里的东西会告诉你实际发生的事情,或至少告诉你什么代码或没有被打。


I am getting a JavaScript error: Error calling method on NPObject when calling a method in my NPAPI plugin in Chrome & Firefox on XP. Running the same code on Windows 7 with the same browsers was successful.

I have built a Scriptable plugin using the NPAPI, so far I can debug into the Invoke method of my scriptable object. But I don't believe I have any control after it's finished.
Does anyone have any ideas? Is this an issue only in Windows XP?

bool MY_ScriptableObject::Invoke(NPObject*        npobj,   
                                 NPIdentifier     name,    
                                 const NPVariant* args,    
                                 uint32_t         argCount,
                                 NPVariant*       result)  
{ 
bool                    rc   = true;
char*                   wptr = NULL;

    rc = false;
    wptr = NULL;

    if  (name == NPN_GetStringIdentifier("getVersion"))
        {
        wptr = (NPUTF8*)NPN_MemAlloc(strlen("version:1.0.1") + 1); //Should be freed by browser
        if  (wptr != NULL)                                                      
            {
            rc = true;
            memset(wptr,
                   0x00,
                   strlen("version:1.0.1")+1);
            memcpy(wptr,
                   "version:1.0.1",
                   strlen("version:1.0.1"));
            STRINGZ_TO_NPVARIANT(wptr,
                                 *result);
            }
        }
    return (rc);
}

Here is the HTML function that I am executing:

function Version()
{
var plugin = document.getElementById("plugin");
if (plugin == undefined)
    {
    alert("plugin failed");
    return;
    }
var text = plugin.getVersion();  //Error happens at this line
alert(text);
}

解决方案

The (sarcasm)awesome(/sarcasm) thing about NPAPI in current versions of the browsers is that if anything goes wrong with the call you automatically get that error message, even if the plugin has otherwise tried to set an exception with NPN_SetException.

My first guess would be that you compiled your code targeting a later version of windows than windows XP; I'm not sure if that would produce this issue or not. I have never seen the issue you're describing, and I've got plugins running on xp, vista, and 7 with no trouble. You might also try playing with a FireBreath plugin and see if the issue occurs there or not.

I would recommend that you attach with a debugger and set some breakpoints. Start in NPN_GetValue and make sure that it's instantiating your NPObject, then set breakpoints in your NPObject's HasMethod and Invoke methods and see what is hit. Likely something in there will show you what is actually happening, or at least tell you what code is or isn't getting hit.

这篇关于脚本插件:在NPObject上调用方法时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆