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/. */
12 #include "vm/JSContext.h"
13 #include "vm/NativeObject.h"
17 class TupleType final
: public js::NativeObject
{
19 static const js::ClassSpec classSpec_
;
20 static const JSClass class_
;
21 static const JSClass protoClass_
;
24 static TupleType
* create(JSContext
* cx
, uint32_t length
,
25 const Value
* elements
);
27 static TupleType
* createUninitialized(JSContext
* cx
, uint32_t initialLength
);
29 static TupleType
* createUnchecked(JSContext
* cx
,
30 Handle
<js::ArrayObject
*> aObj
);
32 bool initializeNextElement(JSContext
* cx
, HandleValue elt
);
33 void finishInitialization(JSContext
* cx
);
34 static js::Shape
* getInitialShape(JSContext
* cx
);
36 static bool copy(JSContext
* cx
, Handle
<TupleType
*> in
,
37 MutableHandle
<TupleType
*> out
);
39 bool getOwnProperty(HandleId id
, MutableHandleValue vp
) const;
40 inline uint32_t length() const { return getElementsHeader()->length
; }
42 // Methods defined on Tuple.prototype
43 [[nodiscard
]] static bool lengthAccessor(JSContext
* cx
, unsigned argc
,
46 // Comparison functions
47 static bool sameValueZero(JSContext
* cx
, TupleType
* lhs
, TupleType
* rhs
,
49 static bool sameValue(JSContext
* cx
, TupleType
* lhs
, TupleType
* rhs
,
52 using ElementHasher
= std::function
<js::HashNumber(const Value
& child
)>;
53 js::HashNumber
hash(const ElementHasher
& hasher
) const;
55 bool ensureAtomized(JSContext
* cx
);
56 bool isAtomized() const { return getElementsHeader()->tupleIsAtomized(); }
58 // This can be used to compare atomized tuples.
59 static bool sameValueZero(TupleType
* lhs
, TupleType
* rhs
);
61 static TupleType
& thisTupleValue(const Value
& val
);
64 template <bool Comparator(JSContext
*, HandleValue
, HandleValue
, bool*)>
65 static bool sameValueWith(JSContext
* cx
, TupleType
* lhs
, TupleType
* rhs
,
73 extern JSString
* TupleToSource(JSContext
* cx
, Handle
<TupleType
*> tup
);
75 bool IsTuple(const Value
& v
);
77 extern bool tuple_toReversed(JSContext
* cx
, unsigned argc
, Value
* vp
);
78 extern bool tuple_with(JSContext
* cx
, unsigned argc
, Value
* vp
);
79 extern bool tuple_slice(JSContext
* cx
, unsigned argc
, Value
* vp
);
80 extern bool tuple_is_tuple(JSContext
* cx
, unsigned argc
, Value
* vp
);
81 extern bool tuple_value_of(JSContext
* cx
, unsigned argc
, Value
* vp
);
82 extern bool tuple_of(JSContext
* cx
, unsigned argc
, Value
* vp
);
83 extern bool tuple_construct(JSContext
* cx
, unsigned argc
, Value
* vp
);