commit c6641d8197e0e81657e5284160adce2047405069
parent a805e95c66b946927146357b95497c912d897bc7
Author: Jan de Mooij <jdemooij@mozilla.com>
Date: Mon, 10 Nov 2025 13:53:48 +0000
Bug 1999246 - Tidy up ListObject code a bit. r=jonco
Removes some dead code and changes the `HandleValue` argument of `append` to `Value`.
Differential Revision: https://phabricator.services.mozilla.com/D271969
Diffstat:
4 files changed, 8 insertions(+), 101 deletions(-)
diff --git a/js/src/jit/CacheIR.cpp b/js/src/jit/CacheIR.cpp
@@ -4043,8 +4043,7 @@ AttachDecision HasPropIRGenerator::tryAttachSmallObjectVariableKey(
return AttachDecision::NoAction;
}
- RootedValue key(cx_, StringValue(iter->key().toAtom()));
- if (!keyListObj->append(cx_, key)) {
+ if (!keyListObj->append(cx_, StringValue(iter->key().toAtom()))) {
cx_->recoverFromOutOfMemory();
return AttachDecision::NoAction;
}
diff --git a/js/src/vm/AsyncIteration.cpp b/js/src/vm/AsyncIteration.cpp
@@ -148,17 +148,15 @@ AsyncGeneratorRequest* AsyncGeneratorObject::createRequest(
return true;
}
- Rooted<ListObject*> queue(cx, ListObject::create(cx));
+ ListObject* queue = ListObject::create(cx);
if (!queue) {
return false;
}
- RootedValue requestVal(cx, ObjectValue(*generator->singleQueueRequest()));
- if (!queue->append(cx, requestVal)) {
+ if (!queue->append(cx, ObjectValue(*generator->singleQueueRequest()))) {
return false;
}
- requestVal = ObjectValue(*request);
- if (!queue->append(cx, requestVal)) {
+ if (!queue->append(cx, ObjectValue(*request))) {
return false;
}
@@ -166,9 +164,7 @@ AsyncGeneratorRequest* AsyncGeneratorObject::createRequest(
return true;
}
- Rooted<ListObject*> queue(cx, generator->queue());
- RootedValue requestVal(cx, ObjectValue(*request));
- return queue->append(cx, requestVal);
+ return generator->queue()->append(cx, ObjectValue(*request));
}
/* static */
diff --git a/js/src/vm/List-inl.h b/js/src/vm/List-inl.h
@@ -13,21 +13,18 @@
#include <stdint.h> // uint32_t
-#include "js/RootingAPI.h" // JS::Handle, JS::Rooted
-#include "js/Value.h" // JS::Value, JS::ObjectValue
+#include "js/Value.h" // JS::Value
#include "vm/JSContext.h" // JSContext
#include "vm/NativeObject.h" // js::NativeObject
-#include "vm/Compartment-inl.h" // JS::Compartment::wrap
#include "vm/JSObject-inl.h" // js::NewObjectWithGivenProto
#include "vm/NativeObject-inl.h" // js::NativeObject::*
-#include "vm/Realm-inl.h" // js::AutoRealm
inline /* static */ js::ListObject* js::ListObject::create(JSContext* cx) {
return NewObjectWithGivenProto<ListObject>(cx, nullptr);
}
-inline bool js::ListObject::append(JSContext* cx, JS::Handle<JS::Value> value) {
+inline bool js::ListObject::append(JSContext* cx, Value value) {
uint32_t len = length();
if (!ensureElements(cx, len + 1)) {
@@ -39,21 +36,6 @@ inline bool js::ListObject::append(JSContext* cx, JS::Handle<JS::Value> value) {
return true;
}
-inline bool js::ListObject::appendValueAndSize(JSContext* cx,
- JS::Handle<JS::Value> value,
- double size) {
- uint32_t len = length();
-
- if (!ensureElements(cx, len + 2)) {
- return false;
- }
-
- ensureDenseInitializedLength(len, 2);
- setDenseElement(len, value);
- setDenseElement(len + 1, JS::DoubleValue(size));
- return true;
-}
-
inline JS::Value js::ListObject::popFirst(JSContext* cx) {
uint32_t len = length();
MOZ_ASSERT(len > 0);
@@ -69,61 +51,9 @@ inline JS::Value js::ListObject::popFirst(JSContext* cx) {
return entry;
}
-inline void js::ListObject::popFirstPair(JSContext* cx) {
- uint32_t len = length();
- MOZ_ASSERT(len > 0);
- MOZ_ASSERT((len % 2) == 0);
-
- if (!tryShiftDenseElements(2)) {
- moveDenseElements(0, 2, len - 2);
- setDenseInitializedLength(len - 2);
- shrinkElements(cx, len - 2);
- }
-
- MOZ_ASSERT(length() == len - 2);
-}
-
template <class T>
inline T& js::ListObject::popFirstAs(JSContext* cx) {
return popFirst(cx).toObject().as<T>();
}
-namespace js {
-
-/**
- * Stores an empty ListObject in the given fixed slot of |obj|.
- */
-[[nodiscard]] inline bool StoreNewListInFixedSlot(JSContext* cx,
- JS::Handle<NativeObject*> obj,
- uint32_t slot) {
- AutoRealm ar(cx, obj);
- ListObject* list = ListObject::create(cx);
- if (!list) {
- return false;
- }
-
- obj->setFixedSlot(slot, JS::ObjectValue(*list));
- return true;
-}
-
-/**
- * Given an object |obj| whose fixed slot |slot| contains a ListObject, append
- * |toAppend| to that list.
- */
-[[nodiscard]] inline bool AppendToListInFixedSlot(
- JSContext* cx, JS::Handle<NativeObject*> obj, uint32_t slot,
- JS::Handle<JSObject*> toAppend) {
- JS::Rooted<ListObject*> list(
- cx, &obj->getFixedSlot(slot).toObject().as<ListObject>());
-
- AutoRealm ar(cx, list);
- JS::Rooted<JS::Value> val(cx, JS::ObjectValue(*toAppend));
- if (!cx->compartment()->wrap(cx, &val)) {
- return false;
- }
- return list->append(cx, val);
-}
-
-} // namespace js
-
#endif // vm_List_inl_h
diff --git a/js/src/vm/List.h b/js/src/vm/List.h
@@ -49,19 +49,7 @@ class ListObject : public NativeObject {
/**
* Add an element to the end of the list. Returns false on OOM.
*/
- [[nodiscard]] inline bool append(JSContext* cx, HandleValue value);
-
- /**
- * Adds |value| and |size| elements to a list consisting of (value, size)
- * pairs stored in successive elements.
- *
- * This function is intended for use by streams code's queue-with-sizes data
- * structure and related operations. See builtin/streams/QueueWithSizes*.
- * (You *could* use this on any list of even length without issue, but it's
- * hard to imagine realistic situations where you'd want to...)
- */
- [[nodiscard]] inline bool appendValueAndSize(JSContext* cx, HandleValue value,
- double size);
+ [[nodiscard]] inline bool append(JSContext* cx, Value value);
/**
* Remove and return the first element of the list.
@@ -71,12 +59,6 @@ class ListObject : public NativeObject {
inline JS::Value popFirst(JSContext* cx);
/**
- * Remove the first two elements from a nonempty list of (value, size) pairs
- * of elements.
- */
- inline void popFirstPair(JSContext* cx);
-
- /**
* Remove and return the first element of the list.
*
* Precondition: This list is not empty, and the first element