1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 # You can obtain one at http://mozilla.org/MPL/2.0/.
5 # Pretty-printers for JSID values.
7 import mozilla
.prettyprinters
9 from mozilla
.prettyprinters
import pretty_printer
11 # Forget any printers from previous loads of this module.
12 mozilla
.prettyprinters
.clear_module_printers(__name__
)
15 @pretty_printer("JS::PropertyKey")
16 class PropertyKey(object):
17 # Since people don't always build with macro debugging info, I can't
18 # think of any way to avoid copying these values here, short of using
19 # inferior calls for every operation (which, I hear, is broken from
20 # pretty-printers in some recent GDBs).
27 def __init__(self
, value
, cache
):
30 self
.concrete_type
= self
.value
.type.strip_typedefs()
33 bits
= self
.value
["asBits_"]
34 tag
= bits
& PropertyKey
.TypeMask
35 if tag
== PropertyKey
.StringTypeTag
:
36 body
= bits
.cast(self
.cache
.JSString_ptr_t
)
37 elif tag
& PropertyKey
.IntTagBit
:
39 elif tag
== PropertyKey
.VoidTypeTag
:
40 return "JS::VoidPropertyKey"
41 elif tag
== PropertyKey
.SymbolTypeTag
:
42 body
= (bits
& ~PropertyKey
.TypeMask
).cast(self
.cache
.JSSymbol_ptr_t
)
44 body
= "<unrecognized>"
45 return "$jsid(%s)" % (body
,)
48 @pretty_printer("JS::Rooted<long>")
49 def RootedPropertyKey(value
, cache
):
50 # Hard-code the referent type pretty-printer for PropertyKey roots and
51 # handles. See the comment for mozilla.Root.Common.__init__.
52 return mozilla
.Root
.Rooted(value
, cache
, PropertyKey
)
55 @pretty_printer("JS::Handle<long>")
56 def HandlePropertyKey(value
, cache
):
57 return mozilla
.Root
.Handle(value
, cache
, PropertyKey
)
60 @pretty_printer("JS::MutableHandle<long>")
61 def MutableHandlePropertyKey(value
, cache
):
62 return mozilla
.Root
.MutableHandle(value
, cache
, PropertyKey
)