1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #include "WorkerPrivate.h"
8 #include "ChromeWorkerScope.h"
9
10 #include "jsapi.h"
11 #include "mozilla/dom/DebuggerNotificationObserverBinding.h"
12 #include "mozilla/dom/RegisterWorkerBindings.h"
13 #include "mozilla/dom/RegisterWorkerDebuggerBindings.h"
14 #include "mozilla/OSFileConstants.h"
15
16 using namespace mozilla::dom;
17
RegisterBindings(JSContext * aCx,JS::Handle<JSObject * > aGlobal)18 bool WorkerPrivate::RegisterBindings(JSContext* aCx,
19 JS::Handle<JSObject*> aGlobal) {
20 // Init Web IDL bindings
21 if (!RegisterWorkerBindings(aCx, aGlobal)) {
22 return false;
23 }
24
25 if (IsChromeWorker()) {
26 if (!DefineChromeWorkerFunctions(aCx, aGlobal)) {
27 return false;
28 }
29
30 RefPtr<OSFileConstantsService> service =
31 OSFileConstantsService::GetOrCreate();
32 if (!service->DefineOSFileConstants(aCx, aGlobal)) {
33 return false;
34 }
35 }
36
37 return true;
38 }
39
RegisterDebuggerBindings(JSContext * aCx,JS::Handle<JSObject * > aGlobal)40 bool WorkerPrivate::RegisterDebuggerBindings(JSContext* aCx,
41 JS::Handle<JSObject*> aGlobal) {
42 // Init Web IDL bindings
43 if (!RegisterWorkerDebuggerBindings(aCx, aGlobal)) {
44 return false;
45 }
46
47 if (!ChromeUtils_Binding::GetConstructorObject(aCx)) {
48 return false;
49 }
50
51 if (!DebuggerNotificationObserver_Binding::GetConstructorObject(aCx)) {
52 return false;
53 }
54
55 if (!JS_DefineDebuggerObject(aCx, aGlobal)) {
56 return false;
57 }
58
59 return true;
60 }
61