Bug 919457: Allow bindings specific to workers without the old-style worker ownership model. r=bz

This commit is contained in:
Kyle Huey 2013-09-30 12:15:37 +08:00
parent a2bd6fa53c
commit 755922ca39
11 changed files with 123 additions and 136 deletions

View File

@ -24,8 +24,9 @@
# their primary interface (and hence whose prototype is this
# interface's prototype object). Always False for callback
# interfaces. Defaults to True otherwise.
# * workers - Indicates whether the descriptor is intended to be used for
# worker threads (defaults to false).
# * workers - Indicates whether the descriptor is intended to be used solely
# for worker threads (defaults to false). If true the interface
# will not be made available on the main thread.
# * customTrace - The native class will use a custom trace hook (defaults to
# true for workers, false otherwise).
# * customFinalize - The native class will use a custom finalize hook
@ -59,7 +60,7 @@
# call delete through XPConnect's deferred finalization
# mechanism, for a refcounted object it'll call Release
# through XPConnect's deferred finalization mechanism.
# Always 'worker' for worker descriptors. Defaults to
# 'worker' opts into old style worker models. Defaults to
# 'refcounted'.
#
# The following fields are either a string, an array (defaults to an empty
@ -387,7 +388,14 @@ DOMInterfaces = {
},
{
'workers': True,
'concrete': False
'nativeOwnership': 'worker',
'concrete': False,
# XXXkhuey ownerGlobal returns WindowProxy? which boils down to a JSObject*
# on a worker, and nsRefPtr<JSObject> fails in the expected way. This is
# ugly but it's all going away soon anyways.
'resultNotAddRefed': [
'ownerGlobal'
]
}],
'Exception': {
@ -414,6 +422,7 @@ DOMInterfaces = {
'FileReaderSync': {
'workers': True,
'wrapperCache': False,
},
'FileRequest': {
@ -1245,6 +1254,7 @@ DOMInterfaces = {
},
{
'workers': True,
'nativeOwnership': 'worker',
}],
'VTTCue': {
@ -1425,13 +1435,11 @@ DOMInterfaces = {
'WorkerLocation': {
'headerFile': 'mozilla/dom/workers/bindings/Location.h',
'castable': True,
'workers': True,
},
'WorkerNavigator': {
'headerFile': 'mozilla/dom/workers/bindings/Navigator.h',
'castable': True,
'workers': True,
},
@ -1443,6 +1451,13 @@ DOMInterfaces = {
},
{
'workers': True,
'nativeOwnership': 'worker',
# XXXkhuey responseXML returns Document? which boils down to a JSObject*
# on a worker, and nsRefPtr<JSObject> fails in the expected way. channel is
# similar. This is ugly but it's all going away soon anyways.
'resultNotAddRefed': [
'responseXML', 'channel'
]
}],
'XMLHttpRequestEventTarget': [
@ -1453,6 +1468,7 @@ DOMInterfaces = {
},
{
'workers': True,
'nativeOwnership': 'worker',
'concrete': False,
}],
@ -1463,6 +1479,7 @@ DOMInterfaces = {
},
{
'workers': True,
'nativeOwnership': 'worker',
}],
'XMLSerializer': {

View File

@ -147,7 +147,7 @@ def DOMClass(descriptor):
# padding.
protoList.extend(['prototypes::id::_ID_Count'] * (descriptor.config.maxProtoChainLength - len(protoList)))
prototypeChainString = ', '.join(protoList)
if descriptor.workers:
if descriptor.nativeOwnership == 'worker':
participant = "nullptr"
else:
participant = "GetCCParticipant<%s>::Get()" % descriptor.nativeType
@ -209,7 +209,7 @@ static const DOMJSClass Class = {
};
""" % (self.descriptor.interface.identifier.name,
classFlags,
ADDPROPERTY_HOOK_NAME if self.descriptor.concrete and not self.descriptor.workers and self.descriptor.wrapperCache else 'JS_PropertyStub',
ADDPROPERTY_HOOK_NAME if self.descriptor.concrete and not self.descriptor.nativeOwnership == 'worker' and self.descriptor.wrapperCache else 'JS_PropertyStub',
enumerateHook, newResolveHook, FINALIZE_HOOK_NAME, callHook, traceHook,
CGIndenter(CGGeneric(DOMClass(self.descriptor))).define())
@ -1027,7 +1027,7 @@ class CGAddPropertyHook(CGAbstractClassHook):
'bool', args)
def generate_code(self):
assert not self.descriptor.workers and self.descriptor.wrapperCache
assert not self.descriptor.nativeOwnership == 'worker' and self.descriptor.wrapperCache
return (" // We don't want to preserve if we don't have a wrapper.\n"
" if (self->GetWrapperPreserveColor()) {\n"
" PreserveWrapper(self);\n"
@ -1050,7 +1050,7 @@ def finalizeHook(descriptor, hookName, context):
finalize += "ClearWrapper(self, self);\n"
if descriptor.interface.getExtendedAttribute('OverrideBuiltins'):
finalize += "self->mExpandoAndGeneration.expando = JS::UndefinedValue();\n"
if descriptor.workers:
if descriptor.nativeOwnership == 'worker':
finalize += "self->Release();"
else:
finalize += ("AddForDeferredFinalization<%s, %s >(self);" %
@ -4459,9 +4459,8 @@ def getRetvalDeclarationForType(returnType, descriptorProvider,
raise TypeError("Don't know how to declare return value for %s" %
returnType)
def isResultAlreadyAddRefed(descriptor, extendedAttributes):
# Default to already_AddRefed on the main thread, raw pointer in workers
return not descriptor.workers and not 'resultNotAddRefed' in extendedAttributes
def isResultAlreadyAddRefed(extendedAttributes):
return not 'resultNotAddRefed' in extendedAttributes
def needCx(returnType, arguments, extendedAttributes, considerTypes):
return (considerTypes and
@ -4492,8 +4491,7 @@ class CGCallGenerator(CGThing):
isFallible = errorReport is not None
resultAlreadyAddRefed = isResultAlreadyAddRefed(descriptorProvider,
extendedAttributes)
resultAlreadyAddRefed = isResultAlreadyAddRefed(extendedAttributes)
(result, resultOutParam,
resultRooter, resultArgs) = getRetvalDeclarationForType(
returnType, descriptorProvider, resultAlreadyAddRefed)
@ -4860,14 +4858,13 @@ if (!${obj}) {
isCreator = memberIsCreator(self.idlNode)
if isCreator:
# We better be returning addrefed things!
assert(isResultAlreadyAddRefed(self.descriptor,
self.extendedAttributes) or
assert(isResultAlreadyAddRefed(self.extendedAttributes) or
# Creators can return raw pointers to owned objects
(self.returnType.isGeckoInterface() and
self.descriptor.getDescriptor(self.returnType.unroll().inner.identifier.name).nativeOwnership == 'owned') or
# Workers use raw pointers for new-object return
# values or something
self.descriptor.workers)
self.descriptor.getDescriptor(self.returnType.unroll().inner.identifier.name).nativeOwnership == 'worker')
resultTemplateValues = { 'jsvalRef': 'args.rval()',
'jsvalHandle': 'args.rval()',
@ -6083,10 +6080,6 @@ def getUnionAccessorSignatureType(type, descriptorProvider):
return CGGeneric(type.inner.identifier.name)
if type.isCallback():
if descriptorProvider.workers:
if type.nullable():
return CGGeneric("JSObject*")
return CGGeneric("JSObject&")
if type.nullable():
typeName = "%s*"
else:
@ -7987,7 +7980,7 @@ class CGDescriptor(CGThing):
cgThings.append(CGConstructNavigatorObject(descriptor))
if descriptor.concrete and not descriptor.proxy:
if not descriptor.workers and descriptor.wrapperCache:
if not descriptor.nativeOwnership == 'worker' and descriptor.wrapperCache:
cgThings.append(CGAddPropertyHook(descriptor))
# Always have a finalize hook, regardless of whether the class
@ -9029,8 +9022,7 @@ class CGNativeMember(ClassMethod):
self.descriptorProvider = descriptorProvider
self.member = member
self.extendedAttrs = extendedAttrs
self.resultAlreadyAddRefed = isResultAlreadyAddRefed(self.descriptorProvider,
self.extendedAttrs)
self.resultAlreadyAddRefed = isResultAlreadyAddRefed(self.extendedAttrs)
self.passJSBitsAsNeeded = passJSBitsAsNeeded
self.jsObjectsArePtr = jsObjectsArePtr
self.variadicIsSequence = variadicIsSequence

View File

@ -346,7 +346,7 @@ class Descriptor(DescriptorProvider):
iface = iface.parent
self.operations = operations
if self.workers and desc.get('nativeOwnership', 'worker') == 'worker':
if self.workers and desc.get('nativeOwnership', None) == 'worker':
self.nativeOwnership = "worker"
else:
self.nativeOwnership = desc.get('nativeOwnership', 'refcounted')
@ -354,8 +354,10 @@ class Descriptor(DescriptorProvider):
raise TypeError("Descriptor for %s has unrecognized value (%s) "
"for nativeOwnership" %
(self.interface.identifier.name, self.nativeOwnership))
self.customTrace = desc.get('customTrace', self.workers)
self.customFinalize = desc.get('customFinalize', self.workers)
self.customTrace = desc.get('customTrace', self.nativeOwnership == 'worker')
self.customFinalize = desc.get('customFinalize', self.nativeOwnership == 'worker')
if desc.get('wantsQI', None) != None:
self._wantsQI = desc.get('wantsQI', None)
self.wrapperCache = (not self.interface.isCallback() and
(self.nativeOwnership == 'worker' or
(self.nativeOwnership != 'owned' and

View File

@ -6,22 +6,16 @@
#ifndef mozilla_dom_workers_dombindinginlines_h__
#define mozilla_dom_workers_dombindinginlines_h__
#include "mozilla/dom/FileReaderSyncBinding.h"
#include "mozilla/dom/JSSlots.h"
#include "mozilla/dom/XMLHttpRequestBinding.h"
#include "mozilla/dom/XMLHttpRequestUploadBinding.h"
#include "mozilla/dom/WorkerLocationBinding.h"
#include "mozilla/dom/WorkerNavigatorBinding.h"
#include "mozilla/dom/URLBinding.h"
#include "jsfriendapi.h"
BEGIN_WORKERS_NAMESPACE
class FileReaderSync;
class XMLHttpRequest;
class XMLHttpRequestUpload;
class WorkerLocation;
class WorkerNavigator;
class URL;
namespace {
@ -51,11 +45,8 @@ struct WrapPrototypeTraits
} \
};
SPECIALIZE_PROTO_TRAITS(FileReaderSync)
SPECIALIZE_PROTO_TRAITS(XMLHttpRequest)
SPECIALIZE_PROTO_TRAITS(XMLHttpRequestUpload)
SPECIALIZE_PROTO_TRAITS(WorkerLocation)
SPECIALIZE_PROTO_TRAITS(WorkerNavigator)
SPECIALIZE_PROTO_TRAITS(URL)
#undef SPECIALIZE_PROTO_TRAITS

View File

@ -33,45 +33,25 @@ using namespace mozilla;
using mozilla::dom::Optional;
using mozilla::dom::GlobalObject;
NS_IMPL_ADDREF_INHERITED(FileReaderSync, DOMBindingBase)
NS_IMPL_RELEASE_INHERITED(FileReaderSync, DOMBindingBase)
NS_IMPL_ADDREF(FileReaderSync)
NS_IMPL_RELEASE(FileReaderSync)
NS_INTERFACE_MAP_BEGIN(FileReaderSync)
NS_INTERFACE_MAP_ENTRY(nsICharsetDetectionObserver)
NS_INTERFACE_MAP_END_INHERITING(DOMBindingBase)
FileReaderSync::FileReaderSync(JSContext* aCx)
: DOMBindingBase(aCx)
{
}
void
FileReaderSync::_trace(JSTracer* aTrc)
{
DOMBindingBase::_trace(aTrc);
}
void
FileReaderSync::_finalize(JSFreeOp* aFop)
{
DOMBindingBase::_finalize(aFop);
}
NS_INTERFACE_MAP_END
// static
FileReaderSync*
already_AddRefed<FileReaderSync>
FileReaderSync::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
{
nsRefPtr<FileReaderSync> frs = new FileReaderSync(aGlobal.GetContext());
nsRefPtr<FileReaderSync> frs = new FileReaderSync();
if (!Wrap(aGlobal.GetContext(), aGlobal.Get(), frs)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
return frs;
return frs.forget();
}
JSObject*
FileReaderSync::ReadAsArrayBuffer(JSContext* aCx, JS::Handle<JSObject*> aBlob,
FileReaderSync::ReadAsArrayBuffer(JSContext* aCx,
JS::Handle<JSObject*> aScopeObj,
JS::Handle<JSObject*> aBlob,
ErrorResult& aRv)
{
nsIDOMBlob* blob = file::GetDOMBlobFromJSObject(aBlob);

View File

@ -8,11 +8,11 @@
#define mozilla_dom_workers_filereadersync_h__
#include "Workers.h"
#include "mozilla/dom/workers/bindings/DOMBindingBase.h"
#include "nsICharsetDetectionObserver.h"
#include "nsString.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/FileReaderSyncBinding.h"
class nsIInputStream;
class nsIDOMBlob;
@ -28,8 +28,7 @@ template<typename> class Optional;
BEGIN_WORKERS_NAMESPACE
class FileReaderSync MOZ_FINAL : public DOMBindingBase,
public nsICharsetDetectionObserver
class FileReaderSync MOZ_FINAL : public nsICharsetDetectionObserver
{
nsCString mCharset;
nsresult ConvertStream(nsIInputStream *aStream, const char *aCharset,
@ -37,20 +36,18 @@ class FileReaderSync MOZ_FINAL : public DOMBindingBase,
nsresult GuessCharset(nsIInputStream *aStream, nsACString &aCharset);
public:
virtual void
_trace(JSTracer* aTrc) MOZ_OVERRIDE;
virtual void
_finalize(JSFreeOp* aFop) MOZ_OVERRIDE;
static FileReaderSync*
static already_AddRefed<FileReaderSync>
Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
NS_DECL_ISUPPORTS_INHERITED
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
return FileReaderSyncBinding_workers::Wrap(aCx, aScope, this);
}
FileReaderSync(JSContext* aCx);
NS_DECL_ISUPPORTS
JSObject* ReadAsArrayBuffer(JSContext* aCx, JS::Handle<JSObject*> aBlob,
JSObject* ReadAsArrayBuffer(JSContext* aCx, JS::Handle<JSObject*> aScopeObj,
JS::Handle<JSObject*> aBlob,
ErrorResult& aRv);
void ReadAsBinaryString(JS::Handle<JSObject*> aBlob, nsAString& aResult,
ErrorResult& aRv);

View File

@ -8,16 +8,21 @@
#include "DOMBindingInlines.h"
#include "nsTraceRefcnt.h"
#include "mozilla/dom/WorkerLocationBinding.h"
BEGIN_WORKERS_NAMESPACE
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WorkerLocation)
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WorkerLocation, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WorkerLocation, Release)
/* static */ already_AddRefed<WorkerLocation>
WorkerLocation::Create(JSContext* aCx, JS::Handle<JSObject*> aGlobal,
WorkerPrivate::LocationInfo& aInfo)
{
nsRefPtr<WorkerLocation> location =
new WorkerLocation(aCx,
NS_ConvertUTF8toUTF16(aInfo.mHref),
new WorkerLocation(NS_ConvertUTF8toUTF16(aInfo.mHref),
NS_ConvertUTF8toUTF16(aInfo.mProtocol),
NS_ConvertUTF8toUTF16(aInfo.mHost),
NS_ConvertUTF8toUTF16(aInfo.mHostname),
@ -26,23 +31,13 @@ WorkerLocation::Create(JSContext* aCx, JS::Handle<JSObject*> aGlobal,
NS_ConvertUTF8toUTF16(aInfo.mSearch),
NS_ConvertUTF8toUTF16(aInfo.mHash));
if (!Wrap(aCx, aGlobal, location)) {
return nullptr;
}
return location.forget();
}
void
WorkerLocation::_trace(JSTracer* aTrc)
JSObject*
WorkerLocation::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
DOMBindingBase::_trace(aTrc);
}
void
WorkerLocation::_finalize(JSFreeOp* aFop)
{
DOMBindingBase::_finalize(aFop);
return WorkerLocationBinding_workers::Wrap(aCx, aScope, this);
}
END_WORKERS_NAMESPACE

View File

@ -7,12 +7,12 @@
#define mozilla_dom_workers_location_h__
#include "Workers.h"
#include "DOMBindingBase.h"
#include "WorkerPrivate.h"
#include "nsWrapperCache.h"
BEGIN_WORKERS_NAMESPACE
class WorkerLocation MOZ_FINAL : public DOMBindingBase
class WorkerLocation MOZ_FINAL : public nsWrapperCache
{
nsString mHref;
nsString mProtocol;
@ -23,8 +23,7 @@ class WorkerLocation MOZ_FINAL : public DOMBindingBase
nsString mSearch;
nsString mHash;
WorkerLocation(JSContext* aCx,
const nsAString& aHref,
WorkerLocation(const nsAString& aHref,
const nsAString& aProtocol,
const nsAString& aHost,
const nsAString& aHostname,
@ -32,8 +31,7 @@ class WorkerLocation MOZ_FINAL : public DOMBindingBase
const nsAString& aPathname,
const nsAString& aSearch,
const nsAString& aHash)
: DOMBindingBase(aCx)
, mHref(aHref)
: mHref(aHref)
, mProtocol(aProtocol)
, mHost(aHost)
, mHostname(aHostname)
@ -42,23 +40,29 @@ class WorkerLocation MOZ_FINAL : public DOMBindingBase
, mSearch(aSearch)
, mHash(aHash)
{
MOZ_COUNT_CTOR(mozilla::dom::workers::WorkerLocation);
MOZ_COUNT_CTOR(WorkerLocation);
SetIsDOMBinding();
}
public:
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WorkerLocation)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WorkerLocation)
static already_AddRefed<WorkerLocation>
Create(JSContext* aCx, JS::Handle<JSObject*> aGlobal,
WorkerPrivate::LocationInfo& aInfo);
virtual void
_trace(JSTracer* aTrc) MOZ_OVERRIDE;
virtual JSObject*
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
virtual void
_finalize(JSFreeOp* aFop) MOZ_OVERRIDE;
nsISupports* GetParentObject() const {
return nullptr;
}
~WorkerLocation()
{
MOZ_COUNT_DTOR(mozilla::dom::workers::WorkerLocation);
MOZ_COUNT_DTOR(WorkerLocation);
}
void Stringify(nsString& aHref) const
@ -97,7 +101,6 @@ public:
{
aHash = mHash;
}
};
END_WORKERS_NAMESPACE

View File

@ -7,9 +7,15 @@
#include "DOMBindingInlines.h"
#include "RuntimeService.h"
#include "mozilla/dom/WorkerNavigatorBinding.h"
BEGIN_WORKERS_NAMESPACE
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WorkerNavigator)
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WorkerNavigator, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WorkerNavigator, Release)
/* static */ already_AddRefed<WorkerNavigator>
WorkerNavigator::Create(JSContext* aCx, JS::Handle<JSObject*> aGlobal)
{
@ -20,26 +26,16 @@ WorkerNavigator::Create(JSContext* aCx, JS::Handle<JSObject*> aGlobal)
rts->GetNavigatorStrings();
nsRefPtr<WorkerNavigator> navigator =
new WorkerNavigator(aCx, strings.mAppName, strings.mAppVersion,
new WorkerNavigator(strings.mAppName, strings.mAppVersion,
strings.mPlatform, strings.mUserAgent);
if (!Wrap(aCx, aGlobal, navigator)) {
return nullptr;
}
return navigator.forget();
}
void
WorkerNavigator::_trace(JSTracer* aTrc)
JSObject*
WorkerNavigator::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
DOMBindingBase::_trace(aTrc);
}
void
WorkerNavigator::_finalize(JSFreeOp* aFop)
{
DOMBindingBase::_finalize(aFop);
return WorkerNavigatorBinding_workers::Wrap(aCx, aScope, this);
}
END_WORKERS_NAMESPACE

View File

@ -7,45 +7,49 @@
#define mozilla_dom_workers_navigator_h__
#include "Workers.h"
#include "mozilla/dom/workers/bindings/DOMBindingBase.h"
#include "nsString.h"
#include "nsWrapperCache.h"
BEGIN_WORKERS_NAMESPACE
class WorkerNavigator MOZ_FINAL : public DOMBindingBase
class WorkerNavigator MOZ_FINAL : public nsWrapperCache
{
nsString mAppName;
nsString mAppVersion;
nsString mPlatform;
nsString mUserAgent;
WorkerNavigator(JSContext* aCx,
const nsAString& aAppName,
WorkerNavigator(const nsAString& aAppName,
const nsAString& aAppVersion,
const nsAString& aPlatform,
const nsAString& aUserAgent)
: DOMBindingBase(aCx)
, mAppName(aAppName)
: mAppName(aAppName)
, mAppVersion(aAppVersion)
, mPlatform(aPlatform)
, mUserAgent(aUserAgent)
{
MOZ_COUNT_CTOR(mozilla::dom::workers::WorkerNavigator);
MOZ_COUNT_CTOR(WorkerNavigator);
SetIsDOMBinding();
}
public:
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WorkerNavigator)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WorkerNavigator)
static already_AddRefed<WorkerNavigator>
Create(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
virtual void
_trace(JSTracer* aTrc) MOZ_OVERRIDE;
virtual JSObject*
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
virtual void
_finalize(JSFreeOp* aFop) MOZ_OVERRIDE;
nsISupports* GetParentObject() const {
return nullptr;
}
~WorkerNavigator()
{
MOZ_COUNT_DTOR(mozilla::dom::workers::WorkerNavigator);
MOZ_COUNT_DTOR(WorkerNavigator);
}
void GetAppName(nsString& aAppName) const
@ -64,8 +68,8 @@ public:
{
aUserAgent = mUserAgent;
}
};
END_WORKERS_NAMESPACE
#endif // mozilla_dom_workers_navigator_h__

View File

@ -268,7 +268,12 @@ private:
return false;
}
scope->mSlots[SLOT_location] = OBJECT_TO_JSVAL(location->GetJSObject());
JS::Rooted<JS::Value> val(aCx);
if (!WrapNewBindingObject(aCx, obj, location, &val)) {
return false;
}
scope->mSlots[SLOT_location] = val;
}
aArgs.rval().set(scope->mSlots[SLOT_location]);
@ -418,7 +423,12 @@ private:
return false;
}
scope->mSlots[SLOT_navigator] = OBJECT_TO_JSVAL(navigator->GetJSObject());
JS::Rooted<JS::Value> val(aCx);
if (!WrapNewBindingObject(aCx, obj, navigator, &val)) {
return false;
}
scope->mSlots[SLOT_navigator] = val;
}
aArgs.rval().set(scope->mSlots[SLOT_navigator]);