Cocoa / Mac:JavaScript第38次调用时核心崩溃 [英] Cocoa/Mac: JavaScript Core crash on the 38th call

查看:312
本文介绍了Cocoa / Mac:JavaScript第38次调用时核心崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在为Mac OSX(10.8)开发一个Cocoa应用程序,需要使用JavaScript库(为什么我们必须使用JavaScript)。



在演示应用程序中,一切似乎都很好,但在我们的项目中包含代码时,我们可以调用该函数37次,没有问题,然后第38次崩溃。



要调用JS代码,我们使用Apple的JSWrappers.m(来自JavaScriptCoreHeadStart示例)。
崩溃的行(带有EXC_BAD_ACCESS)是#149:

  JSObjectCallAsFunction(self.jsContext,jsFunction,NULL ,argumentCount,arguments,NULL); 

如上所述,它在第38次崩溃 -callStringJSFunction:withParameters: 被调用,不管输入是什么(它与任何输入字符串崩溃,并且如果在之前的迭代中使用相同的字符串,则是相同的字符串)。
EXC_BAD_ACCESS不是由输入变量引起的,因为访问它们(例如调用 self.jsContext 刚好在该行之前)工作:它是函数调用



我们不知道这可能是什么造成这个问题,不知道如何调试更多。有人有任何提示吗?
谢谢。



// EDIT



我必须更正自己: 演示应用程序。即使在这种情况下,代码崩溃第38次我们调用 -callStringJSFunction:withParameters:



// EDIT2



如果每次调用函数时重新创建JSWrappers对象(和一个新的JSGlobalContext),它不会崩溃。但是,这使得代码慢得多(不奇怪,因为JS解释器必须每次都读取脚本 - 这是一个相当大的脚本)。



// EDIT3



另一个发现:以32位元构建应用程式会导致程式码崩溃。建立在64位,相反,工作完美:JS代码执行没有任何时间,我们希望的问题。这很奇怪:这可能是JavaScript核心框架本身中的一个错误?

解决方案

回答自己的问题。 >

显然,这是JavaScript Core中的一个错误(?)。在32位二进制,由于某些原因,我们不能调用该函数超过37次(内存问题?)。
这些问题不出现在64位二进制文​​件上。



这种行为发生在OSX 10.8.4上。


We are developing a Cocoa app for Mac OSX (10.8) which needs to use a JavaScript library (long story why we must use JavaScript).

In a demo application everything seemed to be just fine, but while incorporating the code in our project, we can call the function 37 times without issues and then crashes the 38th time.

To call the JS code we are using Apple's JSWrappers.m (from the JavaScriptCoreHeadStart example). The line that crashes (with a EXC_BAD_ACCESS) is #149:

JSObjectCallAsFunction(self.jsContext, jsFunction, NULL, argumentCount, arguments, NULL);

As stated above, it crashes on the 38th time -callStringJSFunction:withParameters: is called, no matter what the input is (it crashes with any input string, and the same string works if used in the 37 previous iterations). The EXC_BAD_ACCESS is not caused by an input variable, as accessing them (such as calling self.jsContext just immediately before that line) works: it is the function call itself that causes the crash.

We have no idea on what it may be causing this issue, and no idea on how to debug more. Does anyone have any hint? Thanks.

//EDIT

I must correct myself: it doesn't work on the "demo app" too. Even in that case, the code crashes the 38th time we call -callStringJSFunction:withParameters:

//EDIT2

If we re-create the JSWrappers object (and a new JSGlobalContext) every time the function is called, it does not crash anymore. However, this makes the code a lot slower (not surprisingly, as the JS interpreter has to read the script every time - and it's a rather big one).

//EDIT3

Another discovery: building the app in 32 bit makes the code crash. Building in 64 bit, instead, works flawlessly: the JS code is executed without issues any time we wish. This is strange: could this possibly be a bug in the JavaScript Core framework itself?

解决方案

Answering my own question.

Apparently it is a bug (?) in JavaScript Core. On 32-bit binaries, for some reasons we cannot call the function more than 37 times (memory issues?). Those issues do not appear on 64-bit binaries.

This behavior happens on OSX 10.8.4.

这篇关于Cocoa / Mac:JavaScript第38次调用时核心崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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