Bug 1266391 - Introduce an enum class mozilla::unicode::Script, and use this instead of bare integers to specify script codes for better type checking. r=masayuki
authorJonathan Kew <jkew@mozilla.com>
Thu, 21 Apr 2016 18:58:59 +0100
changeset 332234 1b2c3cc8c06f7e257a8040c04086a99889356b2d
parent 332233 9e5cdc2e73c495cd48ced4de33a52047fedb2a55
child 332235 eb1d405b1239f342187201225a6cac0ff21440c2
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1266391
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1266391 - Introduce an enum class mozilla::unicode::Script, and use this instead of bare integers to specify script codes for better type checking. r=masayuki
gfx/thebes/gfxAndroidPlatform.cpp
gfx/thebes/gfxAndroidPlatform.h
gfx/thebes/gfxCoreTextShaper.cpp
gfx/thebes/gfxCoreTextShaper.h
gfx/thebes/gfxDWriteFontList.cpp
gfx/thebes/gfxDWriteFontList.h
gfx/thebes/gfxFT2Fonts.cpp
gfx/thebes/gfxFT2Fonts.h
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxFont.h
gfx/thebes/gfxFontEntry.cpp
gfx/thebes/gfxFontEntry.h
gfx/thebes/gfxFontconfigFonts.cpp
gfx/thebes/gfxFontconfigFonts.h
gfx/thebes/gfxGDIFont.cpp
gfx/thebes/gfxGDIFont.h
gfx/thebes/gfxGraphiteShaper.cpp
gfx/thebes/gfxGraphiteShaper.h
gfx/thebes/gfxHarfBuzzShaper.cpp
gfx/thebes/gfxHarfBuzzShaper.h
gfx/thebes/gfxMacFont.cpp
gfx/thebes/gfxMacFont.h
gfx/thebes/gfxMacPlatformFontList.h
gfx/thebes/gfxMacPlatformFontList.mm
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxPlatformFontList.cpp
gfx/thebes/gfxPlatformFontList.h
gfx/thebes/gfxPlatformGtk.cpp
gfx/thebes/gfxPlatformGtk.h
gfx/thebes/gfxPlatformMac.cpp
gfx/thebes/gfxPlatformMac.h
gfx/thebes/gfxScriptItemizer.cpp
gfx/thebes/gfxScriptItemizer.h
gfx/thebes/gfxTextRun.cpp
gfx/thebes/gfxTextRun.h
gfx/thebes/gfxWindowsPlatform.cpp
gfx/thebes/gfxWindowsPlatform.h
intl/unicharutil/tools/genUnicodePropertyData.pl
intl/unicharutil/util/nsUnicodeProperties.cpp
intl/unicharutil/util/nsUnicodeProperties.h
intl/unicharutil/util/nsUnicodePropertyData.cpp
intl/unicharutil/util/nsUnicodeScriptCodes.h
layout/generic/MathMLTextRunFactory.cpp
layout/generic/nsTextFrame.cpp
layout/mathml/nsMathMLChar.cpp
netwerk/dns/nsIDNService.cpp
netwerk/dns/nsIDNService.h
--- a/gfx/thebes/gfxAndroidPlatform.cpp
+++ b/gfx/thebes/gfxAndroidPlatform.cpp
@@ -165,17 +165,17 @@ IsJapaneseLocale()
         } while (false);
     }
 
     return sIsJapanese;
 }
 
 void
 gfxAndroidPlatform::GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
-                                           int32_t aRunScript,
+                                           Script aRunScript,
                                            nsTArray<const char*>& aFontList)
 {
     static const char kDroidSansJapanese[] = "Droid Sans Japanese";
     static const char kMotoyaLMaru[] = "MotoyaLMaru";
     static const char kNotoColorEmoji[] = "Noto Color Emoji";
 #ifdef MOZ_WIDGET_GONK
     static const char kFirefoxEmoji[] = "Firefox Emoji";
 #endif
--- a/gfx/thebes/gfxAndroidPlatform.h
+++ b/gfx/thebes/gfxAndroidPlatform.h
@@ -42,17 +42,17 @@ public:
     // to support IPC font list (sharing between chrome and content)
     void GetSystemFontList(InfallibleTArray<FontListEntry>* retValue);
 
     // platform implementations of font functions
     virtual bool IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags);
     virtual gfxPlatformFontList* CreatePlatformFontList();
 
     virtual void GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
-                                        int32_t aRunScript,
+                                        Script aRunScript,
                                         nsTArray<const char*>& aFontList);
 
     gfxFontGroup*
     CreateFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
                     const gfxFontStyle *aStyle,
                     gfxTextPerfMetrics* aTextPerf,
                     gfxUserFontSet *aUserFontSet,
                     gfxFloat aDevToCssSize) override;
--- a/gfx/thebes/gfxCoreTextShaper.cpp
+++ b/gfx/thebes/gfxCoreTextShaper.cpp
@@ -104,27 +104,28 @@ gfxCoreTextShaper::~gfxCoreTextShaper()
         ::CFRelease(mAttributesDictRTL);
     }
     if (mCTFont) {
         ::CFRelease(mCTFont);
     }
 }
 
 static bool
-IsBuggyIndicScript(int32_t aScript)
+IsBuggyIndicScript(unicode::Script aScript)
 {
-    return aScript == MOZ_SCRIPT_BENGALI || aScript == MOZ_SCRIPT_KANNADA;
+    return aScript == unicode::Script::BENGALI ||
+           aScript == unicode::Script::KANNADA;
 }
 
 bool
 gfxCoreTextShaper::ShapeText(DrawTarget      *aDrawTarget,
                              const char16_t *aText,
                              uint32_t         aOffset,
                              uint32_t         aLength,
-                             int32_t          aScript,
+                             Script           aScript,
                              bool             aVertical,
                              gfxShapedText   *aShapedText)
 {
     // Create a CFAttributedString with text and style info, so we can use CoreText to lay it out.
     bool isRightToLeft = aShapedText->IsRightToLeft();
     const UniChar* text = reinterpret_cast<const UniChar*>(aText);
     uint32_t length = aLength;
 
--- a/gfx/thebes/gfxCoreTextShaper.h
+++ b/gfx/thebes/gfxCoreTextShaper.h
@@ -17,17 +17,17 @@ public:
     explicit gfxCoreTextShaper(gfxMacFont *aFont);
 
     virtual ~gfxCoreTextShaper();
 
     virtual bool ShapeText(DrawTarget      *aDrawTarget,
                            const char16_t *aText,
                            uint32_t         aOffset,
                            uint32_t         aLength,
-                           int32_t          aScript,
+                           Script           aScript,
                            bool             aVertical,
                            gfxShapedText   *aShapedText);
 
     // clean up static objects that may have been cached
     static void Shutdown();
 
 protected:
     CTFontRef mCTFont;
--- a/gfx/thebes/gfxDWriteFontList.cpp
+++ b/gfx/thebes/gfxDWriteFontList.cpp
@@ -1394,17 +1394,17 @@ IFACEMETHODIMP DWriteFontFallbackRendere
         mFamilyName.Truncate();
         return E_FAIL;
     }
     return hr;
 }
 
 gfxFontEntry*
 gfxDWriteFontList::GlobalFontFallback(const uint32_t aCh,
-                                      int32_t aRunScript,
+                                      Script aRunScript,
                                       const gfxFontStyle* aMatchStyle,
                                       uint32_t& aCmapCount,
                                       gfxFontFamily** aMatchedFamily)
 {
     bool useCmaps = gfxPlatform::GetPlatform()->UseCmapsDuringSystemFallback();
 
     if (useCmaps) {
         return gfxPlatformFontList::GlobalFontFallback(aCh,
--- a/gfx/thebes/gfxDWriteFontList.h
+++ b/gfx/thebes/gfxDWriteFontList.h
@@ -394,17 +394,17 @@ private:
     friend class gfxDWriteFontFamily;
 
     nsresult GetFontSubstitutes();
 
     void GetDirectWriteSubstitutes();
 
     // search fonts system-wide for a given character, null otherwise
     virtual gfxFontEntry* GlobalFontFallback(const uint32_t aCh,
-                                             int32_t aRunScript,
+                                             Script aRunScript,
                                              const gfxFontStyle* aMatchStyle,
                                              uint32_t& aCmapCount,
                                              gfxFontFamily** aMatchedFamily);
 
     virtual bool UsesSystemFallback() { return true; }
 
     void GetFontsFromCollection(IDWriteFontCollection* aCollection);
 
--- a/gfx/thebes/gfxFT2Fonts.cpp
+++ b/gfx/thebes/gfxFT2Fonts.cpp
@@ -42,17 +42,17 @@
  * gfxFT2Font
  */
 
 bool
 gfxFT2Font::ShapeText(DrawTarget     *aDrawTarget,
                       const char16_t *aText,
                       uint32_t        aOffset,
                       uint32_t        aLength,
-                      int32_t         aScript,
+                      Script          aScript,
                       bool            aVertical,
                       gfxShapedText  *aShapedText)
 {
     if (!gfxFont::ShapeText(aDrawTarget, aText, aOffset, aLength, aScript,
                             aVertical, aShapedText)) {
         // harfbuzz must have failed(?!), just render raw glyphs
         AddRange(aText, aOffset, aLength, aShapedText);
         PostShapingFixup(aDrawTarget, aText, aOffset, aLength,
--- a/gfx/thebes/gfxFT2Fonts.h
+++ b/gfx/thebes/gfxFT2Fonts.h
@@ -64,17 +64,17 @@ public: // new functions
         GetGlyphRenderingOptions(const TextRunDrawParams* aRunParams = nullptr) override;
 #endif
 
 protected:
     virtual bool ShapeText(DrawTarget      *aDrawTarget,
                            const char16_t *aText,
                            uint32_t         aOffset,
                            uint32_t         aLength,
-                           int32_t          aScript,
+                           Script           aScript,
                            bool             aVertical,
                            gfxShapedText   *aShapedText);
 
     void FillGlyphDataForChar(uint32_t ch, CachedGlyphData *gd);
 
     void AddRange(const char16_t *aText,
                   uint32_t         aOffset,
                   uint32_t         aLength,
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -1081,22 +1081,23 @@ HasLookupRuleWithGlyph(hb_face_t *aFace,
         }
     }
 
     hb_set_destroy(glyphs);
     hb_set_destroy(specificFeatureLookups);
     hb_set_destroy(otherLookups);
 }
 
-nsDataHashtable<nsUint32HashKey, int32_t> *gfxFont::sScriptTagToCode = nullptr;
-nsTHashtable<nsUint32HashKey>             *gfxFont::sDefaultFeatures = nullptr;
+nsDataHashtable<nsUint32HashKey,Script> *gfxFont::sScriptTagToCode = nullptr;
+nsTHashtable<nsUint32HashKey>           *gfxFont::sDefaultFeatures = nullptr;
 
 static inline bool
-HasSubstitution(uint32_t *aBitVector, uint32_t aBit) {
-    return (aBitVector[aBit >> 5] & (1 << (aBit & 0x1f))) != 0;
+HasSubstitution(uint32_t *aBitVector, Script aScript) {
+    return (aBitVector[static_cast<uint32_t>(aScript) >> 5]
+           & (1 << (static_cast<uint32_t>(aScript) & 0x1f))) != 0;
 }
 
 // union of all default substitution features across scripts
 static const hb_tag_t defaultFeatures[] = {
     HB_TAG('a','b','v','f'),
     HB_TAG('a','b','v','s'),
     HB_TAG('a','k','h','n'),
     HB_TAG('b','l','w','f'),
@@ -1160,19 +1161,20 @@ gfxFont::CheckForFeaturesInvolvingSpace(
 
     // GSUB lookups - examine per script
     if (hb_ot_layout_has_substitution(face)) {
 
         // set up the script ==> code hashtable if needed
         if (!sScriptTagToCode) {
             sScriptTagToCode =
                 new nsDataHashtable<nsUint32HashKey,
-                                    int32_t>(MOZ_NUM_SCRIPT_CODES);
-            sScriptTagToCode->Put(HB_TAG('D','F','L','T'), MOZ_SCRIPT_COMMON);
-            for (int32_t s = MOZ_SCRIPT_ARABIC; s < MOZ_NUM_SCRIPT_CODES; s++) {
+                                    Script>(size_t(Script::NUM_SCRIPT_CODES));
+            sScriptTagToCode->Put(HB_TAG('D','F','L','T'), Script::COMMON);
+            for (Script s = Script::ARABIC; s < Script::NUM_SCRIPT_CODES;
+                 s = Script(static_cast<int>(s) + 1)) {
                 hb_script_t scriptTag = hb_script_t(GetScriptTagForCode(s));
                 hb_tag_t s1, s2;
                 hb_ot_tags_from_script(scriptTag, &s1, &s2);
                 sScriptTagToCode->Put(s1, s);
                 if (s2 != HB_OT_TAG_DEFAULT_SCRIPT) {
                     sScriptTagToCode->Put(s2, s);
                 }
             }
@@ -1190,44 +1192,44 @@ gfxFont::CheckForFeaturesInvolvingSpace(
 
         uint32_t len, offset = 0;
         do {
             len = ArrayLength(scriptTags);
             hb_ot_layout_table_get_script_tags(face, HB_OT_TAG_GSUB, offset,
                                                &len, scriptTags);
             for (uint32_t i = 0; i < len; i++) {
                 bool isDefaultFeature = false;
-                int32_t s;
+                Script s;
                 if (!HasLookupRuleWithGlyphByScript(face, HB_OT_TAG_GSUB,
                                                     scriptTags[i], offset + i,
                                                     spaceGlyph,
                                                     *sDefaultFeatures,
                                                     isDefaultFeature) ||
                     !sScriptTagToCode->Get(scriptTags[i], &s))
                 {
                     continue;
                 }
                 result = true;
-                uint32_t index = s >> 5;
-                uint32_t bit = s & 0x1f;
+                uint32_t index = static_cast<uint32_t>(s) >> 5;
+                uint32_t bit = static_cast<uint32_t>(s) & 0x1f;
                 if (isDefaultFeature) {
                     mFontEntry->mDefaultSubSpaceFeatures[index] |= (1 << bit);
                 } else {
                     mFontEntry->mNonDefaultSubSpaceFeatures[index] |= (1 << bit);
                 }
             }
             offset += len;
         } while (len == ArrayLength(scriptTags));
     }
 
     // spaces in default features of default script?
     // ==> can't use word cache, skip GPOS analysis
     bool canUseWordCache = true;
     if (HasSubstitution(mFontEntry->mDefaultSubSpaceFeatures,
-                        MOZ_SCRIPT_COMMON)) {
+                        Script::COMMON)) {
         canUseWordCache = false;
     }
 
     // GPOS lookups - distinguish kerning from non-kerning features
     mFontEntry->mHasSpaceFeaturesKerning = false;
     mFontEntry->mHasSpaceFeaturesNonKerning = false;
 
     if (canUseWordCache && hb_ot_layout_has_positioning(face)) {
@@ -1263,52 +1265,52 @@ gfxFont::CheckForFeaturesInvolvingSpace(
             (mFontEntry->mHasSpaceFeaturesKerning ? "true" : "false"),
             (mFontEntry->mHasSpaceFeaturesNonKerning ? "true" : "false"),
             elapsed.ToMilliseconds()
         ));
     }
 }
 
 bool
-gfxFont::HasSubstitutionRulesWithSpaceLookups(int32_t aRunScript)
+gfxFont::HasSubstitutionRulesWithSpaceLookups(Script aRunScript)
 {
     NS_ASSERTION(GetFontEntry()->mHasSpaceFeaturesInitialized,
                  "need to initialize space lookup flags");
-    NS_ASSERTION(aRunScript < MOZ_NUM_SCRIPT_CODES, "weird script code");
-    if (aRunScript == MOZ_SCRIPT_INVALID ||
-        aRunScript >= MOZ_NUM_SCRIPT_CODES) {
+    NS_ASSERTION(aRunScript < Script::NUM_SCRIPT_CODES, "weird script code");
+    if (aRunScript == Script::INVALID ||
+        aRunScript >= Script::NUM_SCRIPT_CODES) {
         return false;
     }
 
     // default features have space lookups ==> true
     if (HasSubstitution(mFontEntry->mDefaultSubSpaceFeatures,
-                        MOZ_SCRIPT_COMMON) ||
+                        Script::COMMON) ||
         HasSubstitution(mFontEntry->mDefaultSubSpaceFeatures,
                         aRunScript))
     {
         return true;
     }
 
     // non-default features have space lookups and some type of
     // font feature, in font or style is specified ==> true
     if ((HasSubstitution(mFontEntry->mNonDefaultSubSpaceFeatures,
-                         MOZ_SCRIPT_COMMON) ||
+                         Script::COMMON) ||
          HasSubstitution(mFontEntry->mNonDefaultSubSpaceFeatures,
                          aRunScript)) &&
         (!mStyle.featureSettings.IsEmpty() ||
          !mFontEntry->mFeatureSettings.IsEmpty()))
     {
         return true;
     }
 
     return false;
 }
 
 bool
-gfxFont::SpaceMayParticipateInShaping(int32_t aRunScript)
+gfxFont::SpaceMayParticipateInShaping(Script aRunScript)
 {
     // avoid checking fonts known not to include default space-dependent features
     if (MOZ_UNLIKELY(mFontEntry->mSkipDefaultFeatureSpaceCheck)) {
         if (!mKerningSet && mStyle.featureSettings.IsEmpty() &&
             mFontEntry->mFeatureSettings.IsEmpty()) {
             return false;
         }
     }
@@ -1344,26 +1346,26 @@ gfxFont::SpaceMayParticipateInShaping(in
     if (mKerningSet && mFontEntry->mHasSpaceFeaturesKerning) {
         return mKerningEnabled;
     }
 
     return false;
 }
 
 bool
-gfxFont::SupportsFeature(int32_t aScript, uint32_t aFeatureTag)
+gfxFont::SupportsFeature(Script aScript, uint32_t aFeatureTag)
 {
     if (mGraphiteShaper && gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
         return GetFontEntry()->SupportsGraphiteFeature(aFeatureTag);
     }
     return GetFontEntry()->SupportsOpenTypeFeature(aScript, aFeatureTag);
 }
 
 bool
-gfxFont::SupportsVariantCaps(int32_t aScript,
+gfxFont::SupportsVariantCaps(Script aScript,
                              uint32_t aVariantCaps,
                              bool& aFallbackToSmallCaps,
                              bool& aSyntheticLowerToSmallCaps,
                              bool& aSyntheticUpperToSmallCaps)
 {
     bool ok = true;  // cases without fallback are fine
     aFallbackToSmallCaps = false;
     aSyntheticLowerToSmallCaps = false;
@@ -1418,28 +1420,28 @@ gfxFont::SupportsVariantCaps(int32_t aSc
                  "if we found a usable fallback, that counts as ok");
 
     return ok;
 }
 
 bool
 gfxFont::SupportsSubSuperscript(uint32_t aSubSuperscript,
                                 const uint8_t *aString,
-                                uint32_t aLength, int32_t aRunScript)
+                                uint32_t aLength, Script aRunScript)
 {
     NS_ConvertASCIItoUTF16 unicodeString(reinterpret_cast<const char*>(aString),
                                          aLength);
     return SupportsSubSuperscript(aSubSuperscript, unicodeString.get(),
                                   aLength, aRunScript);
 }
 
 bool
 gfxFont::SupportsSubSuperscript(uint32_t aSubSuperscript,
                                 const char16_t *aString,
-                                uint32_t aLength, int32_t aRunScript)
+                                uint32_t aLength, Script aRunScript)
 {
     NS_ASSERTION(aSubSuperscript == NS_FONT_VARIANT_POSITION_SUPER ||
                  aSubSuperscript == NS_FONT_VARIANT_POSITION_SUB,
                  "unknown value of font-variant-position");
 
     uint32_t feature = aSubSuperscript == NS_FONT_VARIANT_POSITION_SUPER ?
                        HB_TAG('s','u','p','s') : HB_TAG('s','u','b','s');
 
@@ -2494,17 +2496,17 @@ IsBoundarySpace(char16_t aChar, char16_t
 #endif
 
 template<typename T>
 gfxShapedWord*
 gfxFont::GetShapedWord(DrawTarget *aDrawTarget,
                        const T    *aText,
                        uint32_t    aLength,
                        uint32_t    aHash,
-                       int32_t     aRunScript,
+                       Script      aRunScript,
                        bool        aVertical,
                        int32_t     aAppUnitsPerDevUnit,
                        uint32_t    aFlags,
                        gfxTextPerfMetrics *aTextPerf GFX_MAYBE_UNUSED)
 {
     // if the cache is getting too big, flush it and start over
     uint32_t wordCacheMaxEntries =
         gfxPlatform::GetPlatform()->WordCacheMaxEntries();
@@ -2571,17 +2573,17 @@ gfxFont::CacheHashEntry::KeyEquals(const
 {
     const gfxShapedWord* sw = mShapedWord.get();
     if (!sw) {
         return false;
     }
     if (sw->GetLength() != aKey->mLength ||
         sw->GetFlags() != aKey->mFlags ||
         sw->GetAppUnitsPerDevUnit() != aKey->mAppUnitsPerDevUnit ||
-        sw->Script() != aKey->mScript) {
+        sw->GetScript() != aKey->mScript) {
         return false;
     }
     if (sw->TextIs8Bit()) {
         if (aKey->mTextIs8Bit) {
             return (0 == memcmp(sw->Text8Bit(), aKey->mText.mSingle,
                                 aKey->mLength * sizeof(uint8_t)));
         }
         // The key has 16-bit text, even though all the characters are < 256,
@@ -2603,17 +2605,17 @@ gfxFont::CacheHashEntry::KeyEquals(const
                         aKey->mLength * sizeof(char16_t)));
 }
 
 bool
 gfxFont::ShapeText(DrawTarget    *aDrawTarget,
                    const uint8_t *aText,
                    uint32_t       aOffset,
                    uint32_t       aLength,
-                   int32_t        aScript,
+                   Script         aScript,
                    bool           aVertical,
                    gfxShapedText *aShapedText)
 {
     nsDependentCSubstring ascii((const char*)aText, aLength);
     nsAutoString utf16;
     AppendASCIItoUTF16(ascii, utf16);
     if (utf16.Length() != aLength) {
         return false;
@@ -2622,17 +2624,17 @@ gfxFont::ShapeText(DrawTarget    *aDrawT
                      aScript, aVertical, aShapedText);
 }
 
 bool
 gfxFont::ShapeText(DrawTarget      *aDrawTarget,
                    const char16_t *aText,
                    uint32_t         aOffset,
                    uint32_t         aLength,
-                   int32_t          aScript,
+                   Script           aScript,
                    bool             aVertical,
                    gfxShapedText   *aShapedText)
 {
     bool ok = false;
 
     // XXX Currently, we do all vertical shaping through harfbuzz.
     // Vertical graphite support may be wanted as a future enhancement.
     if (FontCanSupportGraphite() && !aVertical) {
@@ -2687,17 +2689,17 @@ gfxFont::PostShapingFixup(DrawTarget*   
                                // to split into fragments for separate shaping
 
 template<typename T>
 bool
 gfxFont::ShapeFragmentWithoutWordCache(DrawTarget *aDrawTarget,
                                        const T    *aText,
                                        uint32_t    aOffset,
                                        uint32_t    aLength,
-                                       int32_t     aScript,
+                                       Script      aScript,
                                        bool        aVertical,
                                        gfxTextRun *aTextRun)
 {
     aTextRun->SetupClusterBoundaries(aOffset, aText, aLength);
 
     bool ok = true;
 
     while (ok && aLength > 0) {
@@ -2752,17 +2754,17 @@ IsInvalidControlChar(uint32_t aCh)
 }
 
 template<typename T>
 bool
 gfxFont::ShapeTextWithoutWordCache(DrawTarget *aDrawTarget,
                                    const T    *aText,
                                    uint32_t    aOffset,
                                    uint32_t    aLength,
-                                   int32_t     aScript,
+                                   Script      aScript,
                                    bool        aVertical,
                                    gfxTextRun *aTextRun)
 {
     uint32_t fragStart = 0;
     bool ok = true;
 
     for (uint32_t i = 0; i <= aLength && ok; ++i) {
         T ch = (i < aLength) ? aText[i] : '\n';
@@ -2834,17 +2836,17 @@ inline static bool HasSpaces(const char1
 
 template<typename T>
 bool
 gfxFont::SplitAndInitTextRun(DrawTarget *aDrawTarget,
                              gfxTextRun *aTextRun,
                              const T *aString, // text for this font run
                              uint32_t aRunStart, // position in the textrun
                              uint32_t aRunLength,
-                             int32_t aRunScript,
+                             Script aRunScript,
                              bool aVertical)
 {
     if (aRunLength == 0) {
         return true;
     }
 
     gfxTextPerfMetrics *tp = nullptr;
 
@@ -3026,37 +3028,37 @@ gfxFont::SplitAndInitTextRun(DrawTarget 
 
 // Explicit instantiations of SplitAndInitTextRun, to avoid libxul link failure
 template bool
 gfxFont::SplitAndInitTextRun(DrawTarget *aDrawTarget,
                              gfxTextRun *aTextRun,
                              const uint8_t *aString,
                              uint32_t aRunStart,
                              uint32_t aRunLength,
-                             int32_t aRunScript,
+                             Script aRunScript,
                              bool aVertical);
 template bool
 gfxFont::SplitAndInitTextRun(DrawTarget *aDrawTarget,
                              gfxTextRun *aTextRun,
                              const char16_t *aString,
                              uint32_t aRunStart,
                              uint32_t aRunLength,
-                             int32_t aRunScript,
+                             Script aRunScript,
                              bool aVertical);
 
 template<>
 bool
 gfxFont::InitFakeSmallCapsRun(DrawTarget     *aDrawTarget,
                               gfxTextRun     *aTextRun,
                               const char16_t *aText,
                               uint32_t        aOffset,
                               uint32_t        aLength,
                               uint8_t         aMatchType,
                               uint16_t        aOrientation,
-                              int32_t         aScript,
+                              Script          aScript,
                               bool            aSyntheticLower,
                               bool            aSyntheticUpper)
 {
     bool ok = true;
 
     RefPtr<gfxFont> smallCapsFont = GetSmallCapsFont();
 
     enum RunCaseAction {
@@ -3212,17 +3214,17 @@ template<>
 bool
 gfxFont::InitFakeSmallCapsRun(DrawTarget     *aDrawTarget,
                               gfxTextRun     *aTextRun,
                               const uint8_t  *aText,
                               uint32_t        aOffset,
                               uint32_t        aLength,
                               uint8_t         aMatchType,
                               uint16_t        aOrientation,
-                              int32_t         aScript,
+                              Script          aScript,
                               bool            aSyntheticLower,
                               bool            aSyntheticUpper)
 {
     NS_ConvertASCIItoUTF16 unicodeString(reinterpret_cast<const char*>(aText),
                                          aLength);
     return InitFakeSmallCapsRun(aDrawTarget, aTextRun, static_cast<const char16_t*>(unicodeString.get()),
                                 aOffset, aLength, aMatchType, aOrientation,
                                 aScript, aSyntheticLower, aSyntheticUpper);
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -611,33 +611,34 @@ protected:
  * shaping APIs such as Uniscribe or CoreText may rely on features of a
  * specific font subclass to access native font references
  * (such as CTFont, HFONT, DWriteFont, etc).
  */
 
 class gfxFontShaper {
 public:
     typedef mozilla::gfx::DrawTarget DrawTarget;
+    typedef mozilla::unicode::Script Script;
 
     explicit gfxFontShaper(gfxFont *aFont)
         : mFont(aFont)
     {
         NS_ASSERTION(aFont, "shaper requires a valid font!");
     }
 
     virtual ~gfxFontShaper() { }
 
     // Shape a piece of text and store the resulting glyph data into
     // aShapedText. Parameters aOffset/aLength indicate the range of
     // aShapedText to be updated; aLength is also the length of aText.
     virtual bool ShapeText(DrawTarget     *aDrawTarget,
                            const char16_t *aText,
                            uint32_t        aOffset,
                            uint32_t        aLength,
-                           int32_t         aScript,
+                           Script          aScript,
                            bool            aVertical,
                            gfxShapedText  *aShapedText) = 0;
 
     gfxFont *GetFont() const { return mFont; }
 
     static void
     MergeFontFeatures(const gfxFontStyle *aStyle,
                       const nsTArray<gfxFontFeature>& aFontFeatures,
@@ -677,16 +678,18 @@ protected:
  * gfxFontShaper can shape text into either a gfxShapedWord (cached by a gfxFont)
  * or directly into a gfxTextRun (for cases where we want to shape textruns in
  * their entirety rather than using cached words, because there may be layout
  * features that depend on the inter-word spaces).
  */
 class gfxShapedText
 {
 public:
+    typedef mozilla::unicode::Script Script;
+
     gfxShapedText(uint32_t aLength, uint32_t aFlags,
                   int32_t aAppUnitsPerDevUnit)
         : mLength(aLength)
         , mFlags(aFlags)
         , mAppUnitsPerDevUnit(aAppUnitsPerDevUnit)
     { }
 
     virtual ~gfxShapedText() { }
@@ -1161,27 +1164,29 @@ protected:
  * particular font, without regard to external context.
  *
  * The glyph data is copied into gfxTextRuns as needed from the cache of
  * ShapedWords associated with each gfxFont instance.
  */
 class gfxShapedWord final : public gfxShapedText
 {
 public:
+    typedef mozilla::unicode::Script Script;
+
     // Create a ShapedWord that can hold glyphs for aLength characters,
     // with mCharacterGlyphs sized appropriately.
     //
     // Returns null on allocation failure (does NOT use infallible alloc)
     // so caller must check for success.
     //
     // This does NOT perform shaping, so the returned word contains no
     // glyph data; the caller must call gfxFont::ShapeText() with appropriate
     // parameters to set up the glyphs.
     static gfxShapedWord* Create(const uint8_t *aText, uint32_t aLength,
-                                 int32_t aRunScript,
+                                 Script aRunScript,
                                  int32_t aAppUnitsPerDevUnit,
                                  uint32_t aFlags) {
         NS_ASSERTION(aLength <= gfxPlatform::GetPlatform()->WordCacheCharLimit(),
                      "excessive length for gfxShapedWord!");
 
         // Compute size needed including the mCharacterGlyphs array
         // and a copy of the original text
         uint32_t size =
@@ -1193,17 +1198,17 @@ public:
         }
 
         // Construct in the pre-allocated storage, using placement new
         return new (storage) gfxShapedWord(aText, aLength, aRunScript,
                                            aAppUnitsPerDevUnit, aFlags);
     }
 
     static gfxShapedWord* Create(const char16_t *aText, uint32_t aLength,
-                                 int32_t aRunScript,
+                                 Script aRunScript,
                                  int32_t aAppUnitsPerDevUnit,
                                  uint32_t aFlags) {
         NS_ASSERTION(aLength <= gfxPlatform::GetPlatform()->WordCacheCharLimit(),
                      "excessive length for gfxShapedWord!");
 
         // In the 16-bit version of Create, if the TEXT_IS_8BIT flag is set,
         // then we convert the text to an 8-bit version and call the 8-bit
         // Create function instead.
@@ -1248,17 +1253,17 @@ public:
     }
 
     char16_t GetCharAt(uint32_t aOffset) const {
         NS_ASSERTION(aOffset < GetLength(), "aOffset out of range");
         return TextIs8Bit() ?
             char16_t(Text8Bit()[aOffset]) : TextUnicode()[aOffset];
     }
 
-    int32_t Script() const {
+    Script GetScript() const {
         return mScript;
     }
 
     void ResetAge() {
         mAgeCounter = 0;
     }
     uint32_t IncrementAge() {
         return ++mAgeCounter;
@@ -1271,42 +1276,42 @@ public:
     }
 
 private:
     // so that gfxTextRun can share our DetailedGlyphStore class
     friend class gfxTextRun;
 
     // Construct storage for a ShapedWord, ready to receive glyph data
     gfxShapedWord(const uint8_t *aText, uint32_t aLength,
-                  int32_t aRunScript, int32_t aAppUnitsPerDevUnit,
-                  uint32_t aFlags)
+                  Script aRunScript,
+                  int32_t aAppUnitsPerDevUnit, uint32_t aFlags)
         : gfxShapedText(aLength, aFlags | gfxTextRunFactory::TEXT_IS_8BIT,
                         aAppUnitsPerDevUnit)
         , mScript(aRunScript)
         , mAgeCounter(0)
     {
         memset(mCharGlyphsStorage, 0, aLength * sizeof(CompressedGlyph));
         uint8_t *text = reinterpret_cast<uint8_t*>(&mCharGlyphsStorage[aLength]);
         memcpy(text, aText, aLength * sizeof(uint8_t));
     }
 
     gfxShapedWord(const char16_t *aText, uint32_t aLength,
-                  int32_t aRunScript, int32_t aAppUnitsPerDevUnit,
-                  uint32_t aFlags)
+                  Script aRunScript,
+                  int32_t aAppUnitsPerDevUnit, uint32_t aFlags)
         : gfxShapedText(aLength, aFlags, aAppUnitsPerDevUnit)
         , mScript(aRunScript)
         , mAgeCounter(0)
     {
         memset(mCharGlyphsStorage, 0, aLength * sizeof(CompressedGlyph));
         char16_t *text = reinterpret_cast<char16_t*>(&mCharGlyphsStorage[aLength]);
         memcpy(text, aText, aLength * sizeof(char16_t));
         SetupClusterBoundaries(0, aText, aLength);
     }
 
-    int32_t          mScript;
+    Script           mScript;
 
     uint32_t         mAgeCounter;
 
     // The mCharGlyphsStorage array is actually a variable-size member;
     // when the ShapedWord is created, its size will be increased as necessary
     // to allow the proper number of glyphs to be stored.
     // The original text, in either 8-bit or 16-bit form, will be stored
     // immediately following the CompressedGlyphs.
@@ -1320,16 +1325,17 @@ struct EmphasisMarkDrawParams;
 
 class gfxFont {
 
     friend class gfxHarfBuzzShaper;
     friend class gfxGraphiteShaper;
 
 protected:
     typedef mozilla::gfx::DrawTarget DrawTarget;
+    typedef mozilla::unicode::Script Script;
 
 public:
     nsrefcnt AddRef(void) {
         NS_PRECONDITION(int32_t(mRefCnt) >= 0, "illegal refcnt");
         if (mExpirationState.IsTracked()) {
             gfxFontCache::GetCache()->RemoveObject(this);
         }
         ++mRefCnt;
@@ -1451,35 +1457,37 @@ public:
         return mFontEntry->TryGetColorGlyphs() ||
                mFontEntry->TryGetSVGData(this) ||
                mFontEntry->HasFontTable(TRUETYPE_TAG('C','B','D','T')) ||
                mFontEntry->HasFontTable(TRUETYPE_TAG('s','b','i','x'));
     }
 
     // whether a feature is supported by the font (limited to a small set
     // of features for which some form of fallback needs to be implemented)
-    bool SupportsFeature(int32_t aScript, uint32_t aFeatureTag);
+    bool SupportsFeature(Script aScript, uint32_t aFeatureTag);
 
     // whether the font supports "real" small caps, petite caps etc.
     // aFallbackToSmallCaps true when petite caps should fallback to small caps
-    bool SupportsVariantCaps(int32_t aScript, uint32_t aVariantCaps,
+    bool SupportsVariantCaps(Script aScript, uint32_t aVariantCaps,
                              bool& aFallbackToSmallCaps,
                              bool& aSyntheticLowerToSmallCaps,
                              bool& aSyntheticUpperToSmallCaps);
 
     // whether the font supports subscript/superscript feature
     // for fallback, need to verify that all characters in the run
     // have variant substitutions
     bool SupportsSubSuperscript(uint32_t aSubSuperscript,
                                 const uint8_t *aString,
-                                uint32_t aLength, int32_t aRunScript);
+                                uint32_t aLength,
+                                Script aRunScript);
 
     bool SupportsSubSuperscript(uint32_t aSubSuperscript,
                                 const char16_t *aString,
-                                uint32_t aLength, int32_t aRunScript);
+                                uint32_t aLength,
+                                Script aRunScript);
 
     // Subclasses may choose to look up glyph ids for characters.
     // If they do not override this, gfxHarfBuzzShaper will fetch the cmap
     // table and use that.
     virtual bool ProvidesGetGlyph() const {
         return false;
     }
     // Map unicode character to glyph ID.
@@ -1713,40 +1721,40 @@ public:
     template<typename T>
     bool InitFakeSmallCapsRun(DrawTarget *aDrawTarget,
                               gfxTextRun *aTextRun,
                               const T    *aText,
                               uint32_t    aOffset,
                               uint32_t    aLength,
                               uint8_t     aMatchType,
                               uint16_t    aOrientation,
-                              int32_t     aScript,
+                              Script      aScript,
                               bool        aSyntheticLower,
                               bool        aSyntheticUpper);
 
     // call the (virtual) InitTextRun method to do glyph generation/shaping,
     // limiting the length of text passed by processing the run in multiple
     // segments if necessary
     template<typename T>
     bool SplitAndInitTextRun(DrawTarget *aDrawTarget,
                              gfxTextRun *aTextRun,
                              const T *aString,
                              uint32_t aRunStart,
                              uint32_t aRunLength,
-                             int32_t aRunScript,
+                             Script aRunScript,
                              bool aVertical);
 
     // Get a ShapedWord representing the given text (either 8- or 16-bit)
     // for use in setting up a gfxTextRun.
     template<typename T>
     gfxShapedWord* GetShapedWord(DrawTarget *aDrawTarget,
                                  const T *aText,
                                  uint32_t aLength,
                                  uint32_t aHash,
-                                 int32_t aRunScript,
+                                 Script aRunScript,
                                  bool aVertical,
                                  int32_t aAppUnitsPerDevUnit,
                                  uint32_t aFlags,
                                  gfxTextPerfMetrics *aTextPerf);
 
     // Ensure the ShapedWord cache is initialized. This MUST be called before
     // any attempt to use GetShapedWord().
     void InitWordCache() {
@@ -1909,37 +1917,37 @@ protected:
 
     bool IsSpaceGlyphInvisible(DrawTarget* aRefDrawTarget,
                                gfxTextRun* aTextRun);
 
     void AddGlyphChangeObserver(GlyphChangeObserver *aObserver);
     void RemoveGlyphChangeObserver(GlyphChangeObserver *aObserver);
 
     // whether font contains substitution lookups containing spaces
-    bool HasSubstitutionRulesWithSpaceLookups(int32_t aRunScript);
+    bool HasSubstitutionRulesWithSpaceLookups(Script aRunScript);
 
     // do spaces participate in shaping rules? if so, can't used word cache
-    bool SpaceMayParticipateInShaping(int32_t aRunScript);
+    bool SpaceMayParticipateInShaping(Script aRunScript);
 
     // For 8-bit text, expand to 16-bit and then call the following method.
     bool ShapeText(DrawTarget    *aContext,
                    const uint8_t *aText,
                    uint32_t       aOffset, // dest offset in gfxShapedText
                    uint32_t       aLength,
-                   int32_t        aScript,
+                   Script         aScript,
                    bool           aVertical,
                    gfxShapedText *aShapedText); // where to store the result
 
     // Call the appropriate shaper to generate glyphs for aText and store
     // them into aShapedText.
     virtual bool ShapeText(DrawTarget      *aContext,
                            const char16_t *aText,
                            uint32_t         aOffset,
                            uint32_t         aLength,
-                           int32_t          aScript,
+                           Script           aScript,
                            bool             aVertical,
                            gfxShapedText   *aShapedText);
 
     // Helper to adjust for synthetic bold and set character-type flags
     // in the shaped text; implementations of ShapeText should call this
     // after glyph shaping has been completed.
     void PostShapingFixup(DrawTarget*     aContext,
                           const char16_t* aText,
@@ -1955,84 +1963,84 @@ protected:
     // This will split the text on "invalid" characters (tab/newline) that are
     // not handled via normal shaping, but does not otherwise divide up the
     // text.
     template<typename T>
     bool ShapeTextWithoutWordCache(DrawTarget *aDrawTarget,
                                    const T    *aText,
                                    uint32_t    aOffset,
                                    uint32_t    aLength,
-                                   int32_t     aScript,
+                                   Script      aScript,
                                    bool        aVertical,
                                    gfxTextRun *aTextRun);
 
     // Shape a fragment of text (a run that is known to contain only
     // "valid" characters, no newlines/tabs/other control chars).
     // All non-wordcache shaping goes through here; this is the function
     // that will ensure we don't pass excessively long runs to the various
     // platform shapers.
     template<typename T>
     bool ShapeFragmentWithoutWordCache(DrawTarget *aDrawTarget,
                                        const T    *aText,
                                        uint32_t    aOffset,
                                        uint32_t    aLength,
-                                       int32_t     aScript,
+                                       Script      aScript,
                                        bool        aVertical,
                                        gfxTextRun *aTextRun);
 
     void CheckForFeaturesInvolvingSpace();
 
     // whether a given feature is included in feature settings from both the
     // font and the style. aFeatureOn set if resolved feature value is non-zero
     bool HasFeatureSet(uint32_t aFeature, bool& aFeatureOn);
 
     // used when analyzing whether a font has space contextual lookups
-    static nsDataHashtable<nsUint32HashKey, int32_t> *sScriptTagToCode;
-    static nsTHashtable<nsUint32HashKey>             *sDefaultFeatures;
+    static nsDataHashtable<nsUint32HashKey,Script> *sScriptTagToCode;
+    static nsTHashtable<nsUint32HashKey>           *sDefaultFeatures;
 
     RefPtr<gfxFontEntry> mFontEntry;
 
     struct CacheHashKey {
         union {
             const uint8_t   *mSingle;
             const char16_t *mDouble;
         }                mText;
         uint32_t         mLength;
         uint32_t         mFlags;
-        int32_t          mScript;
+        Script           mScript;
         int32_t          mAppUnitsPerDevUnit;
         PLDHashNumber    mHashKey;
         bool             mTextIs8Bit;
 
         CacheHashKey(const uint8_t *aText, uint32_t aLength,
                      uint32_t aStringHash,
-                     int32_t aScriptCode, int32_t aAppUnitsPerDevUnit,
+                     Script aScriptCode, int32_t aAppUnitsPerDevUnit,
                      uint32_t aFlags)
             : mLength(aLength),
               mFlags(aFlags),
               mScript(aScriptCode),
               mAppUnitsPerDevUnit(aAppUnitsPerDevUnit),
-              mHashKey(aStringHash + aScriptCode +
+              mHashKey(aStringHash + static_cast<int32_t>(aScriptCode) +
                   aAppUnitsPerDevUnit * 0x100 + aFlags * 0x10000),
               mTextIs8Bit(true)
         {
             NS_ASSERTION(aFlags & gfxTextRunFactory::TEXT_IS_8BIT,
                          "8-bit flag should have been set");
             mText.mSingle = aText;
         }
 
         CacheHashKey(const char16_t *aText, uint32_t aLength,
                      uint32_t aStringHash,
-                     int32_t aScriptCode, int32_t aAppUnitsPerDevUnit,
+                     Script aScriptCode, int32_t aAppUnitsPerDevUnit,
                      uint32_t aFlags)
             : mLength(aLength),
               mFlags(aFlags),
               mScript(aScriptCode),
               mAppUnitsPerDevUnit(aAppUnitsPerDevUnit),
-              mHashKey(aStringHash + aScriptCode +
+              mHashKey(aStringHash + static_cast<int32_t>(aScriptCode) +
                   aAppUnitsPerDevUnit * 0x100 + aFlags * 0x10000),
               mTextIs8Bit(false)
         {
             // We can NOT assert that TEXT_IS_8BIT is false in aFlags here,
             // because this might be an 8bit-only word from a 16-bit textrun,
             // in which case the text we're passed is still in 16-bit form,
             // and we'll have to use an 8-to-16bit comparison in KeyEquals.
             mText.mDouble = aText;
--- a/gfx/thebes/gfxFontEntry.cpp
+++ b/gfx/thebes/gfxFontEntry.cpp
@@ -875,24 +875,24 @@ gfxFontEntry::HasGraphiteSpaceContextual
         mGraphiteSpaceContextualsInitialized = true;
     }
     return mHasGraphiteSpaceContextuals;
 }
 
 #define FEATURE_SCRIPT_MASK 0x000000ff // script index replaces low byte of tag
 
 // check for too many script codes
-PR_STATIC_ASSERT(MOZ_NUM_SCRIPT_CODES <= FEATURE_SCRIPT_MASK);
+PR_STATIC_ASSERT(int(Script::NUM_SCRIPT_CODES) <= FEATURE_SCRIPT_MASK);
 
 // high-order three bytes of tag with script in low-order byte
 #define SCRIPT_FEATURE(s,tag) (((~FEATURE_SCRIPT_MASK) & (tag)) | \
-                               ((FEATURE_SCRIPT_MASK) & (s)))
+                               ((FEATURE_SCRIPT_MASK) & static_cast<uint32_t>(s)))
 
 bool
-gfxFontEntry::SupportsOpenTypeFeature(int32_t aScript, uint32_t aFeatureTag)
+gfxFontEntry::SupportsOpenTypeFeature(Script aScript, uint32_t aFeatureTag)
 {
     if (!mSupportedFeatures) {
         mSupportedFeatures = MakeUnique<nsDataHashtable<nsUint32HashKey,bool>>();
     }
 
     // note: high-order three bytes *must* be unique for each feature
     // listed below (see SCRIPT_FEATURE macro def'n)
     NS_ASSERTION(aFeatureTag == HB_TAG('s','m','c','p') ||
@@ -900,17 +900,17 @@ gfxFontEntry::SupportsOpenTypeFeature(in
                  aFeatureTag == HB_TAG('p','c','a','p') ||
                  aFeatureTag == HB_TAG('c','2','p','c') ||
                  aFeatureTag == HB_TAG('s','u','p','s') ||
                  aFeatureTag == HB_TAG('s','u','b','s') ||
                  aFeatureTag == HB_TAG('v','e','r','t'),
                  "use of unknown feature tag");
 
     // note: graphite feature support uses the last script index
-    NS_ASSERTION(aScript < FEATURE_SCRIPT_MASK - 1,
+    NS_ASSERTION(int(aScript) < FEATURE_SCRIPT_MASK - 1,
                  "need to bump the size of the feature shift");
 
     uint32_t scriptFeature = SCRIPT_FEATURE(aScript, aFeatureTag);
     bool result;
     if (mSupportedFeatures->Get(scriptFeature, &result)) {
         return result;
     }
 
@@ -960,17 +960,17 @@ gfxFontEntry::SupportsOpenTypeFeature(in
     hb_face_destroy(face);
 
     mSupportedFeatures->Put(scriptFeature, result);
 
     return result;
 }
 
 const hb_set_t*
-gfxFontEntry::InputsForOpenTypeFeature(int32_t aScript, uint32_t aFeatureTag)
+gfxFontEntry::InputsForOpenTypeFeature(Script aScript, uint32_t aFeatureTag)
 {
     if (!mFeatureInputs) {
         mFeatureInputs = MakeUnique<nsDataHashtable<nsUint32HashKey,hb_set_t*>>();
     }
 
     NS_ASSERTION(aFeatureTag == HB_TAG('s','u','p','s') ||
                  aFeatureTag == HB_TAG('s','u','b','s'),
                  "use of unknown feature tag");
@@ -1520,22 +1520,22 @@ gfxFontFamily::FindFontForChar(GlobalFon
         if (fe->HasCharacter(aMatchData->mCh)) {
             rank += RANK_MATCHED_CMAP;
             aMatchData->mCount++;
 
             LogModule* log = gfxPlatform::GetLog(eGfxLog_textrun);
 
             if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Debug))) {
                 uint32_t unicodeRange = FindCharUnicodeRange(aMatchData->mCh);
-                uint32_t script = GetScriptCode(aMatchData->mCh);
+                Script script = GetScriptCode(aMatchData->mCh);
                 MOZ_LOG(log, LogLevel::Debug,\
                        ("(textrun-systemfallback-fonts) char: u+%6.6x "
                         "unicode-range: %d script: %d match: [%s]\n",
                         aMatchData->mCh,
-                        unicodeRange, script,
+                        unicodeRange, int(script),
                         NS_ConvertUTF16toUTF8(fe->Name()).get()));
             }
         }
 
         aMatchData->mCmapsTested++;
         if (rank == 0) {
             return;
         }
--- a/gfx/thebes/gfxFontEntry.h
+++ b/gfx/thebes/gfxFontEntry.h
@@ -92,16 +92,17 @@ protected:
 private:
     gfxCharacterMap(const gfxCharacterMap&);
     gfxCharacterMap& operator=(const gfxCharacterMap&);
 };
 
 class gfxFontEntry {
 public:
     typedef mozilla::gfx::DrawTarget DrawTarget;
+    typedef mozilla::unicode::Script Script;
 
     NS_INLINE_DECL_REFCOUNTING(gfxFontEntry)
 
     explicit gfxFontEntry(const nsAString& aName, bool aIsStandardFace = false);
 
     // unique name for the face, *not* the family; not necessarily the
     // "real" or user-friendly name, may be an internal identifier
     const nsString& Name() const { return mName; }
@@ -128,22 +129,22 @@ public:
     bool IsOblique() const { return mStyle == NS_FONT_STYLE_OBLIQUE; }
     bool IsUpright() const { return mStyle == NS_FONT_STYLE_NORMAL; }
     bool IsBold() const { return mWeight >= 600; } // bold == weights 600 and above
     bool IgnoreGDEF() const { return mIgnoreGDEF; }
     bool IgnoreGSUB() const { return mIgnoreGSUB; }
 
     // whether a feature is supported by the font (limited to a small set
     // of features for which some form of fallback needs to be implemented)
-    bool SupportsOpenTypeFeature(int32_t aScript, uint32_t aFeatureTag);
+    bool SupportsOpenTypeFeature(Script aScript, uint32_t aFeatureTag);
     bool SupportsGraphiteFeature(uint32_t aFeatureTag);
 
     // returns a set containing all input glyph ids for a given feature
     const hb_set_t*
-    InputsForOpenTypeFeature(int32_t aScript, uint32_t aFeatureTag);
+    InputsForOpenTypeFeature(Script aScript, uint32_t aFeatureTag);
 
     virtual bool IsSymbolFont();
 
     virtual bool HasFontTable(uint32_t aTableTag);
 
     inline bool HasGraphiteTables() {
         if (!mCheckedForGraphiteTables) {
             CheckForGraphiteTables();
@@ -418,18 +419,18 @@ public:
     bool             mHasGraphiteTables : 1;
     bool             mCheckedForGraphiteTables : 1;
     bool             mHasCmapTable : 1;
     bool             mGrFaceInitialized : 1;
     bool             mCheckedForColorGlyph : 1;
 
     // bitvector of substitution space features per script, one each
     // for default and non-default features
-    uint32_t         mDefaultSubSpaceFeatures[(MOZ_NUM_SCRIPT_CODES + 31) / 32];
-    uint32_t         mNonDefaultSubSpaceFeatures[(MOZ_NUM_SCRIPT_CODES + 31) / 32];
+    uint32_t         mDefaultSubSpaceFeatures[(int(Script::NUM_SCRIPT_CODES) + 31) / 32];
+    uint32_t         mNonDefaultSubSpaceFeatures[(int(Script::NUM_SCRIPT_CODES) + 31) / 32];
 
     uint16_t         mWeight;
     int16_t          mStretch;
 
     RefPtr<gfxCharacterMap> mCharacterMap;
     uint32_t         mUVSOffset;
     mozilla::UniquePtr<uint8_t[]> mUVSData;
     mozilla::UniquePtr<gfxUserFontData> mUserFontData;
@@ -629,26 +630,26 @@ private:
     gfxFontEntry(const gfxFontEntry&);
     gfxFontEntry& operator=(const gfxFontEntry&);
 };
 
 
 // used when iterating over all fonts looking for a match for a given character
 struct GlobalFontMatch {
     GlobalFontMatch(const uint32_t aCharacter,
-                    int32_t aRunScript,
+                    mozilla::unicode::Script aRunScript,
                     const gfxFontStyle *aStyle) :
         mCh(aCharacter), mRunScript(aRunScript), mStyle(aStyle),
         mMatchRank(0), mCount(0), mCmapsTested(0)
         {
 
         }
 
     const uint32_t         mCh;          // codepoint to be matched
-    int32_t                mRunScript;   // Unicode script for the codepoint
+    mozilla::unicode::Script mRunScript;   // Unicode script for the codepoint
     const gfxFontStyle*    mStyle;       // style to match
     int32_t                mMatchRank;   // metric indicating closest match
     RefPtr<gfxFontEntry> mBestMatch;   // current best match
     RefPtr<gfxFontFamily> mMatchedFamily; // the family it belongs to
     uint32_t               mCount;       // number of fonts matched
     uint32_t               mCmapsTested; // number of cmaps tested
 };
 
--- a/gfx/thebes/gfxFontconfigFonts.cpp
+++ b/gfx/thebes/gfxFontconfigFonts.cpp
@@ -1541,17 +1541,17 @@ gfxPangoFontGroup::GetFontSet(PangoLangu
         MakeFontSet(aLang, mSizeAdjustFactor);
     mFontSets.AppendElement(FontSetByLangEntry(aLang, fontSet));
 
     return fontSet;
 }
 
 already_AddRefed<gfxFont>
 gfxPangoFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
-                                   uint32_t aNextCh, int32_t aRunScript,
+                                   uint32_t aNextCh, Script aRunScript,
                                    gfxFont *aPrevMatchedFont,
                                    uint8_t *aMatchType)
 {
     if (aPrevMatchedFont) {
         // Don't switch fonts for control characters, regardless of
         // whether they are present in the current font, as they won't
         // actually be rendered (see bug 716229)
         uint8_t category = GetGeneralCategory(aCh);
--- a/gfx/thebes/gfxFontconfigFonts.h
+++ b/gfx/thebes/gfxFontconfigFonts.h
@@ -32,17 +32,17 @@ public:
     virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle);
 
     virtual gfxFont* GetFirstValidFont(uint32_t aCh = 0x20);
 
     virtual void UpdateUserFonts();
 
     virtual already_AddRefed<gfxFont>
         FindFontForChar(uint32_t aCh, uint32_t aPrevCh, uint32_t aNextCh,
-                        int32_t aRunScript, gfxFont *aPrevMatchedFont,
+                        Script aRunScript, gfxFont *aPrevMatchedFont,
                         uint8_t *aMatchType);
 
     static void Shutdown();
 
     // Used for @font-face { src: local(); }
     static gfxFontEntry *NewFontEntry(const nsAString& aFontName,
                                       uint16_t aWeight,
                                       int16_t aStretch,
--- a/gfx/thebes/gfxGDIFont.cpp
+++ b/gfx/thebes/gfxGDIFont.cpp
@@ -77,17 +77,17 @@ gfxGDIFont::CopyWithAntialiasOption(Anti
                           &mStyle, mNeedsBold, anAAOption);
 }
 
 bool
 gfxGDIFont::ShapeText(DrawTarget     *aDrawTarget,
                       const char16_t *aText,
                       uint32_t        aOffset,
                       uint32_t        aLength,
-                      int32_t         aScript,
+                      Script          aScript,
                       bool            aVertical,
                       gfxShapedText  *aShapedText)
 {
     if (!mMetrics) {
         Initialize();
     }
     if (!mIsValid) {
         NS_WARNING("invalid font! expect incorrect text rendering");
--- a/gfx/thebes/gfxGDIFont.h
+++ b/gfx/thebes/gfxGDIFont.h
@@ -81,17 +81,17 @@ public:
 protected:
     virtual const Metrics& GetHorizontalMetrics() override;
 
     /* override to ensure the cairo font is set up properly */
     virtual bool ShapeText(DrawTarget     *aDrawTarget,
                            const char16_t *aText,
                            uint32_t        aOffset,
                            uint32_t        aLength,
-                           int32_t         aScript,
+                           Script          aScript,
                            bool            aVertical,
                            gfxShapedText  *aShapedText) override;
 
     void Initialize(); // creates metrics and Cairo fonts
 
     // Fill the given LOGFONT record according to our style, but don't adjust
     // the lfItalic field if we're going to use a cairo transform for fake
     // italics.
--- a/gfx/thebes/gfxGraphiteShaper.cpp
+++ b/gfx/thebes/gfxGraphiteShaper.cpp
@@ -81,17 +81,17 @@ AddFeature(const uint32_t& aTag, uint32_
     }
 }
 
 bool
 gfxGraphiteShaper::ShapeText(DrawTarget      *aDrawTarget,
                              const char16_t *aText,
                              uint32_t         aOffset,
                              uint32_t         aLength,
-                             int32_t          aScript,
+                             Script           aScript,
                              bool             aVertical,
                              gfxShapedText   *aShapedText)
 {
     // some font back-ends require this in order to get proper hinted metrics
     if (!mFont->SetupCairoFont(aDrawTarget)) {
         return false;
     }
 
--- a/gfx/thebes/gfxGraphiteShaper.h
+++ b/gfx/thebes/gfxGraphiteShaper.h
@@ -18,17 +18,17 @@ class gfxGraphiteShaper : public gfxFont
 public:
     explicit gfxGraphiteShaper(gfxFont *aFont);
     virtual ~gfxGraphiteShaper();
 
     virtual bool ShapeText(DrawTarget      *aDrawTarget,
                            const char16_t *aText,
                            uint32_t         aOffset,
                            uint32_t         aLength,
-                           int32_t          aScript,
+                           Script           aScript,
                            bool             aVertical,
                            gfxShapedText   *aShapedText);
 
     static void Shutdown();
 
 protected:
     nsresult SetGlyphsFromSegment(DrawTarget      *aDrawTarget,
                                   gfxShapedText   *aShapedText,
--- a/gfx/thebes/gfxHarfBuzzShaper.cpp
+++ b/gfx/thebes/gfxHarfBuzzShaper.cpp
@@ -1490,17 +1490,17 @@ gfxHarfBuzzShaper::InitializeVertical()
     return true;
 }
 
 bool
 gfxHarfBuzzShaper::ShapeText(DrawTarget      *aDrawTarget,
                              const char16_t *aText,
                              uint32_t         aOffset,
                              uint32_t         aLength,
-                             int32_t          aScript,
+                             Script           aScript,
                              bool             aVertical,
                              gfxShapedText   *aShapedText)
 {
     // some font back-ends require this in order to get proper hinted metrics
     if (!mFont->SetupCairoFont(aDrawTarget)) {
         return false;
     }
 
--- a/gfx/thebes/gfxHarfBuzzShaper.h
+++ b/gfx/thebes/gfxHarfBuzzShaper.h
@@ -26,17 +26,17 @@ public:
         mozilla::gfx::DrawTarget* mDrawTarget;
     };
 
     bool Initialize();
     virtual bool ShapeText(DrawTarget      *aDrawTarget,
                            const char16_t *aText,
                            uint32_t         aOffset,
                            uint32_t         aLength,
-                           int32_t          aScript,
+                           Script           aScript,
                            bool             aVertical,
                            gfxShapedText   *aShapedText);
 
     // get a given font table in harfbuzz blob form
     hb_blob_t * GetFontTable(hb_tag_t aTag) const;
 
     // map unicode character to glyph ID
     hb_codepoint_t GetNominalGlyph(hb_codepoint_t unicode) const;
@@ -74,20 +74,20 @@ public:
                               hb_glyph_extents_t *aExtents) const;
 
     bool UseVerticalPresentationForms() const
     {
         return mUseVerticalPresentationForms;
     }
 
     static hb_script_t
-    GetHBScriptUsedForShaping(int32_t aScript) {
+    GetHBScriptUsedForShaping(Script aScript) {
         // Decide what harfbuzz script code will be used for shaping
         hb_script_t hbScript;
-        if (aScript <= MOZ_SCRIPT_INHERITED) {
+        if (aScript <= Script::INHERITED) {
             // For unresolved "common" or "inherited" runs,
             // default to Latin for now.
             hbScript = HB_SCRIPT_LATIN;
         } else {
             hbScript =
                 hb_script_t(mozilla::unicode::GetScriptTagForCode(aScript));
         }
         return hbScript;
--- a/gfx/thebes/gfxMacFont.cpp
+++ b/gfx/thebes/gfxMacFont.cpp
@@ -119,17 +119,17 @@ gfxMacFont::~gfxMacFont()
     }
 }
 
 bool
 gfxMacFont::ShapeText(DrawTarget     *aDrawTarget,
                       const char16_t *aText,
                       uint32_t        aOffset,
                       uint32_t        aLength,
-                      int32_t         aScript,
+                      Script          aScript,
                       bool            aVertical,
                       gfxShapedText  *aShapedText)
 {
     if (!mIsValid) {
         NS_WARNING("invalid font! expect incorrect text rendering");
         return false;
     }
 
--- a/gfx/thebes/gfxMacFont.h
+++ b/gfx/thebes/gfxMacFont.h
@@ -66,17 +66,17 @@ protected:
         return mMetrics;
     }
 
     // override to prefer CoreText shaping with fonts that depend on AAT
     virtual bool ShapeText(DrawTarget     *aDrawTarget,
                            const char16_t *aText,
                            uint32_t        aOffset,
                            uint32_t        aLength,
-                           int32_t         aScript,
+                           Script          aScript,
                            bool            aVertical,
                            gfxShapedText  *aShapedText) override;
 
     void InitMetrics();
     void InitMetricsFromPlatform();
 
     // Get width and glyph ID for a character; uses aConvFactor
     // to convert font units as returned by CG to actual dimensions
--- a/gfx/thebes/gfxMacPlatformFontList.h
+++ b/gfx/thebes/gfxMacPlatformFontList.h
@@ -128,17 +128,17 @@ private:
     static void RegisteredFontsChangedNotificationCallback(CFNotificationCenterRef center,
                                                            void *observer,
                                                            CFStringRef name,
                                                            const void *object,
                                                            CFDictionaryRef userInfo);
 
     // search fonts system-wide for a given character, null otherwise
     gfxFontEntry* GlobalFontFallback(const uint32_t aCh,
-                                     int32_t aRunScript,
+                                     Script aRunScript,
                                      const gfxFontStyle* aMatchStyle,
                                      uint32_t& aCmapCount,
                                      gfxFontFamily** aMatchedFamily) override;
 
     bool UsesSystemFallback() override { return true; }
 
     already_AddRefed<FontInfoData> CreateFontInfoData() override;
 
--- a/gfx/thebes/gfxMacPlatformFontList.mm
+++ b/gfx/thebes/gfxMacPlatformFontList.mm
@@ -884,17 +884,17 @@ gfxMacPlatformFontList::RegisteredFontsC
     fl->UpdateFontList();
 
     // modify a preference that will trigger reflow everywhere
     fl->ForceGlobalReflow();
 }
 
 gfxFontEntry*
 gfxMacPlatformFontList::GlobalFontFallback(const uint32_t aCh,
-                                           int32_t aRunScript,
+                                           Script aRunScript,
                                            const gfxFontStyle* aMatchStyle,
                                            uint32_t& aCmapCount,
                                            gfxFontFamily** aMatchedFamily)
 {
     bool useCmaps = gfxPlatform::GetPlatform()->UseCmapsDuringSystemFallback();
 
     if (useCmaps) {
         return gfxPlatformFontList::GlobalFontFallback(aCh,
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -6,16 +6,17 @@
 #ifndef GFX_PLATFORM_H
 #define GFX_PLATFORM_H
 
 #include "mozilla/Logging.h"
 #include "mozilla/gfx/Types.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
+#include "nsUnicodeScriptCodes.h"
 
 #include "gfxTypes.h"
 #include "gfxFontFamilyList.h"
 #include "gfxBlur.h"
 #include "nsRect.h"
 
 #include "qcms.h"
 
@@ -144,16 +145,17 @@ class gfxPlatform {
     friend class SRGBOverrideObserver;
 
 public:
     typedef mozilla::gfx::Color Color;
     typedef mozilla::gfx::DataSourceSurface DataSourceSurface;
     typedef mozilla::gfx::DrawTarget DrawTarget;
     typedef mozilla::gfx::IntSize IntSize;
     typedef mozilla::gfx::SourceSurface SourceSurface;
+    typedef mozilla::unicode::Script Script;
 
     /**
      * Return a pointer to the current active platform.
      * This is a singleton; it contains mostly convenience
      * functions to obtain platform-specific objects.
      */
     static gfxPlatform *GetPlatform();
 
@@ -431,17 +433,17 @@ public:
     // check whether format is supported on a platform or not (if unclear, returns true)
     virtual bool IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags) { return false; }
 
     virtual bool DidRenderingDeviceReset(DeviceResetReason* aResetReason = nullptr) { return false; }
 
     // returns a list of commonly used fonts for a given character
     // these are *possible* matches, no cmap-checking is done at this level
     virtual void GetCommonFallbackFonts(uint32_t /*aCh*/, uint32_t /*aNextCh*/,
-                                        int32_t /*aRunScript*/,
+                                        Script /*aRunScript*/,
                                         nsTArray<const char*>& /*aFontList*/)
     {
         // platform-specific override, by default do nothing
     }
 
     // Are we in safe mode?
     static bool InSafeMode();
 
--- a/gfx/thebes/gfxPlatformFontList.cpp
+++ b/gfx/thebes/gfxPlatformFontList.cpp
@@ -472,17 +472,17 @@ gfxPlatformFontList::GetFontFamilyList(n
     for (auto iter = mFontFamilies.Iter(); !iter.Done(); iter.Next()) {
         RefPtr<gfxFontFamily>& family = iter.Data();
         aFamilyArray.AppendElement(family);
     }
 }
 
 gfxFontEntry*
 gfxPlatformFontList::SystemFindFontForChar(uint32_t aCh, uint32_t aNextCh,
-                                           int32_t aRunScript,
+                                           Script aRunScript,
                                            const gfxFontStyle* aStyle)
  {
     gfxFontEntry* fontEntry = nullptr;
 
     // is codepoint with no matching font? return null immediately
     if (mCodepointsWithNoFonts.test(aCh)) {
         return nullptr;
     }
@@ -521,17 +521,17 @@ gfxPlatformFontList::SystemFindFontForCh
                                        &fallbackFamily);
     }
     TimeDuration elapsed = TimeStamp::Now() - start;
 
     LogModule* log = gfxPlatform::GetLog(eGfxLog_textrun);
 
     if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Warning))) {
         uint32_t unicodeRange = FindCharUnicodeRange(aCh);
-        int32_t script = mozilla::unicode::GetScriptCode(aCh);
+        Script script = mozilla::unicode::GetScriptCode(aCh);
         MOZ_LOG(log, LogLevel::Warning,\
                ("(textrun-systemfallback-%s) char: u+%6.6x "
                  "unicode-range: %d script: %d match: [%s]"
                 " time: %dus cmaps: %d\n",
                 (common ? "common" : "global"), aCh,
                  unicodeRange, script,
                 (fontEntry ? NS_ConvertUTF16toUTF8(fontEntry->Name()).get() :
                     "<none>"),
@@ -552,26 +552,27 @@ gfxPlatformFontList::SystemFindFontForCh
                                          elapsed.ToMicroseconds());
     Telemetry::Accumulate((first ? Telemetry::SYSTEM_FONT_FALLBACK_FIRST :
                                    Telemetry::SYSTEM_FONT_FALLBACK),
                           intElapsed);
     first = false;
 
     // track the script for which fallback occurred (incremented one make it
     // 1-based)
-    Telemetry::Accumulate(Telemetry::SYSTEM_FONT_FALLBACK_SCRIPT, aRunScript + 1);
+    Telemetry::Accumulate(Telemetry::SYSTEM_FONT_FALLBACK_SCRIPT,
+                          int(aRunScript) + 1);
 
     return fontEntry;
 }
 
 #define NUM_FALLBACK_FONTS        8
 
 gfxFontEntry*
 gfxPlatformFontList::CommonFontFallback(uint32_t aCh, uint32_t aNextCh,
-                                        int32_t aRunScript,
+                                        Script aRunScript,
                                         const gfxFontStyle* aMatchStyle,
                                         gfxFontFamily** aMatchedFamily)
 {
     AutoTArray<const char*,NUM_FALLBACK_FONTS> defaultFallbacks;
     uint32_t i, numFallbacks;
 
     gfxPlatform::GetPlatform()->GetCommonFallbackFonts(aCh, aNextCh,
                                                        aRunScript,
@@ -597,17 +598,17 @@ gfxPlatformFontList::CommonFontFallback(
         }
     }
 
     return nullptr;
 }
 
 gfxFontEntry*
 gfxPlatformFontList::GlobalFontFallback(const uint32_t aCh,
-                                        int32_t aRunScript,
+                                        Script aRunScript,
                                         const gfxFontStyle* aMatchStyle,
                                         uint32_t& aCmapCount,
                                         gfxFontFamily** aMatchedFamily)
 {
     // otherwise, try to find it among local fonts
     GlobalFontMatch data(aCh, aRunScript, aMatchStyle);
 
     // iterate over all font families to find a font that support the character
--- a/gfx/thebes/gfxPlatformFontList.h
+++ b/gfx/thebes/gfxPlatformFontList.h
@@ -86,16 +86,18 @@ struct FontListSizes {
     uint32_t mCharMapsSize; // memory used for cmap coverage info
 };
 
 class gfxUserFontSet;
 
 class gfxPlatformFontList : public gfxFontInfoLoader
 {
 public:
+    typedef mozilla::unicode::Script Script;
+
     static gfxPlatformFontList* PlatformFontList() {
         return sPlatformFontList;
     }
 
     static nsresult Init() {
         NS_ASSERTION(!sPlatformFontList, "What's this doing here?");
         gfxPlatform::GetPlatform()->CreatePlatformFontList();
         if (!sPlatformFontList) {
@@ -121,17 +123,17 @@ public:
     void UpdateFontList();
 
     virtual void ClearLangGroupPrefFonts();
 
     virtual void GetFontFamilyList(nsTArray<RefPtr<gfxFontFamily> >& aFamilyArray);
 
     gfxFontEntry*
     SystemFindFontForChar(uint32_t aCh, uint32_t aNextCh,
-                          int32_t aRunScript,
+                          Script aRunScript,
                           const gfxFontStyle* aStyle);
 
     // Find family(ies) matching aFamily and append to the aOutput array
     // (there may be multiple results in the case of fontconfig aliases, etc).
     // Return true if any match was found and appended, false if none.
     virtual bool
     FindAndAddFamilies(const nsAString& aFamily,
                        nsTArray<gfxFontFamily*>* aOutput,
@@ -279,23 +281,23 @@ protected:
         if ((familyEntry = mFontFamilies.GetWeak(key))) {
             return CheckFamily(familyEntry);
         }
         return nullptr;
     }
 
     // returns default font for a given character, null otherwise
     gfxFontEntry* CommonFontFallback(uint32_t aCh, uint32_t aNextCh,
-                                     int32_t aRunScript,
+                                     Script aRunScript,
                                      const gfxFontStyle* aMatchStyle,
                                      gfxFontFamily** aMatchedFamily);
 
     // search fonts system-wide for a given character, null otherwise
     virtual gfxFontEntry* GlobalFontFallback(const uint32_t aCh,
-                                             int32_t aRunScript,
+                                             Script aRunScript,
                                              const gfxFontStyle* aMatchStyle,
                                              uint32_t& aCmapCount,
                                              gfxFontFamily** aMatchedFamily);
 
     // whether system-based font fallback is used or not
     // if system fallback is used, no need to load all cmaps
     virtual bool UsesSystemFallback() { return false; }
 
--- a/gfx/thebes/gfxPlatformGtk.cpp
+++ b/gfx/thebes/gfxPlatformGtk.cpp
@@ -193,17 +193,17 @@ static const char kFontFreeSans[] = "Fre
 static const char kFontFreeSerif[] = "FreeSerif";
 static const char kFontTakaoPGothic[] = "TakaoPGothic";
 static const char kFontDroidSansFallback[] = "Droid Sans Fallback";
 static const char kFontWenQuanYiMicroHei[] = "WenQuanYi Micro Hei";
 static const char kFontNanumGothic[] = "NanumGothic";
 
 void
 gfxPlatformGtk::GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
-                                       int32_t aRunScript,
+                                       Script aRunScript,
                                        nsTArray<const char*>& aFontList)
 {
     aFontList.AppendElement(kFontDejaVuSerif);
     aFontList.AppendElement(kFontFreeSerif);
     aFontList.AppendElement(kFontDejaVuSans);
     aFontList.AppendElement(kFontFreeSans);
 
     // add fonts for CJK ranges
--- a/gfx/thebes/gfxPlatformGtk.h
+++ b/gfx/thebes/gfxPlatformGtk.h
@@ -37,17 +37,17 @@ public:
     virtual nsresult GetFontList(nsIAtom *aLangGroup,
                                  const nsACString& aGenericFamily,
                                  nsTArray<nsString>& aListOfFonts) override;
 
     virtual nsresult UpdateFontList() override;
 
     virtual void
     GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
-                           int32_t aRunScript,
+                           Script aRunScript,
                            nsTArray<const char*>& aFontList) override;
 
     virtual gfxPlatformFontList* CreatePlatformFontList() override;
 
     virtual nsresult GetStandardFamilyName(const nsAString& aFontName,
                                            nsAString& aFamilyName) override;
 
     gfxFontGroup*
--- a/gfx/thebes/gfxPlatformMac.cpp
+++ b/gfx/thebes/gfxPlatformMac.cpp
@@ -188,17 +188,17 @@ static const char kFontPlantagenetCherok
 static const char kFontSimSunExtB[] = "SimSun-ExtB";
 static const char kFontSongtiSC[] = "Songti SC";
 static const char kFontSTHeiti[] = "STHeiti";
 static const char kFontSTIXGeneral[] = "STIXGeneral";
 static const char kFontTamilMN[] = "Tamil MN";
 
 void
 gfxPlatformMac::GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
-                                       int32_t aRunScript,
+                                       Script aRunScript,
                                        nsTArray<const char*>& aFontList)
 {
     if (aNextCh == 0xfe0f) {
         aFontList.AppendElement(kFontAppleColorEmoji);
     }
 
     aFontList.AppendElement(kFontLucidaGrande);
 
--- a/gfx/thebes/gfxPlatformMac.h
+++ b/gfx/thebes/gfxPlatformMac.h
@@ -40,17 +40,17 @@ public:
                     gfxUserFontSet *aUserFontSet,
                     gfxFloat aDevToCssSize) override;
 
     virtual gfxPlatformFontList* CreatePlatformFontList() override;
 
     bool IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags) override;
 
     virtual void GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
-                                        int32_t aRunScript,
+                                        Script aRunScript,
                                         nsTArray<const char*>& aFontList) override;
 
     // lookup the system font for a particular system font type and set
     // the name and style characteristics
     static void
     LookupSystemFont(mozilla::LookAndFeel::FontID aSystemFontID,
                      nsAString& aSystemFontName,
                      gfxFontStyle &aFontStyle,
--- a/gfx/thebes/gfxScriptItemizer.cpp
+++ b/gfx/thebes/gfxScriptItemizer.cpp
@@ -59,17 +59,17 @@
 #define DEC(sp,count) (MOD((sp) + PAREN_STACK_DEPTH - (count)))
 #define DEC1(sp) (DEC(sp, 1))
 #define STACK_IS_EMPTY() (pushCount <= 0)
 #define STACK_IS_NOT_EMPTY() (! STACK_IS_EMPTY())
 #define TOP() (parenStack[parenSP])
 #define SYNC_FIXUP() (fixupCount = 0)
 
 void
-gfxScriptItemizer::push(uint32_t endPairChar, int32_t newScriptCode)
+gfxScriptItemizer::push(uint32_t endPairChar, Script newScriptCode)
 {
     pushCount  = LIMIT_INC(pushCount);
     fixupCount = LIMIT_INC(fixupCount);
 
     parenSP = INC1(parenSP);
     parenStack[parenSP].endPairChar = endPairChar;
     parenStack[parenSP].scriptCode = newScriptCode;
 }
@@ -92,31 +92,31 @@ gfxScriptItemizer::pop()
        pointers to their initial values.
      */
     if (STACK_IS_EMPTY()) {
         parenSP = -1;
     }
 }
 
 void
-gfxScriptItemizer::fixup(int32_t newScriptCode)
+gfxScriptItemizer::fixup(Script newScriptCode)
 {
     int32_t fixupSP = DEC(parenSP, fixupCount);
 
     while (fixupCount-- > 0) {
         fixupSP = INC1(fixupSP);
         parenStack[fixupSP].scriptCode = newScriptCode;
     }
 }
 
 static inline bool
-SameScript(int32_t runScript, int32_t currCharScript)
+SameScript(Script runScript, Script currCharScript)
 {
-    return runScript <= MOZ_SCRIPT_INHERITED ||
-           currCharScript <= MOZ_SCRIPT_INHERITED ||
+    return runScript <= Script::INHERITED ||
+           currCharScript <= Script::INHERITED ||
            currCharScript == runScript;
 }
 
 gfxScriptItemizer::gfxScriptItemizer(const char16_t *src, uint32_t length)
     : textPtr(src), textLength(length)
 {
     reset();
 }
@@ -127,29 +127,29 @@ gfxScriptItemizer::SetText(const char16_
     textPtr  = src;
     textLength = length;
 
     reset();
 }
 
 bool
 gfxScriptItemizer::Next(uint32_t& aRunStart, uint32_t& aRunLimit,
-                        int32_t& aRunScript)
+                        Script& aRunScript)
 {
     /* if we've fallen off the end of the text, we're done */
     if (scriptLimit >= textLength) {
         return false;
     }
 
     SYNC_FIXUP();
-    scriptCode = MOZ_SCRIPT_COMMON;
+    scriptCode = Script::COMMON;
 
     for (scriptStart = scriptLimit; scriptLimit < textLength; scriptLimit += 1) {
         uint32_t ch;
-        int32_t sc;
+        Script sc;
         uint32_t startOfChar = scriptLimit;
 
         ch = textPtr[scriptLimit];
 
         /* decode UTF-16 (may be surrogate pair) */
         if (NS_IS_HIGH_SURROGATE(ch) && scriptLimit < textLength - 1) {
             uint32_t low = textPtr[scriptLimit + 1];
             if (NS_IS_LOW_SURROGATE(low)) {
@@ -158,17 +158,17 @@ gfxScriptItemizer::Next(uint32_t& aRunSt
             }
         }
 
         // Initialize gc to UNASSIGNED; we'll only set it to the true GC
         // if the character has script=COMMON, otherwise we don't care.
         uint8_t gc = HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED;
 
         sc = GetScriptCode(ch);
-        if (sc == MOZ_SCRIPT_COMMON) {
+        if (sc == Script::COMMON) {
             /*
              * Paired character handling:
              *
              * if it's an open character, push it onto the stack.
              * if it's a close character, find the matching open on the
              * stack, and use that script code. Any non-matching open
              * characters above it on the stack will be popped.
              *
@@ -190,18 +190,18 @@ gfxScriptItemizer::Next(uint32_t& aRunSt
 
                 if (STACK_IS_NOT_EMPTY()) {
                     sc = TOP().scriptCode;
                 }
             }
         }
 
         if (SameScript(scriptCode, sc)) {
-            if (scriptCode <= MOZ_SCRIPT_INHERITED &&
-                sc > MOZ_SCRIPT_INHERITED)
+            if (scriptCode <= Script::INHERITED &&
+                sc > Script::INHERITED)
             {
                 scriptCode = sc;
                 fixup(scriptCode);
             }
 
             /*
              * if this character is a close paired character,
              * pop the matching open character from the stack
--- a/gfx/thebes/gfxScriptItemizer.h
+++ b/gfx/thebes/gfxScriptItemizer.h
@@ -53,48 +53,50 @@
 #include <stdint.h>
 #include "nsUnicodeScriptCodes.h"
 
 #define PAREN_STACK_DEPTH 32
 
 class gfxScriptItemizer
 {
 public:
+    typedef mozilla::unicode::Script Script;
+
     gfxScriptItemizer(const char16_t *src, uint32_t length);
 
     void SetText(const char16_t *src, uint32_t length);
 
     bool Next(uint32_t& aRunStart, uint32_t& aRunLimit,
-              int32_t& aRunScript);
+              Script& aRunScript);
 
 protected:
     void reset() {
         scriptStart = 0;
         scriptLimit = 0;
-        scriptCode  = MOZ_SCRIPT_INVALID;
+        scriptCode  = Script::INVALID;
         parenSP     = -1;
         pushCount   =  0;
         fixupCount  =  0;
     }
 
-    void push(uint32_t endPairChar, int32_t newScriptCode);
+    void push(uint32_t endPairChar, Script newScriptCode);
     void pop();
-    void fixup(int32_t newScriptCode);
+    void fixup(Script newScriptCode);
 
     struct ParenStackEntry {
         uint32_t endPairChar;
-        int32_t  scriptCode;
+        Script  scriptCode;
     };
 
     const char16_t *textPtr;
     uint32_t textLength;
 
     uint32_t scriptStart;
     uint32_t scriptLimit;
-    int32_t  scriptCode;
+    Script  scriptCode;
 
     struct ParenStackEntry parenStack[PAREN_STACK_DEPTH];
     uint32_t parenSP;
     uint32_t pushCount;
     uint32_t fixupCount;
 };
 
 #endif /* GFX_SCRIPTITEMIZER_H */
--- a/gfx/thebes/gfxTextRun.cpp
+++ b/gfx/thebes/gfxTextRun.cpp
@@ -1343,17 +1343,17 @@ gfxTextRun::SetSpaceGlyph(gfxFont* aFont
                      gfxTextRunFactory::TEXT_IS_ASCII |
                      gfxTextRunFactory::TEXT_IS_PERSISTENT |
                      aOrientation;
     bool vertical =
         (GetFlags() & gfxTextRunFactory::TEXT_ORIENT_VERTICAL_UPRIGHT) != 0;
     gfxShapedWord* sw = aFont->GetShapedWord(aDrawTarget,
                                              &space, 1,
                                              gfxShapedWord::HashMix(0, ' '), 
-                                             MOZ_SCRIPT_LATIN,
+                                             Script::LATIN,
                                              vertical,
                                              mAppUnitsPerDevUnit,
                                              flags,
                                              nullptr);
     if (sw) {
         AddGlyphRun(aFont, gfxTextRange::kFontGroup, aCharIndex, false,
                     aOrientation);
         CopyGlyphDataFrom(sw, aCharIndex);
@@ -1999,17 +1999,17 @@ gfxFontGroup::MakeSpaceTextRun(const Par
             // Normally, the font has a cached space glyph, so we can avoid
             // the cost of calling FindFontForChar.
             textRun->SetSpaceGlyph(font, aParams->mDrawTarget, 0, orientation);
         } else {
             // In case the primary font doesn't have <space> (bug 970891),
             // find one that does.
             uint8_t matchType;
             RefPtr<gfxFont> spaceFont =
-                FindFontForChar(' ', 0, 0, MOZ_SCRIPT_LATIN, nullptr,
+                FindFontForChar(' ', 0, 0, Script::LATIN, nullptr,
                                 &matchType);
             if (spaceFont) {
                 textRun->SetSpaceGlyph(spaceFont, aParams->mDrawTarget, 0,
                                        orientation);
             }
         }
     }
 
@@ -2200,46 +2200,46 @@ gfxFontGroup::InitTextRun(DrawTarget* aD
                         "len %d weight: %d width: %d style: %s size: %6.2f %d-byte "
                         "TEXTRUN [%s] ENDTEXTRUN\n",
                         (mStyle.systemFont ? "textrunui" : "textrun"),
                         NS_ConvertUTF16toUTF8(families).get(),
                         (mFamilyList.GetDefaultFontType() == eFamily_serif ?
                          "serif" :
                          (mFamilyList.GetDefaultFontType() == eFamily_sans_serif ?
                           "sans-serif" : "none")),
-                        lang.get(), MOZ_SCRIPT_LATIN, aLength,
+                        lang.get(), Script::LATIN, aLength,
                         uint32_t(mStyle.weight), uint32_t(mStyle.stretch),
                         (mStyle.style & NS_FONT_STYLE_ITALIC ? "italic" :
                         (mStyle.style & NS_FONT_STYLE_OBLIQUE ? "oblique" :
                                                                 "normal")),
                         mStyle.size,
                         sizeof(T),
                         str.get()));
             }
 
             // the text is still purely 8-bit; bypass the script-run itemizer
             // and treat it as a single Latin run
             InitScriptRun(aDrawTarget, aTextRun, aString,
-                          0, aLength, MOZ_SCRIPT_LATIN, aMFR);
+                          0, aLength, Script::LATIN, aMFR);
         } else {
             const char16_t *textPtr;
             if (transformedString) {
                 textPtr = transformedString.get();
             } else {
                 // typecast to avoid compilation error for the 8-bit version,
                 // even though this is dead code in that case
                 textPtr = reinterpret_cast<const char16_t*>(aString);
             }
 
             // split into script runs so that script can potentially influence
             // the font matching process below
             gfxScriptItemizer scriptRuns(textPtr, aLength);
 
             uint32_t runStart = 0, runLimit = aLength;
-            int32_t runScript = MOZ_SCRIPT_LATIN;
+            Script runScript = Script::LATIN;
             while (scriptRuns.Next(runStart, runLimit, runScript)) {
 
                 if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Warning))) {
                     nsAutoCString lang;
                     mStyle.language->ToUTF8String(lang);
                     nsAutoString families;
                     mFamilyList.ToString(families);
                     uint32_t runLen = runLimit - runStart;
@@ -2312,17 +2312,17 @@ template<typename T>
 void
 gfxFontGroup::InitScriptRun(DrawTarget* aDrawTarget,
                             gfxTextRun *aTextRun,
                             const T *aString, // text for this script run,
                                               // not the entire textrun
                             uint32_t aOffset, // position of the script run
                                               // within the textrun
                             uint32_t aLength, // length of the script run
-                            int32_t aRunScript,
+                            Script aRunScript,
                             gfxMissingFontRecorder *aMFR)
 {
     NS_ASSERTION(aLength > 0, "don't call InitScriptRun for a 0-length run");
     NS_ASSERTION(aTextRun->GetShapingState() != gfxTextRun::eShapingState_Aborted,
                  "don't call InitScriptRun with aborted shaping state");
 
     // confirm the load state of userfonts in the list
     if (!mSkipUpdateUserFonts && mUserFontSet &&
@@ -2575,17 +2575,17 @@ gfxFontGroup::GetEllipsisTextRun(int32_t
     // don't let the presence of a cached ellipsis textrun prolong the
     // fontgroup's life
     mCachedEllipsisTextRun->ReleaseFontGroup();
     return mCachedEllipsisTextRun.get();
 }
 
 already_AddRefed<gfxFont>
 gfxFontGroup::FindFallbackFaceForChar(gfxFontFamily* aFamily, uint32_t aCh,
-                                      int32_t aRunScript)
+                                      Script aRunScript)
 {
     GlobalFontMatch data(aCh, aRunScript, &mStyle);
     aFamily->SearchAllFontsForChar(&data);
     gfxFontEntry* fe = data.mBestMatch;
     if (!fe) {
         return nullptr;
     }
 
@@ -2627,17 +2627,17 @@ gfxFontGroup::GetUnderlineOffset()
             GetMetrics(gfxFont::eHorizontal).underlineOffset;
     }
 
     return mUnderlineOffset;
 }
 
 already_AddRefed<gfxFont>
 gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh, uint32_t aNextCh,
-                              int32_t aRunScript, gfxFont *aPrevMatchedFont,
+                              Script aRunScript, gfxFont *aPrevMatchedFont,
                               uint8_t *aMatchType)
 {
     // If the char is a cluster extender, we want to use the same font
     // as the preceding character if possible. This is preferable to using
     // the font group because it avoids breaks in shaping within a cluster.
     if (aPrevMatchedFont && IsClusterExtender(aCh) &&
         aPrevMatchedFont->HasCharacter(aCh)) {
         RefPtr<gfxFont> ret = aPrevMatchedFont;
@@ -2827,17 +2827,17 @@ gfxFontGroup::FindFontForChar(uint32_t a
     // -- before searching for something else check the font used for the previous character
     if (aPrevMatchedFont && aPrevMatchedFont->HasCharacter(aCh)) {
         *aMatchType = gfxTextRange::kSystemFallback;
         RefPtr<gfxFont> ret = aPrevMatchedFont;
         return ret.forget();
     }
 
     // never fall back for characters from unknown scripts
-    if (aRunScript == MOZ_SCRIPT_UNKNOWN) {
+    if (aRunScript == Script::UNKNOWN) {
         return nullptr;
     }
 
     // for known "space" characters, don't do a full system-fallback search;
     // we'll synthesize appropriate-width spaces instead of missing-glyph boxes
     if (GetGeneralCategory(aCh) ==
             HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR &&
         GetFirstValidFont()->SynthesizeSpaceWidth(aCh) >= 0.0)
@@ -2849,17 +2849,17 @@ gfxFontGroup::FindFontForChar(uint32_t a
     *aMatchType = gfxTextRange::kSystemFallback;
     font = WhichSystemFontSupportsChar(aCh, aNextCh, aRunScript);
     return font.forget();
 }
 
 template<typename T>
 void gfxFontGroup::ComputeRanges(nsTArray<gfxTextRange>& aRanges,
                                  const T *aString, uint32_t aLength,
-                                 int32_t aRunScript, uint16_t aOrientation)
+                                 Script aRunScript, uint16_t aOrientation)
 {
     NS_ASSERTION(aRanges.Length() == 0, "aRanges must be initially empty");
     NS_ASSERTION(aLength > 0, "don't call ComputeRanges for zero-length text");
 
     uint32_t prevCh = 0;
     uint32_t nextCh = aString[0];
     if (sizeof(T) == sizeof(char16_t)) {
         if (aLength > 1 && NS_IS_HIGH_SURROGATE(nextCh) &&
@@ -3157,17 +3157,17 @@ gfxFontGroup::WhichPrefFontSupportsChar(
         }
     }
 
     return nullptr;
 }
 
 already_AddRefed<gfxFont>
 gfxFontGroup::WhichSystemFontSupportsChar(uint32_t aCh, uint32_t aNextCh,
-                                          int32_t aRunScript)
+                                          Script aRunScript)
 {
     gfxFontEntry *fe = 
         gfxPlatformFontList::PlatformFontList()->
             SystemFindFontForChar(aCh, aNextCh, aRunScript, &mStyle);
     if (fe) {
         bool wantBold = mStyle.ComputeWeight() >= 6;
         RefPtr<gfxFont> font =
             fe->FindOrMakeFont(&mStyle, wantBold && !fe->IsBold());
@@ -3204,17 +3204,20 @@ gfxMissingFontRecorder::Flush()
         for (uint32_t j = 0; j < 32; ++j) {
             if (!(mMissingFonts[i] & (1 << j))) {
                 continue;
             }
             mNotifiedFonts[i] |= (1 << j);
             if (!fontNeeded.IsEmpty()) {
                 fontNeeded.Append(char16_t(','));
             }
-            uint32_t tag = GetScriptTagForCode(i * 32 + j);
+            uint32_t sc = i * 32 + j;
+            MOZ_ASSERT(sc < static_cast<uint32_t>(Script::NUM_SCRIPT_CODES),
+                       "how did we set the bit for an invalid script code?");
+            uint32_t tag = GetScriptTagForCode(static_cast<Script>(sc));
             fontNeeded.Append(char16_t(tag >> 24));
             fontNeeded.Append(char16_t((tag >> 16) & 0xff));
             fontNeeded.Append(char16_t((tag >> 8) & 0xff));
             fontNeeded.Append(char16_t(tag & 0xff));
         }
         mMissingFonts[i] = 0;
     }
     if (!fontNeeded.IsEmpty()) {
--- a/gfx/thebes/gfxTextRun.h
+++ b/gfx/thebes/gfxTextRun.h
@@ -754,16 +754,18 @@ private:
 
     // shaping state for handling variant fallback features
     // such as subscript/superscript variant glyphs
     ShapingState      mShapingState;
 };
 
 class gfxFontGroup : public gfxTextRunFactory {
 public:
+    typedef mozilla::unicode::Script Script;
+
     static void Shutdown(); // platform must call this to release the languageAtomService
 
     gfxFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
                  const gfxFontStyle* aStyle,
                  gfxTextPerfMetrics* aTextPerf,
                  gfxUserFontSet* aUserFontSet,
                  gfxFloat aDevToCssSize);
 
@@ -858,17 +860,17 @@ public:
     // initialized mUnderlineOffset. The value should be lower value of
     // first font's metrics and the bad font's metrics. Otherwise, this
     // returns from first font's metrics.
     enum { UNDERLINE_OFFSET_NOT_SET = INT16_MAX };
     virtual gfxFloat GetUnderlineOffset();
 
     virtual already_AddRefed<gfxFont>
         FindFontForChar(uint32_t ch, uint32_t prevCh, uint32_t aNextCh,
-                        int32_t aRunScript, gfxFont *aPrevMatchedFont,
+                        Script aRunScript, gfxFont *aPrevMatchedFont,
                         uint8_t *aMatchType);
 
     gfxUserFontSet* GetUserFontSet();
 
     // With downloadable fonts, the composition of the font group can change as fonts are downloaded
     // for each change in state of the user font set, the generation value is bumped to avoid picking up
     // previously created text runs in the text run word cache.  For font groups based on stylesheets
     // with no @font-face rule, this always returns 0.
@@ -907,22 +909,22 @@ public:
                                    LazyReferenceDrawTargetGetter& aRefDrawTargetGetter);
 
 protected:
     // search through pref fonts for a character, return nullptr if no matching pref font
     already_AddRefed<gfxFont> WhichPrefFontSupportsChar(uint32_t aCh);
 
     already_AddRefed<gfxFont>
         WhichSystemFontSupportsChar(uint32_t aCh, uint32_t aNextCh,
-                                    int32_t aRunScript);
+                                    Script aRunScript);
 
     template<typename T>
     void ComputeRanges(nsTArray<gfxTextRange>& mRanges,
                        const T *aString, uint32_t aLength,
-                       int32_t aRunScript, uint16_t aOrientation);
+                       Script aRunScript, uint16_t aOrientation);
 
     class FamilyFace {
     public:
         FamilyFace() : mFamily(nullptr), mFontEntry(nullptr),
                        mNeedsBold(false), mFontCreated(false),
                        mLoading(false), mInvalid(false),
                        mCheckForFallbackFaces(false)
         { }
@@ -1139,25 +1141,25 @@ protected:
     // InitTextRun helper to handle a single script run, by finding font ranges
     // and calling each font's InitTextRun() as appropriate
     template<typename T>
     void InitScriptRun(DrawTarget* aDrawTarget,
                        gfxTextRun *aTextRun,
                        const T *aString,
                        uint32_t aScriptRunStart,
                        uint32_t aScriptRunEnd,
-                       int32_t aRunScript,
+                       Script aRunScript,
                        gfxMissingFontRecorder *aMFR);
 
     // Helper for font-matching:
     // search all faces in a family for a fallback in cases where it's unclear
     // whether the family might have a font for a given character
     already_AddRefed<gfxFont>
     FindFallbackFaceForChar(gfxFontFamily* aFamily, uint32_t aCh,
-                            int32_t aRunScript);
+                            Script aRunScript);
 
    // helper methods for looking up fonts
 
     // lookup and add a font with a given name (i.e. *not* a generic!)
     void AddPlatformFont(const nsAString& aName,
                          nsTArray<gfxFontFamily*>& aFamilyList);
 
     // do style selection and add entries to list
@@ -1188,33 +1190,33 @@ public:
             NS_ASSERTION(mMissingFonts[i] == 0,
                          "failed to flush the missing-font recorder");
         }
 #endif
         MOZ_COUNT_DTOR(gfxMissingFontRecorder);
     }
 
     // record this script code in our mMissingFonts bitset
-    void RecordScript(int32_t aScriptCode)
+    void RecordScript(mozilla::unicode::Script aScriptCode)
     {
-        mMissingFonts[uint32_t(aScriptCode) >> 5] |=
-            (1 << (uint32_t(aScriptCode) & 0x1f));
+        mMissingFonts[static_cast<uint32_t>(aScriptCode) >> 5] |=
+            (1 << (static_cast<uint32_t>(aScriptCode) & 0x1f));
     }
 
     // send a notification of any missing-scripts that have been
     // recorded, and clear the mMissingFonts set for re-use
     void Flush();
 
     // forget any missing-scripts that have been recorded up to now;
     // called before discarding a recorder we no longer care about
     void Clear()
     {
         memset(&mMissingFonts, 0, sizeof(mMissingFonts));
     }
 
 private:
     // Number of 32-bit words needed for the missing-script flags
     static const uint32_t kNumScriptBitsWords =
-        ((MOZ_NUM_SCRIPT_CODES + 31) / 32);
+        ((static_cast<int>(mozilla::unicode::Script::NUM_SCRIPT_CODES) + 31) / 32);
     uint32_t mMissingFonts[kNumScriptBitsWords];
 };
 
 #endif
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -698,17 +698,17 @@ static const char kFontSegoeUIEmoji[] = 
 static const char kFontSegoeUISymbol[] = "Segoe UI Symbol";
 static const char kFontSylfaen[] = "Sylfaen";
 static const char kFontTraditionalArabic[] = "Traditional Arabic";
 static const char kFontUtsaah[] = "Utsaah";
 static const char kFontYuGothic[] = "Yu Gothic";
 
 void
 gfxWindowsPlatform::GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
-                                           int32_t aRunScript,
+                                           Script aRunScript,
                                            nsTArray<const char*>& aFontList)
 {
     if (aNextCh == 0xfe0fu) {
         aFontList.AppendElement(kFontSegoeUIEmoji);
     }
 
     // Arial is used as the default fallback for system fallback
     aFontList.AppendElement(kFontArial);
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -156,17 +156,17 @@ public:
      * it is non-functional or non-existant.
      *
      * \param aAttemptForce Attempt to force D2D cairo device creation by using
      * cairo device creation routines.
      */
     void VerifyD2DDevice(bool aAttemptForce);
 
     virtual void GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
-                                        int32_t aRunScript,
+                                        Script aRunScript,
                                         nsTArray<const char*>& aFontList) override;
 
     gfxFontGroup*
     CreateFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
                     const gfxFontStyle *aStyle,
                     gfxTextPerfMetrics* aTextPerf,
                     gfxUserFontSet *aUserFontSet,
                     gfxFloat aDevToCssSize) override;
--- a/intl/unicharutil/tools/genUnicodePropertyData.pl
+++ b/intl/unicharutil/tools/genUnicodePropertyData.pl
@@ -795,23 +795,27 @@ sub genTables
 print DATA_TABLES <<__END;
 /*
  * * * * * This file contains MACHINE-GENERATED DATA, do not edit! * * * * *
  */
 __END
 
 close DATA_TABLES;
 
-print HEADER "enum {\n";
+print HEADER "namespace mozilla {\n";
+print HEADER "namespace unicode {\n";
+print HEADER "enum class Script {\n";
 for (my $i = 0; $i < scalar @scriptCodeToName; ++$i) {
-  print HEADER "  MOZ_SCRIPT_", $scriptCodeToName[$i], " = ", $i, ",\n";
+  print HEADER "  ", $scriptCodeToName[$i], " = ", $i, ",\n";
 }
-print HEADER "\n  MOZ_NUM_SCRIPT_CODES = ", scalar @scriptCodeToName, ",\n";
-print HEADER "\n  MOZ_SCRIPT_INVALID = -1\n";
-print HEADER "};\n\n";
+print HEADER "\n  NUM_SCRIPT_CODES = ", scalar @scriptCodeToName, ",\n";
+print HEADER "\n  INVALID = -1\n";
+print HEADER "};\n";
+print HEADER "} // namespace unicode\n";
+print HEADER "} // namespace mozilla\n\n";
 
 print HEADER <<__END;
 #endif
 /*
  * * * * * This file contains MACHINE-GENERATED DATA, do not edit! * * * * *
  */
 __END
 
--- a/intl/unicharutil/util/nsUnicodeProperties.cpp
+++ b/intl/unicharutil/util/nsUnicodeProperties.cpp
@@ -58,17 +58,17 @@ GetCharProps2(uint32_t aCh)
     // Default values for unassigned
     using namespace mozilla::unicode;
     static const nsCharProps2 undefined = {
 #if ENABLE_INTL_API
         PAIRED_BRACKET_TYPE_NONE,
         VERTICAL_ORIENTATION_R,
         XIDMOD_NOT_CHARS
 #else
-        MOZ_SCRIPT_UNKNOWN,
+        uint8_t(Script::UNKNOWN),
         PAIRED_BRACKET_TYPE_NONE,
         HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED,
         eCharType_LeftToRight,
         XIDMOD_NOT_CHARS,
         -1, // Numeric Value
         VERTICAL_ORIENTATION_R
 #endif
     };
@@ -225,39 +225,39 @@ GetCombiningClass(uint32_t aCh)
 {
 #if ENABLE_INTL_API
     return u_getCombiningClass(aCh);
 #else
     return GetCharProps1(aCh).mCombiningClass;
 #endif
 }
 
-uint8_t
+Script
 GetScriptCode(uint32_t aCh)
 {
 #if ENABLE_INTL_API
     UErrorCode err = U_ZERO_ERROR;
-    return uscript_getScript(aCh, &err);
+    return Script(uscript_getScript(aCh, &err));
 #else
-    return GetCharProps2(aCh).mScriptCode;
+    return Script(GetCharProps2(aCh).mScriptCode);
 #endif
 }
 
 uint32_t
-GetScriptTagForCode(int32_t aScriptCode)
+GetScriptTagForCode(Script aScriptCode)
 {
 #if ENABLE_INTL_API
     const char* tag = uscript_getShortName(UScriptCode(aScriptCode));
     return HB_TAG(tag[0], tag[1], tag[2], tag[3]);
 #else
     // this will safely return 0 for negative script codes, too :)
-    if (uint32_t(aScriptCode) > ArrayLength(sScriptCodeToTag)) {
+    if (static_cast<uint32_t>(aScriptCode) > ArrayLength(sScriptCodeToTag)) {
         return 0;
     }
-    return sScriptCodeToTag[aScriptCode];
+    return sScriptCodeToTag[static_cast<uint32_t>(aScriptCode)];
 #endif
 }
 
 PairedBracketType GetPairedBracketType(uint32_t aCh)
 {
 #if ENABLE_INTL_API
   return PairedBracketType
            (u_getIntPropertyValue(aCh, UCHAR_BIDI_PAIRED_BRACKET_TYPE));
--- a/intl/unicharutil/util/nsUnicodeProperties.h
+++ b/intl/unicharutil/util/nsUnicodeProperties.h
@@ -30,19 +30,19 @@ uint8_t GetGeneralCategory(uint32_t aCh)
 
 // returns the simplified Gen Category as defined in nsIUGenCategory
 inline nsIUGenCategory::nsUGenCategory GetGenCategory(uint32_t aCh) {
   return sDetailedToGeneralCategory[GetGeneralCategory(aCh)];
 }
 
 nsCharType GetBidiCat(uint32_t aCh);
 
-uint8_t GetScriptCode(uint32_t aCh);
+Script GetScriptCode(uint32_t aCh);
 
-uint32_t GetScriptTagForCode(int32_t aScriptCode);
+uint32_t GetScriptTagForCode(Script aScriptCode);
 
 /* This MUST match the values assigned by genUnicodePropertyData.pl! */
 enum VerticalOrientation {
   VERTICAL_ORIENTATION_U  = 0,
   VERTICAL_ORIENTATION_R  = 1,
   VERTICAL_ORIENTATION_Tu = 2,
   VERTICAL_ORIENTATION_Tr = 3
 };
--- a/intl/unicharutil/util/nsUnicodePropertyData.cpp
+++ b/intl/unicharutil/util/nsUnicodePropertyData.cpp
@@ -6,17 +6,17 @@
 
 /*
  * Derived from the Unicode Character Database by genUnicodePropertyData.pl
  *
  * For Unicode terms of use, see http://www.unicode.org/terms_of_use.html
  */
 
 /*
- * Created on Thu Nov 26 21:24:13 2015 from UCD data files with version info:
+ * Created on Thu Apr 21 12:58:48 2016 from UCD data files with version info:
  *
 
 # Date: 2015-06-16, 20:24:00 GMT [KW]
 #
 # Unicode Character Database
 # Copyright (c) 1991-2015 Unicode, Inc.
 # For terms of use, see http://www.unicode.org/terms_of_use.html
 #
--- a/intl/unicharutil/util/nsUnicodeScriptCodes.h
+++ b/intl/unicharutil/util/nsUnicodeScriptCodes.h
@@ -6,17 +6,17 @@
 
 /*
  * Derived from the Unicode Character Database by genUnicodePropertyData.pl
  *
  * For Unicode terms of use, see http://www.unicode.org/terms_of_use.html
  */
 
 /*
- * Created on Thu Nov 26 21:24:13 2015 from UCD data files with version info:
+ * Created on Thu Apr 21 12:58:48 2016 from UCD data files with version info:
  *
 
 # Date: 2015-06-16, 20:24:00 GMT [KW]
 #
 # Unicode Character Database
 # Copyright (c) 1991-2015 Unicode, Inc.
 # For terms of use, see http://www.unicode.org/terms_of_use.html
 #
@@ -95,186 +95,190 @@ struct nsCharProps2 {
   signed char   mNumericValue:5;
   unsigned char mVertOrient:2;
 };
 
 #endif
 
 #pragma pack()
 
-enum {
-  MOZ_SCRIPT_COMMON = 0,
-  MOZ_SCRIPT_INHERITED = 1,
-  MOZ_SCRIPT_ARABIC = 2,
-  MOZ_SCRIPT_ARMENIAN = 3,
-  MOZ_SCRIPT_BENGALI = 4,
-  MOZ_SCRIPT_BOPOMOFO = 5,
-  MOZ_SCRIPT_CHEROKEE = 6,
-  MOZ_SCRIPT_COPTIC = 7,
-  MOZ_SCRIPT_CYRILLIC = 8,
-  MOZ_SCRIPT_DESERET = 9,
-  MOZ_SCRIPT_DEVANAGARI = 10,
-  MOZ_SCRIPT_ETHIOPIC = 11,
-  MOZ_SCRIPT_GEORGIAN = 12,
-  MOZ_SCRIPT_GOTHIC = 13,
-  MOZ_SCRIPT_GREEK = 14,
-  MOZ_SCRIPT_GUJARATI = 15,
-  MOZ_SCRIPT_GURMUKHI = 16,
-  MOZ_SCRIPT_HAN = 17,
-  MOZ_SCRIPT_HANGUL = 18,
-  MOZ_SCRIPT_HEBREW = 19,
-  MOZ_SCRIPT_HIRAGANA = 20,
-  MOZ_SCRIPT_KANNADA = 21,
-  MOZ_SCRIPT_KATAKANA = 22,
-  MOZ_SCRIPT_KHMER = 23,
-  MOZ_SCRIPT_LAO = 24,
-  MOZ_SCRIPT_LATIN = 25,
-  MOZ_SCRIPT_MALAYALAM = 26,
-  MOZ_SCRIPT_MONGOLIAN = 27,
-  MOZ_SCRIPT_MYANMAR = 28,
-  MOZ_SCRIPT_OGHAM = 29,
-  MOZ_SCRIPT_OLD_ITALIC = 30,
-  MOZ_SCRIPT_ORIYA = 31,
-  MOZ_SCRIPT_RUNIC = 32,
-  MOZ_SCRIPT_SINHALA = 33,
-  MOZ_SCRIPT_SYRIAC = 34,
-  MOZ_SCRIPT_TAMIL = 35,
-  MOZ_SCRIPT_TELUGU = 36,
-  MOZ_SCRIPT_THAANA = 37,
-  MOZ_SCRIPT_THAI = 38,
-  MOZ_SCRIPT_TIBETAN = 39,
-  MOZ_SCRIPT_CANADIAN_ABORIGINAL = 40,
-  MOZ_SCRIPT_YI = 41,
-  MOZ_SCRIPT_TAGALOG = 42,
-  MOZ_SCRIPT_HANUNOO = 43,
-  MOZ_SCRIPT_BUHID = 44,
-  MOZ_SCRIPT_TAGBANWA = 45,
-  MOZ_SCRIPT_BRAILLE = 46,
-  MOZ_SCRIPT_CYPRIOT = 47,
-  MOZ_SCRIPT_LIMBU = 48,
-  MOZ_SCRIPT_LINEAR_B = 49,
-  MOZ_SCRIPT_OSMANYA = 50,
-  MOZ_SCRIPT_SHAVIAN = 51,
-  MOZ_SCRIPT_TAI_LE = 52,
-  MOZ_SCRIPT_UGARITIC = 53,
-  MOZ_SCRIPT_KATAKANA_OR_HIRAGANA = 54,
-  MOZ_SCRIPT_BUGINESE = 55,
-  MOZ_SCRIPT_GLAGOLITIC = 56,
-  MOZ_SCRIPT_KHAROSHTHI = 57,
-  MOZ_SCRIPT_SYLOTI_NAGRI = 58,
-  MOZ_SCRIPT_NEW_TAI_LUE = 59,
-  MOZ_SCRIPT_TIFINAGH = 60,
-  MOZ_SCRIPT_OLD_PERSIAN = 61,
-  MOZ_SCRIPT_BALINESE = 62,
-  MOZ_SCRIPT_BATAK = 63,
-  MOZ_SCRIPT_BLISSYMBOLS = 64,
-  MOZ_SCRIPT_BRAHMI = 65,
-  MOZ_SCRIPT_CHAM = 66,
-  MOZ_SCRIPT_CIRTH = 67,
-  MOZ_SCRIPT_OLD_CHURCH_SLAVONIC_CYRILLIC = 68,
-  MOZ_SCRIPT_DEMOTIC_EGYPTIAN = 69,
-  MOZ_SCRIPT_HIERATIC_EGYPTIAN = 70,
-  MOZ_SCRIPT_EGYPTIAN_HIEROGLYPHS = 71,
-  MOZ_SCRIPT_KHUTSURI = 72,
-  MOZ_SCRIPT_SIMPLIFIED_HAN = 73,
-  MOZ_SCRIPT_TRADITIONAL_HAN = 74,
-  MOZ_SCRIPT_PAHAWH_HMONG = 75,
-  MOZ_SCRIPT_OLD_HUNGARIAN = 76,
-  MOZ_SCRIPT_HARAPPAN_INDUS = 77,
-  MOZ_SCRIPT_JAVANESE = 78,
-  MOZ_SCRIPT_KAYAH_LI = 79,
-  MOZ_SCRIPT_LATIN_FRAKTUR = 80,
-  MOZ_SCRIPT_LATIN_GAELIC = 81,
-  MOZ_SCRIPT_LEPCHA = 82,
-  MOZ_SCRIPT_LINEAR_A = 83,
-  MOZ_SCRIPT_MANDAIC = 84,
-  MOZ_SCRIPT_MAYAN_HIEROGLYPHS = 85,
-  MOZ_SCRIPT_MEROITIC_HIEROGLYPHS = 86,
-  MOZ_SCRIPT_NKO = 87,
-  MOZ_SCRIPT_OLD_TURKIC = 88,
-  MOZ_SCRIPT_OLD_PERMIC = 89,
-  MOZ_SCRIPT_PHAGS_PA = 90,
-  MOZ_SCRIPT_PHOENICIAN = 91,
-  MOZ_SCRIPT_MIAO = 92,
-  MOZ_SCRIPT_RONGORONGO = 93,
-  MOZ_SCRIPT_SARATI = 94,
-  MOZ_SCRIPT_ESTRANGELO_SYRIAC = 95,
-  MOZ_SCRIPT_WESTERN_SYRIAC = 96,
-  MOZ_SCRIPT_EASTERN_SYRIAC = 97,
-  MOZ_SCRIPT_TENGWAR = 98,
-  MOZ_SCRIPT_VAI = 99,
-  MOZ_SCRIPT_VISIBLE_SPEECH = 100,
-  MOZ_SCRIPT_CUNEIFORM = 101,
-  MOZ_SCRIPT_UNWRITTEN_LANGUAGES = 102,
-  MOZ_SCRIPT_UNKNOWN = 103,
-  MOZ_SCRIPT_CARIAN = 104,
-  MOZ_SCRIPT_JAPANESE = 105,
-  MOZ_SCRIPT_TAI_THAM = 106,
-  MOZ_SCRIPT_LYCIAN = 107,
-  MOZ_SCRIPT_LYDIAN = 108,
-  MOZ_SCRIPT_OL_CHIKI = 109,
-  MOZ_SCRIPT_REJANG = 110,
-  MOZ_SCRIPT_SAURASHTRA = 111,
-  MOZ_SCRIPT_SIGNWRITING = 112,
-  MOZ_SCRIPT_SUNDANESE = 113,
-  MOZ_SCRIPT_MOON = 114,
-  MOZ_SCRIPT_MEETEI_MAYEK = 115,
-  MOZ_SCRIPT_IMPERIAL_ARAMAIC = 116,
-  MOZ_SCRIPT_AVESTAN = 117,
-  MOZ_SCRIPT_CHAKMA = 118,
-  MOZ_SCRIPT_KOREAN = 119,
-  MOZ_SCRIPT_KAITHI = 120,
-  MOZ_SCRIPT_MANICHAEAN = 121,
-  MOZ_SCRIPT_INSCRIPTIONAL_PAHLAVI = 122,
-  MOZ_SCRIPT_PSALTER_PAHLAVI = 123,
-  MOZ_SCRIPT_BOOK_PAHLAVI = 124,
-  MOZ_SCRIPT_INSCRIPTIONAL_PARTHIAN = 125,
-  MOZ_SCRIPT_SAMARITAN = 126,
-  MOZ_SCRIPT_TAI_VIET = 127,
-  MOZ_SCRIPT_MATHEMATICAL_NOTATION = 128,
-  MOZ_SCRIPT_SYMBOLS = 129,
-  MOZ_SCRIPT_BAMUM = 130,
-  MOZ_SCRIPT_LISU = 131,
-  MOZ_SCRIPT_NAKHI_GEBA = 132,
-  MOZ_SCRIPT_OLD_SOUTH_ARABIAN = 133,
-  MOZ_SCRIPT_BASSA_VAH = 134,
-  MOZ_SCRIPT_DUPLOYAN = 135,
-  MOZ_SCRIPT_ELBASAN = 136,
-  MOZ_SCRIPT_GRANTHA = 137,
-  MOZ_SCRIPT_KPELLE = 138,
-  MOZ_SCRIPT_LOMA = 139,
-  MOZ_SCRIPT_MENDE_KIKAKUI = 140,
-  MOZ_SCRIPT_MEROITIC_CURSIVE = 141,
-  MOZ_SCRIPT_OLD_NORTH_ARABIAN = 142,
-  MOZ_SCRIPT_NABATAEAN = 143,
-  MOZ_SCRIPT_PALMYRENE = 144,
-  MOZ_SCRIPT_KHUDAWADI = 145,
-  MOZ_SCRIPT_WARANG_CITI = 146,
-  MOZ_SCRIPT_AFAKA = 147,
-  MOZ_SCRIPT_JURCHEN = 148,
-  MOZ_SCRIPT_MRO = 149,
-  MOZ_SCRIPT_NUSHU = 150,
-  MOZ_SCRIPT_SHARADA = 151,
-  MOZ_SCRIPT_SORA_SOMPENG = 152,
-  MOZ_SCRIPT_TAKRI = 153,
-  MOZ_SCRIPT_TANGUT = 154,
-  MOZ_SCRIPT_WOLEAI = 155,
-  MOZ_SCRIPT_ANATOLIAN_HIEROGLYPHS = 156,
-  MOZ_SCRIPT_KHOJKI = 157,
-  MOZ_SCRIPT_TIRHUTA = 158,
-  MOZ_SCRIPT_CAUCASIAN_ALBANIAN = 159,
-  MOZ_SCRIPT_MAHAJANI = 160,
-  MOZ_SCRIPT_AHOM = 161,
-  MOZ_SCRIPT_HATRAN = 162,
-  MOZ_SCRIPT_MODI = 163,
-  MOZ_SCRIPT_MULTANI = 164,
-  MOZ_SCRIPT_PAU_CIN_HAU = 165,
-  MOZ_SCRIPT_SIDDHAM = 166,
+namespace mozilla {
+namespace unicode {
+enum class Script {
+  COMMON = 0,
+  INHERITED = 1,
+  ARABIC = 2,
+  ARMENIAN = 3,
+  BENGALI = 4,
+  BOPOMOFO = 5,
+  CHEROKEE = 6,
+  COPTIC = 7,
+  CYRILLIC = 8,
+  DESERET = 9,
+  DEVANAGARI = 10,
+  ETHIOPIC = 11,
+  GEORGIAN = 12,
+  GOTHIC = 13,
+  GREEK = 14,
+  GUJARATI = 15,
+  GURMUKHI = 16,
+  HAN = 17,
+  HANGUL = 18,
+  HEBREW = 19,
+  HIRAGANA = 20,
+  KANNADA = 21,
+  KATAKANA = 22,
+  KHMER = 23,
+  LAO = 24,
+  LATIN = 25,
+  MALAYALAM = 26,
+  MONGOLIAN = 27,
+  MYANMAR = 28,
+  OGHAM = 29,
+  OLD_ITALIC = 30,
+  ORIYA = 31,
+  RUNIC = 32,
+  SINHALA = 33,
+  SYRIAC = 34,
+  TAMIL = 35,
+  TELUGU = 36,
+  THAANA = 37,
+  THAI = 38,
+  TIBETAN = 39,
+  CANADIAN_ABORIGINAL = 40,
+  YI = 41,
+  TAGALOG = 42,
+  HANUNOO = 43,
+  BUHID = 44,
+  TAGBANWA = 45,
+  BRAILLE = 46,
+  CYPRIOT = 47,
+  LIMBU = 48,
+  LINEAR_B = 49,
+  OSMANYA = 50,
+  SHAVIAN = 51,
+  TAI_LE = 52,
+  UGARITIC = 53,
+  KATAKANA_OR_HIRAGANA = 54,
+  BUGINESE = 55,
+  GLAGOLITIC = 56,
+  KHAROSHTHI = 57,
+  SYLOTI_NAGRI = 58,
+  NEW_TAI_LUE = 59,
+  TIFINAGH = 60,
+  OLD_PERSIAN = 61,
+  BALINESE = 62,
+  BATAK = 63,
+  BLISSYMBOLS = 64,
+  BRAHMI = 65,
+  CHAM = 66,
+  CIRTH = 67,
+  OLD_CHURCH_SLAVONIC_CYRILLIC = 68,
+  DEMOTIC_EGYPTIAN = 69,
+  HIERATIC_EGYPTIAN = 70,
+  EGYPTIAN_HIEROGLYPHS = 71,
+  KHUTSURI = 72,
+  SIMPLIFIED_HAN = 73,
+  TRADITIONAL_HAN = 74,
+  PAHAWH_HMONG = 75,
+  OLD_HUNGARIAN = 76,
+  HARAPPAN_INDUS = 77,
+  JAVANESE = 78,
+  KAYAH_LI = 79,
+  LATIN_FRAKTUR = 80,
+  LATIN_GAELIC = 81,
+  LEPCHA = 82,
+  LINEAR_A = 83,
+  MANDAIC = 84,
+  MAYAN_HIEROGLYPHS = 85,
+  MEROITIC_HIEROGLYPHS = 86,
+  NKO = 87,
+  OLD_TURKIC = 88,
+  OLD_PERMIC = 89,
+  PHAGS_PA = 90,
+  PHOENICIAN = 91,
+  MIAO = 92,
+  RONGORONGO = 93,
+  SARATI = 94,
+  ESTRANGELO_SYRIAC = 95,
+  WESTERN_SYRIAC = 96,
+  EASTERN_SYRIAC = 97,
+  TENGWAR = 98,
+  VAI = 99,
+  VISIBLE_SPEECH = 100,
+  CUNEIFORM = 101,
+  UNWRITTEN_LANGUAGES = 102,
+  UNKNOWN = 103,
+  CARIAN = 104,
+  JAPANESE = 105,
+  TAI_THAM = 106,
+  LYCIAN = 107,
+  LYDIAN = 108,
+  OL_CHIKI = 109,
+  REJANG = 110,
+  SAURASHTRA = 111,
+  SIGNWRITING = 112,
+  SUNDANESE = 113,
+  MOON = 114,
+  MEETEI_MAYEK = 115,
+  IMPERIAL_ARAMAIC = 116,
+  AVESTAN = 117,
+  CHAKMA = 118,
+  KOREAN = 119,
+  KAITHI = 120,
+  MANICHAEAN = 121,
+  INSCRIPTIONAL_PAHLAVI = 122,
+  PSALTER_PAHLAVI = 123,
+  BOOK_PAHLAVI = 124,
+  INSCRIPTIONAL_PARTHIAN = 125,
+  SAMARITAN = 126,
+  TAI_VIET = 127,
+  MATHEMATICAL_NOTATION = 128,
+  SYMBOLS = 129,
+  BAMUM = 130,
+  LISU = 131,
+  NAKHI_GEBA = 132,
+  OLD_SOUTH_ARABIAN = 133,
+  BASSA_VAH = 134,
+  DUPLOYAN = 135,
+  ELBASAN = 136,
+  GRANTHA = 137,
+  KPELLE = 138,
+  LOMA = 139,
+  MENDE_KIKAKUI = 140,
+  MEROITIC_CURSIVE = 141,
+  OLD_NORTH_ARABIAN = 142,
+  NABATAEAN = 143,
+  PALMYRENE = 144,
+  KHUDAWADI = 145,
+  WARANG_CITI = 146,
+  AFAKA = 147,
+  JURCHEN = 148,
+  MRO = 149,
+  NUSHU = 150,
+  SHARADA = 151,
+  SORA_SOMPENG = 152,
+  TAKRI = 153,
+  TANGUT = 154,
+  WOLEAI = 155,
+  ANATOLIAN_HIEROGLYPHS = 156,
+  KHOJKI = 157,
+  TIRHUTA = 158,
+  CAUCASIAN_ALBANIAN = 159,
+  MAHAJANI = 160,
+  AHOM = 161,
+  HATRAN = 162,
+  MODI = 163,
+  MULTANI = 164,
+  PAU_CIN_HAU = 165,
+  SIDDHAM = 166,
 
-  MOZ_NUM_SCRIPT_CODES = 167,
+  NUM_SCRIPT_CODES = 167,
 
-  MOZ_SCRIPT_INVALID = -1
+  INVALID = -1
 };
+} // namespace unicode
+} // namespace mozilla
 
 #endif
 /*
  * * * * * This file contains MACHINE-GENERATED DATA, do not edit! * * * * *
  */
--- a/layout/generic/MathMLTextRunFactory.cpp
+++ b/layout/generic/MathMLTextRunFactory.cpp
@@ -664,26 +664,26 @@ MathMLTextRunFactory::RebuildTextRun(nsT
         doMathvariantStyling = false;
       }
       if (ch2 != ch) {
         // Bug 930504. Some platforms do not have fonts for Mathematical
         // Alphanumeric Symbols. Hence we check whether the transformed
         // character is actually available.
         uint8_t matchType;
         RefPtr<gfxFont> mathFont = fontGroup->
-          FindFontForChar(ch2, 0, 0, MOZ_SCRIPT_COMMON, nullptr, &matchType);
+          FindFontForChar(ch2, 0, 0, unicode::Script::COMMON, nullptr, &matchType);
         if (mathFont) {
           // Don't apply the CSS style if there is a math font for at least one
           // of the transformed character in this text run.
           doMathvariantStyling = false;
         } else {
           // We fallback to the original character.
           ch2 = ch;
           if (aMFR) {
-            aMFR->RecordScript(MOZ_SCRIPT_MATHEMATICAL_NOTATION);
+            aMFR->RecordScript(unicode::Script::MATHEMATICAL_NOTATION);
           }
         }
       }
     }
 
     deletedCharsArray.AppendElement(false);
     charsToMergeArray.AppendElement(false);
     styleArray.AppendElement(styles[i]);
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -7587,61 +7587,62 @@ FindFirstLetterRange(const nsTextFragmen
 
   // consume another cluster (the actual first letter)
 
   // For complex scripts such as Indic and SEAsian, where first-letter
   // should extend to entire orthographic "syllable" clusters, we don't
   // want to allow this to split a ligature.
   bool allowSplitLigature;
 
+  typedef unicode::Script Script;
   switch (unicode::GetScriptCode(aFrag->CharAt(aOffset + i))) {
     default:
       allowSplitLigature = true;
       break;
 
     // For now, lacking any definitive specification of when to apply this
     // behavior, we'll base the decision on the HarfBuzz shaping engine
     // used for each script: those that are handled by the Indic, Tibetan,
     // Myanmar and SEAsian shapers will apply the "don't split ligatures"
     // rule.
 
     // Indic
-    case MOZ_SCRIPT_BENGALI:
-    case MOZ_SCRIPT_DEVANAGARI:
-    case MOZ_SCRIPT_GUJARATI:
-    case MOZ_SCRIPT_GURMUKHI:
-    case MOZ_SCRIPT_KANNADA:
-    case MOZ_SCRIPT_MALAYALAM:
-    case MOZ_SCRIPT_ORIYA:
-    case MOZ_SCRIPT_TAMIL:
-    case MOZ_SCRIPT_TELUGU:
-    case MOZ_SCRIPT_SINHALA:
-    case MOZ_SCRIPT_BALINESE:
-    case MOZ_SCRIPT_LEPCHA:
-    case MOZ_SCRIPT_REJANG:
-    case MOZ_SCRIPT_SUNDANESE:
-    case MOZ_SCRIPT_JAVANESE:
-    case MOZ_SCRIPT_KAITHI:
-    case MOZ_SCRIPT_MEETEI_MAYEK:
-    case MOZ_SCRIPT_CHAKMA:
-    case MOZ_SCRIPT_SHARADA:
-    case MOZ_SCRIPT_TAKRI:
-    case MOZ_SCRIPT_KHMER:
+    case Script::BENGALI:
+    case Script::DEVANAGARI:
+    case Script::GUJARATI:
+    case Script::GURMUKHI:
+    case Script::KANNADA:
+    case Script::MALAYALAM:
+    case Script::ORIYA:
+    case Script::TAMIL:
+    case Script::TELUGU:
+    case Script::SINHALA:
+    case Script::BALINESE:
+    case Script::LEPCHA:
+    case Script::REJANG:
+    case Script::SUNDANESE:
+    case Script::JAVANESE:
+    case Script::KAITHI:
+    case Script::MEETEI_MAYEK:
+    case Script::CHAKMA:
+    case Script::SHARADA:
+    case Script::TAKRI:
+    case Script::KHMER:
 
     // Tibetan
-    case MOZ_SCRIPT_TIBETAN:
+    case Script::TIBETAN:
 
     // Myanmar
-    case MOZ_SCRIPT_MYANMAR:
+    case Script::MYANMAR:
 
     // Other SEAsian
-    case MOZ_SCRIPT_BUGINESE:
-    case MOZ_SCRIPT_NEW_TAI_LUE:
-    case MOZ_SCRIPT_CHAM:
-    case MOZ_SCRIPT_TAI_THAM:
+    case Script::BUGINESE:
+    case Script::NEW_TAI_LUE:
+    case Script::CHAM:
+    case Script::TAI_THAM:
 
     // What about Thai/Lao - any special handling needed?
     // Should we special-case Arabic lam-alef?
 
       allowSplitLigature = false;
       break;
   }
 
--- a/layout/mathml/nsMathMLChar.cpp
+++ b/layout/mathml/nsMathMLChar.cpp
@@ -1684,17 +1684,17 @@ nsMathMLChar::StretchInternal(nsPresCont
     return NS_OK;
   }
 
   // We did not find a size variant or a glyph assembly to stretch this
   // operator. Verify whether a font with an OpenType MATH table is available
   // and record missing math script otherwise.
   gfxMissingFontRecorder* MFR = aPresContext->MissingFontRecorder();
   if (MFR && !fm->GetThebesFontGroup()->GetFirstMathFont()) {
-    MFR->RecordScript(MOZ_SCRIPT_MATHEMATICAL_NOTATION);
+    MFR->RecordScript(unicode::Script::MATHEMATICAL_NOTATION);
   }
 
   // If the scale_stretchy_operators option is disabled, we are done.
   if (!Preferences::GetBool("mathml.scale_stretchy_operators.enabled", true)) {
     return NS_OK;
   }
   
   // stretchy character
--- a/netwerk/dns/nsIDNService.cpp
+++ b/netwerk/dns/nsIDNService.cpp
@@ -793,17 +793,17 @@ bool nsIDNService::isLabelSafe(const nsA
   if (mRestrictionProfile == eASCIIOnlyProfile) {
     return false;
   }
 
   nsAString::const_iterator current, end;
   label.BeginReading(current);
   label.EndReading(end);
 
-  int32_t lastScript = MOZ_SCRIPT_INVALID;
+  Script lastScript = Script::INVALID;
   uint32_t previousChar = 0;
   uint32_t savedNumberingSystem = 0;
 // Simplified/Traditional Chinese check temporarily disabled -- bug 857481
 #if 0
   HanVariantType savedHanVariant = HVT_NotHan;
 #endif
 
   int32_t savedScript = -1;
@@ -820,19 +820,19 @@ bool nsIDNService::isLabelSafe(const nsA
     XidmodType xm = GetIdentifierModification(ch);
     if (xm != XIDMOD_RECOMMENDED &&
         xm != XIDMOD_INCLUSION &&
         xm != XIDMOD_ASPIRATIONAL) {
       return false;
     }
 
     // Check for mixed script
-    int32_t script = GetScriptCode(ch);
-    if (script != MOZ_SCRIPT_COMMON &&
-        script != MOZ_SCRIPT_INHERITED &&
+    Script script = GetScriptCode(ch);
+    if (script != Script::COMMON &&
+        script != Script::INHERITED &&
         script != lastScript) {
       if (illegalScriptCombo(script, savedScript)) {
         return false;
       }
       lastScript = script;
     }
 
     // Check for mixed numbering systems
@@ -870,37 +870,37 @@ bool nsIDNService::isLabelSafe(const nsA
 #endif
 
     previousChar = ch;
   }
   return true;
 }
 
 // Scripts that we care about in illegalScriptCombo
-static const int32_t scriptTable[] = {
-  MOZ_SCRIPT_BOPOMOFO, MOZ_SCRIPT_CYRILLIC, MOZ_SCRIPT_GREEK,
-  MOZ_SCRIPT_HANGUL,   MOZ_SCRIPT_HAN,      MOZ_SCRIPT_HIRAGANA,
-  MOZ_SCRIPT_KATAKANA, MOZ_SCRIPT_LATIN };
+static const Script scriptTable[] = {
+  Script::BOPOMOFO, Script::CYRILLIC, Script::GREEK,
+  Script::HANGUL,   Script::HAN,      Script::HIRAGANA,
+  Script::KATAKANA, Script::LATIN };
 
 #define BOPO 0
 #define CYRL 1
 #define GREK 2
 #define HANG 3
 #define HANI 4
 #define HIRA 5
 #define KATA 6
 #define LATN 7
 #define OTHR 8
 #define JPAN 9    // Latin + Han + Hiragana + Katakana
 #define CHNA 10   // Latin + Han + Bopomofo
 #define KORE 11   // Latin + Han + Hangul
 #define HNLT 12   // Latin + Han (could be any of the above combinations)
 #define FAIL 13
 
-static inline int32_t findScriptIndex(int32_t aScript)
+static inline int32_t findScriptIndex(Script aScript)
 {
   int32_t tableLength = sizeof(scriptTable) / sizeof(int32_t);
   for (int32_t index = 0; index < tableLength; ++index) {
     if (aScript == scriptTable[index]) {
       return index;
     }
   }
   return OTHR;
@@ -919,17 +919,17 @@ static const int32_t scriptComboTable[13
  /* LATN */  { CHNA, FAIL, FAIL, KORE, HNLT, JPAN, JPAN, LATN, OTHR },
  /* OTHR */  { FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, OTHR, FAIL },
  /* JPAN */  { FAIL, FAIL, FAIL, FAIL, JPAN, JPAN, JPAN, JPAN, FAIL },
  /* CHNA */  { CHNA, FAIL, FAIL, FAIL, CHNA, FAIL, FAIL, CHNA, FAIL },
  /* KORE */  { FAIL, FAIL, FAIL, KORE, KORE, FAIL, FAIL, KORE, FAIL },
  /* HNLT */  { CHNA, FAIL, FAIL, KORE, HNLT, JPAN, JPAN, HNLT, FAIL }
 };
 
-bool nsIDNService::illegalScriptCombo(int32_t script, int32_t& savedScript)
+bool nsIDNService::illegalScriptCombo(Script script, int32_t& savedScript)
 {
   if (savedScript == -1) {
     savedScript = findScriptIndex(script);
     return false;
   }
 
   savedScript = scriptComboTable[savedScript] [findScriptIndex(script)];
   /*
--- a/netwerk/dns/nsIDNService.h
+++ b/netwerk/dns/nsIDNService.h
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsIDNService_h__
 #define nsIDNService_h__
 
 #include "nsIIDNService.h"
 #include "nsCOMPtr.h"
 #include "nsIObserver.h"
+#include "nsUnicodeScriptCodes.h"
 #include "nsWeakReference.h"
 
 #ifdef IDNA2008
 #include "unicode/uidna.h"
 #else
 #include "nsIUnicodeNormalizer.h"
 #include "nsIDNKitInterface.h"
 #endif
@@ -142,17 +143,18 @@ private:
    * identifier must be from a single script, or from the combinations:
    *  Latin + Han + Hiragana + Katakana;
    *  Latin + Han + Bopomofo; or
    *  Latin + Han + Hangul
    *
    * For the "Moderately restrictive" profile, Latin is also allowed
    *  with other scripts except Cyrillic and Greek
    */
-  bool illegalScriptCombo(int32_t script, int32_t& savedScript);
+  bool illegalScriptCombo(mozilla::unicode::Script script,
+                          int32_t& savedScript);
 
 #ifdef IDNA2008
   /**
    * Convert a DNS label from ASCII to Unicode using IDNA2008
    */
   nsresult IDNA2008ToUnicode(const nsACString& input, nsAString& output);
 
   /**