MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / array_iterator_func

Function array_iterator_func

src/PyListProxyHandler.cc:1907–1943  ·  view source on GitHub ↗

private util

Source from the content-addressed store, hash-verified

1905
1906// private util
1907static bool array_iterator_func(JSContext *cx, unsigned argc, JS::Value *vp, int itemKind) {
1908 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1909
1910 JS::RootedObject proxy(cx, JS::ToObject(cx, args.thisv()));
1911 if (!proxy) {
1912 return false;
1913 }
1914 PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);
1915
1916 JS::RootedObject global(cx, JS::GetNonCCWObjectGlobal(proxy));
1917
1918 JS::RootedValue constructor_val(cx);
1919 if (!JS_GetProperty(cx, global, "ListIterator", &constructor_val)) return false;
1920 if (!constructor_val.isObject()) {
1921 if (!DefineListIterator(cx, global)) {
1922 return false;
1923 }
1924
1925 if (!JS_GetProperty(cx, global, "ListIterator", &constructor_val)) return false;
1926 if (!constructor_val.isObject()) {
1927 JS_ReportErrorASCII(cx, "ListIterator is not a constructor");
1928 return false;
1929 }
1930 }
1931 JS::RootedObject constructor(cx, &constructor_val.toObject());
1932
1933 JS::RootedObject obj(cx);
1934 if (!JS::Construct(cx, constructor_val, JS::HandleValueArray::empty(), &obj)) return false;
1935 if (!obj) return false;
1936
1937 JS::SetReservedSlot(obj, ListIteratorSlotIteratedObject, JS::PrivateValue((void *)self));
1938 JS::SetReservedSlot(obj, ListIteratorSlotNextIndex, JS::Int32Value(0));
1939 JS::SetReservedSlot(obj, ListIteratorSlotItemKind, JS::Int32Value(itemKind));
1940
1941 args.rval().setObject(*obj);
1942 return true;
1943}
1944
1945static bool array_entries(JSContext *cx, unsigned argc, JS::Value *vp) {
1946 return array_iterator_func(cx, argc, vp, ITEM_KIND_KEY_AND_VALUE);

Callers 3

array_entriesFunction · 0.70
array_keysFunction · 0.70
array_valuesFunction · 0.70

Calls 1

DefineListIteratorFunction · 0.85

Tested by

no test coverage detected