bool document_resolve(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned flags, JS::MutableHandleObject objp) { // If id is "all", resolve document.all=true. JS::RootedValue v(cx); if (!JS_IdToValue(cx, id, &v)) return false; if (JSVAL_IS_STRING(v)) { JSString *str = JSVAL_TO_STRING(v); JSFlatString *flatStr = JS_FlattenString(cx, str); if (!flatStr) return false; if (JS_FlatStringEqualsAscii(flatStr, "all")) { JS::Rooted<JSObject*> docAll(cx, JS_NewObject(cx, &DocumentAllClass, JS::NullPtr(), JS::NullPtr())); if (!docAll) return false; JS::Rooted<JS::Value> allValue(cx, ObjectValue(*docAll)); bool ok = JS_DefinePropertyById(cx, obj, id, allValue, nullptr, nullptr, 0); objp.set(ok ? obj.get() : nullptr); return ok; } } objp.set(nullptr); return true; }
bool document_resolve(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *resolvedp) { // If id is "all", resolve document.all=true. JS::RootedValue v(cx); if (!JS_IdToValue(cx, id, &v)) return false; if (v.isString()) { JSString *str = v.toString(); JSFlatString *flatStr = JS_FlattenString(cx, str); if (!flatStr) return false; if (JS_FlatStringEqualsAscii(flatStr, "all")) { JS::Rooted<JSObject*> docAll(cx, JS_NewObject(cx, &DocumentAllClass, JS::NullPtr(), JS::NullPtr())); if (!docAll) return false; JS::Rooted<JS::Value> allValue(cx, JS::ObjectValue(*docAll)); if (!JS_DefinePropertyById(cx, obj, id, allValue, 0)) return false; *resolvedp = true; return true; } } *resolvedp = false; return true; }