Bug 1914685 - [wpt-sync] Update web-platform-tests to 26c88095d89792c886494e30c85aca3...
[gecko.git] / js / src / vm / TupleType.h
blobefeafcac1572a52a11b0cb62b0bd367f141c9c72
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/. */
7 #ifndef vm_TupleType_h
8 #define vm_TupleType_h
10 #include <cstdint>
11 #include <functional>
12 #include "vm/JSContext.h"
13 #include "vm/NativeObject.h"
15 namespace JS {
17 class TupleType final : public js::NativeObject {
18 public:
19 static const js::ClassSpec classSpec_;
20 static const JSClass class_;
21 static const JSClass protoClass_;
23 public:
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,
44 Value* vp);
46 // Comparison functions
47 static bool sameValueZero(JSContext* cx, TupleType* lhs, TupleType* rhs,
48 bool* equal);
49 static bool sameValue(JSContext* cx, TupleType* lhs, TupleType* rhs,
50 bool* equal);
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);
63 private:
64 template <bool Comparator(JSContext*, HandleValue, HandleValue, bool*)>
65 static bool sameValueWith(JSContext* cx, TupleType* lhs, TupleType* rhs,
66 bool* equal);
69 } // namespace JS
71 namespace js {
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);
85 } // namespace js
87 #endif