static JSValue defineProperties(ExecState* exec, JSObject* object, JSObject* properties) { PropertyNameArray propertyNames(exec); asObject(properties)->methodTable()->getOwnPropertyNames(asObject(properties), exec, propertyNames, ExcludeDontEnumProperties); size_t numProperties = propertyNames.size(); Vector<PropertyDescriptor> descriptors; MarkedArgumentBuffer markBuffer; for (size_t i = 0; i < numProperties; i++) { PropertySlot slot; JSValue prop = properties->get(exec, propertyNames[i]); if (exec->hadException()) return jsNull(); PropertyDescriptor descriptor; if (!toPropertyDescriptor(exec, prop, descriptor)) return jsNull(); descriptors.append(descriptor); // Ensure we mark all the values that we're accumulating if (descriptor.isDataDescriptor() && descriptor.value()) markBuffer.append(descriptor.value()); if (descriptor.isAccessorDescriptor()) { if (descriptor.getter()) markBuffer.append(descriptor.getter()); if (descriptor.setter()) markBuffer.append(descriptor.setter()); } } for (size_t i = 0; i < numProperties; i++) { object->methodTable()->defineOwnProperty(object, exec, propertyNames[i], descriptors[i], true); if (exec->hadException()) return jsNull(); } return object; }
JSPropertyNameIterator* JSPropertyNameIterator::create(ExecState* exec, JSObject* o) { ASSERT(!o->structure()->enumerationCache() || o->structure()->enumerationCache()->cachedStructure() != o->structure() || o->structure()->enumerationCache()->cachedPrototypeChain() != o->structure()->prototypeChain(exec)); PropertyNameArray propertyNames(exec); o->getPropertyNames(exec, propertyNames); size_t numCacheableSlots = 0; if (!o->structure()->hasNonEnumerableProperties() && !o->structure()->hasAnonymousSlots() && !o->structure()->isUncacheableDictionary() && !o->structure()->typeInfo().overridesGetPropertyNames()) numCacheableSlots = o->structure()->propertyStorageSize(); JSPropertyNameIterator* jsPropertyNameIterator = new (exec) JSPropertyNameIterator(exec, propertyNames.data(), numCacheableSlots); if (o->structure()->isDictionary()) return jsPropertyNameIterator; if (o->structure()->typeInfo().overridesGetPropertyNames()) return jsPropertyNameIterator; size_t count = normalizePrototypeChain(exec, o); StructureChain* structureChain = o->structure()->prototypeChain(exec); RefPtr<Structure>* structure = structureChain->head(); for (size_t i = 0; i < count; ++i) { if (structure[i]->typeInfo().overridesGetPropertyNames()) return jsPropertyNameIterator; } jsPropertyNameIterator->setCachedPrototypeChain(structureChain); jsPropertyNameIterator->setCachedStructure(o->structure()); o->structure()->setEnumerationCache(jsPropertyNameIterator); return jsPropertyNameIterator; }
JSPropertyNameIterator* JSPropertyNameIterator::create(ExecState* exec, JSObject* o) { ASSERT(!o->structure()->enumerationCache() || o->structure()->enumerationCache()->cachedStructure() != o->structure() || o->structure()->enumerationCache()->cachedPrototypeChain() != o->structure()->prototypeChain(exec)); PropertyNameArray propertyNames(exec); o->methodTable()->getPropertyNames(o, exec, propertyNames, ExcludeDontEnumProperties); size_t numCacheableSlots = 0; if (!o->structure()->hasNonEnumerableProperties() && !o->structure()->hasGetterSetterProperties() && !o->structure()->isUncacheableDictionary() && !o->structure()->typeInfo().overridesGetPropertyNames()) numCacheableSlots = o->structure()->totalStorageSize(); JSPropertyNameIterator* jsPropertyNameIterator = new (NotNull, allocateCell<JSPropertyNameIterator>(*exec->heap())) JSPropertyNameIterator(exec, propertyNames.data(), numCacheableSlots); jsPropertyNameIterator->finishCreation(exec, propertyNames.data(), o); if (o->structure()->isDictionary()) return jsPropertyNameIterator; if (o->structure()->typeInfo().overridesGetPropertyNames()) return jsPropertyNameIterator; size_t count = normalizePrototypeChain(exec, o); StructureChain* structureChain = o->structure()->prototypeChain(exec); WriteBarrier<Structure>* structure = structureChain->head(); for (size_t i = 0; i < count; ++i) { if (structure[i]->typeInfo().overridesGetPropertyNames()) return jsPropertyNameIterator; } jsPropertyNameIterator->setCachedPrototypeChain(exec->globalData(), structureChain); jsPropertyNameIterator->setCachedStructure(exec->globalData(), o->structure()); o->structure()->setEnumerationCache(exec->globalData(), jsPropertyNameIterator); return jsPropertyNameIterator; }
JSPropertyNameEnumerator* JSPropertyNameEnumerator::create(VM& vm) { if (!vm.emptyPropertyNameEnumerator.get()) { PropertyNameArray propertyNames(&vm); vm.emptyPropertyNameEnumerator = Strong<JSCell>(vm, create(vm, 0, 0, 0, propertyNames)); } return jsCast<JSPropertyNameEnumerator*>(vm.emptyPropertyNameEnumerator.get()); }
static RefPtr<InspectorValue> jsToInspectorValue(ExecState* scriptState, JSValue value, int maxDepth) { if (!value) { ASSERT_NOT_REACHED(); return nullptr; } if (!maxDepth) return nullptr; maxDepth--; if (value.isNull() || value.isUndefined()) return InspectorValue::null(); if (value.isBoolean()) return InspectorValue::create(value.asBoolean()); if (value.isNumber() && value.isDouble()) return InspectorValue::create(value.asNumber()); if (value.isNumber() && value.isMachineInt()) return InspectorValue::create(static_cast<int>(value.asMachineInt())); if (value.isString()) return InspectorValue::create(value.getString(scriptState)); if (value.isObject()) { if (isJSArray(value)) { Ref<InspectorArray> inspectorArray = InspectorArray::create(); JSArray* array = asArray(value); unsigned length = array->length(); for (unsigned i = 0; i < length; i++) { JSValue element = array->getIndex(scriptState, i); RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element, maxDepth); if (!elementValue) return nullptr; inspectorArray->pushValue(WTFMove(elementValue)); } return WTFMove(inspectorArray); } Ref<InspectorObject> inspectorObject = InspectorObject::create(); JSObject* object = value.getObject(); PropertyNameArray propertyNames(scriptState, PropertyNameMode::Strings); object->methodTable()->getOwnPropertyNames(object, scriptState, propertyNames, EnumerationMode()); for (size_t i = 0; i < propertyNames.size(); i++) { const Identifier& name = propertyNames[i]; JSValue propertyValue = object->get(scriptState, name); RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue, maxDepth); if (!inspectorValue) return nullptr; inspectorObject->setValue(name.string(), WTFMove(inspectorValue)); } return WTFMove(inspectorObject); } ASSERT_NOT_REACHED(); return nullptr; }
JSPropertyNameIterator* JSPropertyNameIterator::create(ExecState* exec, JSValue* v) { if (v->isUndefinedOrNull()) return new (exec) JSPropertyNameIterator(0, 0, 0); JSObject* o = v->toObject(exec); PropertyNameArray propertyNames(exec); o->getPropertyNames(exec, propertyNames); size_t numProperties = propertyNames.size(); return new (exec) JSPropertyNameIterator(o, propertyNames.releaseIdentifiers(), numProperties); }
static PassRefPtr<InspectorValue> jsToInspectorValue(ScriptState* scriptState, JSValue value, int maxDepth) { if (!value) { ASSERT_NOT_REACHED(); return 0; } if (!maxDepth) return 0; maxDepth--; if (value.isNull() || value.isUndefined()) return InspectorValue::null(); if (value.isBoolean()) return InspectorBasicValue::create(value.asBoolean()); if (value.isNumber()) return InspectorBasicValue::create(value.asNumber()); if (value.isString()) { String s = value.getString(scriptState); return InspectorString::create(String(s.characters(), s.length())); } if (value.isObject()) { if (isJSArray(value)) { RefPtr<InspectorArray> inspectorArray = InspectorArray::create(); JSArray* array = asArray(value); unsigned length = array->length(); for (unsigned i = 0; i < length; i++) { // FIXME: What if the array is in sparse mode? https://bugs.webkit.org/show_bug.cgi?id=95610 JSValue element = array->getIndexQuickly(i); RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element, maxDepth); if (!elementValue) return 0; inspectorArray->pushValue(elementValue); } return inspectorArray; } RefPtr<InspectorObject> inspectorObject = InspectorObject::create(); JSObject* object = value.getObject(); PropertyNameArray propertyNames(scriptState); object->methodTable()->getOwnPropertyNames(object, scriptState, propertyNames, ExcludeDontEnumProperties); for (size_t i = 0; i < propertyNames.size(); i++) { const Identifier& name = propertyNames[i]; JSValue propertyValue = object->get(scriptState, name); RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue, maxDepth); if (!inspectorValue) return 0; inspectorObject->setValue(String(name.characters(), name.length()), inspectorValue); } return inspectorObject; } ASSERT_NOT_REACHED(); return 0; }
static PassRefPtr<InspectorValue> jsToInspectorValue(ScriptState* scriptState, JSValue value) { if (!value) { ASSERT_NOT_REACHED(); return 0; } if (value.isNull() || value.isUndefined()) return InspectorValue::null(); if (value.isBoolean()) return InspectorBasicValue::create(value.getBoolean()); if (value.isNumber()) return InspectorBasicValue::create(value.uncheckedGetNumber()); if (value.isString()) { UString s = value.getString(scriptState); return InspectorString::create(String(s.characters(), s.length())); } if (value.isObject()) { if (isJSArray(&scriptState->globalData(), value)) { RefPtr<InspectorArray> inspectorArray = InspectorArray::create(); JSArray* array = asArray(value); unsigned length = array->length(); for (unsigned i = 0; i < length; i++) { JSValue element = array->getIndex(i); RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element); if (!elementValue) { ASSERT_NOT_REACHED(); elementValue = InspectorValue::null(); } inspectorArray->pushValue(elementValue); } return inspectorArray; } RefPtr<InspectorObject> inspectorObject = InspectorObject::create(); JSObject* object = value.getObject(); PropertyNameArray propertyNames(scriptState); object->getOwnPropertyNames(scriptState, propertyNames); for (size_t i = 0; i < propertyNames.size(); i++) { const Identifier& name = propertyNames[i]; JSValue propertyValue = object->get(scriptState, name); RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue); if (!inspectorValue) { ASSERT_NOT_REACHED(); inspectorValue = InspectorValue::null(); } inspectorObject->setValue(String(name.characters(), name.length()), inspectorValue); } return inspectorObject; } ASSERT_NOT_REACHED(); return 0; }
void ScopeChainNode::print() { ScopeChainIterator scopeEnd = end(); for (ScopeChainIterator scopeIter = begin(); scopeIter != scopeEnd; ++scopeIter) { JSObject* o = scopeIter->get(); PropertyNameArray propertyNames(globalObject->globalExec()); o->methodTable()->getPropertyNames(o, globalObject->globalExec(), propertyNames, ExcludeDontEnumProperties); PropertyNameArray::const_iterator propEnd = propertyNames.end(); dataLog("----- [scope %p] -----\n", o); for (PropertyNameArray::const_iterator propIter = propertyNames.begin(); propIter != propEnd; propIter++) { Identifier name = *propIter; dataLog("%s, ", name.ustring().utf8().data()); } dataLog("\n"); } }
//start QString QObjectWriter:: toString(const QObject* obj, int indentLevel) const { QStringList result; QString indentspace; indentspace.fill(' ', indentLevel * 3 ); QString className = obj->metaObject()->className(); QString objectName = obj->objectName(); QStringList propnames = propertyNames(obj); foreach (const QString &propName, propnames) { if (propName == "objectName") continue; QVariant qv = obj->property(propName.toAscii()); if (propName == "className") { className = qv.toString(); continue; } const QMetaObject* meta = obj->metaObject(); int idx = meta->indexOfProperty(propName.toAscii()); QMetaProperty mprop = meta->property(idx); result << QString("%1 <property name=\"%2\" type=\"%3\" value=\"%4\" />") .arg(indentspace).arg(propName). arg(qv.typeName()).arg(toString(qv, mprop)); } /* Query over QObjects */ if (m_children) { QList<QObject*> childlist = qFindChildren<QObject*>(obj, QString()); foreach (const QObject* child, childlist) { if (child->parent() != obj) { // qDebug() << "This is not my child!!"; continue; } if (child != 0) { result << toString(child, indentLevel+1); } } } result.insert(0, QString("\n%1<object class=\"%2\" name=\"%3\" >") .arg(indentspace).arg(className).arg(objectName)); result << QString("%1</object>\n").arg(indentspace); return result.join("\n"); }
void ScopeChainNode::print() const { ScopeChainIterator scopeEnd = end(); for (ScopeChainIterator scopeIter = begin(); scopeIter != scopeEnd; ++scopeIter) { JSObject* o = *scopeIter; PropertyNameArray propertyNames(globalObject->globalExec()); o->getPropertyNames(globalObject->globalExec(), propertyNames); PropertyNameArray::const_iterator propEnd = propertyNames.end(); fprintf(stderr, "----- [scope %p] -----\n", o); for (PropertyNameArray::const_iterator propIter = propertyNames.begin(); propIter != propEnd; propIter++) { Identifier name = *propIter; fprintf(stderr, "%s, ", name.ustring().utf8().data()); } fprintf(stderr, "\n"); } }
bool Dictionary::getOwnPropertyNames(Vector<String>& names) const { if (!m_dictionary.isValid()) return false; JSObject* object = m_dictionary.initializerObject(); ExecState* exec = m_dictionary.execState(); PropertyNameArray propertyNames(exec); JSObject::getOwnPropertyNames(object, exec, propertyNames, EnumerationMode()); for (PropertyNameArray::const_iterator it = propertyNames.begin(); it != propertyNames.end(); ++it) { String stringKey = it->string(); if (!stringKey.isEmpty()) names.append(stringKey); } return true; }
QJsonArray Utils::serializeType(const QMetaObject& meta, qlonglong timestamp) { QString className = meta.className(); QStringList properties; properties << "_id" << "modified" << "deleted"; properties << propertyNames(meta); QSqlQuery query; query.prepare(QString("SELECT %1 FROM %2 WHERE modified>:timestamp OR deleted>:timestamp").arg(properties.join(",")).arg(className)); query.bindValue(":timestamp", timestamp); query.exec(); QJsonArray array; while (query.next()) { array.append(serializeObject(properties, query)); } return array; }
bool NPJSObject::enumerate(NPIdentifier** identifiers, uint32_t* identifierCount) { ExecState* exec = m_objectMap->globalExec(); if (!exec) return false; JSLock lock(SilenceAssertionsOnly); PropertyNameArray propertyNames(exec); m_jsObject->methodTable()->getPropertyNames(m_jsObject.get(), exec, propertyNames, ExcludeDontEnumProperties); NPIdentifier* nameIdentifiers = npnMemNewArray<NPIdentifier>(propertyNames.size()); for (size_t i = 0; i < propertyNames.size(); ++i) nameIdentifiers[i] = static_cast<NPIdentifier>(IdentifierRep::get(propertyNames[i].ustring().utf8().data())); *identifiers = nameIdentifiers; *identifierCount = propertyNames.size(); return true; }
bool NPJSObject::enumerate(NPIdentifier** identifiers, uint32_t* identifierCount) { ExecState* exec = m_objectMap->globalExec(); if (!exec) return false; JSLock lock(SilenceAssertionsOnly); PropertyNameArray propertyNames(exec); m_jsObject->getPropertyNames(exec, propertyNames); // This should use NPN_MemAlloc, but we know that it uses malloc under the hood. NPIdentifier* nameIdentifiers = static_cast<NPIdentifier*>(malloc(sizeof(NPIdentifier) * propertyNames.size())); for (size_t i = 0; i < propertyNames.size(); ++i) nameIdentifiers[i] = static_cast<NPIdentifier>(IdentifierRep::get(propertyNames[i].ustring().utf8().data())); *identifiers = nameIdentifiers; *identifierCount = propertyNames.size(); return true; }
QString QQmlContextData::findObjectId(const QObject *obj) const { const QV4::IdentifierHash<int> &properties = propertyNames(); if (propertyNameCache.isEmpty()) return QString(); for (int ii = 0; ii < idValueCount; ii++) { if (idValues[ii] == obj) return properties.findId(ii); } if (publicContext) { QQmlContextPrivate *p = QQmlContextPrivate::get(publicContext); for (int ii = 0; ii < p->propertyValues.count(); ++ii) if (p->propertyValues.at(ii) == QVariant::fromValue(const_cast<QObject *>(obj))) return properties.findId(ii); } if (linkedContext) return linkedContext->findObjectId(obj); return QString(); }
bool Dictionary::getOwnPropertiesAsStringHashMap(HashMap<String, String>& map) const { if (!m_dictionary.isValid()) return false; JSObject* object = m_dictionary.initializerObject(); ExecState* exec = m_dictionary.execState(); PropertyNameArray propertyNames(exec); JSObject::getOwnPropertyNames(object, exec, propertyNames, EnumerationMode()); for (PropertyNameArray::const_iterator it = propertyNames.begin(); it != propertyNames.end(); ++it) { String stringKey = it->string(); if (stringKey.isEmpty()) continue; JSValue value = object->get(exec, *it); if (exec->hadException()) continue; String stringValue = value.toString(exec)->value(exec); if (!exec->hadException()) map.set(stringKey, stringValue); } return true; }
QV4::IdentifierHash<int> &QQmlContextData::detachedPropertyNames() { propertyNames(); propertyNameCache.detach(); return propertyNameCache; }