Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 0021ec7

Browse files
committed
Bug 1547824 - Remove js::Value::payload union from 64-bit platforms. r=iain
Use well-defined conversions on the asBits_ instead. The remaining union arms were not even helpful for debuggers so we remove entirely. Differential Revision: https://phabricator.services.mozilla.com/D46323 --HG-- extra : moz-landing-system : lando
1 parent 50cb5ab commit 0021ec7

1 file changed

Lines changed: 9 additions & 16 deletions

File tree

js/public/Value.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,8 @@ union alignas(8) Value {
342342
private:
343343
uint64_t asBits_;
344344

345+
#if defined(JS_NUNBOX32)
345346
struct {
346-
#if defined(JS_PUNBOX64)
347-
# if MOZ_BIG_ENDIAN
348-
uint32_t : 32; // padding
349-
# endif // MOZ_BIG_ENDIAN
350-
union {
351-
int32_t i32_;
352-
uint32_t u32_;
353-
JSWhyMagic why_;
354-
} payload_;
355-
#elif defined(JS_NUNBOX32)
356347
# if MOZ_BIG_ENDIAN
357348
JSValueTag tag_;
358349
# endif // MOZ_BIG_ENDIAN
@@ -371,8 +362,8 @@ union alignas(8) Value {
371362
# if MOZ_LITTLE_ENDIAN
372363
JSValueTag tag_;
373364
# endif // MOZ_LITTLE_ENDIAN
374-
#endif // defined(JS_PUNBOX64)
375365
} s_;
366+
#endif // defined(JS_NUNBOX32)
376367

377368
public:
378369
constexpr Value() : asBits_(bitsFromTagAndPayload(JSVAL_TAG_UNDEFINED, 0)) {}
@@ -501,6 +492,8 @@ union alignas(8) Value {
501492
}
502493

503494
void setMagicUint32(uint32_t payload) {
495+
MOZ_ASSERT(payload >= JS_WHY_MAGIC_COUNT,
496+
"This should only be used for non-standard magic values");
504497
asBits_ = bitsFromTagAndPayload(JSVAL_TAG_MAGIC, payload);
505498
MOZ_ASSERT(magicUint32() == payload);
506499
}
@@ -666,7 +659,7 @@ union alignas(8) Value {
666659
if (!isMagic()) {
667660
return false;
668661
}
669-
MOZ_RELEASE_ASSERT(s_.payload_.why_ == why);
662+
MOZ_RELEASE_ASSERT(whyMagic() == why);
670663
return true;
671664
}
672665

@@ -688,13 +681,13 @@ union alignas(8) Value {
688681
}
689682

690683
JSWhyMagic whyMagic() const {
691-
MOZ_ASSERT(isMagic());
692-
return s_.payload_.why_;
684+
MOZ_ASSERT(magicUint32() < JS_WHY_MAGIC_COUNT);
685+
return static_cast<JSWhyMagic>(magicUint32());
693686
}
694687

695688
uint32_t magicUint32() const {
696689
MOZ_ASSERT(isMagic());
697-
return s_.payload_.u32_;
690+
return uint32_t(asBits_);
698691
}
699692

700693
/*** Comparison ***/
@@ -805,7 +798,7 @@ union alignas(8) Value {
805798

806799
uint32_t payloadAsRawUint32() const {
807800
MOZ_ASSERT(!isDouble());
808-
return s_.payload_.u32_;
801+
return uint32_t(asBits_);
809802
}
810803

811804
uint64_t asRawBits() const { return asBits_; }

0 commit comments

Comments
 (0)