Bug 817194. Make WebIDL dictionary types sanely initialized by default; add a new Fast subclass to handle cases when we can skip the initialization safely. r=khuey

This commit is contained in:
Boris Zbarsky 2013-10-09 12:05:22 -04:00
parent 08f36be2ef
commit e9898392f2
14 changed files with 54 additions and 33 deletions

View File

@ -18,4 +18,4 @@
# Modifying this file will now automatically clobber the buildbot machines \o/
#
Bug 899574 needed a clobber, at least on Windows.
Bug 817194 needs a clobber on Windows due to bug 924992.

View File

@ -526,11 +526,11 @@ nsDOMMutationObserver::TakeRecords(
}
void
nsDOMMutationObserver::GetObservingInfo(nsTArray<Nullable<MutationObservingInfoInitializer> >& aResult)
nsDOMMutationObserver::GetObservingInfo(nsTArray<Nullable<MutationObservingInfo> >& aResult)
{
aResult.SetCapacity(mReceivers.Count());
for (int32_t i = 0; i < mReceivers.Count(); ++i) {
MutationObservingInfoInitializer& info = aResult.AppendElement()->SetValue();
MutationObservingInfo& info = aResult.AppendElement()->SetValue();
nsMutationReceiver* mr = mReceivers[i];
info.mChildList = mr->ChildList();
info.mAttributes = mr->Attributes();

View File

@ -26,7 +26,7 @@
#include "nsIDocument.h"
class nsDOMMutationObserver;
using mozilla::dom::MutationObservingInfoInitializer;
using mozilla::dom::MutationObservingInfo;
class nsDOMMutationRecord : public nsISupports,
public nsWrapperCache
@ -379,7 +379,7 @@ public:
void HandleMutation();
void GetObservingInfo(nsTArray<Nullable<MutationObservingInfoInitializer> >& aResult);
void GetObservingInfo(nsTArray<Nullable<MutationObservingInfo> >& aResult);
mozilla::dom::MutationCallback* MutationCallback() { return mCallback; }

View File

@ -911,7 +911,7 @@ WebGLContext::GetCanvasLayer(nsDisplayListBuilder* aBuilder,
}
void
WebGLContext::GetContextAttributes(Nullable<dom::WebGLContextAttributesInitializer> &retval)
WebGLContext::GetContextAttributes(Nullable<dom::WebGLContextAttributes> &retval)
{
retval.SetNull();
if (IsContextLost())

View File

@ -76,7 +76,6 @@ namespace dom {
class ImageData;
struct WebGLContextAttributes;
struct WebGLContextAttributesInitializer;
template<typename> struct Nullable;
}
@ -258,7 +257,7 @@ public:
GLsizei DrawingBufferWidth() const { return IsContextLost() ? 0 : mWidth; }
GLsizei DrawingBufferHeight() const { return IsContextLost() ? 0 : mHeight; }
void GetContextAttributes(dom::Nullable<dom::WebGLContextAttributesInitializer>& retval);
void GetContextAttributes(dom::Nullable<dom::WebGLContextAttributes>& retval);
bool IsContextLost() const { return mContextStatus != ContextNotLost; }
void GetSupportedExtensions(JSContext *cx, dom::Nullable< nsTArray<nsString> > &retval);
JSObject* GetExtension(JSContext* cx, const nsAString& aName, ErrorResult& rv);

View File

@ -492,7 +492,7 @@ MediaRecorder::CreateAndDispatchBlobEvent(Session *aSession)
return NS_ERROR_DOM_SECURITY_ERR;
}
BlobEventInitInitializer init;
BlobEventInit init;
init.mBubbles = false;
init.mCancelable = false;
init.mData = aSession->GetEncodedData();

View File

@ -120,7 +120,7 @@ void
TextTrackList::CreateAndDispatchTrackEventRunner(TextTrack* aTrack,
const nsAString& aEventName)
{
TrackEventInitInitializer eventInit;
TrackEventInit eventInit;
eventInit.mBubbles = false;
eventInit.mCancelable = false;
eventInit.mTrack = aTrack;

View File

@ -713,7 +713,7 @@ SpeechRecognition::Start(ErrorResult& aRv)
NS_ENSURE_SUCCESS_VOID(rv);
AutoSafeJSContext cx;
MediaStreamConstraintsInitializer constraints;
MediaStreamConstraints constraints;
constraints.mAudio.SetAsBoolean() = true;
if (!mTestConfig.mFakeFSMEvents) {

View File

@ -4999,7 +4999,7 @@ nsGlobalWindow::DispatchResizeEvent(const nsIntSize& aSize)
AutoSafeJSContext cx;
JSAutoCompartment ac(cx, mJSObject);
DOMWindowResizeEventDetailInitializer detail;
DOMWindowResizeEventDetail detail;
detail.mWidth = aSize.width;
detail.mHeight = aSize.height;
JS::Rooted<JS::Value> detailValue(cx);

View File

@ -3544,9 +3544,13 @@ for (uint32_t i = 0; i < length; ++i) {
assert not isOptional
typeName = CGDictionary.makeDictionaryName(type.inner)
actualTypeName = typeName
if not isMember:
# Since we're not a member and not nullable or optional, no one will
# see our real type, so we can do the fast version of the dictionary
# that doesn't pre-initialize members.
typeName = "detail::Fast" + typeName
declType = CGGeneric(actualTypeName)
declType = CGGeneric(typeName)
# We do manual default value handling here, because we
# actually do want a jsval, and we only handle null anyway
@ -4424,8 +4428,7 @@ def getRetvalDeclarationForType(returnType, descriptorProvider,
return result, True, rooter, None
if returnType.isDictionary():
nullable = returnType.nullable()
dictName = (CGDictionary.makeDictionaryName(returnType.unroll().inner) +
"Initializer")
dictName = CGDictionary.makeDictionaryName(returnType.unroll().inner)
result = CGGeneric(dictName)
if not isMember and typeNeedsRooting(returnType):
if nullable:
@ -8379,7 +8382,20 @@ if (""",
visibility="public",
body=self.getMemberInitializer(m))
for m in self.memberInfo]
ctors = [ClassConstructor([], bodyInHeader=True, visibility="public")]
ctors = [
ClassConstructor(
[],
visibility="public",
body=(
"// Safe to pass a null context if we pass a null value\n"
"Init(nullptr, JS::NullHandleValue);")),
ClassConstructor(
[Argument("int", "")],
visibility="protected",
explicit=True,
bodyInHeader=True,
body='// Do nothing here; this is used by our "Fast" subclass')
]
methods = []
if self.needToInitIds:
@ -8413,17 +8429,23 @@ if (""",
disallowCopyConstruction=disallowCopyConstruction)
initializerCtor = ClassConstructor([],
fastDictionaryCtor = ClassConstructor(
[],
visibility="public",
body=(
"// Safe to pass a null context if we pass a null value\n"
"Init(nullptr, JS::NullHandleValue);"))
initializerStruct = CGClass(selfName + "Initializer",
bodyInHeader=True,
baseConstructors=["%s(42)" % selfName],
body="// Doesn't matter what int we pass to the parent constructor"
)
fastStruct = CGClass("Fast" + selfName,
bases=[ClassBase(selfName)],
constructors=[initializerCtor],
constructors=[fastDictionaryCtor],
isStruct=True)
return CGList([struct, initializerStruct])
return CGList([struct,
CGNamespace.build(['detail'],
fastStruct)],
"\n")
def deps(self):
return self.dictionary.getDeps()

View File

@ -587,7 +587,7 @@ public:
// Dictionary tests
void PassDictionary(JSContext*, const Dict&);
void ReceiveDictionary(JSContext*, Dict&);
void ReceiveNullableDictionary(JSContext*, Nullable<DictInitializer>&);
void ReceiveNullableDictionary(JSContext*, Nullable<Dict>&);
void PassOtherDictionary(const GrandparentDict&);
void PassSequenceOfDictionaries(JSContext*, const Sequence<Dict>&);
void PassDictionaryOrLong(JSContext*, const Dict&);

View File

@ -134,7 +134,7 @@ BrowserElementParent::DispatchOpenWindowEvent(Element* aOpenerFrameElement,
// aFeatures.
// Create the event's detail object.
OpenWindowEventDetailInitializer detail;
OpenWindowEventDetail detail;
detail.mUrl = aURL;
detail.mName = aName;
detail.mFeatures = aFeatures;
@ -307,7 +307,7 @@ NS_IMETHODIMP DispatchAsyncScrollEventRunnable::Run()
NS_ENSURE_TRUE(globalObject, NS_ERROR_UNEXPECTED);
// Create the event's detail object.
AsyncScrollEventDetailInitializer detail;
AsyncScrollEventDetail detail;
detail.mLeft = mContentRect.x;
detail.mTop = mContentRect.y;
detail.mWidth = mContentRect.width;

View File

@ -244,7 +244,7 @@ GamepadService::FireButtonEvent(EventTarget* aTarget,
{
nsString name = aValue == 1.0L ? NS_LITERAL_STRING("gamepadbuttondown") :
NS_LITERAL_STRING("gamepadbuttonup");
GamepadButtonEventInitInitializer init;
GamepadButtonEventInit init;
init.mBubbles = false;
init.mCancelable = false;
init.mGamepad = aGamepad;
@ -307,7 +307,7 @@ GamepadService::FireAxisMoveEvent(EventTarget* aTarget,
uint32_t aAxis,
double aValue)
{
GamepadAxisMoveEventInitInitializer init;
GamepadAxisMoveEventInit init;
init.mBubbles = false;
init.mCancelable = false;
init.mGamepad = aGamepad;
@ -388,7 +388,7 @@ GamepadService::FireConnectionEvent(EventTarget* aTarget,
{
nsString name = aConnected ? NS_LITERAL_STRING("gamepadconnected") :
NS_LITERAL_STRING("gamepaddisconnected");
GamepadEventInitInitializer init;
GamepadEventInit init;
init.mBubbles = false;
init.mCancelable = false;
init.mGamepad = aGamepad;

View File

@ -239,7 +239,7 @@ void
nsDeviceSensors::FireDOMLightEvent(mozilla::dom::EventTarget* aTarget,
double aValue)
{
DeviceLightEventInitInitializer init;
DeviceLightEventInit init;
init.mBubbles = true;
init.mCancelable = false;
init.mValue = aValue;
@ -258,7 +258,7 @@ nsDeviceSensors::FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget,
double aMin,
double aMax)
{
DeviceProximityEventInitInitializer init;
DeviceProximityEventInit init;
init.mBubbles = true;
init.mCancelable = false;
init.mValue = aValue;
@ -289,7 +289,7 @@ void
nsDeviceSensors::FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget,
bool aNear)
{
UserProximityEventInitInitializer init;
UserProximityEventInit init;
init.mBubbles = true;
init.mCancelable = false;
init.mNear = aNear;