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

Method getOwnPropertyDescriptor

src/PyBytesProxyHandler.cc:271–423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269}
270
271bool PyBytesProxyHandler::getOwnPropertyDescriptor(
272 JSContext *cx, JS::HandleObject proxy, JS::HandleId id,
273 JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc
274) const {
275 // see if we're calling a function
276 if (id.isString()) {
277 for (size_t index = 0;; index++) {
278 bool isThatFunction;
279 const char *methodName = array_methods[index].name;
280 if (methodName == NULL) {
281 break;
282 }
283 else if (JS_StringEqualsAscii(cx, id.toString(), methodName, &isThatFunction) && isThatFunction) {
284 JSFunction *newFunction = JS_NewFunction(cx, array_methods[index].call, array_methods[index].nargs, 0, NULL);
285 if (!newFunction) return false;
286 JS::RootedObject funObj(cx, JS_GetFunctionObject(newFunction));
287 desc.set(mozilla::Some(
288 JS::PropertyDescriptor::Data(
289 JS::ObjectValue(*funObj),
290 {JS::PropertyAttribute::Enumerable}
291 )
292 ));
293 return true;
294 }
295 }
296 }
297
298 if (id.isString()) {
299 bool isProperty;
300
301 JSString *idString = id.toString();
302
303 // "length" and "byteLength" properties have the same value
304 if ((JS_StringEqualsLiteral(cx, idString, "length", &isProperty) && isProperty) || (JS_StringEqualsLiteral(cx, id.toString(), "byteLength", &isProperty) && isProperty)) {
305 JS::PersistentRootedObject *arrayBuffer = JS::GetMaybePtrFromReservedSlot<JS::PersistentRootedObject>(proxy, OtherSlot);
306
307 JS::RootedObject rootedArrayBuffer(cx, arrayBuffer->get());
308
309 auto byteLength = JS::GetArrayBufferByteLength(rootedArrayBuffer);
310
311 desc.set(mozilla::Some(
312 JS::PropertyDescriptor::Data(
313 JS::Int32Value(byteLength)
314 )
315 ));
316 return true;
317 }
318
319 // "buffer" property
320 if (JS_StringEqualsLiteral(cx, idString, "buffer", &isProperty) && isProperty) {
321 JS::PersistentRootedObject *arrayBuffer = JS::GetMaybePtrFromReservedSlot<JS::PersistentRootedObject>(proxy, OtherSlot);
322
323 desc.set(mozilla::Some(
324 JS::PropertyDescriptor::Data(
325 JS::ObjectValue(*(arrayBuffer->get()))
326 )
327 ));
328 return true;

Callers

nothing calls this directly

Calls 5

idToIndexFunction · 0.85
idToKeyFunction · 0.85
getMethod · 0.80
toStringMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected