Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "WorkerPrivate.h" |
michael@0 | 7 | #include "ChromeWorkerScope.h" |
michael@0 | 8 | #include "File.h" |
michael@0 | 9 | #include "RuntimeService.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "jsapi.h" |
michael@0 | 12 | #include "js/OldDebugAPI.h" |
michael@0 | 13 | #include "mozilla/dom/BindingUtils.h" |
michael@0 | 14 | #include "mozilla/dom/ConsoleBinding.h" |
michael@0 | 15 | #include "mozilla/dom/DOMExceptionBinding.h" |
michael@0 | 16 | #include "mozilla/dom/EventBinding.h" |
michael@0 | 17 | #include "mozilla/dom/EventHandlerBinding.h" |
michael@0 | 18 | #include "mozilla/dom/EventTargetBinding.h" |
michael@0 | 19 | #include "mozilla/dom/FileReaderSyncBinding.h" |
michael@0 | 20 | #include "mozilla/dom/ImageData.h" |
michael@0 | 21 | #include "mozilla/dom/ImageDataBinding.h" |
michael@0 | 22 | #include "mozilla/dom/MessageEventBinding.h" |
michael@0 | 23 | #include "mozilla/dom/MessagePortBinding.h" |
michael@0 | 24 | #include "mozilla/dom/PromiseBinding.h" |
michael@0 | 25 | #include "mozilla/dom/TextDecoderBinding.h" |
michael@0 | 26 | #include "mozilla/dom/TextEncoderBinding.h" |
michael@0 | 27 | #include "mozilla/dom/XMLHttpRequestBinding.h" |
michael@0 | 28 | #include "mozilla/dom/XMLHttpRequestUploadBinding.h" |
michael@0 | 29 | #include "mozilla/dom/URLBinding.h" |
michael@0 | 30 | #include "mozilla/dom/URLSearchParamsBinding.h" |
michael@0 | 31 | #include "mozilla/dom/WorkerBinding.h" |
michael@0 | 32 | #include "mozilla/dom/WorkerLocationBinding.h" |
michael@0 | 33 | #include "mozilla/dom/WorkerNavigatorBinding.h" |
michael@0 | 34 | #include "mozilla/OSFileConstants.h" |
michael@0 | 35 | |
michael@0 | 36 | USING_WORKERS_NAMESPACE |
michael@0 | 37 | using namespace mozilla::dom; |
michael@0 | 38 | |
michael@0 | 39 | bool |
michael@0 | 40 | WorkerPrivate::RegisterBindings(JSContext* aCx, JS::Handle<JSObject*> aGlobal) |
michael@0 | 41 | { |
michael@0 | 42 | JS::Rooted<JSObject*> eventTargetProto(aCx, |
michael@0 | 43 | EventTargetBinding::GetProtoObject(aCx, aGlobal)); |
michael@0 | 44 | if (!eventTargetProto) { |
michael@0 | 45 | return false; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | if (IsChromeWorker()) { |
michael@0 | 49 | if (!ChromeWorkerBinding::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 50 | !DefineChromeWorkerFunctions(aCx, aGlobal) || |
michael@0 | 51 | !DefineOSFileConstants(aCx, aGlobal)) { |
michael@0 | 52 | return false; |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | // Init other classes we care about. |
michael@0 | 57 | if (!file::InitClasses(aCx, aGlobal)) { |
michael@0 | 58 | return false; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | // Init other paris-bindings. |
michael@0 | 62 | if (!ConsoleBinding::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 63 | !DOMExceptionBinding::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 64 | !EventBinding::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 65 | !FileReaderSyncBinding_workers::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 66 | !ImageDataBinding::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 67 | !MessageEventBinding::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 68 | !MessagePortBinding::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 69 | !PromiseBinding::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 70 | !TextDecoderBinding::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 71 | !TextEncoderBinding::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 72 | !XMLHttpRequestBinding_workers::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 73 | !XMLHttpRequestUploadBinding_workers::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 74 | !URLBinding_workers::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 75 | !URLSearchParamsBinding::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 76 | !WorkerBinding::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 77 | !WorkerLocationBinding_workers::GetConstructorObject(aCx, aGlobal) || |
michael@0 | 78 | !WorkerNavigatorBinding_workers::GetConstructorObject(aCx, aGlobal)) { |
michael@0 | 79 | return false; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | if (!JS_DefineProfilingFunctions(aCx, aGlobal)) { |
michael@0 | 83 | return false; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | return true; |
michael@0 | 87 | } |