| 1993 | |
| 1994 | |
| 1995 | bool PyListProxyHandler::getOwnPropertyDescriptor( |
| 1996 | JSContext *cx, JS::HandleObject proxy, JS::HandleId id, |
| 1997 | JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc |
| 1998 | ) const { |
| 1999 | // see if we're calling a function |
| 2000 | if (id.isString()) { |
| 2001 | for (size_t index = 0;; index++) { |
| 2002 | bool isThatFunction; |
| 2003 | const char *methodName = array_methods[index].name; |
| 2004 | if (methodName == NULL) { // reached end of list |
| 2005 | break; |
| 2006 | } |
| 2007 | else if (JS_StringEqualsAscii(cx, id.toString(), methodName, &isThatFunction) && isThatFunction) { |
| 2008 | JSFunction *newFunction = JS_NewFunction(cx, array_methods[index].call, array_methods[index].nargs, 0, NULL); |
| 2009 | if (!newFunction) return false; |
| 2010 | JS::RootedObject funObj(cx, JS_GetFunctionObject(newFunction)); |
| 2011 | desc.set(mozilla::Some( |
| 2012 | JS::PropertyDescriptor::Data( |
| 2013 | JS::ObjectValue(*funObj), |
| 2014 | {JS::PropertyAttribute::Enumerable} |
| 2015 | ) |
| 2016 | )); |
| 2017 | return true; |
| 2018 | } |
| 2019 | } |
| 2020 | } |
| 2021 | |
| 2022 | PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot); |
| 2023 | // "length" property |
| 2024 | bool isLengthProperty; |
| 2025 | if (id.isString() && JS_StringEqualsLiteral(cx, id.toString(), "length", &isLengthProperty) && isLengthProperty) { |
| 2026 | desc.set(mozilla::Some( |
| 2027 | JS::PropertyDescriptor::Data( |
| 2028 | JS::Int32Value(PyList_Size(self)) |
| 2029 | ) |
| 2030 | )); |
| 2031 | return true; |
| 2032 | } |
| 2033 | |
| 2034 | // "constructor" property |
| 2035 | bool isConstructorProperty; |
| 2036 | if (id.isString() && JS_StringEqualsLiteral(cx, id.toString(), "constructor", &isConstructorProperty) && isConstructorProperty) { |
| 2037 | JS::RootedObject rootedArrayPrototype(cx); |
| 2038 | if (!JS_GetClassPrototype(cx, JSProto_Array, &rootedArrayPrototype)) { |
| 2039 | return false; |
| 2040 | } |
| 2041 | |
| 2042 | JS::RootedValue Array_Prototype_Constructor(cx); |
| 2043 | if (!JS_GetProperty(cx, rootedArrayPrototype, "constructor", &Array_Prototype_Constructor)) { |
| 2044 | return false; |
| 2045 | } |
| 2046 | |
| 2047 | JS::RootedObject rootedArrayPrototypeConstructor(cx, Array_Prototype_Constructor.toObjectOrNull()); |
| 2048 | |
| 2049 | desc.set(mozilla::Some( |
| 2050 | JS::PropertyDescriptor::Data( |
| 2051 | JS::ObjectValue(*rootedArrayPrototypeConstructor), |
| 2052 | {JS::PropertyAttribute::Enumerable} |
no test coverage detected