RuntimeFuses.cpp (2518B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "vm/RuntimeFuses.h" 8 9 #include <stddef.h> 10 #include <stdint.h> 11 12 #include "builtin/String.h" 13 #include "js/friend/UsageStatistics.h" 14 #include "vm/GlobalObject.h" 15 #include "vm/JSContext.h" 16 #include "vm/Runtime.h" 17 18 using namespace js; 19 20 int32_t js::RuntimeFuses::fuseOffsets[uint8_t( 21 RuntimeFuses::FuseIndex::LastFuseIndex)] = { 22 #define FUSE(Name, LowerName) offsetof(RuntimeFuses, LowerName), 23 FOR_EACH_RUNTIME_FUSE(FUSE) 24 #undef FUSE 25 }; 26 27 // static 28 int32_t js::RuntimeFuses::offsetOfFuseWordRelativeToRuntime( 29 RuntimeFuses::FuseIndex index) { 30 int32_t base_offset = offsetof(JSRuntime, runtimeFuses); 31 int32_t fuse_offset = RuntimeFuses::fuseOffsets[uint8_t(index)]; 32 int32_t fuseWordOffset = GuardFuse::fuseOffset(); 33 34 return base_offset + fuse_offset + fuseWordOffset; 35 } 36 37 const char* js::RuntimeFuses::fuseNames[] = { 38 #define FUSE(Name, LowerName) #LowerName, 39 FOR_EACH_RUNTIME_FUSE(FUSE) 40 #undef FUSE 41 }; 42 43 // TODO: It is not elegant that we have both this mechanism, but also 44 // GuardFuse::name, and all the overrides for naming fuses. The issue is 45 // that this method is static to handle consumers that don't have a 46 // RuntimeFuses around but work with indexes (e.g. spew code). 47 // 48 // I'd love it if we had a better answer. 49 const char* js::RuntimeFuses::getFuseName(RuntimeFuses::FuseIndex index) { 50 uint8_t rawIndex = uint8_t(index); 51 MOZ_ASSERT(index < RuntimeFuses::FuseIndex::LastFuseIndex); 52 return fuseNames[rawIndex]; 53 } 54 55 void js::HasSeenObjectEmulateUndefinedFuse::popFuse(JSContext* cx) { 56 js::InvalidatingRuntimeFuse::popFuse(cx); 57 MOZ_ASSERT(cx->global()); 58 cx->runtime()->setUseCounter(cx->global(), JSUseCounter::ISHTMLDDA_FUSE); 59 } 60 61 void js::HasSeenArrayExceedsInt32LengthFuse::popFuse(JSContext* cx) { 62 js::InvalidatingRuntimeFuse::popFuse(cx); 63 } 64 65 bool js::DefaultLocaleHasDefaultCaseMappingFuse::checkInvariant(JSContext* cx) { 66 #if JS_HAS_INTL_API 67 const char* locale = cx->runtime()->getDefaultLocaleIfInitialized(); 68 if (!locale) { 69 return true; 70 } 71 return LocaleHasDefaultCaseMapping(locale); 72 #else 73 return true; 74 #endif 75 } 76 77 void js::DefaultLocaleHasDefaultCaseMappingFuse::popFuse(JSContext* cx) { 78 js::InvalidatingRuntimeFuse::popFuse(cx); 79 }