Bug 683885 - 'Assertion failure: self, at dom/workers/EventTarget.cpp:170'. r=sicking.

--HG--
extra : transplant_source : %E4bPv%BC%9D%CD%D9%5E%DA%26%0E.%CB%7B%04%F2%97%F6%06
This commit is contained in:
Ben Turner 2011-09-08 17:04:57 -07:00
Родитель f5384abe47
Коммит 8c0ffa5cb1
5 изменённых файлов: 94 добавлений и 17 удалений

Просмотреть файл

@ -141,7 +141,9 @@ EventTarget::AddEventListener(JSContext* aCx, uintN aArgc, jsval* aVp)
JSObject* obj = JS_THIS_OBJECT(aCx, aVp);
EventTarget* self = GetPrivate(aCx, obj);
JS_ASSERT(self);
if (!self) {
return true;
}
JSString* type;
JSObject* listener;
@ -167,7 +169,9 @@ EventTarget::RemoveEventListener(JSContext* aCx, uintN aArgc, jsval* aVp)
JSObject* obj = JS_THIS_OBJECT(aCx, aVp);
EventTarget* self = GetPrivate(aCx, obj);
JS_ASSERT(self);
if (!self) {
return true;
}
JSString* type;
JSObject* listener;
@ -193,7 +197,9 @@ EventTarget::DispatchEvent(JSContext* aCx, uintN aArgc, jsval* aVp)
JSObject* obj = JS_THIS_OBJECT(aCx, aVp);
EventTarget* self = GetPrivate(aCx, obj);
JS_ASSERT(self);
if (!self) {
return true;
}
JSObject* event;
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "o", &event)) {

Просмотреть файл

@ -112,6 +112,27 @@ public:
return proto;
}
static void
ClearPrivateSlot(JSContext* aCx, JSObject* aObj)
{
JS_ASSERT(!JS_IsExceptionPending(aCx));
WorkerPrivate* worker = GetJSPrivateSafeish<WorkerPrivate>(aCx, aObj);
JS_ASSERT(worker);
for (int index = 0; index < STRING_COUNT; index++) {
const char* name = sEventStrings[index];
jsval listener;
if (!worker->GetEventListenerOnEventTarget(aCx, name + 2, &listener) ||
!JS_DefineProperty(aCx, aObj, name, listener, NULL, NULL,
(PROPERTY_FLAGS & ~JSPROP_SHARED))) {
JS_ClearPendingException(aCx);
}
}
SetJSPrivateSafeish(aCx, aObj, NULL);
}
protected:
static WorkerPrivate*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName);
@ -337,6 +358,12 @@ public:
return proto;
}
static void
ClearPrivateSlot(JSContext* aCx, JSObject* aObj)
{
Worker::ClearPrivateSlot(aCx, aObj);
}
private:
// No instance of this class should ever be created so these are explicitly
// left without an implementation to prevent linking in case someone tries to
@ -425,6 +452,20 @@ InitClass(JSContext* aCx, JSObject* aGlobal, JSObject* aProto,
return Worker::InitClass(aCx, aGlobal, aProto, aMainRuntime);
}
void
ClearPrivateSlot(JSContext* aCx, JSObject* aObj)
{
JSClass* clasp = JS_GET_CLASS(aCx, aObj);
JS_ASSERT(clasp == Worker::Class() || clasp == ChromeWorker::Class());
if (clasp == ChromeWorker::Class()) {
ChromeWorker::ClearPrivateSlot(aCx, aObj);
}
else {
Worker::ClearPrivateSlot(aCx, aObj);
}
}
} // namespace worker
namespace chromeworker {

Просмотреть файл

@ -51,6 +51,9 @@ JSObject*
InitClass(JSContext* aCx, JSObject* aGlobal, JSObject* aProto,
bool aMainRuntime);
void
ClearPrivateSlot(JSContext* aCx, JSObject* aObj);
} // namespace worker
namespace chromeworker {

Просмотреть файл

@ -76,6 +76,7 @@
#include "Principal.h"
#include "RuntimeService.h"
#include "ScriptLoader.h"
#include "Worker.h"
#include "WorkerFeature.h"
#include "WorkerScope.h"
@ -1873,7 +1874,7 @@ WorkerPrivateParent<Derived>::FinalizeInstance(JSContext* aCx)
if (mJSObject) {
// Decouple the object from the private now.
SetJSPrivateSafeish(aCx, mJSObject, nsnull);
worker::ClearPrivateSlot(aCx, mJSObject);
// Clear the JS object.
mJSObject = nsnull;

Просмотреть файл

@ -26,6 +26,43 @@ Tests of DOM Worker terminate feature
var interval;
var worker;
function messageListener(event) {
is(event.data, "Still alive!", "Correct message!");
if (messageCount++ == 20) {
ok(worker.onmessage === messageListener,
"Correct listener before terminate");
worker.terminate();
var exception = false;
try {
worker.addEventListener("message", messageListener, false);
}
catch (e) {
exception = true;
}
is(exception, false, "addEventListener didn't throw after terminate");
exception = false;
try {
worker.removeEventListener("message", messageListener, false);
}
catch (e) {
exception = true;
}
is(exception, false, "removeEventListener didn't throw after terminate");
ok(worker.onmessage === messageListener,
"Correct listener after terminate");
worker.onmessage = function(event) { }
interval = setInterval(testCount, 1000);
}
}
function testCount() {
is(messageCount, 21, "Received another message after terminated!");
if (intervalCount++ == 5) {
@ -34,19 +71,8 @@ Tests of DOM Worker terminate feature
}
}
var worker = new Worker("terminate_worker.js");
worker.onmessage = function(event) {
is(event.data, "Still alive!", "Bad message!");
if (messageCount++ == 20) {
worker.terminate();
interval = setInterval(testCount, 1000);
}
};
worker.onerror = function(event) {
ok(false, "Worker had an error: " + event.data);
SimpleTest.finish();
}
worker = new Worker("terminate_worker.js");
worker.onmessage = messageListener;
SimpleTest.waitForExplicitFinish();