From ec87989351fb5c59f0acac09bc8dcaafed785366 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 14 Mar 2014 14:51:22 -0400 Subject: [PATCH] Bug 983228. Add a sequence tracer for sequences of unions. r=baku --- dom/bindings/BindingDeclarations.h | 6 +++++ dom/bindings/BindingUtils.h | 31 ++++++++++++++++++------- dom/bindings/Codegen.py | 2 ++ dom/bindings/test/TestBindingHeader.h | 1 + dom/bindings/test/TestCodeGen.webidl | 1 + dom/bindings/test/TestExampleGen.webidl | 1 + dom/bindings/test/TestJSImplGen.webidl | 1 + 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/dom/bindings/BindingDeclarations.h b/dom/bindings/BindingDeclarations.h index 91ed3ba97e6..e2fa580d045 100644 --- a/dom/bindings/BindingDeclarations.h +++ b/dom/bindings/BindingDeclarations.h @@ -47,6 +47,12 @@ protected: struct AllTypedArraysBase { }; +// Struct that serves as a base class for all owning unions. +// Particularly useful so we can use IsBaseOf to detect owning union +// template arguments. +struct AllOwningUnionBase { +}; + struct EnumEntry { const char* value; diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index 24a4d0488e5..ade25f78cb1 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -1657,7 +1657,8 @@ public: // sequence types. template::value, - bool isTypedArray=IsBaseOf::value> + bool isTypedArray=IsBaseOf::value, + bool isOwningUnion=IsBaseOf::value> class SequenceTracer { explicit SequenceTracer() MOZ_DELETE; // Should never be instantiated @@ -1665,7 +1666,7 @@ class SequenceTracer // sequence or sequence template<> -class SequenceTracer +class SequenceTracer { explicit SequenceTracer() MOZ_DELETE; // Should never be instantiated @@ -1679,7 +1680,7 @@ public: // sequence template<> -class SequenceTracer +class SequenceTracer { explicit SequenceTracer() MOZ_DELETE; // Should never be instantiated @@ -1693,7 +1694,7 @@ public: // sequence> template -class SequenceTracer, false, false> +class SequenceTracer, false, false, false> { explicit SequenceTracer() MOZ_DELETE; // Should never be instantiated @@ -1707,7 +1708,7 @@ public: // sequence> as return value template -class SequenceTracer, false, false> +class SequenceTracer, false, false, false> { explicit SequenceTracer() MOZ_DELETE; // Should never be instantiated @@ -1721,7 +1722,7 @@ public: // sequence template -class SequenceTracer +class SequenceTracer { explicit SequenceTracer() MOZ_DELETE; // Should never be instantiated @@ -1735,7 +1736,7 @@ public: // sequence template -class SequenceTracer +class SequenceTracer { explicit SequenceTracer() MOZ_DELETE; // Should never be instantiated @@ -1747,9 +1748,23 @@ public: } }; +// sequence +template +class SequenceTracer +{ + explicit SequenceTracer() MOZ_DELETE; // Should never be instantiated + +public: + static void TraceSequence(JSTracer* trc, T* arrayp, T* end) { + for (; arrayp != end; ++arrayp) { + arrayp->TraceUnion(trc); + } + } +}; + // sequence with T? being a Nullable template -class SequenceTracer, false, false> +class SequenceTracer, false, false, false> { explicit SequenceTracer() MOZ_DELETE; // Should never be instantiated diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 60081cfd71b..fb6f4ad135c 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -7201,7 +7201,9 @@ class CGUnionStruct(CGThing): disallowCopyConstruction = True friend=" friend class %sArgument;\n" % str(self.type) if not self.ownsMembers else "" + bases = [ClassBase("AllOwningUnionBase")] if self.ownsMembers else [] return CGClass(selfName, + bases=bases, members=members, constructors=constructors, methods=methods, diff --git a/dom/bindings/test/TestBindingHeader.h b/dom/bindings/test/TestBindingHeader.h index bf5ce2cb2cd..f6cf3d7988e 100644 --- a/dom/bindings/test/TestBindingHeader.h +++ b/dom/bindings/test/TestBindingHeader.h @@ -567,6 +567,7 @@ public: void PassNullableUnionWithDefaultValue12(const Nullable& arg); void PassSequenceOfUnions(const Sequence&); + void PassSequenceOfUnions2(JSContext*, const Sequence&); void PassVariadicUnion(const Sequence&); void PassSequenceOfNullableUnions(const Sequence>&); diff --git a/dom/bindings/test/TestCodeGen.webidl b/dom/bindings/test/TestCodeGen.webidl index 35e8d9998e2..5729d6c10d6 100644 --- a/dom/bindings/test/TestCodeGen.webidl +++ b/dom/bindings/test/TestCodeGen.webidl @@ -522,6 +522,7 @@ interface TestInterface { void passNullableUnionWithDefaultValue12(optional (unrestricted float or DOMString)? arg = null); void passSequenceOfUnions(sequence<(CanvasPattern or CanvasGradient)> arg); + void passSequenceOfUnions2(sequence<(object or long)> arg); void passVariadicUnion((CanvasPattern or CanvasGradient)... arg); void passSequenceOfNullableUnions(sequence<(CanvasPattern or CanvasGradient)?> arg); diff --git a/dom/bindings/test/TestExampleGen.webidl b/dom/bindings/test/TestExampleGen.webidl index 2e36bb7730d..2f2b122f401 100644 --- a/dom/bindings/test/TestExampleGen.webidl +++ b/dom/bindings/test/TestExampleGen.webidl @@ -415,6 +415,7 @@ interface TestExampleInterface { void passNullableUnionWithDefaultValue12(optional (unrestricted float or DOMString)? arg = null); void passSequenceOfUnions(sequence<(CanvasPattern or CanvasGradient)> arg); + void passSequenceOfUnions2(sequence<(object or long)> arg); void passVariadicUnion((CanvasPattern or CanvasGradient)... arg); void passSequenceOfNullableUnions(sequence<(CanvasPattern or CanvasGradient)?> arg); diff --git a/dom/bindings/test/TestJSImplGen.webidl b/dom/bindings/test/TestJSImplGen.webidl index 234d908a88b..ad92d30bc16 100644 --- a/dom/bindings/test/TestJSImplGen.webidl +++ b/dom/bindings/test/TestJSImplGen.webidl @@ -436,6 +436,7 @@ interface TestJSImplInterface { void passNullableUnionWithDefaultValue12(optional (unrestricted float or DOMString)? arg = null); void passSequenceOfUnions(sequence<(CanvasPattern or CanvasGradient)> arg); + void passSequenceOfUnions2(sequence<(object or long)> arg); void passVariadicUnion((CanvasPattern or CanvasGradient)... arg); void passSequenceOfNullableUnions(sequence<(CanvasPattern or CanvasGradient)?> arg);