Use LazyNeverDestroyed instead of DEFINE_GLOBAL for MediaFeatureNames
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Aug 2017 06:42:51 +0000 (06:42 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Aug 2017 06:42:51 +0000 (06:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175008

Patch by Fujii Hironori <Hironori.Fujii@sony.com> on 2017-07-31
Reviewed by Alex Christensen.

No new tests because no behavior change.

Stop using DEFINE_GLOBAL hack in favor of LazyNeverDestroyed.

* css/MediaFeatureNames.cpp:
(WebCore::MediaFeatureNames::init): Do not include
<wtf/StaticConstructors.h>. Use LazyNeverDestroyed instead of
DEFINE_GLOBAL. Call LazyNeverDestroyed::construct instead of
placement new.
* css/MediaFeatureNames.h: Use LazyNeverDestroyed.
* css/MediaQueryEvaluator.cpp:
(WebCore::MediaQueryEvaluator::evaluate const): Dereference with ->.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220090 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/MediaFeatureNames.cpp
Source/WebCore/css/MediaFeatureNames.h
Source/WebCore/css/MediaQueryEvaluator.cpp

index c50110d30f4cc05cc7f29ce1c620e2209d5ea611..59e33d1e4e643737af8bee60ff251a30d606d91a 100644 (file)
@@ -1,3 +1,23 @@
+2017-07-31  Fujii Hironori  <Hironori.Fujii@sony.com>
+
+        Use LazyNeverDestroyed instead of DEFINE_GLOBAL for MediaFeatureNames
+        https://bugs.webkit.org/show_bug.cgi?id=175008
+
+        Reviewed by Alex Christensen.
+
+        No new tests because no behavior change.
+
+        Stop using DEFINE_GLOBAL hack in favor of LazyNeverDestroyed.
+
+        * css/MediaFeatureNames.cpp:
+        (WebCore::MediaFeatureNames::init): Do not include
+        <wtf/StaticConstructors.h>. Use LazyNeverDestroyed instead of
+        DEFINE_GLOBAL. Call LazyNeverDestroyed::construct instead of
+        placement new.
+        * css/MediaFeatureNames.h: Use LazyNeverDestroyed.
+        * css/MediaQueryEvaluator.cpp:
+        (WebCore::MediaQueryEvaluator::evaluate const): Dereference with ->.
+
 2017-07-31  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         Use LazyNeverDestroyed instead of DEFINE_GLOBAL for QualifiedName
index 18430c90c14f7e1b36dbd39ae10b39394cb376c7..ea4601164b85bf22e8b35201f9ebf86c2e5d0528 100644 (file)
  */
 
 #include "config.h"
-
-#ifdef SKIP_STATIC_CONSTRUCTORS_ON_GCC
-#define CSS_MEDIAQUERY_NAMES_HIDE_GLOBALS 1
-#endif
-
 #include "MediaFeatureNames.h"
-#include <wtf/StaticConstructors.h>
 
 namespace WebCore {
 namespace MediaFeatureNames {
 
-#define DEFINE_MEDIAFEATURE_GLOBAL(name, string) DEFINE_GLOBAL(AtomicString, name)
+#define DEFINE_MEDIAFEATURE_GLOBAL(name, string) LazyNeverDestroyed<const AtomicString> name;
 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(DEFINE_MEDIAFEATURE_GLOBAL)
 #undef DEFINE_MEDIAFEATURE_GLOBAL
 
@@ -38,9 +32,8 @@ void init()
 {
     static bool initialized;
     if (!initialized) {
-        // Use placement new to initialize the globals.
         AtomicString::init();
-#define INITIALIZE_GLOBAL(name, string) new (NotNull, (void*)&name) AtomicString(string, AtomicString::ConstructFromLiteral);
+#define INITIALIZE_GLOBAL(name, string) name.construct(string, AtomicString::ConstructFromLiteral);
         CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(INITIALIZE_GLOBAL)
 #undef INITIALIZE_GLOBAL
         initialized = true;
index 664d34f1bd3305e030e8eaed8b6fb7dd136787f5..4e754f5486cccf1723625e60ae8c03788fe70f26 100644 (file)
@@ -20,6 +20,7 @@
 
 #pragma once
 
+#include <wtf/NeverDestroyed.h>
 #include <wtf/text/AtomicString.h>
 
 #if ENABLE(VIEW_MODE_CSS_MEDIA)
 namespace WebCore {
 namespace MediaFeatureNames {
 
-#ifndef CSS_MEDIAQUERY_NAMES_HIDE_GLOBALS
-#define CSS_MEDIAQUERY_NAMES_DECLARE(name, string) extern const AtomicString name;
+#define CSS_MEDIAQUERY_NAMES_DECLARE(name, string) extern LazyNeverDestroyed<const AtomicString> name;
     CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(CSS_MEDIAQUERY_NAMES_DECLARE)
 #undef CSS_MEDIAQUERY_NAMES_DECLARE
-#endif
 
     void init();
 
index 873db9d7b3556ed0a76ed237c8e200d991f40652..277902dbdba5a284b457010889f6e0f0aca0ba39 100644 (file)
@@ -718,7 +718,7 @@ bool MediaQueryEvaluator::evaluate(const MediaQueryExpression& expression) const
 
     static NeverDestroyed<MediaQueryFunctionMap> map = [] {
         MediaQueryFunctionMap map;
-#define ADD_TO_FUNCTIONMAP(name, str) add(map, MediaFeatureNames::name.impl(), name##Evaluate);
+#define ADD_TO_FUNCTIONMAP(name, str) add(map, MediaFeatureNames::name->impl(), name##Evaluate);
         CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP);
 #undef ADD_TO_FUNCTIONMAP
         return map;