Bug 827274 - 'crash in [@ anonymous namespace::CTypesActivityCallback(JSContext*, js::CTypesActivityType)], add ctypes closure support to new worker memory reporting mechanism. r=khuey+mrbkap.

This commit is contained in:
Ben Turner 2013-01-08 13:57:44 +01:00
parent 15ae159d9e
commit 421eeb84d3
6 changed files with 73 additions and 8 deletions

View File

@ -389,6 +389,14 @@ CTypesActivityCallback(JSContext* aCx,
worker->EndCTypesCall();
break;
case js::CTYPES_CALLBACK_BEGIN:
worker->BeginCTypesCallback();
break;
case js::CTYPES_CALLBACK_END:
worker->EndCTypesCallback();
break;
default:
MOZ_NOT_REACHED("Unknown type flag!");
}
@ -434,7 +442,7 @@ CreateJSContextForWorker(WorkerPrivate* aWorkerPrivate)
return nullptr;
}
JS_SetContextPrivate(workerCx, aWorkerPrivate);
JS_SetRuntimePrivate(runtime, aWorkerPrivate);
JS_SetErrorReporter(workerCx, ErrorReporter);

View File

@ -4200,7 +4200,7 @@ WorkerPrivate*
GetWorkerPrivateFromContext(JSContext* aCx)
{
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
return static_cast<WorkerPrivate*>(JS_GetContextPrivate(aCx));
return static_cast<WorkerPrivate*>(JS_GetRuntimePrivate(JS_GetRuntime(aCx)));
}
JSStructuredCloneCallbacks*

View File

@ -771,6 +771,22 @@ public:
void
EndCTypesCall();
void
BeginCTypesCallback()
{
// If a callback is beginning then we need to do the exact same thing as
// when a ctypes call ends.
EndCTypesCall();
}
void
EndCTypesCallback()
{
// If a callback is ending then we need to do the exact same thing as
// when a ctypes call begins.
BeginCTypesCall();
}
private:
WorkerPrivate(JSContext* aCx, JSObject* aObject, WorkerPrivate* aParent,
JSContext* aParentJSContext, const nsAString& aScriptURL,

View File

@ -5790,9 +5790,7 @@ FunctionType::Call(JSContext* cx,
}
// Let the runtime callback know that we are about to call into C.
js::CTypesActivityCallback activityCallback = cx->runtime->ctypesActivityCallback;
if (activityCallback)
activityCallback(cx, js::CTYPES_CALL_BEGIN);
js::AutoCTypesActivityCallback autoCallback(cx, js::CTYPES_CALL_BEGIN, js::CTYPES_CALL_END);
uintptr_t fn = *reinterpret_cast<uintptr_t*>(CData::GetData(obj));
@ -5821,8 +5819,8 @@ FunctionType::Call(JSContext* cx,
errno = savedErrno;
if (activityCallback)
activityCallback(cx, js::CTYPES_CALL_END);
// We're no longer calling into C.
autoCallback.DoEndCallback();
// Store the error value for later consultation with |ctypes.getStatus|
JSObject *objCTypes = CType::GetGlobalCTypes(cx, typeObj);
@ -6105,6 +6103,12 @@ CClosure::ClosureStub(ffi_cif* cif, void* result, void** args, void* userData)
// Retrieve the essentials from our closure object.
ClosureInfo* cinfo = static_cast<ClosureInfo*>(userData);
JSContext* cx = cinfo->cx;
// Let the runtime callback know that we are about to call into JS again. The end callback will
// fire automatically when we exit this function.
js::AutoCTypesActivityCallback autoCallback(cx, js::CTYPES_CALLBACK_BEGIN,
js::CTYPES_CALLBACK_END);
RootedObject typeObj(cx, cinfo->typeObj);
RootedObject thisObj(cx, cinfo->thisObj);
RootedObject jsfnObj(cx, cinfo->jsfnObj);

View File

@ -990,3 +990,15 @@ js::SetCTypesActivityCallback(JSRuntime *rt, CTypesActivityCallback cb)
{
rt->ctypesActivityCallback = cb;
}
js::AutoCTypesActivityCallback::AutoCTypesActivityCallback(JSContext *cx,
js::CTypesActivityType beginType,
js::CTypesActivityType endType
MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
: cx(cx), callback(cx->runtime->ctypesActivityCallback), beginType(beginType), endType(endType)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
if (callback)
callback(cx, beginType);
}

View File

@ -1569,7 +1569,9 @@ IsTypedArrayThisCheck(JS::IsAcceptableThis test);
enum CTypesActivityType {
CTYPES_CALL_BEGIN,
CTYPES_CALL_END
CTYPES_CALL_END,
CTYPES_CALLBACK_BEGIN,
CTYPES_CALLBACK_END
};
typedef void
@ -1582,6 +1584,29 @@ typedef void
JS_FRIEND_API(void)
SetCTypesActivityCallback(JSRuntime *rt, CTypesActivityCallback cb);
class JS_FRIEND_API(AutoCTypesActivityCallback) {
private:
JSContext *cx;
CTypesActivityCallback callback;
CTypesActivityType beginType;
CTypesActivityType endType;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
public:
AutoCTypesActivityCallback(JSContext *cx, CTypesActivityType beginType,
CTypesActivityType endType
MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
~AutoCTypesActivityCallback() {
DoEndCallback();
}
void DoEndCallback() {
if (callback) {
callback(cx, endType);
callback = NULL;
}
}
};
} /* namespace js */
#endif /* jsfriendapi_h___ */