void tvCastToObjectInPlace(TypedValue* tv) { assert(tvIsPlausible(*tv)); tvUnboxIfNeeded(tv); ObjectData* o; switch (tv->m_type) { case KindOfUninit: case KindOfNull: o = SystemLib::AllocStdClassObject(); break; case KindOfBoolean: case KindOfInt64: case KindOfDouble: case KindOfStaticString: o = SystemLib::AllocStdClassObject(); o->o_set(s_scalar, tvAsVariant(tv)); break; case KindOfString: o = SystemLib::AllocStdClassObject(); o->o_set(s_scalar, tvAsVariant(tv)); tvDecRefStr(tv); break; case KindOfArray: // For arrays, we fall back on the Variant machinery tvAsVariant(tv) = ObjectData::FromArray(tv->m_data.parr); return; case KindOfObject: return; case KindOfResource: return; default: assert(false); o = SystemLib::AllocStdClassObject(); break; } tv->m_data.pobj = o; tv->m_type = KindOfObject; tv->m_data.pobj->incRefCount(); }
void tvCastToObjectInPlace(TypedValue* tv) { assert(tvIsPlausible(*tv)); tvUnboxIfNeeded(tv); ObjectData* o; do { switch (tv->m_type) { case KindOfUninit: case KindOfNull: o = SystemLib::AllocStdClassObject().detach(); continue; case KindOfBoolean: case KindOfInt64: case KindOfDouble: case KindOfPersistentString: case KindOfResource: o = SystemLib::AllocStdClassObject().detach(); o->o_set(s_scalar, tvAsVariant(tv)); continue; case KindOfString: o = SystemLib::AllocStdClassObject().detach(); o->o_set(s_scalar, tvAsVariant(tv)); tvDecRefStr(tv); continue; case KindOfPersistentVec: case KindOfVec: case KindOfPersistentDict: case KindOfDict: case KindOfPersistentKeyset: case KindOfKeyset: tvCastToArrayInPlace(tv); // Fall-through to array case case KindOfPersistentArray: case KindOfArray: // For arrays, we fall back on the Variant machinery tvAsVariant(tv) = ObjectData::FromArray(tv->m_data.parr); return; case KindOfObject: return; case KindOfRef: case KindOfClass: break; } not_reached(); } while (0); tv->m_data.pobj = o; tv->m_type = KindOfObject; assert(cellIsPlausible(*tv)); }
Object Variant::toObjectHelper() const { if (m_type == KindOfRef) return m_data.pref->var()->toObject(); switch (m_type) { case KindOfUninit: case KindOfNull: break; case KindOfBoolean: case KindOfInt64: case KindOfDouble: case KindOfStaticString: case KindOfString: case KindOfResource: { ObjectData *obj = SystemLib::AllocStdClassObject(); obj->o_set(s_scalar, *this, false); return obj; } case KindOfArray: return ObjectData::FromArray(m_data.parr); case KindOfObject: return m_data.pobj; default: assert(false); break; } return Object(SystemLib::AllocStdClassObject()); }
bool SetVariableCommand::setObjectVariable( DebuggerSession* session, const std::string& name, const std::string& value, VariableObject* object, folly::dynamic* result ) { Variant& var = object->m_variable; assertx(var.isObject()); HPHP::String key(name); ObjectData* obj = var.getObjectData(); Variant currentValue = obj->o_get(key, false); if (!currentValue.isInitialized()) { throw DebuggerCommandException( "Failed to set variable: Property not found on object." ); } TypedValue* propValue = currentValue.asTypedValue(); setVariableValue( session, name, value, propValue, object->m_requestId, result ); obj->o_set(key, currentValue); return true; }
Variant f_hphp_recursiveiteratoriterator_key(CObjRef obj) { RecursiveIteratorIterator *rii = get_recursiveiteratoriterator(obj); unsigned int size = rii->m_iterators.size(); assert(size > 0); if (rii->m_iterator.is<RecursiveDirectoryIterator>()) { ObjectData* rdi = SystemLib::AllocRecursiveDirectoryIteratorObject(); rdi->o_set("rsrc", rii->m_iterators[size-1].first, "SplFileInfo"); return f_hphp_recursivedirectoryiterator_key(rdi); } throw NotImplementedException("this type of iterator"); }
void f_hphp_recursiveiteratoriterator_rewind(CObjRef obj) { RecursiveIteratorIterator *rii = get_recursiveiteratoriterator(obj); rii->freeAllIterators(); rii->m_iterators.push_back(std::make_pair(rii->m_iterator.get(), 0)); rii->m_iterator->incRefCount(); if (rii->m_iterator.is<RecursiveDirectoryIterator>()) { ObjectData* rdi = SystemLib::AllocRecursiveDirectoryIteratorObject(); rdi->o_set("rsrc", rii->m_iterator, "SplFileInfo"); f_hphp_recursivedirectoryiterator_rewind(rdi); if (!f_hphp_recursiveiteratoriterator_valid(obj)) { f_hphp_recursiveiteratoriterator_next(obj); } return; } throw NotImplementedException("this type of iterator"); }