tor-browser

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

ParseRecordObject.h (2044B)


      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 builtin_ParseRecordObject_h
      8 #define builtin_ParseRecordObject_h
      9 
     10 #include "js/HashTable.h"
     11 #include "js/TracingAPI.h"
     12 #include "vm/JSContext.h"
     13 
     14 namespace js {
     15 
     16 using JSONParseNode = JSString;
     17 
     18 class ParseRecordObject : public NativeObject {
     19  enum { ParseNodeSlot, ValueSlot, KeySlot, SlotCount };
     20 
     21 public:
     22  static const JSClass class_;
     23 
     24  static ParseRecordObject* create(JSContext* cx, const Value& val);
     25  static ParseRecordObject* create(JSContext* cx,
     26                                   Handle<js::JSONParseNode*> parseNode,
     27                                   const Value& val);
     28 
     29  // The source text that was parsed for this record. According to the spec, we
     30  // don't track this for objects and arrays, so it will be a null pointer.
     31  JSONParseNode* getParseNode() const {
     32    const Value& slot = getSlot(ParseNodeSlot);
     33    return slot.isUndefined() ? nullptr : slot.toString();
     34  }
     35 
     36  // For object members, the member key. For arrays, the index. For JSON
     37  // primitives, it will be undefined.
     38  JS::PropertyKey getKey(JSContext* cx) const;
     39 
     40  bool setKey(JSContext* cx, const JS::PropertyKey& key);
     41 
     42  // The original value corresponding to this record, used to determine if the
     43  // reviver function has modified it.
     44  const Value& getValue() const { return getSlot(ValueSlot); }
     45 
     46  void setValue(JS::Handle<JS::Value> value) { setSlot(ValueSlot, value); }
     47 
     48  bool hasValue() const { return !getValue().isUndefined(); }
     49 
     50  // For objects and arrays, the records for the members and elements
     51  // (respectively) are added to the ParseRecordObject.
     52  bool addEntries(JSContext* cx, Handle<JS::PropertyKey> key,
     53                  Handle<ParseRecordObject*> parseRecord);
     54 };
     55 
     56 }  // namespace js
     57 
     58 #endif