From df8270946fe60383263aef6c59f7402cc9082aab Mon Sep 17 00:00:00 2001 From: Kyle Machulis Date: Mon, 23 Oct 2017 17:34:28 -0700 Subject: [PATCH] Bug 792059 - Add NeedsWindowsUndef extended attribute for constants; r=bz When defining WebIDL constants in C++, we may need to undefine some constant names that conflict with windows.h preprocessor defines. Doing this in the binding header is far easier than tracking down the include orders that may cause conflicts. MozReview-Commit-ID: A0UoYezIQs5 --HG-- extra : rebase_source : d9100af2ccdb5c6e6468542ac68f74b2e4f9050c --- dom/bindings/Codegen.py | 10 ++++++++++ dom/bindings/parser/WebIDL.py | 3 ++- dom/bindings/test/TestBindingHeader.h | 5 +++++ dom/bindings/test/TestCodeGen.webidl | 4 ++++ dom/bindings/test/TestExampleGen.webidl | 4 ++++ dom/bindings/test/TestJSImplGen.webidl | 4 ++++ dom/webidl/WebGL2RenderingContext.webidl | 1 + dom/webidl/WebGLRenderingContext.webidl | 1 + 8 files changed, 31 insertions(+), 1 deletion(-) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index b04c04d54fad..4a8ab76c5967 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -2855,6 +2855,16 @@ class CGConstDefinition(CGThing): self.const = "static const %s %s = %s;" % (builtinNames[tag], name, value) + if member.getExtendedAttribute("NeedsWindowsUndef"): + self.const = fill( + """ + #ifdef XP_WIN + #undef ${name} + #endif // XP_WIN + ${constDecl} + """, + name=name, + constDecl=self.const) def declare(self): return self.const diff --git a/dom/bindings/parser/WebIDL.py b/dom/bindings/parser/WebIDL.py index 56d558bf2810..d21e9fa3fd20 100644 --- a/dom/bindings/parser/WebIDL.py +++ b/dom/bindings/parser/WebIDL.py @@ -3976,7 +3976,8 @@ class IDLConst(IDLInterfaceMember): identifier == "ChromeOnly" or identifier == "Func" or identifier == "SecureContext" or - identifier == "NonEnumerable"): + identifier == "NonEnumerable" or + identifier == "NeedsWindowsUndef"): # Known attributes that we don't need to do anything with here pass else: diff --git a/dom/bindings/test/TestBindingHeader.h b/dom/bindings/test/TestBindingHeader.h index e1cd5d74427c..357f06ab477f 100644 --- a/dom/bindings/test/TestBindingHeader.h +++ b/dom/bindings/test/TestBindingHeader.h @@ -27,6 +27,11 @@ class Promise; } // namespace mozilla // We don't export TestCodeGenBinding.h, but it's right in our parent dir. +#ifdef XP_WIN +// If we're on windows, simulate including windows.h. This step will cause +// compilation failure if NeedsWindowsUndef is not defined. +#define NO_ERROR 0x1 +#endif #include "../TestCodeGenBinding.h" extern bool TestFuncControlledMember(JSContext*, JSObject*); diff --git a/dom/bindings/test/TestCodeGen.webidl b/dom/bindings/test/TestCodeGen.webidl index 611a01bc1c60..8e2cb20bd6c7 100644 --- a/dom/bindings/test/TestCodeGen.webidl +++ b/dom/bindings/test/TestCodeGen.webidl @@ -983,6 +983,10 @@ interface TestInterface { [NonEnumerable] void nonEnumerableMethod(); + // [NeedsWindowsUndef] test generation + [NeedsWindowsUndef] + const unsigned long NO_ERROR = 0xffffffff; + // If you add things here, add them to TestExampleGen and TestJSImplGen as well }; diff --git a/dom/bindings/test/TestExampleGen.webidl b/dom/bindings/test/TestExampleGen.webidl index 63bd35643364..53f06ca40bce 100644 --- a/dom/bindings/test/TestExampleGen.webidl +++ b/dom/bindings/test/TestExampleGen.webidl @@ -810,6 +810,10 @@ interface TestExampleInterface { [NonEnumerable] void nonEnumerableMethod(); + // [NeedsWindowsUndef] test generation + [NeedsWindowsUndef] + const unsigned long NO_ERROR = 0xffffffff; + // If you add things here, add them to TestCodeGen and TestJSImplGen as well }; diff --git a/dom/bindings/test/TestJSImplGen.webidl b/dom/bindings/test/TestJSImplGen.webidl index b848f5fdb999..ee0bce586adf 100644 --- a/dom/bindings/test/TestJSImplGen.webidl +++ b/dom/bindings/test/TestJSImplGen.webidl @@ -830,6 +830,10 @@ interface TestJSImplInterface { [NonEnumerable] void nonEnumerableMethod(); + // [NeedsWindowsUndef] test generation + [NeedsWindowsUndef] + const unsigned long NO_ERROR = 0xffffffff; + // If you add things here, add them to TestCodeGen as well }; diff --git a/dom/webidl/WebGL2RenderingContext.webidl b/dom/webidl/WebGL2RenderingContext.webidl index f7cc203ba9ec..336687ff6c79 100644 --- a/dom/webidl/WebGL2RenderingContext.webidl +++ b/dom/webidl/WebGL2RenderingContext.webidl @@ -280,6 +280,7 @@ interface WebGL2RenderingContextBase const GLenum ALREADY_SIGNALED = 0x911A; const GLenum TIMEOUT_EXPIRED = 0x911B; const GLenum CONDITION_SATISFIED = 0x911C; + [NeedsWindowsUndef] const GLenum WAIT_FAILED = 0x911D; const GLenum SYNC_FLUSH_COMMANDS_BIT = 0x00000001; const GLenum VERTEX_ATTRIB_ARRAY_DIVISOR = 0x88FE; diff --git a/dom/webidl/WebGLRenderingContext.webidl b/dom/webidl/WebGLRenderingContext.webidl index 7ccc2f022178..b2cd316883a4 100644 --- a/dom/webidl/WebGLRenderingContext.webidl +++ b/dom/webidl/WebGLRenderingContext.webidl @@ -217,6 +217,7 @@ interface WebGLRenderingContextBase { const GLenum SAMPLE_COVERAGE = 0x80A0; /* ErrorCode */ + [NeedsWindowsUndef] const GLenum NO_ERROR = 0; const GLenum INVALID_ENUM = 0x0500; const GLenum INVALID_VALUE = 0x0501;