Debian Codegraph @

js/src/vm/TypeofEqOperand.h

raw
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 #ifndef vm_TypeofEqOperand_h
8 #define vm_TypeofEqOperand_h
9
10 #include "mozilla/Assertions.h" // MOZ_ASSERT
11
12 #include <stdint.h> // uint8_t
13
14 #include "jspubtd.h" // JSType
15 #include "vm/Opcodes.h" // JSOp
16
17 namespace js {
18
19 struct TypeofEqOperand {
20 static constexpr uint8_t TYPE_MASK = 0x0f;
21 static constexpr uint8_t NEQ_BIT = 0x80;
22
23 private:
24 uint8_t value;
25
26 static uint8_t toNeqBit(JSOp compareOp) {
27 MOZ_ASSERT(compareOp == JSOp::Eq || compareOp == JSOp::Ne);
28 return compareOp == JSOp::Ne ? NEQ_BIT : 0;
29 }
30
31 explicit TypeofEqOperand(uint8_t value) : value(value) {}
32
33 public:
34 TypeofEqOperand(JSType type, JSOp compareOp)
35 : value(type | toNeqBit(compareOp)) {}
36
37 static TypeofEqOperand fromRawValue(uint8_t value) {
38 return TypeofEqOperand(value);
39 }
40
41 JSType type() const { return JSType(value & TYPE_MASK); }
42 JSOp compareOp() const { return (value & NEQ_BIT) ? JSOp::Ne : JSOp::Eq; }
43 uint8_t rawValue() const { return value; }
44 };
45
46 static_assert((JSTYPE_LIMIT & TypeofEqOperand::TYPE_MASK) == JSTYPE_LIMIT);
47
48 } // namespace js
49
50 #endif // vm_TypeofEqOperand_h