使用IE9 JS引擎(Chakra)添加SCRIPTITEM_CODEONLY符号时出错 [英] Error adding SCRIPTITEM_CODEONLY symbol using IE9 JS engine (Chakra)

查看:142
本文介绍了使用IE9 JS引擎(Chakra)添加SCRIPTITEM_CODEONLY符号时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我们一直在使用旧的JScript引擎(CLSID_JScript)在浏览器扩展(BHO)中使用活动脚本,最近我们决定也支持新的IE9脚本引擎(Chakra).我们要做的一件事是使用带有SCRIPTITEM_CODEONLY选项的AddNamedItem向引擎添加符号,以创建我们自己的模块(命名空间).不幸的是,我们无法将此功能与Chakra一起使用.即使是最简单的示例,我们在其中添加符号并立即检索其脚本调度也会产生E_OUTOFMEMORY错误.

We've been using active scripting in our browser extension (BHO) for a while with the old JScript engine (CLSID_JScript), and we recently decided to support the new IE9 script engine (Chakra) as well. One thing we do is add symbols to the engine using AddNamedItem with the SCRIPTITEM_CODEONLY option to create our own modules (namespaces). Unfortunately, we haven't been able to get this to work with Chakra. Even the most trivial example where we add a symbol and immediately retrieve its script dispatch yields an E_OUTOFMEMORY error.

if (SUCCEEDED(hr)) {
  hr = scriptEngine->AddNamedItem(L"test", SCRIPTITEM_CODEONLY);
}
if (SUCCEEDED(hr)) {
   hr = scriptEngine->GetScriptDispatch(L"test", &scriptDispatch);
}

GetScriptDispatch调用返回错误.您可以在Github上看到整个示例 .

The GetScriptDispatch call returns the error. You can see the whole example on Github.

我在所有IActiveScriptSite方法上都设置了断点,并且仅调用了GetLCIDOnStateChange,所以不要以为站点实现是问题.

I set breakpoints on all the IActiveScriptSite methods and the only ones that are called are GetLCID and OnStateChange, so don't think the site implementation is the problem.

我查看了所有可以找到的示例,并尝试了所有可以想到的示例,包括手动将引擎状态设置为SCRIPTSTATE_CONNECTED,实现其QI所需的任何其他接口,等等.我什至尝试返回有效的LCID.似乎没有什么改变.

I've looked at every example I can find and tried everything I can think of, including setting the engine state to SCRIPTSTATE_CONNECTED manually, implementing any additional interfaces that it QIs for, etc. I even tried returning a valid LCID. Nothing seems to make a difference.

有什么主意吗?我认为这个基本示例应该在Chakra中起作用.

Any idea what gives? I assume this basic example should work in Chakra.

推荐答案

不幸的现实是,Chakra公开的IActiveScript接口集并非供公众使用. (正是出于这个原因,GUID并未发布到注册表中.)Chakra仅实现了IActiveScript接口中支持Internet Explorer和Visual Studio编辑器/调试器所需的那部分,并且未作任何努力来确保完整性或正确性.除了这两个客户端使用的接口以外的其他接口.

The unfortunate reality is that the set of IActiveScript interfaces that Chakra exposes is not intended for public consumption. (The GUID isn't published into the registry for exactly that reason.) Chakra only implements that portion of the IActiveScript interfaces needed to support Internet Explorer and the Visual Studio editor/debugger, and no effort has been made to ensure the completeness or correctness of the interfaces beyond that which those two clients use.

您的情况似乎是未按规范实现的情况之一,可能是因为IE/VS没有以这种特定方式使用该接口.可悲的是,除非决定在将来的IE版本中公开支持IActiveScript接口,否则几乎不可能解决此问题.

It looks like your scenario is one of those that's not implemented to spec, probably because IE/VS doesn't use the interface in this particular way. Sadly, there's almost no chance this would be fixed unless there is a decision to publicly support the IActiveScript interfaces in some future version of IE.

IE11为Chakra引入了公共API,但它不是基于IActiveScript的,而是基于Win32的.您可以在此处获取更多详细信息: http://www.panopticoncentral.net/2013/07/02/introducing-jsrt-embedding-javascript-on-windows/.我不知道这是否会对您的情况有所帮助.

IE11 has introduced a public API for Chakra, but it is not IActiveScript-based, it's Win32-based. You can get more details here: http://www.panopticoncentral.net/2013/07/02/introducing-jsrt-embedding-javascript-on-windows/. I have no idea if that would help you in your situation or not.

抱歉,不是您想要的答案,我确定...

Sorry, not the answer you were hoping for, I'm sure...

这篇关于使用IE9 JS引擎(Chakra)添加SCRIPTITEM_CODEONLY符号时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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