2011-07-17 23:09:13 +04:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2011-08-16 07:40:38 +04:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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 23:09:13 +04:00
|
|
|
|
|
|
|
#include "WorkerScope.h"
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
2013-08-27 06:05:20 +04:00
|
|
|
#include "js/OldDebugAPI.h"
|
2012-03-31 08:42:20 +04:00
|
|
|
#include "mozilla/Util.h"
|
2012-05-03 08:35:38 +04:00
|
|
|
#include "mozilla/dom/DOMJSClass.h"
|
2013-09-10 22:27:32 +04:00
|
|
|
#include "mozilla/dom/EventBinding.h"
|
2013-09-20 09:07:03 +04:00
|
|
|
#include "mozilla/dom/EventHandlerBinding.h"
|
2012-05-03 08:35:38 +04:00
|
|
|
#include "mozilla/dom/EventTargetBinding.h"
|
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2013-09-09 07:29:21 +04:00
|
|
|
#include "mozilla/dom/DOMExceptionBinding.h"
|
2012-09-21 06:47:47 +04:00
|
|
|
#include "mozilla/dom/FileReaderSyncBinding.h"
|
2013-08-04 03:55:40 +04:00
|
|
|
#include "mozilla/dom/ImageData.h"
|
|
|
|
#include "mozilla/dom/ImageDataBinding.h"
|
2012-12-22 04:16:14 +04:00
|
|
|
#include "mozilla/dom/TextDecoderBinding.h"
|
|
|
|
#include "mozilla/dom/TextEncoderBinding.h"
|
2012-05-03 08:35:38 +04:00
|
|
|
#include "mozilla/dom/XMLHttpRequestBinding.h"
|
|
|
|
#include "mozilla/dom/XMLHttpRequestUploadBinding.h"
|
2013-02-06 03:17:17 +04:00
|
|
|
#include "mozilla/dom/URLBinding.h"
|
2013-10-14 15:58:05 +04:00
|
|
|
#include "mozilla/dom/WorkerBinding.h"
|
2013-07-24 11:41:55 +04:00
|
|
|
#include "mozilla/dom/WorkerLocationBinding.h"
|
2013-07-24 11:38:23 +04:00
|
|
|
#include "mozilla/dom/WorkerNavigatorBinding.h"
|
2012-05-09 14:00:48 +04:00
|
|
|
#include "mozilla/OSFileConstants.h"
|
2013-09-09 07:28:48 +04:00
|
|
|
#include "nsIGlobalObject.h"
|
2011-07-17 23:09:13 +04:00
|
|
|
#include "nsTraceRefcnt.h"
|
2011-12-28 12:13:38 +04:00
|
|
|
#include "xpcpublic.h"
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
#ifdef ANDROID
|
|
|
|
#include <android/log.h>
|
|
|
|
#endif
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
#include "ChromeWorkerScope.h"
|
|
|
|
#include "Events.h"
|
2012-03-31 08:42:20 +04:00
|
|
|
#include "EventListenerManager.h"
|
2011-07-17 23:09:13 +04:00
|
|
|
#include "EventTarget.h"
|
2011-08-16 07:40:38 +04:00
|
|
|
#include "File.h"
|
|
|
|
#include "FileReaderSync.h"
|
2011-07-17 23:09:13 +04:00
|
|
|
#include "Location.h"
|
|
|
|
#include "Navigator.h"
|
|
|
|
#include "Principal.h"
|
|
|
|
#include "ScriptLoader.h"
|
|
|
|
#include "WorkerPrivate.h"
|
|
|
|
#include "XMLHttpRequest.h"
|
|
|
|
|
|
|
|
#include "WorkerInlines.h"
|
|
|
|
|
|
|
|
#define FUNCTION_FLAGS \
|
|
|
|
JSPROP_ENUMERATE
|
|
|
|
|
2011-10-21 14:16:47 +04:00
|
|
|
using namespace mozilla;
|
2012-11-10 19:45:52 +04:00
|
|
|
using namespace mozilla::dom;
|
2011-07-17 23:09:13 +04:00
|
|
|
USING_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-09-09 07:28:48 +04:00
|
|
|
class WorkerGlobalScope : public workers::EventTarget,
|
|
|
|
public nsIGlobalObject
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-09-11 16:49:05 +04:00
|
|
|
static const JSClass sClass;
|
2013-04-23 01:15:36 +04:00
|
|
|
static const JSPropertySpec sProperties[];
|
2013-04-23 01:15:49 +04:00
|
|
|
static const JSFunctionSpec sFunctions[];
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SLOT_wrappedScope = 0,
|
|
|
|
SLOT_wrappedFunction
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SLOT_location = 0,
|
|
|
|
SLOT_navigator,
|
|
|
|
|
|
|
|
SLOT_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
// Must be traced!
|
2013-07-23 13:58:27 +04:00
|
|
|
JS::Heap<JS::Value> mSlots[SLOT_COUNT];
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
STRING_onerror = 0,
|
|
|
|
STRING_onclose,
|
|
|
|
|
|
|
|
STRING_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* const sEventStrings[STRING_COUNT];
|
|
|
|
|
|
|
|
protected:
|
|
|
|
WorkerPrivate* mWorker;
|
|
|
|
|
|
|
|
public:
|
2013-09-11 16:49:05 +04:00
|
|
|
static const JSClass*
|
2011-07-17 23:09:13 +04:00
|
|
|
Class()
|
|
|
|
{
|
|
|
|
return &sClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSObject*
|
|
|
|
InitClass(JSContext* aCx, JSObject* aObj, JSObject* aParentProto)
|
|
|
|
{
|
2012-03-31 08:42:20 +04:00
|
|
|
return JS_InitClass(aCx, aObj, aParentProto, Class(), Construct, 0,
|
2011-07-17 23:09:13 +04:00
|
|
|
sProperties, sFunctions, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2012-04-27 00:57:33 +04:00
|
|
|
using EventTarget::GetEventListener;
|
|
|
|
using EventTarget::SetEventListener;
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
protected:
|
2012-03-31 08:42:20 +04:00
|
|
|
WorkerGlobalScope(JSContext* aCx, WorkerPrivate* aWorker)
|
|
|
|
: EventTarget(aCx), mWorker(aWorker)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(mozilla::dom::workers::WorkerGlobalScope);
|
2012-10-12 03:38:04 +04:00
|
|
|
for (int32_t i = 0; i < SLOT_COUNT; i++) {
|
2011-07-17 23:09:13 +04:00
|
|
|
mSlots[i] = JSVAL_VOID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~WorkerGlobalScope()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(mozilla::dom::workers::WorkerGlobalScope);
|
|
|
|
}
|
|
|
|
|
2013-09-09 07:28:48 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
// nsIGlobalObject
|
|
|
|
virtual JSObject* GetGlobalJSObject() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
mWorker->AssertIsOnWorkerThread();
|
|
|
|
return GetJSObject();
|
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
virtual void
|
2012-04-27 00:57:33 +04:00
|
|
|
_trace(JSTracer* aTrc) MOZ_OVERRIDE
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2012-10-12 03:38:04 +04:00
|
|
|
for (int32_t i = 0; i < SLOT_COUNT; i++) {
|
2013-06-05 18:04:23 +04:00
|
|
|
JS_CallHeapValueTracer(aTrc, &mSlots[i],
|
|
|
|
"WorkerGlobalScope instance slot");
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
mWorker->TraceInternal(aTrc);
|
2012-04-27 00:57:33 +04:00
|
|
|
EventTarget::_trace(aTrc);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
virtual void
|
2012-04-27 00:57:33 +04:00
|
|
|
_finalize(JSFreeOp* aFop) MOZ_OVERRIDE
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2012-04-27 00:57:33 +04:00
|
|
|
EventTarget::_finalize(aFop);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-08-09 02:55:23 +04:00
|
|
|
static bool IsWorkerGlobalScope(JS::Handle<JS::Value> v);
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
2013-08-09 02:55:23 +04:00
|
|
|
GetOnCloseImpl(JSContext* aCx, JS::CallArgs aArgs)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-08-09 02:55:23 +04:00
|
|
|
const char* name = sEventStrings[STRING_onclose];
|
|
|
|
WorkerGlobalScope* scope = GetInstancePrivate(aCx, &aArgs.thisv().toObject(), name);
|
|
|
|
MOZ_ASSERT(scope);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-05-06 05:15:11 +04:00
|
|
|
ErrorResult rv;
|
2013-09-20 09:07:03 +04:00
|
|
|
nsRefPtr<EventHandlerNonNull> handler =
|
2012-03-31 08:42:20 +04:00
|
|
|
scope->GetEventListener(NS_ConvertASCIItoUTF16(name + 2), rv);
|
|
|
|
|
2012-05-06 05:15:11 +04:00
|
|
|
if (rv.Failed()) {
|
2012-03-31 08:42:20 +04:00
|
|
|
JS_ReportError(aCx, "Failed to get event listener!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-20 09:07:03 +04:00
|
|
|
if (!handler) {
|
|
|
|
aArgs.rval().setNull();
|
|
|
|
} else {
|
|
|
|
aArgs.rval().setObject(*handler->Callable());
|
|
|
|
}
|
2012-03-31 08:42:20 +04:00
|
|
|
return true;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
2013-08-09 02:55:23 +04:00
|
|
|
GetOnClose(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-08-09 02:55:23 +04:00
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp);
|
|
|
|
return JS::CallNonGenericMethod<IsWorkerGlobalScope, GetOnCloseImpl>(aCx, args);
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
static bool
|
|
|
|
SetOnCloseImpl(JSContext* aCx, JS::CallArgs aArgs)
|
|
|
|
{
|
|
|
|
const char* name = sEventStrings[STRING_onclose];
|
|
|
|
WorkerGlobalScope* scope =
|
|
|
|
GetInstancePrivate(aCx, &aArgs.thisv().toObject(), name);
|
|
|
|
MOZ_ASSERT(scope);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-09-20 09:07:03 +04:00
|
|
|
if (aArgs.length() == 0 || !aArgs[0].isObjectOrNull()) {
|
2012-03-31 08:42:20 +04:00
|
|
|
JS_ReportError(aCx, "Not an event listener!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-06 05:15:11 +04:00
|
|
|
ErrorResult rv;
|
2013-09-20 09:07:03 +04:00
|
|
|
JS::Rooted<JSObject*> listenerObj(aCx, aArgs[0].toObjectOrNull());
|
|
|
|
nsRefPtr<EventHandlerNonNull> handler;
|
|
|
|
if (listenerObj && JS_ObjectIsCallable(aCx, listenerObj)) {
|
|
|
|
handler = new EventHandlerNonNull(listenerObj);
|
|
|
|
} else {
|
|
|
|
handler = nullptr;
|
|
|
|
}
|
2012-03-31 08:42:20 +04:00
|
|
|
scope->SetEventListener(NS_ConvertASCIItoUTF16(name + 2),
|
2013-09-20 09:07:03 +04:00
|
|
|
handler, rv);
|
2012-05-06 05:15:11 +04:00
|
|
|
if (rv.Failed()) {
|
2012-03-31 08:42:20 +04:00
|
|
|
JS_ReportError(aCx, "Failed to set event listener!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
aArgs.rval().setUndefined();
|
2012-03-31 08:42:20 +04:00
|
|
|
return true;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
static bool
|
|
|
|
SetOnClose(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
|
|
|
|
{
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp);
|
|
|
|
return JS::CallNonGenericMethod<IsWorkerGlobalScope, SetOnCloseImpl>(aCx, args);
|
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
static WorkerGlobalScope*
|
|
|
|
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName);
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2012-02-29 03:11:11 +04:00
|
|
|
Construct(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_WRONG_CONSTRUCTOR,
|
|
|
|
sClass.name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
2013-08-09 02:55:23 +04:00
|
|
|
GetSelfImpl(JSContext* aCx, JS::CallArgs aArgs)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-08-09 02:55:23 +04:00
|
|
|
aArgs.rval().setObject(aArgs.thisv().toObject());
|
2011-07-17 23:09:13 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
2013-08-09 02:55:23 +04:00
|
|
|
GetSelf(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
|
|
|
|
{
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp);
|
|
|
|
return JS::CallNonGenericMethod<IsWorkerGlobalScope, GetSelfImpl>(aCx, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
GetLocationImpl(JSContext* aCx, JS::CallArgs aArgs)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-08-09 02:55:23 +04:00
|
|
|
JS::Rooted<JSObject*> obj(aCx, &aArgs.thisv().toObject());
|
2011-07-17 23:09:13 +04:00
|
|
|
WorkerGlobalScope* scope =
|
2013-08-09 02:55:23 +04:00
|
|
|
GetInstancePrivate(aCx, obj, sProperties[SLOT_location].name);
|
|
|
|
MOZ_ASSERT(scope);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
if (scope->mSlots[SLOT_location].isUndefined()) {
|
2011-07-17 23:09:13 +04:00
|
|
|
WorkerPrivate::LocationInfo& info = scope->mWorker->GetLocationInfo();
|
|
|
|
|
2013-07-24 11:41:55 +04:00
|
|
|
nsRefPtr<WorkerLocation> location =
|
2013-08-09 02:55:23 +04:00
|
|
|
WorkerLocation::Create(aCx, obj, info);
|
2011-07-17 23:09:13 +04:00
|
|
|
if (!location) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-30 08:15:37 +04:00
|
|
|
JS::Rooted<JS::Value> val(aCx);
|
|
|
|
if (!WrapNewBindingObject(aCx, obj, location, &val)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
scope->mSlots[SLOT_location] = val;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
aArgs.rval().set(scope->mSlots[SLOT_location]);
|
2011-07-17 23:09:13 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
static bool
|
|
|
|
GetLocation(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
|
|
|
|
{
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp);
|
|
|
|
return JS::CallNonGenericMethod<IsWorkerGlobalScope, GetLocationImpl>(aCx, args);
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2012-02-29 03:11:11 +04:00
|
|
|
UnwrapErrorEvent(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
|
|
|
JS_ASSERT(aArgc == 1);
|
2012-05-11 19:46:26 +04:00
|
|
|
JS_ASSERT((JS_ARGV(aCx, aVp)[0]).isObject());
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-05-11 19:46:26 +04:00
|
|
|
JSObject* wrapper = &JS_CALLEE(aCx, aVp).toObject();
|
2011-07-17 23:09:13 +04:00
|
|
|
JS_ASSERT(JS_ObjectIsFunction(aCx, wrapper));
|
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
JS::Rooted<JS::Value> scope(aCx,
|
|
|
|
js::GetFunctionNativeReserved(wrapper, SLOT_wrappedScope));
|
|
|
|
JS::Rooted<JS::Value> listener(aCx,
|
|
|
|
js::GetFunctionNativeReserved(wrapper, SLOT_wrappedFunction));
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-05-11 19:46:26 +04:00
|
|
|
JS_ASSERT(scope.isObject());
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-05-09 11:27:40 +04:00
|
|
|
JS::Rooted<JSObject*> event(aCx, &JS_ARGV(aCx, aVp)[0].toObject());
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
jsval argv[3] = { JSVAL_VOID, JSVAL_VOID, JSVAL_VOID };
|
2013-07-26 13:00:38 +04:00
|
|
|
JS::AutoArrayRooter rootedArgv(aCx, ArrayLength(argv), argv);
|
|
|
|
if (!JS_GetProperty(aCx, event, "message", rootedArgv.handleAt(0)) ||
|
|
|
|
!JS_GetProperty(aCx, event, "filename", rootedArgv.handleAt(1)) ||
|
|
|
|
!JS_GetProperty(aCx, event, "lineno", rootedArgv.handleAt(2))) {
|
2011-07-17 23:09:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-11 06:39:45 +04:00
|
|
|
JS::Rooted<JS::Value> rval(aCx, JS::UndefinedValue());
|
2011-07-17 23:09:13 +04:00
|
|
|
if (!JS_CallFunctionValue(aCx, JSVAL_TO_OBJECT(scope), listener,
|
2013-05-11 06:39:45 +04:00
|
|
|
ArrayLength(argv), argv, rval.address())) {
|
2011-07-17 23:09:13 +04:00
|
|
|
JS_ReportPendingException(aCx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (JSVAL_IS_BOOLEAN(rval) && JSVAL_TO_BOOLEAN(rval) &&
|
2013-06-05 18:04:23 +04:00
|
|
|
!JS_CallFunctionName(aCx, event, "preventDefault", 0, NULL,
|
|
|
|
rval.address())) {
|
2011-07-17 23:09:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
2013-08-09 02:55:23 +04:00
|
|
|
GetOnErrorListenerImpl(JSContext* aCx, JS::CallArgs aArgs)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
|
|
|
const char* name = sEventStrings[STRING_onerror];
|
2013-08-09 02:55:23 +04:00
|
|
|
WorkerGlobalScope* scope = GetInstancePrivate(aCx, &aArgs.thisv().toObject(), name);
|
|
|
|
MOZ_ASSERT(scope);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-05-06 05:15:11 +04:00
|
|
|
ErrorResult rv;
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-09-20 09:07:03 +04:00
|
|
|
nsRefPtr<EventHandlerNonNull> adaptor =
|
2012-03-31 08:42:20 +04:00
|
|
|
scope->GetEventListener(NS_ConvertASCIItoUTF16(name + 2), rv);
|
2012-05-06 05:15:11 +04:00
|
|
|
if (rv.Failed()) {
|
2012-03-31 08:42:20 +04:00
|
|
|
JS_ReportError(aCx, "Failed to get event listener!");
|
2011-07-17 23:09:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
if (!adaptor) {
|
2013-08-09 02:55:23 +04:00
|
|
|
aArgs.rval().setNull();
|
2012-01-18 00:06:10 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-20 09:07:03 +04:00
|
|
|
aArgs.rval().set(js::GetFunctionNativeReserved(adaptor->Callable(),
|
|
|
|
SLOT_wrappedFunction));
|
2013-08-09 02:55:23 +04:00
|
|
|
MOZ_ASSERT(aArgs.rval().isObject());
|
2011-07-17 23:09:13 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
2013-08-09 02:55:23 +04:00
|
|
|
GetOnErrorListener(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-08-09 02:55:23 +04:00
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp);
|
|
|
|
return JS::CallNonGenericMethod<IsWorkerGlobalScope, GetOnErrorListenerImpl>(aCx, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
SetOnErrorListenerImpl(JSContext* aCx, JS::CallArgs aArgs)
|
|
|
|
{
|
|
|
|
JS::Rooted<JSObject*> obj(aCx, &aArgs.thisv().toObject());
|
2011-07-17 23:09:13 +04:00
|
|
|
const char* name = sEventStrings[STRING_onerror];
|
2013-08-09 02:55:23 +04:00
|
|
|
WorkerGlobalScope* scope = GetInstancePrivate(aCx, obj, name);
|
|
|
|
MOZ_ASSERT(scope);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
if (aArgs.length() == 0 || !aArgs[0].isObject()) {
|
2012-03-31 08:42:20 +04:00
|
|
|
JS_ReportError(aCx, "Not an event listener!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSFunction* adaptor =
|
|
|
|
js::NewFunctionWithReserved(aCx, UnwrapErrorEvent, 1, 0,
|
2013-07-30 03:45:27 +04:00
|
|
|
JS::CurrentGlobalOrNull(aCx), "unwrap");
|
2011-07-17 23:09:13 +04:00
|
|
|
if (!adaptor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-18 05:48:25 +04:00
|
|
|
JS::Rooted<JSObject*> listener(aCx, JS_GetFunctionObject(adaptor));
|
2011-07-17 23:09:13 +04:00
|
|
|
if (!listener) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-30 05:26:21 +04:00
|
|
|
js::SetFunctionNativeReserved(listener, SLOT_wrappedScope,
|
2013-08-09 02:55:23 +04:00
|
|
|
JS::ObjectValue(*obj));
|
|
|
|
js::SetFunctionNativeReserved(listener, SLOT_wrappedFunction, aArgs[0]);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-05-06 05:15:11 +04:00
|
|
|
ErrorResult rv;
|
2013-09-20 09:07:03 +04:00
|
|
|
nsRefPtr<EventHandlerNonNull> handler = new EventHandlerNonNull(listener);
|
|
|
|
scope->SetEventListener(NS_ConvertASCIItoUTF16(name + 2), handler, rv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2012-05-06 05:15:11 +04:00
|
|
|
if (rv.Failed()) {
|
2012-03-31 08:42:20 +04:00
|
|
|
JS_ReportError(aCx, "Failed to set event listener!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
aArgs.rval().setUndefined();
|
2012-03-31 08:42:20 +04:00
|
|
|
return true;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
2013-08-09 02:55:23 +04:00
|
|
|
SetOnErrorListener(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-08-09 02:55:23 +04:00
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp);
|
|
|
|
return JS::CallNonGenericMethod<IsWorkerGlobalScope, SetOnErrorListenerImpl>(aCx, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
GetNavigatorImpl(JSContext* aCx, JS::CallArgs aArgs)
|
|
|
|
{
|
|
|
|
JS::Rooted<JSObject*> obj(aCx, &aArgs.thisv().toObject());
|
2011-07-17 23:09:13 +04:00
|
|
|
WorkerGlobalScope* scope =
|
2013-08-09 02:55:23 +04:00
|
|
|
GetInstancePrivate(aCx, obj, sProperties[SLOT_navigator].name);
|
|
|
|
MOZ_ASSERT(scope);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
if (scope->mSlots[SLOT_navigator].isUndefined()) {
|
|
|
|
nsRefPtr<WorkerNavigator> navigator = WorkerNavigator::Create(aCx, obj);
|
2011-07-17 23:09:13 +04:00
|
|
|
if (!navigator) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-30 08:15:37 +04:00
|
|
|
JS::Rooted<JS::Value> val(aCx);
|
|
|
|
if (!WrapNewBindingObject(aCx, obj, navigator, &val)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
scope->mSlots[SLOT_navigator] = val;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
aArgs.rval().set(scope->mSlots[SLOT_navigator]);
|
2011-07-17 23:09:13 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
static bool
|
|
|
|
GetNavigator(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
|
|
|
|
{
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp);
|
|
|
|
return JS::CallNonGenericMethod<IsWorkerGlobalScope, GetNavigatorImpl>(aCx, args);
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2012-02-29 03:11:11 +04:00
|
|
|
Close(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
|
2011-12-02 01:30:28 +04:00
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
WorkerGlobalScope* scope = GetInstancePrivate(aCx, obj, sFunctions[0].name);
|
|
|
|
if (!scope) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-04 21:20:51 +04:00
|
|
|
if (!scope->mWorker->CloseInternal(aCx)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_RVAL(aCx, aVp).setUndefined();
|
|
|
|
return true;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2012-02-29 03:11:11 +04:00
|
|
|
ImportScripts(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
|
2011-12-02 01:30:28 +04:00
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
WorkerGlobalScope* scope = GetInstancePrivate(aCx, obj, sFunctions[1].name);
|
|
|
|
if (!scope) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aArgc && !scriptloader::Load(aCx, aArgc, JS_ARGV(aCx, aVp))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-04 21:20:51 +04:00
|
|
|
JS_RVAL(aCx, aVp).setUndefined();
|
2011-07-17 23:09:13 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2012-02-29 03:11:11 +04:00
|
|
|
SetTimeout(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
|
2011-12-02 01:30:28 +04:00
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
WorkerGlobalScope* scope = GetInstancePrivate(aCx, obj, sFunctions[2].name);
|
|
|
|
if (!scope) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-30 00:16:04 +04:00
|
|
|
JS::Rooted<JS::Value> dummy(aCx);
|
2013-06-05 18:04:23 +04:00
|
|
|
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "v",
|
|
|
|
dummy.address())) {
|
2011-07-17 23:09:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return scope->mWorker->SetTimeout(aCx, aArgc, aVp, false);
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2012-02-29 03:11:11 +04:00
|
|
|
ClearTimeout(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
|
2011-12-02 01:30:28 +04:00
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
WorkerGlobalScope* scope = GetInstancePrivate(aCx, obj, sFunctions[3].name);
|
|
|
|
if (!scope) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 07:54:10 +04:00
|
|
|
uint32_t id;
|
2011-07-17 23:09:13 +04:00
|
|
|
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "u", &id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-04 21:20:51 +04:00
|
|
|
if (!scope->mWorker->ClearTimeout(aCx, id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_RVAL(aCx, aVp).setUndefined();
|
|
|
|
return true;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2012-02-29 03:11:11 +04:00
|
|
|
SetInterval(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
|
2011-12-02 01:30:28 +04:00
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
WorkerGlobalScope* scope = GetInstancePrivate(aCx, obj, sFunctions[4].name);
|
|
|
|
if (!scope) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-30 00:16:04 +04:00
|
|
|
JS::Rooted<JS::Value> dummy(aCx);
|
2013-06-05 18:04:23 +04:00
|
|
|
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "v",
|
|
|
|
dummy.address())) {
|
2011-07-17 23:09:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return scope->mWorker->SetTimeout(aCx, aArgc, aVp, true);
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
2012-02-29 03:11:11 +04:00
|
|
|
ClearInterval(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
|
2011-12-02 01:30:28 +04:00
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
WorkerGlobalScope* scope = GetInstancePrivate(aCx, obj, sFunctions[5].name);
|
|
|
|
if (!scope) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 07:54:10 +04:00
|
|
|
uint32_t id;
|
2011-07-17 23:09:13 +04:00
|
|
|
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "u", &id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-04 21:20:51 +04:00
|
|
|
if (!scope->mWorker->ClearTimeout(aCx, id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_RVAL(aCx, aVp).setUndefined();
|
|
|
|
return true;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2012-02-29 03:11:11 +04:00
|
|
|
Dump(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
|
2011-12-02 01:30:28 +04:00
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GetInstancePrivate(aCx, obj, sFunctions[6].name)) {
|
2011-07-17 23:09:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aArgc) {
|
|
|
|
JSString* str = JS_ValueToString(aCx, JS_ARGV(aCx, aVp)[0]);
|
|
|
|
if (!str) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSAutoByteString buffer(aCx, str);
|
|
|
|
if (!buffer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-07 14:29:34 +04:00
|
|
|
#ifdef ANDROID
|
2012-06-28 18:14:11 +04:00
|
|
|
__android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", buffer.ptr());
|
2011-12-07 14:29:34 +04:00
|
|
|
#endif
|
2012-03-06 08:44:37 +04:00
|
|
|
fputs(buffer.ptr(), stdout);
|
|
|
|
fflush(stdout);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-09-04 21:20:51 +04:00
|
|
|
JS_RVAL(aCx, aVp).setUndefined();
|
2011-07-17 23:09:13 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2012-02-29 03:11:11 +04:00
|
|
|
AtoB(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
|
2011-12-02 01:30:28 +04:00
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GetInstancePrivate(aCx, obj, sFunctions[7].name)) {
|
2011-07-17 23:09:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-09 11:27:40 +04:00
|
|
|
JS::Rooted<JS::Value> string(aCx);
|
2013-06-05 18:04:23 +04:00
|
|
|
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "v",
|
|
|
|
string.address())) {
|
2011-07-17 23:09:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-09 11:27:40 +04:00
|
|
|
JS::Rooted<JS::Value> result(aCx);
|
|
|
|
if (!xpc::Base64Decode(aCx, string, result.address())) {
|
2011-07-17 23:09:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_SET_RVAL(aCx, aVp, result);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2012-02-29 03:11:11 +04:00
|
|
|
BtoA(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
|
2011-12-02 01:30:28 +04:00
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GetInstancePrivate(aCx, obj, sFunctions[8].name)) {
|
2011-07-17 23:09:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-09 11:27:40 +04:00
|
|
|
JS::Rooted<JS::Value> binary(aCx);
|
2013-06-05 18:04:23 +04:00
|
|
|
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "v",
|
|
|
|
binary.address())) {
|
2011-07-17 23:09:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-09 11:27:40 +04:00
|
|
|
JS::Rooted<JS::Value> result(aCx);
|
|
|
|
if (!xpc::Base64Encode(aCx, binary, result.address())) {
|
2011-07-17 23:09:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_SET_RVAL(aCx, aVp, result);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-09 07:28:48 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(WorkerGlobalScope, workers::EventTarget)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(WorkerGlobalScope, workers::EventTarget)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(WorkerGlobalScope)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, DOMBindingBase)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-09-11 16:49:05 +04:00
|
|
|
const JSClass WorkerGlobalScope::sClass = {
|
2011-07-17 23:09:13 +04:00
|
|
|
"WorkerGlobalScope",
|
|
|
|
0,
|
2013-06-05 18:04:23 +04:00
|
|
|
JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub,
|
|
|
|
JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub
|
2011-07-17 23:09:13 +04:00
|
|
|
};
|
|
|
|
|
2013-04-23 01:15:36 +04:00
|
|
|
const JSPropertySpec WorkerGlobalScope::sProperties[] = {
|
2013-08-09 02:55:23 +04:00
|
|
|
JS_PSGS("location", GetLocation, GetterOnlyJSNative, JSPROP_ENUMERATE),
|
|
|
|
JS_PSGS(sEventStrings[STRING_onerror], GetOnErrorListener, SetOnErrorListener,
|
|
|
|
JSPROP_ENUMERATE),
|
|
|
|
JS_PSGS(sEventStrings[STRING_onclose], GetOnClose, SetOnClose,
|
|
|
|
JSPROP_ENUMERATE),
|
|
|
|
JS_PSGS("navigator", GetNavigator, GetterOnlyJSNative, JSPROP_ENUMERATE),
|
|
|
|
JS_PSGS("self", GetSelf, GetterOnlyJSNative, JSPROP_ENUMERATE),
|
|
|
|
JS_PS_END
|
2011-07-17 23:09:13 +04:00
|
|
|
};
|
|
|
|
|
2013-04-23 01:15:49 +04:00
|
|
|
const JSFunctionSpec WorkerGlobalScope::sFunctions[] = {
|
2011-07-17 23:09:13 +04:00
|
|
|
JS_FN("close", Close, 0, FUNCTION_FLAGS),
|
|
|
|
JS_FN("importScripts", ImportScripts, 1, FUNCTION_FLAGS),
|
|
|
|
JS_FN("setTimeout", SetTimeout, 1, FUNCTION_FLAGS),
|
|
|
|
JS_FN("clearTimeout", ClearTimeout, 1, FUNCTION_FLAGS),
|
|
|
|
JS_FN("setInterval", SetInterval, 1, FUNCTION_FLAGS),
|
|
|
|
JS_FN("clearInterval", ClearTimeout, 1, FUNCTION_FLAGS),
|
|
|
|
JS_FN("dump", Dump, 1, FUNCTION_FLAGS),
|
|
|
|
JS_FN("atob", AtoB, 1, FUNCTION_FLAGS),
|
|
|
|
JS_FN("btoa", BtoA, 1, FUNCTION_FLAGS),
|
|
|
|
JS_FS_END
|
|
|
|
};
|
|
|
|
|
|
|
|
const char* const WorkerGlobalScope::sEventStrings[STRING_COUNT] = {
|
|
|
|
"onerror",
|
|
|
|
"onclose"
|
|
|
|
};
|
|
|
|
|
|
|
|
class DedicatedWorkerGlobalScope : public WorkerGlobalScope
|
|
|
|
{
|
2013-09-11 16:49:05 +04:00
|
|
|
static const DOMJSClass sClass;
|
|
|
|
static const DOMIfaceAndProtoJSClass sProtoClass;
|
2013-04-23 01:15:36 +04:00
|
|
|
static const JSPropertySpec sProperties[];
|
2013-04-23 01:15:49 +04:00
|
|
|
static const JSFunctionSpec sFunctions[];
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
STRING_onmessage = 0,
|
|
|
|
|
|
|
|
STRING_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* const sEventStrings[STRING_COUNT];
|
|
|
|
|
|
|
|
public:
|
2013-09-11 16:49:05 +04:00
|
|
|
static const JSClass*
|
2011-07-17 23:09:13 +04:00
|
|
|
Class()
|
|
|
|
{
|
2012-03-31 08:42:20 +04:00
|
|
|
return sClass.ToJSClass();
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-09-11 16:49:05 +04:00
|
|
|
static const JSClass*
|
2013-03-28 23:43:33 +04:00
|
|
|
ProtoClass()
|
|
|
|
{
|
|
|
|
return sProtoClass.ToJSClass();
|
|
|
|
}
|
|
|
|
|
2013-09-11 16:49:05 +04:00
|
|
|
static const DOMClass*
|
2013-03-28 23:43:33 +04:00
|
|
|
DOMClassStruct()
|
|
|
|
{
|
|
|
|
return &sClass.mClass;
|
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
static JSObject*
|
|
|
|
InitClass(JSContext* aCx, JSObject* aObj, JSObject* aParentProto)
|
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
JS::Rooted<JSObject*> proto(aCx,
|
2013-03-28 23:43:33 +04:00
|
|
|
JS_InitClass(aCx, aObj, aParentProto, ProtoClass(), Construct, 0,
|
2013-06-05 18:04:23 +04:00
|
|
|
sProperties, sFunctions, NULL, NULL));
|
2013-03-28 23:43:33 +04:00
|
|
|
if (proto) {
|
2013-06-05 18:04:23 +04:00
|
|
|
void* domClass = const_cast<DOMClass *>(DOMClassStruct());
|
2013-03-28 23:43:33 +04:00
|
|
|
js::SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT,
|
2013-06-05 18:04:23 +04:00
|
|
|
JS::PrivateValue(domClass));
|
2013-03-28 23:43:33 +04:00
|
|
|
}
|
|
|
|
return proto;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
2011-07-17 23:09:13 +04:00
|
|
|
InitPrivate(JSContext* aCx, JSObject* aObj, WorkerPrivate* aWorkerPrivate)
|
|
|
|
{
|
2012-03-31 08:42:20 +04:00
|
|
|
JS_ASSERT(JS_GetClass(aObj) == Class());
|
|
|
|
|
2012-10-09 22:50:27 +04:00
|
|
|
dom::AllocateProtoAndIfaceCache(aObj);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
nsRefPtr<DedicatedWorkerGlobalScope> scope =
|
|
|
|
new DedicatedWorkerGlobalScope(aCx, aWorkerPrivate);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-06-06 23:59:46 +04:00
|
|
|
js::SetReservedSlot(aObj, DOM_OBJECT_SLOT, PRIVATE_TO_JSVAL(scope));
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
scope->SetIsDOMBinding();
|
|
|
|
scope->SetWrapper(aObj);
|
|
|
|
|
|
|
|
scope.forget();
|
2011-07-17 23:09:13 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2012-03-31 08:42:20 +04:00
|
|
|
DedicatedWorkerGlobalScope(JSContext* aCx, WorkerPrivate* aWorker)
|
|
|
|
: WorkerGlobalScope(aCx, aWorker)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(mozilla::dom::workers::DedicatedWorkerGlobalScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
~DedicatedWorkerGlobalScope()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(mozilla::dom::workers::DedicatedWorkerGlobalScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-04-27 00:57:33 +04:00
|
|
|
using EventTarget::GetEventListener;
|
|
|
|
using EventTarget::SetEventListener;
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
2013-08-09 02:55:23 +04:00
|
|
|
IsDedicatedWorkerGlobalScope(JS::Handle<JS::Value> v)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-08-09 02:55:23 +04:00
|
|
|
return v.isObject() && JS_GetClass(&v.toObject()) == Class();
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
static bool
|
|
|
|
GetOnMessageImpl(JSContext* aCx, JS::CallArgs aArgs)
|
|
|
|
{
|
|
|
|
const char* name = sEventStrings[STRING_onmessage];
|
|
|
|
DedicatedWorkerGlobalScope* scope =
|
|
|
|
GetInstancePrivate(aCx, &aArgs.thisv().toObject(), name);
|
|
|
|
MOZ_ASSERT(scope);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-05-06 05:15:11 +04:00
|
|
|
ErrorResult rv;
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-09-20 09:07:03 +04:00
|
|
|
nsRefPtr<EventHandlerNonNull> handler =
|
2012-03-31 08:42:20 +04:00
|
|
|
scope->GetEventListener(NS_ConvertASCIItoUTF16(name + 2), rv);
|
2012-05-06 05:15:11 +04:00
|
|
|
if (rv.Failed()) {
|
2012-03-31 08:42:20 +04:00
|
|
|
JS_ReportError(aCx, "Failed to get event listener!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-20 09:07:03 +04:00
|
|
|
if (!handler) {
|
|
|
|
aArgs.rval().setNull();
|
|
|
|
} else {
|
|
|
|
aArgs.rval().setObject(*handler->Callable());
|
|
|
|
}
|
2012-03-31 08:42:20 +04:00
|
|
|
return true;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
2013-08-09 02:55:23 +04:00
|
|
|
GetOnMessage(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-08-09 02:55:23 +04:00
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp);
|
|
|
|
return JS::CallNonGenericMethod<IsDedicatedWorkerGlobalScope, GetOnMessageImpl>(aCx, args);
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
static bool
|
|
|
|
SetOnMessageImpl(JSContext* aCx, JS::CallArgs aArgs)
|
|
|
|
{
|
|
|
|
const char* name = sEventStrings[STRING_onmessage];
|
|
|
|
DedicatedWorkerGlobalScope* scope =
|
|
|
|
GetInstancePrivate(aCx, &aArgs.thisv().toObject(), name);
|
|
|
|
MOZ_ASSERT(scope);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-09-20 09:07:03 +04:00
|
|
|
if (aArgs.length() == 0 || !aArgs[0].isObjectOrNull()) {
|
2012-03-31 08:42:20 +04:00
|
|
|
JS_ReportError(aCx, "Not an event listener!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-06 05:15:11 +04:00
|
|
|
ErrorResult rv;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2013-09-20 09:07:03 +04:00
|
|
|
JS::Rooted<JSObject*> listenerObj(aCx, aArgs[0].toObjectOrNull());
|
|
|
|
nsRefPtr<EventHandlerNonNull> handler;
|
|
|
|
if (listenerObj && JS_ObjectIsCallable(aCx, listenerObj)) {
|
|
|
|
handler = new EventHandlerNonNull(listenerObj);
|
|
|
|
} else {
|
|
|
|
handler = nullptr;
|
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
scope->SetEventListener(NS_ConvertASCIItoUTF16(name + 2), handler, rv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2012-05-06 05:15:11 +04:00
|
|
|
if (rv.Failed()) {
|
2012-03-31 08:42:20 +04:00
|
|
|
JS_ReportError(aCx, "Failed to set event listener!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
aArgs.rval().setUndefined();
|
2012-03-31 08:42:20 +04:00
|
|
|
return true;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
static bool
|
|
|
|
SetOnMessage(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
|
|
|
|
{
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp);
|
|
|
|
return JS::CallNonGenericMethod<IsDedicatedWorkerGlobalScope, SetOnMessageImpl>(aCx, args);
|
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
static DedicatedWorkerGlobalScope*
|
|
|
|
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
|
|
|
|
{
|
2013-09-11 16:49:05 +04:00
|
|
|
const JSClass* classPtr = JS_GetClass(aObj);
|
2012-03-31 08:42:20 +04:00
|
|
|
if (classPtr == Class()) {
|
2012-12-07 00:21:19 +04:00
|
|
|
return UnwrapDOMObject<DedicatedWorkerGlobalScope>(aObj);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
|
2012-03-31 08:42:20 +04:00
|
|
|
JSMSG_INCOMPATIBLE_PROTO, Class()->name, aFunctionName,
|
2012-02-03 22:00:08 +04:00
|
|
|
classPtr->name);
|
2011-07-17 23:09:13 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2012-02-29 03:11:11 +04:00
|
|
|
Construct(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_WRONG_CONSTRUCTOR,
|
2012-03-31 08:42:20 +04:00
|
|
|
Class()->name);
|
2011-07-17 23:09:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
2013-06-05 18:04:23 +04:00
|
|
|
Resolve(JSContext* aCx, JS::Handle<JSObject*> aObj, JS::Handle<jsid> aId,
|
|
|
|
unsigned aFlags, JS::MutableHandle<JSObject*> aObjp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-08-09 02:53:04 +04:00
|
|
|
bool resolved;
|
2011-07-17 23:09:13 +04:00
|
|
|
if (!JS_ResolveStandardClass(aCx, aObj, aId, &resolved)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-05 00:34:42 +04:00
|
|
|
aObjp.set(resolved ? aObj.get() : NULL);
|
2011-07-17 23:09:13 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-03-19 18:34:55 +04:00
|
|
|
Finalize(JSFreeOp* aFop, JSObject* aObj)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2012-03-31 08:42:20 +04:00
|
|
|
JS_ASSERT(JS_GetClass(aObj) == Class());
|
2011-07-17 23:09:13 +04:00
|
|
|
DedicatedWorkerGlobalScope* scope =
|
2012-12-07 00:21:19 +04:00
|
|
|
UnwrapDOMObject<DedicatedWorkerGlobalScope>(aObj);
|
2011-07-17 23:09:13 +04:00
|
|
|
if (scope) {
|
2012-10-09 22:50:27 +04:00
|
|
|
DestroyProtoAndIfaceCache(aObj);
|
2012-04-27 00:57:33 +04:00
|
|
|
scope->_finalize(aFop);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Trace(JSTracer* aTrc, JSObject* aObj)
|
|
|
|
{
|
2012-03-31 08:42:20 +04:00
|
|
|
JS_ASSERT(JS_GetClass(aObj) == Class());
|
2011-07-17 23:09:13 +04:00
|
|
|
DedicatedWorkerGlobalScope* scope =
|
2012-12-07 00:21:19 +04:00
|
|
|
UnwrapDOMObject<DedicatedWorkerGlobalScope>(aObj);
|
2011-07-17 23:09:13 +04:00
|
|
|
if (scope) {
|
2012-10-09 22:50:27 +04:00
|
|
|
TraceProtoAndIfaceCache(aTrc, aObj);
|
2012-04-27 00:57:33 +04:00
|
|
|
scope->_trace(aTrc);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2012-02-29 03:11:11 +04:00
|
|
|
PostMessage(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
|
2011-12-02 01:30:28 +04:00
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-04-23 01:15:49 +04:00
|
|
|
const char* name = sFunctions[0].name;
|
2011-07-17 23:09:13 +04:00
|
|
|
DedicatedWorkerGlobalScope* scope = GetInstancePrivate(aCx, obj, name);
|
|
|
|
if (!scope) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-04 11:53:00 +04:00
|
|
|
JS::Rooted<JS::Value> message(aCx);
|
|
|
|
JS::Rooted<JS::Value> transferable(aCx, JSVAL_VOID);
|
2012-10-04 02:19:22 +04:00
|
|
|
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "v/v",
|
2013-05-04 11:53:00 +04:00
|
|
|
message.address(), transferable.address())) {
|
2011-07-17 23:09:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-03 15:22:31 +04:00
|
|
|
if (!scope->mWorker->PostMessageToParent(aCx, message, transferable)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_RVAL(aCx, aVp).setUndefined();
|
|
|
|
return true;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-11 16:49:05 +04:00
|
|
|
const DOMJSClass DedicatedWorkerGlobalScope::sClass = {
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
2012-10-05 20:59:23 +04:00
|
|
|
// We don't have to worry about Xray expando slots here because we'll never
|
|
|
|
// have an Xray wrapper to a worker global scope.
|
2012-03-31 08:42:20 +04:00
|
|
|
"DedicatedWorkerGlobalScope",
|
|
|
|
JSCLASS_DOM_GLOBAL | JSCLASS_IS_DOMJSCLASS | JSCLASS_IMPLEMENTS_BARRIERS |
|
2013-08-21 08:21:00 +04:00
|
|
|
JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(DOM_GLOBAL_SLOTS) | JSCLASS_NEW_RESOLVE,
|
2013-06-05 18:04:23 +04:00
|
|
|
JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub,
|
|
|
|
JS_StrictPropertyStub, JS_EnumerateStub,
|
|
|
|
reinterpret_cast<JSResolveOp>(Resolve), JS_ConvertStub, Finalize, nullptr,
|
|
|
|
nullptr, nullptr, nullptr, Trace
|
2012-03-31 08:42:20 +04:00
|
|
|
},
|
2012-05-22 17:46:20 +04:00
|
|
|
{
|
2012-12-06 14:41:14 +04:00
|
|
|
INTERFACE_CHAIN_1(prototypes::id::EventTarget_workers),
|
2012-05-22 17:46:20 +04:00
|
|
|
false,
|
2012-10-09 22:50:27 +04:00
|
|
|
&sWorkerNativePropertyHooks
|
2012-09-06 11:14:49 +04:00
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
};
|
|
|
|
|
2013-09-11 16:49:05 +04:00
|
|
|
const DOMIfaceAndProtoJSClass DedicatedWorkerGlobalScope::sProtoClass = {
|
2013-03-28 23:43:33 +04:00
|
|
|
{
|
|
|
|
// XXXbz we use "DedicatedWorkerGlobalScope" here to match sClass
|
|
|
|
// so that we can JS_InitClass this JSClass and then
|
|
|
|
// call JS_NewObject with our sClass and have it find the right
|
|
|
|
// prototype.
|
|
|
|
"DedicatedWorkerGlobalScope",
|
|
|
|
JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(2),
|
|
|
|
JS_PropertyStub, /* addProperty */
|
2013-04-06 08:22:55 +04:00
|
|
|
JS_DeletePropertyStub, /* delProperty */
|
2013-03-28 23:43:33 +04:00
|
|
|
JS_PropertyStub, /* getProperty */
|
|
|
|
JS_StrictPropertyStub, /* setProperty */
|
|
|
|
JS_EnumerateStub,
|
|
|
|
JS_ResolveStub,
|
|
|
|
JS_ConvertStub,
|
|
|
|
nullptr, /* finalize */
|
|
|
|
nullptr, /* checkAccess */
|
|
|
|
nullptr, /* call */
|
|
|
|
nullptr, /* hasInstance */
|
|
|
|
nullptr, /* construct */
|
|
|
|
nullptr, /* trace */
|
|
|
|
JSCLASS_NO_INTERNAL_MEMBERS
|
|
|
|
},
|
|
|
|
eInterfacePrototype,
|
|
|
|
&sWorkerNativePropertyHooks,
|
|
|
|
"[object DedicatedWorkerGlobalScope]",
|
|
|
|
prototypes::id::_ID_Count,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2013-04-23 01:15:36 +04:00
|
|
|
const JSPropertySpec DedicatedWorkerGlobalScope::sProperties[] = {
|
2013-08-09 02:55:23 +04:00
|
|
|
JS_PSGS(sEventStrings[STRING_onmessage], GetOnMessage, SetOnMessage,
|
|
|
|
JSPROP_ENUMERATE),
|
|
|
|
JS_PS_END
|
2011-07-17 23:09:13 +04:00
|
|
|
};
|
|
|
|
|
2013-04-23 01:15:49 +04:00
|
|
|
const JSFunctionSpec DedicatedWorkerGlobalScope::sFunctions[] = {
|
2011-07-17 23:09:13 +04:00
|
|
|
JS_FN("postMessage", PostMessage, 1, FUNCTION_FLAGS),
|
|
|
|
JS_FS_END
|
|
|
|
};
|
|
|
|
|
|
|
|
const char* const DedicatedWorkerGlobalScope::sEventStrings[STRING_COUNT] = {
|
|
|
|
"onmessage",
|
|
|
|
};
|
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
class SharedWorkerGlobalScope : public WorkerGlobalScope
|
|
|
|
{
|
|
|
|
static DOMJSClass sClass;
|
|
|
|
static DOMIfaceAndProtoJSClass sProtoClass;
|
|
|
|
static const JSPropertySpec sProperties[];
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
STRING_onconnect = 0,
|
|
|
|
|
|
|
|
STRING_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* const sEventStrings[STRING_COUNT];
|
|
|
|
|
|
|
|
public:
|
|
|
|
static const JSClass*
|
|
|
|
Class()
|
|
|
|
{
|
|
|
|
return sClass.ToJSClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const JSClass*
|
|
|
|
ProtoClass()
|
|
|
|
{
|
|
|
|
return sProtoClass.ToJSClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const DOMClass*
|
|
|
|
DOMClassStruct()
|
|
|
|
{
|
|
|
|
return &sClass.mClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSObject*
|
|
|
|
InitClass(JSContext* aCx, JSObject* aObj, JSObject* aParentProto)
|
|
|
|
{
|
|
|
|
JS::Rooted<JSObject*> proto(aCx,
|
|
|
|
JS_InitClass(aCx, aObj, aParentProto, ProtoClass(), Construct, 0,
|
|
|
|
sProperties, nullptr, nullptr, nullptr));
|
|
|
|
if (proto) {
|
|
|
|
void* domClass = const_cast<DOMClass *>(DOMClassStruct());
|
|
|
|
js::SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT,
|
|
|
|
JS::PrivateValue(domClass));
|
|
|
|
}
|
|
|
|
return proto;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
InitPrivate(JSContext* aCx, JSObject* aObj, WorkerPrivate* aWorkerPrivate)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(JS_GetClass(aObj) == Class());
|
|
|
|
|
|
|
|
dom::AllocateProtoAndIfaceCache(aObj);
|
|
|
|
|
|
|
|
nsRefPtr<SharedWorkerGlobalScope> scope =
|
|
|
|
new SharedWorkerGlobalScope(aCx, aWorkerPrivate);
|
|
|
|
|
|
|
|
js::SetReservedSlot(aObj, DOM_OBJECT_SLOT, PRIVATE_TO_JSVAL(scope));
|
|
|
|
|
|
|
|
scope->SetIsDOMBinding();
|
|
|
|
scope->SetWrapper(aObj);
|
|
|
|
|
|
|
|
scope.forget();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SharedWorkerGlobalScope(JSContext* aCx, WorkerPrivate* aWorker)
|
|
|
|
: WorkerGlobalScope(aCx, aWorker)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(mozilla::dom::workers::SharedWorkerGlobalScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
~SharedWorkerGlobalScope()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(mozilla::dom::workers::SharedWorkerGlobalScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
using EventTarget::GetEventListener;
|
|
|
|
using EventTarget::SetEventListener;
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsSharedWorkerGlobalScope(JS::Handle<JS::Value> aVal)
|
|
|
|
{
|
|
|
|
return aVal.isObject() && JS_GetClass(&aVal.toObject()) == Class();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
GetOnconnectImpl(JSContext* aCx, JS::CallArgs aArgs)
|
|
|
|
{
|
|
|
|
auto name = sEventStrings[STRING_onconnect];
|
|
|
|
|
|
|
|
auto scope = GetInstancePrivate(aCx, &aArgs.thisv().toObject(), name);
|
|
|
|
MOZ_ASSERT(scope);
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
|
|
|
|
nsRefPtr<EventHandlerNonNull> handler =
|
|
|
|
scope->GetEventListener(NS_ConvertASCIItoUTF16(name + 2), rv);
|
|
|
|
if (rv.Failed()) {
|
|
|
|
JS_ReportError(aCx, "Failed to get event listener!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!handler) {
|
|
|
|
aArgs.rval().setNull();
|
|
|
|
} else {
|
|
|
|
aArgs.rval().setObject(*handler->Callable());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
GetOnconnect(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
|
|
|
|
{
|
|
|
|
auto args = JS::CallArgsFromVp(aArgc, aVp);
|
|
|
|
return JS::CallNonGenericMethod<IsSharedWorkerGlobalScope,
|
|
|
|
GetOnconnectImpl>(aCx, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
SetOnconnectImpl(JSContext* aCx, JS::CallArgs aArgs)
|
|
|
|
{
|
|
|
|
auto name = sEventStrings[STRING_onconnect];
|
|
|
|
|
|
|
|
auto scope = GetInstancePrivate(aCx, &aArgs.thisv().toObject(), name);
|
|
|
|
MOZ_ASSERT(scope);
|
|
|
|
|
|
|
|
if (aArgs.length() == 0 || !aArgs[0].isObject()) {
|
|
|
|
JS_ReportError(aCx, "Not an event listener!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> listenerObj(aCx, aArgs[0].toObjectOrNull());
|
|
|
|
nsRefPtr<EventHandlerNonNull> handler;
|
|
|
|
if (listenerObj && JS_ObjectIsCallable(aCx, listenerObj)) {
|
|
|
|
handler = new EventHandlerNonNull(listenerObj);
|
|
|
|
} else {
|
|
|
|
handler = nullptr;
|
|
|
|
}
|
|
|
|
scope->SetEventListener(NS_ConvertASCIItoUTF16(name + 2), handler, rv);
|
|
|
|
|
|
|
|
if (rv.Failed()) {
|
|
|
|
JS_ReportError(aCx, "Failed to set event listener!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aArgs.rval().setUndefined();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
SetOnconnect(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
|
|
|
|
{
|
|
|
|
auto args = JS::CallArgsFromVp(aArgc, aVp);
|
|
|
|
return JS::CallNonGenericMethod<IsSharedWorkerGlobalScope,
|
|
|
|
SetOnconnectImpl>(aCx, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
GetNameImpl(JSContext* aCx, JS::CallArgs aArgs)
|
|
|
|
{
|
|
|
|
auto scope = GetInstancePrivate(aCx, &aArgs.thisv().toObject(), "name");
|
|
|
|
MOZ_ASSERT(scope);
|
|
|
|
|
|
|
|
auto name = scope->mWorker->SharedWorkerName();
|
|
|
|
MOZ_ASSERT(!name.IsVoid());
|
|
|
|
|
|
|
|
JS::Rooted<JSString*> nameStr(aCx,
|
|
|
|
JS_InternUCStringN(aCx, name.get(), name.Length()));
|
|
|
|
if (!nameStr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aArgs.rval().setString(nameStr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
GetName(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
|
|
|
|
{
|
|
|
|
auto args = JS::CallArgsFromVp(aArgc, aVp);
|
|
|
|
return JS::CallNonGenericMethod<IsSharedWorkerGlobalScope,
|
|
|
|
GetNameImpl>(aCx, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static SharedWorkerGlobalScope*
|
|
|
|
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
|
|
|
|
{
|
|
|
|
const JSClass* classPtr = JS_GetClass(aObj);
|
|
|
|
if (classPtr == Class()) {
|
|
|
|
return UnwrapDOMObject<SharedWorkerGlobalScope>(aObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ReportErrorNumber(aCx, js_GetErrorMessage, nullptr,
|
|
|
|
JSMSG_INCOMPATIBLE_PROTO, Class()->name, aFunctionName,
|
|
|
|
classPtr->name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
Construct(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(aCx, js_GetErrorMessage, nullptr,
|
|
|
|
JSMSG_WRONG_CONSTRUCTOR, Class()->name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
Resolve(JSContext* aCx, JS::Handle<JSObject*> aObj, JS::Handle<jsid> aId,
|
|
|
|
unsigned aFlags, JS::MutableHandle<JSObject*> aObjp)
|
|
|
|
{
|
|
|
|
bool resolved;
|
|
|
|
if (!JS_ResolveStandardClass(aCx, aObj, aId, &resolved)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aObjp.set(resolved ? aObj.get() : nullptr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Finalize(JSFreeOp* aFop, JSObject* aObj)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(JS_GetClass(aObj) == Class());
|
|
|
|
SharedWorkerGlobalScope* scope =
|
|
|
|
UnwrapDOMObject<SharedWorkerGlobalScope>(aObj);
|
|
|
|
if (scope) {
|
|
|
|
DestroyProtoAndIfaceCache(aObj);
|
|
|
|
scope->_finalize(aFop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Trace(JSTracer* aTrc, JSObject* aObj)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(JS_GetClass(aObj) == Class());
|
|
|
|
SharedWorkerGlobalScope* scope =
|
|
|
|
UnwrapDOMObject<SharedWorkerGlobalScope>(aObj);
|
|
|
|
if (scope) {
|
|
|
|
TraceProtoAndIfaceCache(aTrc, aObj);
|
|
|
|
scope->_trace(aTrc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DOMJSClass SharedWorkerGlobalScope::sClass = {
|
|
|
|
{
|
|
|
|
// We don't have to worry about Xray expando slots here because we'll never
|
|
|
|
// have an Xray wrapper to a worker global scope.
|
|
|
|
"SharedWorkerGlobalScope",
|
|
|
|
JSCLASS_DOM_GLOBAL | JSCLASS_IS_DOMJSCLASS | JSCLASS_IMPLEMENTS_BARRIERS |
|
|
|
|
JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(DOM_GLOBAL_SLOTS) | JSCLASS_NEW_RESOLVE,
|
|
|
|
JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub,
|
|
|
|
JS_StrictPropertyStub, JS_EnumerateStub,
|
|
|
|
reinterpret_cast<JSResolveOp>(Resolve), JS_ConvertStub, Finalize, nullptr,
|
|
|
|
nullptr, nullptr, nullptr, Trace
|
|
|
|
},
|
|
|
|
{
|
|
|
|
INTERFACE_CHAIN_1(prototypes::id::EventTarget_workers),
|
|
|
|
false,
|
|
|
|
&sWorkerNativePropertyHooks
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DOMIfaceAndProtoJSClass SharedWorkerGlobalScope::sProtoClass = {
|
|
|
|
{
|
|
|
|
// XXXbz we use "SharedWorkerGlobalScope" here to match sClass
|
|
|
|
// so that we can JS_InitClass this JSClass and then
|
|
|
|
// call JS_NewObject with our sClass and have it find the right
|
|
|
|
// prototype.
|
|
|
|
"SharedWorkerGlobalScope",
|
|
|
|
JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(2),
|
|
|
|
JS_PropertyStub, /* addProperty */
|
|
|
|
JS_DeletePropertyStub, /* delProperty */
|
|
|
|
JS_PropertyStub, /* getProperty */
|
|
|
|
JS_StrictPropertyStub, /* setProperty */
|
|
|
|
JS_EnumerateStub,
|
|
|
|
JS_ResolveStub,
|
|
|
|
JS_ConvertStub,
|
|
|
|
nullptr, /* finalize */
|
|
|
|
nullptr, /* checkAccess */
|
|
|
|
nullptr, /* call */
|
|
|
|
nullptr, /* hasInstance */
|
|
|
|
nullptr, /* construct */
|
|
|
|
nullptr, /* trace */
|
|
|
|
JSCLASS_NO_INTERNAL_MEMBERS
|
|
|
|
},
|
|
|
|
eInterfacePrototype,
|
|
|
|
&sWorkerNativePropertyHooks,
|
|
|
|
"[object SharedWorkerGlobalScope]",
|
|
|
|
prototypes::id::_ID_Count,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
const JSPropertySpec SharedWorkerGlobalScope::sProperties[] = {
|
|
|
|
JS_PSGS(sEventStrings[STRING_onconnect], GetOnconnect, SetOnconnect,
|
|
|
|
JSPROP_ENUMERATE),
|
|
|
|
JS_PSGS("name", GetName, GetterOnlyJSNative, JSPROP_ENUMERATE),
|
|
|
|
JS_PS_END
|
|
|
|
};
|
|
|
|
|
|
|
|
const char* const SharedWorkerGlobalScope::sEventStrings[STRING_COUNT] = {
|
|
|
|
"onconnect",
|
|
|
|
};
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
WorkerGlobalScope*
|
|
|
|
WorkerGlobalScope::GetInstancePrivate(JSContext* aCx, JSObject* aObj,
|
|
|
|
const char* aFunctionName)
|
|
|
|
{
|
2013-09-11 16:49:05 +04:00
|
|
|
const JSClass* classPtr = JS_GetClass(aObj);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
// We can only make [Dedicated|Shared]WorkerGlobalScope, not
|
|
|
|
// WorkerGlobalScope, so this should never happen.
|
|
|
|
MOZ_ASSERT(classPtr != Class());
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
if (classPtr == DedicatedWorkerGlobalScope::Class()) {
|
2012-12-07 00:21:19 +04:00
|
|
|
return UnwrapDOMObject<DedicatedWorkerGlobalScope>(aObj);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
if (classPtr == SharedWorkerGlobalScope::Class()) {
|
|
|
|
return UnwrapDOMObject<SharedWorkerGlobalScope>(aObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ReportErrorNumber(aCx, js_GetErrorMessage, nullptr,
|
|
|
|
JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName,
|
|
|
|
classPtr->name);
|
|
|
|
return nullptr;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:55:23 +04:00
|
|
|
bool
|
2013-06-05 18:04:23 +04:00
|
|
|
WorkerGlobalScope::IsWorkerGlobalScope(JS::Handle<JS::Value> aVal)
|
2013-08-09 02:55:23 +04:00
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
if (!aVal.isObject()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto classPtr = JS_GetClass(&aVal.toObject());
|
|
|
|
|
|
|
|
return classPtr == DedicatedWorkerGlobalScope::Class() ||
|
|
|
|
classPtr == SharedWorkerGlobalScope::Class();
|
2013-08-09 02:55:23 +04:00
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
} /* anonymous namespace */
|
|
|
|
|
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
JSObject*
|
2013-06-05 18:04:23 +04:00
|
|
|
CreateGlobalScope(JSContext* aCx)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2012-05-03 08:35:38 +04:00
|
|
|
using namespace mozilla::dom;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
WorkerPrivate* worker = GetWorkerPrivateFromContext(aCx);
|
2013-06-05 18:04:23 +04:00
|
|
|
MOZ_ASSERT(worker);
|
|
|
|
|
|
|
|
const JSClass* classPtr = worker->IsSharedWorker() ?
|
|
|
|
SharedWorkerGlobalScope::Class() :
|
|
|
|
DedicatedWorkerGlobalScope::Class();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-06-29 19:11:18 +04:00
|
|
|
JS::CompartmentOptions options;
|
2013-06-05 18:04:23 +04:00
|
|
|
if (worker->IsChromeWorker()) {
|
2013-06-29 19:11:18 +04:00
|
|
|
options.setVersion(JSVERSION_LATEST);
|
2013-06-05 18:04:23 +04:00
|
|
|
}
|
|
|
|
|
2013-05-02 07:44:12 +04:00
|
|
|
JS::Rooted<JSObject*> global(aCx,
|
2013-06-05 18:04:23 +04:00
|
|
|
JS_NewGlobalObject(aCx, classPtr, GetWorkerPrincipal(),
|
|
|
|
JS::DontFireOnNewGlobalHook, options));
|
2011-07-17 23:09:13 +04:00
|
|
|
if (!global) {
|
2013-06-05 18:04:23 +04:00
|
|
|
return nullptr;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 05:42:53 +04:00
|
|
|
JSAutoCompartment ac(aCx, global);
|
2011-11-11 00:04:24 +04:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
// Make the private slots now so that all our instance checks succeed.
|
2013-06-05 18:04:23 +04:00
|
|
|
if (worker->IsSharedWorker()) {
|
|
|
|
if (!SharedWorkerGlobalScope::InitPrivate(aCx, global, worker)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} else if (!DedicatedWorkerGlobalScope::InitPrivate(aCx, global, worker)) {
|
|
|
|
return nullptr;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Proto chain should be:
|
2013-06-05 18:04:23 +04:00
|
|
|
// global -> [Dedicated|Shared]WorkerGlobalScope
|
2011-07-17 23:09:13 +04:00
|
|
|
// -> WorkerGlobalScope
|
|
|
|
// -> EventTarget
|
|
|
|
// -> Object
|
|
|
|
|
2013-05-09 11:27:40 +04:00
|
|
|
JS::Rooted<JSObject*> eventTargetProto(aCx,
|
|
|
|
EventTargetBinding_workers::GetProtoObject(aCx, global));
|
2011-07-17 23:09:13 +04:00
|
|
|
if (!eventTargetProto) {
|
2013-06-05 18:04:23 +04:00
|
|
|
return nullptr;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-07-31 20:20:33 +04:00
|
|
|
JS::Rooted<JSObject*> scopeProto(aCx,
|
|
|
|
WorkerGlobalScope::InitClass(aCx, global, eventTargetProto));
|
2011-07-17 23:09:13 +04:00
|
|
|
if (!scopeProto) {
|
2013-06-05 18:04:23 +04:00
|
|
|
return nullptr;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
JS::Rooted<JSObject*> finalScopeProto(aCx,
|
|
|
|
worker->IsSharedWorker() ?
|
|
|
|
SharedWorkerGlobalScope::InitClass(aCx, global, scopeProto) :
|
2013-07-31 20:20:33 +04:00
|
|
|
DedicatedWorkerGlobalScope::InitClass(aCx, global, scopeProto));
|
2013-06-05 18:04:23 +04:00
|
|
|
if (!finalScopeProto) {
|
|
|
|
return nullptr;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
if (!JS_SetPrototype(aCx, global, finalScopeProto)) {
|
|
|
|
return nullptr;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-01-07 23:18:19 +04:00
|
|
|
if (worker->IsChromeWorker()) {
|
2013-10-14 15:58:05 +04:00
|
|
|
if (!DefineChromeWorkerFunctions(aCx, global) ||
|
|
|
|
!DefineOSFileConstants(aCx, global) ||
|
|
|
|
!ChromeWorkerBinding::GetConstructorObject(aCx, global)) {
|
2013-06-05 18:04:23 +04:00
|
|
|
return nullptr;
|
2013-01-07 23:18:19 +04:00
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init other classes we care about.
|
|
|
|
if (!events::InitClasses(aCx, global, false) ||
|
2013-09-09 07:29:21 +04:00
|
|
|
!file::InitClasses(aCx, global)) {
|
2013-06-05 18:04:23 +04:00
|
|
|
return nullptr;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 22:50:27 +04:00
|
|
|
// Init other paris-bindings.
|
2013-09-09 07:29:21 +04:00
|
|
|
if (!DOMExceptionBinding::GetConstructorObject(aCx, global) ||
|
2013-09-10 22:27:32 +04:00
|
|
|
!EventBinding::GetConstructorObject(aCx, global) ||
|
2013-09-09 07:29:21 +04:00
|
|
|
!FileReaderSyncBinding_workers::GetConstructorObject(aCx, global) ||
|
2013-08-04 03:55:40 +04:00
|
|
|
!ImageDataBinding::GetConstructorObject(aCx, global) ||
|
2013-08-23 09:17:09 +04:00
|
|
|
!TextDecoderBinding::GetConstructorObject(aCx, global) ||
|
2013-08-23 09:17:10 +04:00
|
|
|
!TextEncoderBinding::GetConstructorObject(aCx, global) ||
|
2012-10-09 22:50:27 +04:00
|
|
|
!XMLHttpRequestBinding_workers::GetConstructorObject(aCx, global) ||
|
2013-02-06 03:17:17 +04:00
|
|
|
!XMLHttpRequestUploadBinding_workers::GetConstructorObject(aCx, global) ||
|
2013-07-24 11:38:23 +04:00
|
|
|
!URLBinding_workers::GetConstructorObject(aCx, global) ||
|
2013-10-14 15:58:05 +04:00
|
|
|
!WorkerBinding::GetConstructorObject(aCx, global) ||
|
2013-07-24 11:41:55 +04:00
|
|
|
!WorkerLocationBinding_workers::GetConstructorObject(aCx, global) ||
|
2013-07-24 11:38:23 +04:00
|
|
|
!WorkerNavigatorBinding_workers::GetConstructorObject(aCx, global)) {
|
2013-06-05 18:04:23 +04:00
|
|
|
return nullptr;
|
2012-03-31 08:42:20 +04:00
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
if (!JS_DefineProfilingFunctions(aCx, global)) {
|
2013-06-05 18:04:23 +04:00
|
|
|
return nullptr;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:38:47 +04:00
|
|
|
JS_FireOnNewGlobalObject(aCx, global);
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
return global;
|
|
|
|
}
|
|
|
|
|
2013-10-14 15:58:05 +04:00
|
|
|
bool
|
|
|
|
GetterOnlyJSNative(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(aCx, js_GetErrorMessage, nullptr, JSMSG_GETTER_ONLY);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
END_WORKERS_NAMESPACE
|