DXR will be turned off on Tuesday, December 29th. It will redirect to Searchfox.
See the announcement on Discourse.

DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (6863f516ba38)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: set ts=8 sts=2 et sw=2 tw=80:
 * 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/. */

#ifndef vm_ArrayObject_h
#define vm_ArrayObject_h

#include "vm/NativeObject.h"

namespace js {

class AutoSetNewObjectMetadata;

class ArrayObject : public NativeObject {
 public:
  // Array(x) eagerly allocates dense elements if x <= this value. Without
  // the subtraction the max would roll over to the next power-of-two (4096)
  // due to the way that growElements() and goodAllocated() work.
  static const uint32_t EagerAllocationMaxLength =
      2048 - ObjectElements::VALUES_PER_HEADER;

  static const Class class_;

  bool lengthIsWritable() const {
    return !getElementsHeader()->hasNonwritableArrayLength();
  }

  uint32_t length() const { return getElementsHeader()->length; }

  void setNonWritableLength(JSContext* cx) {
    shrinkCapacityToInitializedLength(cx);
    getElementsHeader()->setNonwritableArrayLength();
  }

  inline void setLength(JSContext* cx, uint32_t length);

  // Variant of setLength for use on arrays where the length cannot overflow
  // int32_t.
  void setLengthInt32(uint32_t length) {
    MOZ_ASSERT(lengthIsWritable());
    MOZ_ASSERT_IF(length != getElementsHeader()->length,
                  !denseElementsAreFrozen());
    MOZ_ASSERT(length <= INT32_MAX);
    getElementsHeader()->length = length;
  }

  // Make an array object with the specified initial state.
  static inline ArrayObject* createArray(JSContext* cx, gc::AllocKind kind,
                                         gc::InitialHeap heap,
                                         HandleShape shape,
                                         HandleObjectGroup group,
                                         uint32_t length,
                                         AutoSetNewObjectMetadata& metadata);

  // Make a copy-on-write array object which shares the elements of an
  // existing object.
  static inline ArrayObject* createCopyOnWriteArray(
      JSContext* cx, gc::InitialHeap heap,
      HandleArrayObject sharedElementsOwner);

 private:
  // Helper for the above methods.
  static inline ArrayObject* createArrayInternal(
      JSContext* cx, gc::AllocKind kind, gc::InitialHeap heap,
      HandleShape shape, HandleObjectGroup group, AutoSetNewObjectMetadata&);

  static inline ArrayObject* finishCreateArray(
      ArrayObject* obj, HandleShape shape, AutoSetNewObjectMetadata& metadata);
};

}  // namespace js

#endif  // vm_ArrayObject_h