printf("JS2SpiderMonkeyClass: callJSFunction \n");
js2val callJSFunction(JS2Metadata *meta, FunctionInstance *fnInst, const js2val thisValue, js2val *argv, uint32 argc){//    ASSERT(JS2VAL_IS_OBJECT(thisValue) && !JS2VAL_IS_NULL(thisValue));//    JS2Object *obj = JS2VAL_TO_OBJECT(thisValue);//    ASSERT(obj->kind == SimpleInstanceKind);    SpiderMonkeyFunction *smFun = checked_cast<SpiderMonkeyFunction *>(fnInst);    nsPluginInstance *plug = smFun->pluginInstance;    jsval *outgoingArgs = NULL;    js2val result = JS2VAL_VOID;    nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID());    if (xpc) {        nsIXPCNativeCallContext *aCurrentNativeCallContext;        if (NS_SUCCEEDED(xpc->GetCurrentNativeCallContext(&aCurrentNativeCallContext))) {            JSContext *aJSContext;            if (NS_SUCCEEDED(aCurrentNativeCallContext->GetJSContext(&aJSContext))) {                if (argc) {                    outgoingArgs = new jsval[argc];                    for (uint32 i = 0; i < argc; i++) {                        if (!plug->convertJS2ValueToJSValue(aJSContext, argv[i], &outgoingArgs[i]))                            goto out;                    }                }                jsval resultVal;                jsval thisVal;                if (!plug->convertJS2ValueToJSValue(aJSContext, thisValue, &thisVal))                    goto out;                ASSERT(JSVAL_IS_OBJECT(thisVal));                if (JS_CallFunctionValue(aJSContext, JSVAL_TO_OBJECT(thisVal), OBJECT_TO_JSVAL(smFun->jsObject), argc, outgoingArgs, &resultVal))                        plug->convertJSValueToJS2Value(aJSContext, resultVal, &result);                NS_RELEASE(aCurrentNativeCallContext);            }        }    }out:    if (outgoingArgs)        delete [] outgoingArgs;    return result;}