1 # Pretty-printers for SpiderMonkey strings.
4 import mozilla
.prettyprinters
5 from mozilla
.prettyprinters
import pretty_printer
, ptr_pretty_printer
8 chr(10000) # UPPER RIGHT PENCIL
9 except ValueError as exc
: # yuck, we are in Python 2.x, so chr() is 8-bit
10 chr = unichr # replace with teh unicodes
12 # Forget any printers from previous loads of this module.
13 mozilla
.prettyprinters
.clear_module_printers(__name__
)
15 # Cache information about the JSString type for this objfile.
16 class JSStringTypeCache(object):
17 def __init__(self
, cache
):
18 dummy
= gdb
.Value(0).cast(cache
.JSString_ptr_t
)
19 self
.ROPE_FLAGS
= dummy
['ROPE_FLAGS']
20 self
.ATOM_BIT
= dummy
['ATOM_BIT']
21 self
.INLINE_CHARS_BIT
= dummy
['INLINE_CHARS_BIT']
22 self
.TYPE_FLAGS_MASK
= dummy
['TYPE_FLAGS_MASK']
23 self
.LATIN1_CHARS_BIT
= dummy
['LATIN1_CHARS_BIT']
25 class Common(mozilla
.prettyprinters
.Pointer
):
26 def __init__(self
, value
, cache
):
27 super(Common
, self
).__init
__(value
, cache
)
28 if not cache
.mod_JSString
:
29 cache
.mod_JSString
= JSStringTypeCache(cache
)
30 self
.stc
= cache
.mod_JSString
32 @ptr_pretty_printer("JSString")
33 class JSStringPtr(Common
):
34 def display_hint(self
):
39 length
= d
['u1']['length']
40 flags
= d
['u1']['flags']
41 is_rope
= ((flags
& self
.stc
.TYPE_FLAGS_MASK
) == self
.stc
.ROPE_FLAGS
)
43 for c
in JSStringPtr(d
['s']['u2']['left'], self
.cache
).jschars():
45 for c
in JSStringPtr(d
['s']['u3']['right'], self
.cache
).jschars():
48 is_inline
= (flags
& self
.stc
.INLINE_CHARS_BIT
) != 0
49 is_latin1
= (flags
& self
.stc
.LATIN1_CHARS_BIT
) != 0
52 chars
= d
['inlineStorageLatin1']
54 chars
= d
['inlineStorageTwoByte']
57 chars
= d
['s']['u2']['nonInlineCharsLatin1']
59 chars
= d
['s']['u2']['nonInlineCharsTwoByte']
60 for i
in range(length
):
65 for c
in self
.jschars():
69 @ptr_pretty_printer("JSAtom")
70 class JSAtomPtr(Common
):
72 return self
.value
.cast(self
.cache
.JSString_ptr_t
)