tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ExecutionTracerIntegration.h (3976B)


      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 ExecutionTracerIntegration_h__
      8 #define ExecutionTracerIntegration_h__
      9 
     10 #ifdef MOZ_EXECUTION_TRACING
     11 
     12 #  include <stdint.h>
     13 #  include "jsapi.h"
     14 
     15 #  include "nsINode.h"
     16 
     17 namespace mozilla {
     18 
     19 // ExecutionTracerIntegration is responsible for producing object summaries for
     20 // various DOM types. ExecutionTracerIntegration::Callback is called from the
     21 // JS Execution Tracer where it writes to the Execution Tracer's ring buffer
     22 // using the JS_TracerSummaryWriter interface.
     23 //
     24 // NOTE - See "Value Summary Types" in js/public/Debug.h for information about
     25 // types used but not listed here. All values listed below use little-endian
     26 // byte ordering.
     27 //
     28 // - ExternalObjectSummary
     29 //
     30 //    Each object summary produced by our callback will have the following form
     31 //    at its base:
     32 //
     33 //      version:            uint8_t
     34 //      kind:               uint8_t
     35 //      payload:            determined by kind (see below)
     36 //
     37 //    The structure of `payload` is determined by the value of kind, which must
     38 //    be a valid SummaryKind:
     39 //
     40 //    SummaryKind::Other ->   nothing
     41 //    SummaryKind::Node ->
     42 //      nodeType:               uint16_t
     43 //      nodeName:               SmallString
     44 //      subkindAndIsConnected:  uint8_t (isConnected << 7 | subkind)
     45 //      subkindData:            see below
     46 //
     47 //      The structure of subkindData is as follows, based on the subkind:
     48 //
     49 //        NodeSubkind::Other ->   nothing
     50 //        NodeSubkind::Element ->
     51 //          attributes:           List<Pair<SmallString,SmallString>>
     52 //        NodeSubkind::Attr ->
     53 //          value:                SmallString
     54 //        NodeSubkind::Document ->
     55 //          location:             SmallString
     56 //        NodeSubkind::DocumentFragment ->
     57 //          childNodes:           NestedList<ValueSummary>
     58 //        NodeSubkind::Text ->
     59 //          textContent:          SmallString
     60 //        NodeSubkind::Comment ->
     61 //          textContent:          SmallString
     62 //    SummaryKind::Exception ->
     63 //      name:                     SmallString
     64 //      message:                  SmallString
     65 //      code:                     uint16_t
     66 //                                Only defined for DOM Exceptions, otherwise set
     67 //                                to 0.
     68 //      result:                   uint16_t
     69 //      filename:                 SmallString
     70 //      lineNumber:               uint32_t
     71 //      columnNumber:             uint32_t
     72 //      stack:                    SmallString
     73 class ExecutionTracerIntegration {
     74 public:
     75  // This version will be baked into each entry, and should be incremented
     76  // every time we make a breaking change to the format. Adding new
     77  // SummaryKinds for example should not be considered breaking, as the
     78  // reader can simply skip over SummaryKinds it doesn't know about.
     79  static const uint8_t VERSION = 1;
     80 
     81  enum class SummaryKind : uint8_t {
     82    Other,
     83    Node,
     84    Exception,
     85    // TODO: more SummaryKinds will be implemented soon.
     86  };
     87 
     88  enum class NodeSubkind : uint8_t {
     89    Other,
     90    Element,
     91    Attr,
     92    Document,
     93    DocumentFragment,
     94    Text,
     95    Comment,
     96  };
     97 
     98  static bool Callback(JSContext* aCx, JS::Handle<JSObject*> aObj, bool aNested,
     99                       JS_TracerSummaryWriter* aWriter);
    100 
    101  static bool WriteNodeSummary(JSContext* aCx, nsINode* aNode, bool aNested,
    102                               JS_TracerSummaryWriter* aWriter);
    103 
    104  static bool WriteExceptionSummary(JSContext* aCx, JS::Handle<JSObject*> aObj,
    105                                    bool aNested,
    106                                    JS_TracerSummaryWriter* aWriter);
    107 };
    108 }  // namespace mozilla
    109 #endif
    110 #endif /* ExecutionTracerIntegration_h__ */