зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1364297 - Worker and SharedWorker constructors have an optional WorkerOptions parameter, r=smaug
This commit is contained in:
Родитель
54fe5f66e7
Коммит
7453988cd7
|
@ -15,6 +15,8 @@
|
|||
[Global=(Worker,DedicatedWorker),
|
||||
Exposed=DedicatedWorker]
|
||||
interface DedicatedWorkerGlobalScope : WorkerGlobalScope {
|
||||
readonly attribute DOMString name;
|
||||
|
||||
[Throws]
|
||||
void postMessage(any message, optional sequence<object> transfer = []);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
[Constructor(USVString scriptURL, optional DOMString name)]
|
||||
[Constructor(USVString scriptURL, optional (DOMString or WorkerOptions) options)]
|
||||
interface SharedWorker : EventTarget {
|
||||
readonly attribute MessagePort port;
|
||||
};
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* this document.
|
||||
*/
|
||||
|
||||
[Constructor(USVString scriptURL),
|
||||
[Constructor(USVString scriptURL, optional WorkerOptions options),
|
||||
Func="mozilla::dom::workers::WorkerPrivate::WorkerAvailable",
|
||||
Exposed=(Window,DedicatedWorker,SharedWorker,System)]
|
||||
interface Worker : EventTarget {
|
||||
|
@ -26,6 +26,12 @@ interface Worker : EventTarget {
|
|||
|
||||
Worker implements AbstractWorker;
|
||||
|
||||
dictionary WorkerOptions {
|
||||
// WorkerType type = "classic"; TODO: Bug 1247687
|
||||
// RequestCredentials credentials = "omit"; // credentials is only used if type is "module" TODO: Bug 1247687
|
||||
DOMString name = "";
|
||||
};
|
||||
|
||||
[Constructor(USVString scriptURL),
|
||||
Func="mozilla::dom::workers::ChromeWorkerPrivate::WorkerAvailable",
|
||||
Exposed=(Window,DedicatedWorker,SharedWorker,System)]
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/dom/MessagePort.h"
|
||||
#include "mozilla/dom/SharedWorkerBinding.h"
|
||||
#include "mozilla/dom/WorkerBinding.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
@ -49,7 +50,7 @@ SharedWorker::~SharedWorker()
|
|||
already_AddRefed<SharedWorker>
|
||||
SharedWorker::Constructor(const GlobalObject& aGlobal,
|
||||
const nsAString& aScriptURL,
|
||||
const mozilla::dom::Optional<nsAString>& aName,
|
||||
const StringOrWorkerOptions& aOptions,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
@ -61,8 +62,11 @@ SharedWorker::Constructor(const GlobalObject& aGlobal,
|
|||
}
|
||||
|
||||
nsCString name;
|
||||
if (aName.WasPassed()) {
|
||||
name = NS_ConvertUTF16toUTF8(aName.Value());
|
||||
if (aOptions.IsString()) {
|
||||
name = NS_ConvertUTF16toUTF8(aOptions.GetAsString());
|
||||
} else {
|
||||
MOZ_ASSERT(aOptions.IsWorkerOptions());
|
||||
name = NS_ConvertUTF16toUTF8(aOptions.GetAsWorkerOptions().mName);
|
||||
}
|
||||
|
||||
RefPtr<SharedWorker> sharedWorker;
|
||||
|
|
|
@ -20,6 +20,7 @@ class EventChainPreVisitor;
|
|||
|
||||
namespace dom {
|
||||
class MessagePort;
|
||||
class StringOrWorkerOptions;
|
||||
}
|
||||
} // namespace mozilla
|
||||
|
||||
|
@ -43,7 +44,7 @@ class SharedWorker final : public DOMEventTargetHelper
|
|||
public:
|
||||
static already_AddRefed<SharedWorker>
|
||||
Constructor(const GlobalObject& aGlobal, const nsAString& aScriptURL,
|
||||
const Optional<nsAString>& aName, ErrorResult& aRv);
|
||||
const StringOrWorkerOptions& aOptions, ErrorResult& aRv);
|
||||
|
||||
MessagePort*
|
||||
Port();
|
||||
|
|
|
@ -2739,9 +2739,7 @@ WorkerPrivateParent<Derived>::WorkerPrivateParent(
|
|||
mCreationTimeStamp(TimeStamp::Now()),
|
||||
mCreationTimeHighRes((double)PR_Now() / PR_USEC_PER_MSEC)
|
||||
{
|
||||
MOZ_ASSERT_IF(!IsDedicatedWorker(),
|
||||
!aWorkerName.IsVoid() && NS_IsMainThread());
|
||||
MOZ_ASSERT_IF(IsDedicatedWorker(), aWorkerName.IsEmpty());
|
||||
MOZ_ASSERT_IF(!IsDedicatedWorker(), NS_IsMainThread());
|
||||
|
||||
if (aLoadInfo.mWindow) {
|
||||
AssertIsOnMainThread();
|
||||
|
@ -4447,9 +4445,6 @@ WorkerPrivate::WorkerPrivate(WorkerPrivate* aParent,
|
|||
, mFetchHandlerWasAdded(false)
|
||||
, mOnLine(false)
|
||||
{
|
||||
MOZ_ASSERT_IF(!IsDedicatedWorker(), !aWorkerName.IsVoid());
|
||||
MOZ_ASSERT_IF(IsDedicatedWorker(), aWorkerName.IsEmpty());
|
||||
|
||||
if (aParent) {
|
||||
aParent->AssertIsOnWorkerThread();
|
||||
aParent->GetAllPreferences(mPreferences);
|
||||
|
@ -4506,10 +4501,12 @@ WorkerPrivate::~WorkerPrivate()
|
|||
already_AddRefed<WorkerPrivate>
|
||||
WorkerPrivate::Constructor(const GlobalObject& aGlobal,
|
||||
const nsAString& aScriptURL,
|
||||
const WorkerOptions& aOptions,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
return WorkerPrivate::Constructor(aGlobal, aScriptURL, false,
|
||||
WorkerTypeDedicated, EmptyCString(),
|
||||
WorkerTypeDedicated,
|
||||
NS_ConvertUTF16toUTF8(aOptions.mName),
|
||||
nullptr, aRv);
|
||||
}
|
||||
|
||||
|
@ -4588,12 +4585,6 @@ WorkerPrivate::Constructor(JSContext* aCx,
|
|||
AssertIsOnMainThread();
|
||||
}
|
||||
|
||||
// Only service and shared workers can have names.
|
||||
MOZ_ASSERT_IF(aWorkerType != WorkerTypeDedicated,
|
||||
!aWorkerName.IsVoid());
|
||||
MOZ_ASSERT_IF(aWorkerType == WorkerTypeDedicated,
|
||||
aWorkerName.IsEmpty());
|
||||
|
||||
Maybe<WorkerLoadInfo> stackLoadInfo;
|
||||
if (!aLoadInfo) {
|
||||
stackLoadInfo.emplace();
|
||||
|
@ -6921,7 +6912,7 @@ WorkerPrivate::GetOrCreateGlobalScope(JSContext* aCx)
|
|||
} else if (IsServiceWorker()) {
|
||||
globalScope = new ServiceWorkerGlobalScope(this, ServiceWorkerScope());
|
||||
} else {
|
||||
globalScope = new DedicatedWorkerGlobalScope(this);
|
||||
globalScope = new DedicatedWorkerGlobalScope(this, WorkerName());
|
||||
}
|
||||
|
||||
JS::Rooted<JSObject*> global(aCx);
|
||||
|
|
|
@ -69,6 +69,7 @@ class PromiseNativeHandler;
|
|||
class StructuredCloneHolder;
|
||||
class WorkerDebuggerGlobalScope;
|
||||
class WorkerGlobalScope;
|
||||
struct WorkerOptions;
|
||||
} // namespace dom
|
||||
namespace ipc {
|
||||
class PrincipalInfo;
|
||||
|
@ -266,7 +267,7 @@ protected:
|
|||
WorkerPrivateParent(WorkerPrivate* aParent,
|
||||
const nsAString& aScriptURL, bool aIsChromeWorker,
|
||||
WorkerType aWorkerType,
|
||||
const nsACString& aSharedWorkerName,
|
||||
const nsACString& aWorkerName,
|
||||
WorkerLoadInfo& aLoadInfo);
|
||||
|
||||
~WorkerPrivateParent();
|
||||
|
@ -838,7 +839,6 @@ public:
|
|||
const nsCString&
|
||||
WorkerName() const
|
||||
{
|
||||
MOZ_ASSERT(IsSharedWorker());
|
||||
return mWorkerName;
|
||||
}
|
||||
|
||||
|
@ -1053,17 +1053,18 @@ protected:
|
|||
public:
|
||||
static already_AddRefed<WorkerPrivate>
|
||||
Constructor(const GlobalObject& aGlobal, const nsAString& aScriptURL,
|
||||
const WorkerOptions& aOptions,
|
||||
ErrorResult& aRv);
|
||||
|
||||
static already_AddRefed<WorkerPrivate>
|
||||
Constructor(const GlobalObject& aGlobal, const nsAString& aScriptURL,
|
||||
bool aIsChromeWorker, WorkerType aWorkerType,
|
||||
const nsACString& aSharedWorkerName,
|
||||
const nsACString& aWorkerName,
|
||||
WorkerLoadInfo* aLoadInfo, ErrorResult& aRv);
|
||||
|
||||
static already_AddRefed<WorkerPrivate>
|
||||
Constructor(JSContext* aCx, const nsAString& aScriptURL, bool aIsChromeWorker,
|
||||
WorkerType aWorkerType, const nsACString& aSharedWorkerName,
|
||||
WorkerType aWorkerType, const nsACString& aWorkerName,
|
||||
WorkerLoadInfo* aLoadInfo, ErrorResult& aRv);
|
||||
|
||||
static bool
|
||||
|
@ -1462,7 +1463,7 @@ public:
|
|||
private:
|
||||
WorkerPrivate(WorkerPrivate* aParent,
|
||||
const nsAString& aScriptURL, bool aIsChromeWorker,
|
||||
WorkerType aWorkerType, const nsACString& aSharedWorkerName,
|
||||
WorkerType aWorkerType, const nsACString& aWorkerName,
|
||||
WorkerLoadInfo& aLoadInfo);
|
||||
|
||||
bool
|
||||
|
|
|
@ -489,8 +489,10 @@ WorkerGlobalScope::CreateImageBitmap(JSContext* aCx,
|
|||
}
|
||||
}
|
||||
|
||||
DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate)
|
||||
: WorkerGlobalScope(aWorkerPrivate)
|
||||
DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
|
||||
const nsCString& aName)
|
||||
: WorkerGlobalScope(aWorkerPrivate)
|
||||
, mName(aName)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -207,15 +207,23 @@ public:
|
|||
|
||||
class DedicatedWorkerGlobalScope final : public WorkerGlobalScope
|
||||
{
|
||||
const nsCString mName;
|
||||
|
||||
~DedicatedWorkerGlobalScope() { }
|
||||
|
||||
public:
|
||||
explicit DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate);
|
||||
DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
|
||||
const nsCString& aName);
|
||||
|
||||
virtual bool
|
||||
WrapGlobalObject(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aReflector) override;
|
||||
|
||||
void GetName(DOMString& aName) const
|
||||
{
|
||||
aName.AsAString() = NS_ConvertUTF8toUTF16(mName);
|
||||
}
|
||||
|
||||
void
|
||||
PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
||||
const Sequence<JSObject*>& aTransferable,
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
// now start the worker
|
||||
var finalWorkerURL = "workerxhr-origin-referrer.js";
|
||||
var url = "resources/redirect.py?location=" + encodeURIComponent(finalWorkerURL);
|
||||
var worker = new Worker(url, true)
|
||||
var worker = new Worker(url)
|
||||
worker.onmessage = function (e) {
|
||||
var subtest = async_test(e.data.test)
|
||||
subtest.step(function(){
|
||||
|
|
|
@ -14,7 +14,7 @@ onconnect = function(e) {
|
|||
var worker = new SharedWorker(null, null);
|
||||
worker.port.addEventListener('message', this.step_func(function(e) {
|
||||
assert_equals(e.data[0], 'null', 'first arg');
|
||||
assert_equals(e.data[1], 'null', 'second arg');
|
||||
assert_equals(e.data[1], '', 'second arg');
|
||||
this.done();
|
||||
}), false);
|
||||
worker.port.start();
|
||||
|
@ -22,4 +22,4 @@ onconnect = function(e) {
|
|||
</script>
|
||||
<!--
|
||||
*/
|
||||
//-->
|
||||
//-->
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
importScripts("/resources/testharness.js");
|
||||
|
||||
var unexpected = ['open', 'print', 'stop', 'getComputedStyle', 'getSelection', 'releaseEvents', 'captureEvents', 'alert', 'confirm', 'prompt', 'addEventStream', 'removeEventStream', 'back', 'forward', 'attachEvent', 'detachEvent', 'navigate', 'DOMParser', 'XMLSerializer', 'XPathEvaluator', 'XSLTProcessor', 'opera', 'Image', 'Option', 'frames', 'Audio', 'SVGUnitTypes', 'SVGZoomAndPan', 'java', 'netscape', 'sun', 'Packages', 'ByteArray', 'closed', 'defaultStatus', 'document', 'event', 'frameElement', 'history', 'innerHeight', 'innerWidth', 'name', 'opener', 'outerHeight', 'outerWidth', 'pageXOffset', 'pageYOffset', 'parent', 'screen', 'screenLeft', 'screenTop', 'screenX', 'screenY', 'status', 'top', 'window', 'length']; // iterated window in opera and removed expected ones
|
||||
var unexpected = ['open', 'print', 'stop', 'getComputedStyle', 'getSelection', 'releaseEvents', 'captureEvents', 'alert', 'confirm', 'prompt', 'addEventStream', 'removeEventStream', 'back', 'forward', 'attachEvent', 'detachEvent', 'navigate', 'DOMParser', 'XMLSerializer', 'XPathEvaluator', 'XSLTProcessor', 'opera', 'Image', 'Option', 'frames', 'Audio', 'SVGUnitTypes', 'SVGZoomAndPan', 'java', 'netscape', 'sun', 'Packages', 'ByteArray', 'closed', 'defaultStatus', 'document', 'event', 'frameElement', 'history', 'innerHeight', 'innerWidth', 'opener', 'outerHeight', 'outerWidth', 'pageXOffset', 'pageYOffset', 'parent', 'screen', 'screenLeft', 'screenTop', 'screenX', 'screenY', 'status', 'top', 'window', 'length']; // iterated window in opera and removed expected ones
|
||||
for (var i = 0; i < unexpected.length; ++i) {
|
||||
var property = unexpected[i];
|
||||
test(function() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче