author André Bargull <andre.bargull@gmail.com>
Tue, 02 Jun 2020 20:57:34 +0000
changeset 597698 0880c9f6821008953ea4f4f12d2d6ee84767a636
parent 597585 023c0fdf6679bde4ba0772ff5c060c371e2f268e
child 602326 8ebb83edf3dbc38dd90d3e90223ab119ee577e5e
permissions -rw-r--r--
Bug 1635839 - Part 1: Add PrivateName Symbol code. r=jorendorff Differential Revision: https://phabricator.services.mozilla.com/D74102

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

# Pretty-printer for SpiderMonkey symbols.

import mozilla.prettyprinters
from mozilla.prettyprinters import ptr_pretty_printer
from mozilla.CellHeader import get_header_ptr

# Forget any printers from previous loads of this module.

# JS::SymbolCode enumerators
PrivateNameSymbol = 0xfffffffd
InSymbolRegistry = 0xfffffffe
UniqueSymbol = 0xffffffff

class JSSymbolPtr(mozilla.prettyprinters.Pointer):
    def __init__(self, value, cache):
        super(JSSymbolPtr, self).__init__(value, cache)
        self.value = value

    def to_string(self):
        code = int(self.value['code_']) & 0xffffffff
        desc = str(get_header_ptr(self.value['headerAndDescription_'],
        if code == InSymbolRegistry:
            return "Symbol.for({})".format(desc)
        elif code == UniqueSymbol:
            return "Symbol({})".format(desc)
        elif code == PrivateNameSymbol:
            return "#{}".format(desc)
            # Well-known symbol. Strip off the quotes added by the JSString *
            # pretty-printer.
            assert desc[0] == '"'
            assert desc[-1] == '"'
            return desc[1:-1]