js/src/vm/ArrayObject.h
author Brian Hackett <bhackett1024@gmail.com>
Fri, 19 Jul 2013 08:06:02 -0600
changeset 151522 868ce514bba712fda6578a692505ad5cb938edb7
parent 148778 f6fb32d3e1ffd70f48b037a56638265136567812
child 159462 03174045ef8d72ab2a0486e656c988bb3644951d
permissions -rw-r--r--
Bug 875125 - Allow scripts to be parsed/emitted off the main thread, r=billm.

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: set ts=8 sts=4 et sw=4 tw=99:
 * 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 "jsobj.h"

namespace js {

class ArrayObject : public JSObject
{
  public:
    static Class class_;

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

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

    static inline void setLength(ExclusiveContext *cx, Handle<ArrayObject*> arr, uint32_t length);

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

} // namespace js

#endif // vm_ArrayObject_h