2013-03-25 119 views
0

我在我的應用程序中使用Spidermonkey 1.8.5。 當我使用調試JS庫時,我的應用程序崩潰。我建立了庫,具有以下選項: --enable-調試 - 禁用優化--enable-線程spidermonkey 1.8.5在調試模式下崩潰

崩潰指向這裏: 斷言失敗:(CX) - > thread-> data.requestDepth || (CX) - >螺紋==(CX) - > runtime-> 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; 
} 

如果我建立在發佈模式下,程序工作正常。這個問題只與調試模式有關。我在這裏錯過了什麼?

回答

1

插入JS_BeginRequest(cx);就在撥打JS_NewCompartmentAndGlobalObject之前。

在撥打電話JS_DestroyContext之前插入JS_EndRequest(cx);

大多數JSAPI函數都需要一個請求。 (我不知道爲什麼。線程的原始原因與多線程有關,但現在每個JSRuntime都是單線程的。)

SpiderMonkey的調試版本包含斷言,檢查API使用方式可以使用釋放模式「T。因此,您可能會再次看到僅調試斷言。我強烈建議針對調試構建進行開發,因爲這些斷言幾乎總是指示真正的問題。下一個SpiderMonkey發佈即將推出:https://bugzilla.mozilla.org/show_bug.cgi?id=735599#c54

相關問題