0

アプリケーションでSpidermonkey1.8.5を使用しています。デバッグJSライブラリを使用すると、アプリケーションがクラッシュします。次のオプションを使用してライブラリを構築しています。--enable-debug--disable-optimize--enable-threadsafe

クラッシュはここを指しています:アサーションの失敗:(cx)-> thread-> data.requestDepth || (cx)-> thread ==(cx)-> runtime-> gcThread、at ../../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;
}

リリースモードでビルドしている場合、プログラムは正常に動作します。この問題は、デバッグモードでのみ発生します。ここで何が欠けていますか?

4

1 に答える 1

1

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

于 2013-03-26T18:58:52.377 に答える