| 209 | } |
| 210 | |
| 211 | bool PyIterableProxyHandler::getOwnPropertyDescriptor( |
| 212 | JSContext *cx, JS::HandleObject proxy, JS::HandleId id, |
| 213 | JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc |
| 214 | ) const { |
| 215 | // see if we're calling a function |
| 216 | if (id.isString()) { |
| 217 | for (size_t index = 0;; index++) { |
| 218 | bool isThatFunction; |
| 219 | const char *methodName = iterable_methods[index].name; |
| 220 | if (methodName == NULL) { |
| 221 | break; |
| 222 | } |
| 223 | else if (JS_StringEqualsAscii(cx, id.toString(), methodName, &isThatFunction) && isThatFunction) { |
| 224 | JSFunction *newFunction = JS_NewFunction(cx, iterable_methods[index].call, iterable_methods[index].nargs, 0, NULL); |
| 225 | if (!newFunction) return false; |
| 226 | JS::RootedObject funObj(cx, JS_GetFunctionObject(newFunction)); |
| 227 | desc.set(mozilla::Some( |
| 228 | JS::PropertyDescriptor::Data( |
| 229 | JS::ObjectValue(*funObj), |
| 230 | {JS::PropertyAttribute::Enumerable} |
| 231 | ) |
| 232 | )); |
| 233 | return true; |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // "constructor" property |
| 239 | bool isConstructorProperty; |
| 240 | if (id.isString() && JS_StringEqualsLiteral(cx, id.toString(), "constructor", &isConstructorProperty) && isConstructorProperty) { |
| 241 | JS::RootedObject rootedObjectPrototype(cx); |
| 242 | if (!JS_GetClassPrototype(cx, JSProto_Object, &rootedObjectPrototype)) { |
| 243 | return false; |
| 244 | } |
| 245 | |
| 246 | JS::RootedValue Object_Prototype_Constructor(cx); |
| 247 | if (!JS_GetProperty(cx, rootedObjectPrototype, "constructor", &Object_Prototype_Constructor)) { |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | JS::RootedObject rootedObjectPrototypeConstructor(cx, Object_Prototype_Constructor.toObjectOrNull()); |
| 252 | |
| 253 | desc.set(mozilla::Some( |
| 254 | JS::PropertyDescriptor::Data( |
| 255 | JS::ObjectValue(*rootedObjectPrototypeConstructor), |
| 256 | {JS::PropertyAttribute::Enumerable} |
| 257 | ) |
| 258 | )); |
| 259 | return true; |
| 260 | } |
| 261 | |
| 262 | // symbol property |
| 263 | if (id.isSymbol()) { |
| 264 | JS::RootedSymbol rootedSymbol(cx, id.toSymbol()); |
| 265 | JS::SymbolCode symbolCode = JS::GetSymbolCode(rootedSymbol); |
| 266 | |
| 267 | if (symbolCode == JS::SymbolCode::iterator) { |
| 268 | JSFunction *newFunction = JS_NewFunction(cx, iterable_values, 0, 0, NULL); |