簡體   English   中英

Spidermonkey 1.8.5在調試模式下崩潰

[英]spidermonkey 1.8.5 crashes in debug mode

我在我的應用程序中使用Spidermonkey 1.8.5。 使用調試JS庫時,我的應用程序崩潰。 我正在使用以下選項構建該庫:--enable-debug --disable-optimize --enable-threadsafe

崩潰指向此處:斷言失敗:(cx)->線程-> data.requestDepth || (cx)->線程==(cx)->運行時-> gcThread,位於../../src/jsapi.cpp

這是示例程序

/* Include the JSAPI header file to get access to SpiderMonkey. */
#include "jsapi.h"



/* The class of the global object. */
static JSClass global_class = {
    "global", JSCLASS_GLOBAL_FLAGS,
    JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
    JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
    JSCLASS_NO_OPTIONAL_MEMBERS
};

/* The error reporter callback. */
void reportError(JSContext *cx, const char *message, JSErrorReport *report)
{
    fprintf(stderr, "%s:%u:%s\n",
            report->filename ? report->filename : "<no filename=\"filename\">",
            (unsigned int) report->lineno,
            message);
}

int main(int argc, const char *argv[])
{
    /* JSAPI variables. */
    JSRuntime *rt;
    JSContext *cx;
    JSObject  *global;
    printf("Started\n");
    /* Create a JS runtime. You always need at least one runtime per process. */
    rt = JS_NewRuntime(8 * 1024 * 1024);

    if (rt == NULL)
        return 1;

    /*
     * Create a context. You always need a context per thread.
     * Note that this program is not multi-threaded.
     */
    cx = JS_NewContext(rt, 8192);
    if (cx == NULL)
        return 1;

    JS_SetErrorReporter(cx, reportError);

    /*
     * Create the global object in a new compartment.
     * You always need a global object per context.
     */
    global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL);
    if (global == NULL)
        return 1;

    /*
     * Populate the global object with the standard JavaScript
     * function and object classes, such as Object, Array, Date.
     */
    if (!JS_InitStandardClasses(cx, global))
        return 1;

    /* Your application code here. This may include JSAPI calls
     * to create your own custom JavaScript objects and to run scripts.
     *
     * The following example code creates a literal JavaScript script,
     * evaluates it, and prints the result to stdout.
     *
     * Errors are conventionally saved in a JSBool variable named ok.
     */
    char *script = "'Hello ' + 'World!'";
    jsval rval;
    JSString *str;
    JSBool ok;
    const char *filename = "noname";
    uintN lineno = 0;

    ok = JS_EvaluateScript(cx, global, script, strlen(script),
                           filename, lineno, &rval);
    if (rval == NULL | rval == JS_FALSE)
        return 1;

    str = JS_ValueToString(cx, rval);
    printf("%s\n", JS_EncodeString(cx, str));

    /* End of your application code */

    /* Clean things up and shut down SpiderMonkey. */
    JS_DestroyContext(cx);
    JS_DestroyRuntime(rt);
    JS_ShutDown();
    return 0;
}

如果我以發布模式進行構建,則該程序可以正常運行。 此問題僅與調試模式有關。 我在這里想念什么?

插入JS_BeginRequest(cx); 就在JS_NewCompartmentAndGlobalObject調用之前。

插入JS_EndRequest(cx); 就在調用JS_DestroyContext之前。

大多數JSAPI函數都需要一個請求。 (我不確定為什么。線程的最初原因與多線程有關,但是現在每個JSRuntime都是單線程的。)

SpiderMonkey的調試版本包括斷言,這些斷言以發布模式無法檢查的方式檢查API使用情況。 因此,您可能會再次看到僅調試斷言。 我強烈建議針對調試版本進行開發,因為這些斷言幾乎總是指示實際問題。

下一個SpiderMonkey版本即將推出: https ://bugzilla.mozilla.org/show_bug.cgi?id = 735599#c54

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM