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

Function array_iterator_func

src/PyBytesProxyHandler.cc:194–231  ·  view source on GitHub ↗

private util

Source from the content-addressed store, hash-verified

192
193/// private util
194static bool array_iterator_func(JSContext *cx, unsigned argc, JS::Value *vp, int itemKind) {
195 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
196
197 JS::RootedObject proxy(cx, JS::ToObject(cx, args.thisv()));
198 if (!proxy) {
199 return false;
200 }
201
202 JS::RootedObject global(cx, JS::GetNonCCWObjectGlobal(proxy));
203
204 JS::RootedValue constructor_val(cx);
205 if (!JS_GetProperty(cx, global, "BytesIterator", &constructor_val)) return false;
206 if (!constructor_val.isObject()) {
207 if (!DefineBytesIterator(cx, global)) {
208 return false;
209 }
210
211 if (!JS_GetProperty(cx, global, "BytesIterator", &constructor_val)) return false;
212 if (!constructor_val.isObject()) {
213 JS_ReportErrorASCII(cx, "BytesIterator is not a constructor");
214 return false;
215 }
216 }
217 JS::RootedObject constructor(cx, &constructor_val.toObject());
218
219 JS::RootedObject obj(cx);
220 if (!JS::Construct(cx, constructor_val, JS::HandleValueArray::empty(), &obj)) return false;
221 if (!obj) return false;
222
223 JS::PersistentRootedObject *arrayBuffer = JS::GetMaybePtrFromReservedSlot<JS::PersistentRootedObject>(proxy, OtherSlot);
224
225 JS::SetReservedSlot(obj, BytesIteratorSlotIteratedObject, JS::PrivateValue(arrayBuffer));
226 JS::SetReservedSlot(obj, BytesIteratorSlotNextIndex, JS::Int32Value(0));
227 JS::SetReservedSlot(obj, BytesIteratorSlotItemKind, JS::Int32Value(itemKind));
228
229 args.rval().setObject(*obj);
230 return true;
231}
232
233static bool array_entries(JSContext *cx, unsigned argc, JS::Value *vp) {
234 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

DefineBytesIteratorFunction · 0.85

Tested by

no test coverage detected