Bug 1288457 - Part 8: Use constexpr instead of #defines in js/Class. r=mgaudet

Differential Revision: https://phabricator.services.mozilla.com/D42877

--HG--
extra : moz-landing-system : lando
This commit is contained in:
André Bargull 2019-10-16 12:34:04 +00:00
Родитель ac8c5901a2
Коммит d14b6d410a
1 изменённых файлов: 36 добавлений и 25 удалений

Просмотреть файл

@ -642,9 +642,6 @@ struct MOZ_STATIC_CLASS ClassExtension {
JSObjectMovedOp objectMovedOp;
};
#define JS_NULL_CLASS_SPEC nullptr
#define JS_NULL_CLASS_EXT nullptr
struct MOZ_STATIC_CLASS ObjectOps {
LookupPropertyOp lookupProperty;
DefinePropertyOp defineProperty;
@ -657,10 +654,13 @@ struct MOZ_STATIC_CLASS ObjectOps {
JSFunToStringOp funToString;
};
#define JS_NULL_OBJECT_OPS nullptr
} // namespace js
static constexpr const js::ClassSpec* JS_NULL_CLASS_SPEC = nullptr;
static constexpr const js::ClassExtension* JS_NULL_CLASS_EXT = nullptr;
static constexpr const js::ObjectOps* JS_NULL_OBJECT_OPS = nullptr;
// Classes, objects, and properties.
// Objects have private slot.
@ -703,14 +703,12 @@ static const uint32_t JSCLASS_RESERVED_SLOTS_WIDTH = 8;
static const uint32_t JSCLASS_RESERVED_SLOTS_MASK =
JS_BITMASK(JSCLASS_RESERVED_SLOTS_WIDTH);
#define JSCLASS_HAS_RESERVED_SLOTS(n) \
(((n)&JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)
#define JSCLASS_RESERVED_SLOTS(clasp) \
(((clasp)->flags >> JSCLASS_RESERVED_SLOTS_SHIFT) & \
JSCLASS_RESERVED_SLOTS_MASK)
static constexpr uint32_t JSCLASS_HAS_RESERVED_SLOTS(uint32_t n) {
return (n & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT;
}
#define JSCLASS_HIGH_FLAGS_SHIFT \
(JSCLASS_RESERVED_SLOTS_SHIFT + JSCLASS_RESERVED_SLOTS_WIDTH)
static constexpr uint32_t JSCLASS_HIGH_FLAGS_SHIFT =
JSCLASS_RESERVED_SLOTS_SHIFT + JSCLASS_RESERVED_SLOTS_WIDTH;
static const uint32_t JSCLASS_INTERNAL_FLAG1 =
1 << (JSCLASS_HIGH_FLAGS_SHIFT + 0);
@ -752,13 +750,13 @@ static const uint32_t JSCLASS_GLOBAL_APPLICATION_SLOTS = 5;
static const uint32_t JSCLASS_GLOBAL_SLOT_COUNT =
JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 2 + 32;
#define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n) \
(JSCLASS_IS_GLOBAL | \
JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + (n)))
#define JSCLASS_GLOBAL_FLAGS JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(0)
#define JSCLASS_HAS_GLOBAL_FLAG_AND_SLOTS(clasp) \
(((clasp)->flags & JSCLASS_IS_GLOBAL) && \
JSCLASS_RESERVED_SLOTS(clasp) >= JSCLASS_GLOBAL_SLOT_COUNT)
static constexpr uint32_t JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(uint32_t n) {
return JSCLASS_IS_GLOBAL |
JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + n);
}
static constexpr uint32_t JSCLASS_GLOBAL_FLAGS =
JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(0);
// Fast access to the original value of each standard class's prototype.
static const uint32_t JSCLASS_CACHED_PROTO_SHIFT =
@ -766,11 +764,9 @@ static const uint32_t JSCLASS_CACHED_PROTO_SHIFT =
static const uint32_t JSCLASS_CACHED_PROTO_MASK =
JS_BITMASK(js::JSCLASS_CACHED_PROTO_WIDTH);
#define JSCLASS_HAS_CACHED_PROTO(key) \
(uint32_t(key) << JSCLASS_CACHED_PROTO_SHIFT)
#define JSCLASS_CACHED_PROTO_KEY(clasp) \
((JSProtoKey)(((clasp)->flags >> JSCLASS_CACHED_PROTO_SHIFT) & \
JSCLASS_CACHED_PROTO_MASK))
static constexpr uint32_t JSCLASS_HAS_CACHED_PROTO(JSProtoKey key) {
return uint32_t(key) << JSCLASS_CACHED_PROTO_SHIFT;
}
struct MOZ_STATIC_CLASS JSClassOps {
/* Function pointer members (may be null). */
@ -787,7 +783,7 @@ struct MOZ_STATIC_CLASS JSClassOps {
JSTraceOp trace;
};
#define JS_NULL_CLASS_OPS nullptr
static constexpr const JSClassOps* JS_NULL_CLASS_OPS = nullptr;
struct JSClass {
const char* name;
@ -939,6 +935,21 @@ struct JSClass {
}
};
static constexpr uint32_t JSCLASS_RESERVED_SLOTS(const JSClass* clasp) {
return (clasp->flags >> JSCLASS_RESERVED_SLOTS_SHIFT) &
JSCLASS_RESERVED_SLOTS_MASK;
}
static constexpr bool JSCLASS_HAS_GLOBAL_FLAG_AND_SLOTS(const JSClass* clasp) {
return (clasp->flags & JSCLASS_IS_GLOBAL) &&
JSCLASS_RESERVED_SLOTS(clasp) >= JSCLASS_GLOBAL_SLOT_COUNT;
}
static constexpr JSProtoKey JSCLASS_CACHED_PROTO_KEY(const JSClass* clasp) {
return JSProtoKey((clasp->flags >> JSCLASS_CACHED_PROTO_SHIFT) &
JSCLASS_CACHED_PROTO_MASK);
}
namespace js {
/**