2011-07-17 12:09:13 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
#include "Worker.h"
|
|
|
|
|
2012-05-02 21:35:38 -07:00
|
|
|
#include "mozilla/dom/DOMJSClass.h"
|
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
#include "EventTarget.h"
|
|
|
|
#include "RuntimeService.h"
|
|
|
|
#include "WorkerPrivate.h"
|
|
|
|
|
|
|
|
#include "WorkerInlines.h"
|
|
|
|
|
|
|
|
#define PROPERTY_FLAGS \
|
2012-02-13 00:02:21 -08:00
|
|
|
(JSPROP_ENUMERATE | JSPROP_SHARED)
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
#define FUNCTION_FLAGS \
|
|
|
|
JSPROP_ENUMERATE
|
|
|
|
|
|
|
|
USING_WORKERS_NAMESPACE
|
|
|
|
|
2012-05-02 21:35:38 -07:00
|
|
|
using namespace mozilla::dom;
|
2012-05-05 18:15:11 -07:00
|
|
|
using mozilla::ErrorResult;
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class Worker
|
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
static DOMJSClass sClass;
|
2011-07-17 12:09:13 -07:00
|
|
|
static JSPropertySpec sProperties[];
|
|
|
|
static JSFunctionSpec sFunctions[];
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
STRING_onerror = 0,
|
|
|
|
STRING_onmessage,
|
|
|
|
|
|
|
|
STRING_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* const sEventStrings[STRING_COUNT];
|
|
|
|
|
|
|
|
protected:
|
|
|
|
enum {
|
|
|
|
// The constructor function holds a WorkerPrivate* in its first reserved
|
|
|
|
// slot.
|
|
|
|
CONSTRUCTOR_SLOT_PARENT = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
static JSClass*
|
|
|
|
Class()
|
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
return sClass.ToJSClass();
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static JSObject*
|
|
|
|
InitClass(JSContext* aCx, JSObject* aObj, JSObject* aParentProto,
|
|
|
|
bool aMainRuntime)
|
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
JSObject* proto =
|
|
|
|
js::InitClassWithReserved(aCx, aObj, aParentProto, Class(), Construct, 0,
|
|
|
|
sProperties, sFunctions, NULL, NULL);
|
2011-07-17 12:09:13 -07:00
|
|
|
if (!proto) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aMainRuntime) {
|
|
|
|
WorkerPrivate* parent = GetWorkerPrivateFromContext(aCx);
|
|
|
|
parent->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
JSObject* constructor = JS_GetConstructor(aCx, proto);
|
2011-10-27 15:10:21 -07:00
|
|
|
if (!constructor)
|
2011-07-17 12:09:13 -07:00
|
|
|
return NULL;
|
2011-10-27 15:10:21 -07:00
|
|
|
js::SetFunctionNativeReserved(constructor, CONSTRUCTOR_SLOT_PARENT,
|
|
|
|
PRIVATE_TO_JSVAL(parent));
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return proto;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WorkerPrivate*
|
|
|
|
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName);
|
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
protected:
|
2011-07-17 12:09:13 -07:00
|
|
|
static JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
ConstructInternal(JSContext* aCx, unsigned aArgc, jsval* aVp,
|
2012-03-30 21:42:20 -07:00
|
|
|
bool aIsChromeWorker, JSClass* aClass)
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
|
|
|
if (!aArgc) {
|
|
|
|
JS_ReportError(aCx, "Constructor requires at least one argument!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString* scriptURL = JS_ValueToString(aCx, JS_ARGV(aCx, aVp)[0]);
|
|
|
|
if (!scriptURL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-27 15:10:21 -07:00
|
|
|
jsval priv = js::GetFunctionNativeReserved(JSVAL_TO_OBJECT(JS_CALLEE(aCx, aVp)),
|
|
|
|
CONSTRUCTOR_SLOT_PARENT);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
RuntimeService* runtimeService;
|
|
|
|
WorkerPrivate* parent;
|
|
|
|
|
|
|
|
if (JSVAL_IS_VOID(priv)) {
|
|
|
|
runtimeService = RuntimeService::GetOrCreateService();
|
|
|
|
if (!runtimeService) {
|
|
|
|
JS_ReportError(aCx, "Failed to create runtime service!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
parent = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
runtimeService = RuntimeService::GetService();
|
|
|
|
parent = static_cast<WorkerPrivate*>(JSVAL_TO_PRIVATE(priv));
|
|
|
|
parent->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
JSObject* obj = JS_NewObject(aCx, aClass, nullptr, nullptr);
|
2011-07-17 12:09:13 -07:00
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
nsRefPtr<WorkerPrivate> worker =
|
|
|
|
WorkerPrivate::Create(aCx, obj, parent, scriptURL, aIsChromeWorker);
|
2011-07-17 12:09:13 -07:00
|
|
|
if (!worker) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Worker now owned by the JS object.
|
2012-03-30 21:42:20 -07:00
|
|
|
NS_ADDREF(worker.get());
|
|
|
|
js::SetReservedSlot(obj, DOM_OBJECT_SLOT, PRIVATE_TO_JSVAL(worker));
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
if (!runtimeService->RegisterWorker(aCx, worker)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
// Worker now also owned by its thread.
|
|
|
|
NS_ADDREF(worker.get());
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
JS_SET_RVAL(aCx, aVp, OBJECT_TO_JSVAL(obj));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
// make one.
|
|
|
|
Worker();
|
|
|
|
~Worker();
|
|
|
|
|
|
|
|
static JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
GetEventListener(JSContext* aCx, JSHandleObject aObj, JSHandleId aIdval, JSMutableHandleValue aVp)
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(JSID_IS_INT(aIdval));
|
|
|
|
JS_ASSERT(JSID_TO_INT(aIdval) >= 0 && JSID_TO_INT(aIdval) < STRING_COUNT);
|
|
|
|
|
|
|
|
const char* name = sEventStrings[JSID_TO_INT(aIdval)];
|
|
|
|
WorkerPrivate* worker = GetInstancePrivate(aCx, aObj, name);
|
|
|
|
if (!worker) {
|
2011-10-05 14:10:09 -07:00
|
|
|
return !JS_IsExceptionPending(aCx);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
NS_ConvertASCIItoUTF16 nameStr(name + 2);
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult rv;
|
2012-03-30 21:42:20 -07:00
|
|
|
JSObject* listener = worker->GetEventListener(nameStr, rv);
|
|
|
|
|
2012-05-05 18:15:11 -07:00
|
|
|
if (rv.Failed()) {
|
2012-03-30 21:42:20 -07:00
|
|
|
JS_ReportError(aCx, "Failed to get listener!");
|
|
|
|
}
|
|
|
|
|
2012-07-30 04:19:09 -07:00
|
|
|
aVp.set(listener ? OBJECT_TO_JSVAL(listener) : JSVAL_NULL);
|
2012-03-30 21:42:20 -07:00
|
|
|
return true;
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
SetEventListener(JSContext* aCx, JSHandleObject aObj, JSHandleId aIdval, JSBool aStrict,
|
2012-07-30 04:19:09 -07:00
|
|
|
JSMutableHandleValue aVp)
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(JSID_IS_INT(aIdval));
|
|
|
|
JS_ASSERT(JSID_TO_INT(aIdval) >= 0 && JSID_TO_INT(aIdval) < STRING_COUNT);
|
|
|
|
|
|
|
|
const char* name = sEventStrings[JSID_TO_INT(aIdval)];
|
|
|
|
WorkerPrivate* worker = GetInstancePrivate(aCx, aObj, name);
|
|
|
|
if (!worker) {
|
2011-10-05 14:10:09 -07:00
|
|
|
return !JS_IsExceptionPending(aCx);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
JSObject* listener;
|
2012-07-30 04:19:09 -07:00
|
|
|
if (!JS_ValueToObject(aCx, aVp, &listener)) {
|
2012-03-30 21:42:20 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertASCIItoUTF16 nameStr(name + 2);
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult rv;
|
2012-03-30 21:42:20 -07:00
|
|
|
worker->SetEventListener(nameStr, listener, rv);
|
|
|
|
|
2012-05-05 18:15:11 -07:00
|
|
|
if (rv.Failed()) {
|
2012-03-30 21:42:20 -07:00
|
|
|
JS_ReportError(aCx, "Failed to set listener!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
Construct(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
return ConstructInternal(aCx, aArgc, aVp, false, Class());
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-03-19 07:34:55 -07:00
|
|
|
Finalize(JSFreeOp* aFop, JSObject* aObj)
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
JS_ASSERT(JS_GetClass(aObj) == Class());
|
2012-05-22 06:46:20 -07:00
|
|
|
WorkerPrivate* worker =
|
|
|
|
UnwrapDOMObject<WorkerPrivate>(aObj, eRegularDOMObject);
|
2011-07-17 12:09:13 -07:00
|
|
|
if (worker) {
|
2012-04-26 13:57:33 -07:00
|
|
|
worker->_finalize(aFop);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Trace(JSTracer* aTrc, JSObject* aObj)
|
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
JS_ASSERT(JS_GetClass(aObj) == Class());
|
2012-05-22 06:46:20 -07:00
|
|
|
WorkerPrivate* worker =
|
|
|
|
UnwrapDOMObject<WorkerPrivate>(aObj, eRegularDOMObject);
|
2011-07-17 12:09:13 -07:00
|
|
|
if (worker) {
|
2012-04-26 13:57:33 -07:00
|
|
|
worker->_trace(aTrc);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
Terminate(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
|
|
|
JSObject* obj = JS_THIS_OBJECT(aCx, aVp);
|
2011-12-01 13:30:28 -08:00
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
const char*& name = sFunctions[0].name;
|
|
|
|
WorkerPrivate* worker = GetInstancePrivate(aCx, obj, name);
|
|
|
|
if (!worker) {
|
2011-10-05 14:10:09 -07:00
|
|
|
return !JS_IsExceptionPending(aCx);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return worker->Terminate(aCx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
PostMessage(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
|
|
|
JSObject* obj = JS_THIS_OBJECT(aCx, aVp);
|
2011-12-01 13:30:28 -08:00
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
const char*& name = sFunctions[1].name;
|
|
|
|
WorkerPrivate* worker = GetInstancePrivate(aCx, obj, name);
|
|
|
|
if (!worker) {
|
2011-10-05 14:10:09 -07:00
|
|
|
return !JS_IsExceptionPending(aCx);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
jsval message;
|
2012-10-03 15:19:22 -07:00
|
|
|
jsval transferable = JSVAL_VOID;
|
|
|
|
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "v/v",
|
|
|
|
&message, &transferable)) {
|
2011-07-17 12:09:13 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-03 15:19:22 -07:00
|
|
|
return worker->PostMessage(aCx, message, transferable);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
DOMJSClass Worker::sClass = {
|
|
|
|
{
|
|
|
|
"Worker",
|
2012-10-05 09:59:23 -07:00
|
|
|
JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(2) |
|
2012-03-30 21:42:20 -07:00
|
|
|
JSCLASS_IMPLEMENTS_BARRIERS,
|
|
|
|
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
|
|
|
|
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, Finalize,
|
|
|
|
NULL, NULL, NULL, NULL, Trace
|
|
|
|
},
|
2012-05-22 06:46:20 -07:00
|
|
|
{
|
2012-12-06 02:41:14 -08:00
|
|
|
INTERFACE_CHAIN_1(prototypes::id::EventTarget_workers),
|
2012-05-22 06:46:20 -07:00
|
|
|
false,
|
2012-10-09 11:50:27 -07:00
|
|
|
&sWorkerNativePropertyHooks
|
2012-09-06 00:14:49 -07:00
|
|
|
}
|
2011-07-17 12:09:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
JSPropertySpec Worker::sProperties[] = {
|
|
|
|
{ sEventStrings[STRING_onerror], STRING_onerror, PROPERTY_FLAGS,
|
2012-08-07 22:26:18 -07:00
|
|
|
JSOP_WRAPPER(GetEventListener), JSOP_WRAPPER(SetEventListener) },
|
2011-07-17 12:09:13 -07:00
|
|
|
{ sEventStrings[STRING_onmessage], STRING_onmessage, PROPERTY_FLAGS,
|
2012-08-07 22:26:18 -07:00
|
|
|
JSOP_WRAPPER(GetEventListener), JSOP_WRAPPER(SetEventListener) },
|
|
|
|
{ 0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER }
|
2011-07-17 12:09:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
JSFunctionSpec Worker::sFunctions[] = {
|
|
|
|
JS_FN("terminate", Terminate, 0, FUNCTION_FLAGS),
|
|
|
|
JS_FN("postMessage", PostMessage, 1, FUNCTION_FLAGS),
|
|
|
|
JS_FS_END
|
|
|
|
};
|
|
|
|
|
|
|
|
const char* const Worker::sEventStrings[STRING_COUNT] = {
|
|
|
|
"onerror",
|
|
|
|
"onmessage"
|
|
|
|
};
|
|
|
|
|
|
|
|
class ChromeWorker : public Worker
|
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
static DOMJSClass sClass;
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
static JSClass*
|
|
|
|
Class()
|
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
return sClass.ToJSClass();
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static JSObject*
|
|
|
|
InitClass(JSContext* aCx, JSObject* aObj, JSObject* aParentProto,
|
|
|
|
bool aMainRuntime)
|
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
JSObject* proto =
|
|
|
|
js::InitClassWithReserved(aCx, aObj, aParentProto, Class(), Construct, 0,
|
|
|
|
NULL, NULL, NULL, NULL);
|
2011-07-17 12:09:13 -07:00
|
|
|
if (!proto) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aMainRuntime) {
|
|
|
|
WorkerPrivate* parent = GetWorkerPrivateFromContext(aCx);
|
|
|
|
parent->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
JSObject* constructor = JS_GetConstructor(aCx, proto);
|
2011-10-27 15:10:21 -07:00
|
|
|
if (!constructor)
|
2011-07-17 12:09:13 -07:00
|
|
|
return NULL;
|
2011-10-27 15:10:21 -07:00
|
|
|
js::SetFunctionNativeReserved(constructor, CONSTRUCTOR_SLOT_PARENT,
|
|
|
|
PRIVATE_TO_JSVAL(parent));
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return proto;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
// make one.
|
|
|
|
ChromeWorker();
|
|
|
|
~ChromeWorker();
|
|
|
|
|
|
|
|
static WorkerPrivate*
|
|
|
|
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
|
|
|
|
{
|
|
|
|
if (aObj) {
|
2012-02-03 16:54:57 -08:00
|
|
|
JSClass* classPtr = JS_GetClass(aObj);
|
2012-03-30 21:42:20 -07:00
|
|
|
if (classPtr == Class()) {
|
2012-05-22 06:46:20 -07:00
|
|
|
return UnwrapDOMObject<WorkerPrivate>(aObj, eRegularDOMObject);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Worker::GetInstancePrivate(aCx, aObj, aFunctionName);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
Construct(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
return ConstructInternal(aCx, aArgc, aVp, true, Class());
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-03-19 07:34:55 -07:00
|
|
|
Finalize(JSFreeOp* aFop, JSObject* aObj)
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
JS_ASSERT(JS_GetClass(aObj) == Class());
|
2012-05-22 06:46:20 -07:00
|
|
|
WorkerPrivate* worker =
|
|
|
|
UnwrapDOMObject<WorkerPrivate>(aObj, eRegularDOMObject);
|
2011-07-17 12:09:13 -07:00
|
|
|
if (worker) {
|
2012-04-26 13:57:33 -07:00
|
|
|
worker->_finalize(aFop);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Trace(JSTracer* aTrc, JSObject* aObj)
|
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
JS_ASSERT(JS_GetClass(aObj) == Class());
|
2012-05-22 06:46:20 -07:00
|
|
|
WorkerPrivate* worker =
|
|
|
|
UnwrapDOMObject<WorkerPrivate>(aObj, eRegularDOMObject);
|
2011-07-17 12:09:13 -07:00
|
|
|
if (worker) {
|
2012-04-26 13:57:33 -07:00
|
|
|
worker->_trace(aTrc);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
DOMJSClass ChromeWorker::sClass = {
|
|
|
|
{ "ChromeWorker",
|
2012-10-05 09:59:23 -07:00
|
|
|
JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(2) |
|
2012-03-30 21:42:20 -07:00
|
|
|
JSCLASS_IMPLEMENTS_BARRIERS,
|
|
|
|
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
|
|
|
|
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, Finalize,
|
|
|
|
NULL, NULL, NULL, NULL, Trace,
|
|
|
|
},
|
2012-05-22 06:46:20 -07:00
|
|
|
{
|
2012-12-06 02:41:14 -08:00
|
|
|
INTERFACE_CHAIN_1(prototypes::id::EventTarget_workers),
|
2012-05-22 06:46:20 -07:00
|
|
|
false,
|
2012-10-09 11:50:27 -07:00
|
|
|
&sWorkerNativePropertyHooks
|
2012-09-06 00:14:49 -07:00
|
|
|
}
|
2011-07-17 12:09:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
WorkerPrivate*
|
|
|
|
Worker::GetInstancePrivate(JSContext* aCx, JSObject* aObj,
|
|
|
|
const char* aFunctionName)
|
|
|
|
{
|
2012-02-03 16:54:57 -08:00
|
|
|
JSClass* classPtr = JS_GetClass(aObj);
|
2012-03-30 21:42:20 -07:00
|
|
|
if (classPtr == Class() || classPtr == ChromeWorker::Class()) {
|
2012-05-22 06:46:20 -07:00
|
|
|
return UnwrapDOMObject<WorkerPrivate>(aObj, eRegularDOMObject);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO,
|
2012-03-30 21:42:20 -07:00
|
|
|
Class()->name, aFunctionName, classPtr->name);
|
2011-07-17 12:09:13 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
namespace worker {
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
InitClass(JSContext* aCx, JSObject* aGlobal, JSObject* aProto,
|
|
|
|
bool aMainRuntime)
|
|
|
|
{
|
|
|
|
return Worker::InitClass(aCx, aGlobal, aProto, aMainRuntime);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace worker
|
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
WorkerCrossThreadDispatcher*
|
|
|
|
GetWorkerCrossThreadDispatcher(JSContext* aCx, jsval aWorker)
|
|
|
|
{
|
|
|
|
if (JSVAL_IS_PRIMITIVE(aWorker)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkerPrivate* w =
|
|
|
|
Worker::GetInstancePrivate(aCx, JSVAL_TO_OBJECT(aWorker),
|
|
|
|
"GetWorkerCrossThreadDispatcher");
|
|
|
|
if (!w) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return w->GetCrossThreadDispatcher();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
namespace chromeworker {
|
|
|
|
|
|
|
|
bool
|
|
|
|
InitClass(JSContext* aCx, JSObject* aGlobal, JSObject* aProto,
|
|
|
|
bool aMainRuntime)
|
|
|
|
{
|
|
|
|
return !!ChromeWorker::InitClass(aCx, aGlobal, aProto, aMainRuntime);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chromeworker
|
|
|
|
|
2012-01-18 10:05:38 -08:00
|
|
|
bool
|
|
|
|
ClassIsWorker(JSClass* aClass)
|
|
|
|
{
|
|
|
|
return Worker::Class() == aClass || ChromeWorker::Class() == aClass;
|
|
|
|
}
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
END_WORKERS_NAMESPACE
|