| 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/. |
| 4 |
|
| 5 |
# Pretty-printers for JSID values. |
| 6 |
|
| 7 |
import mozilla.prettyprinters |
| 8 |
import mozilla.Root |
| 9 |
from mozilla.prettyprinters import pretty_printer |
| 10 |
|
| 11 |
# Forget any printers from previous loads of this module. |
| 12 |
mozilla.prettyprinters.clear_module_printers(__name__) |
| 13 |
|
| 14 |
|
| 15 |
@pretty_printer("JS::PropertyKey") |
| 16 |
class PropertyKey: |
| 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). |
| 21 |
StringTypeTag = 0x0 |
| 22 |
IntTagBit = 0x1 |
| 23 |
VoidTypeTag = 0x2 |
| 24 |
SymbolTypeTag = 0x4 |
| 25 |
TypeMask = 0x7 |
| 26 |
|
| 27 |
def __init__(self, value, cache): |
| 28 |
self.value = value |
| 29 |
self.cache = cache |
| 30 |
self.concrete_type = self.value.type.strip_typedefs() |
| 31 |
|
| 32 |
def to_string(self): |
| 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: |
| 38 |
body = bits >> 1 |
| 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) |
| 43 |
else: |
| 44 |
body = "<unrecognized>" |
| 45 |
return "$jsid(%s)" % (body,) |
| 46 |
|
| 47 |
|
| 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) |
| 53 |
|
| 54 |
|
| 55 |
@pretty_printer("JS::Handle<long>") |
| 56 |
def HandlePropertyKey(value, cache): |
| 57 |
return mozilla.Root.Handle(value, cache, PropertyKey) |
| 58 |
|
| 59 |
|
| 60 |
@pretty_printer("JS::MutableHandle<long>") |
| 61 |
def MutableHandlePropertyKey(value, cache): |
| 62 |
return mozilla.Root.MutableHandle(value, cache, PropertyKey) |