bool toVector(JSC::ExecState* exec, JSC::JSValue value, Vector<T, inlineCapacity>& vector) { if (!value.isObject()) return false; JSC::JSObject* object = asObject(value); int32_t length = object->get(exec, JSC::Identifier(exec, "length")).toInt32(exec); vector.resize(length); for (int32_t i = 0; i < length; ++i) { JSC::JSValue v = object->get(exec, i); if (exec->hadException()) return false; vector[i] = static_cast<T>(v.toNumber(exec)); } return true; }
bool toVector(JSC::ExecState& state, JSC::JSValue value, Vector<T, inlineCapacity>& vector) { if (!value.isObject()) return false; JSC::JSObject* object = asObject(value); int32_t length = object->get(&state, state.vm().propertyNames->length).toInt32(&state); if (!vector.tryReserveCapacity(length)) return false; vector.resize(length); for (int32_t i = 0; i < length; ++i) { JSC::JSValue v = object->get(&state, i); if (state.hadException()) return false; vector[i] = static_cast<T>(v.toNumber(&state)); } return true; }
void DragData::asFilenames(Vector<String>& result) const { bool success; JSC::JSValue data = m_platformDragData->getData(ClipboardApolloHelper::FILE_LIST_TYPE, success); JSC::ExecState *exec = m_platformDragData->execState(); if (success && data.isObject()) { JSC::JSObject* filenameArray = data.toObject(exec); uint32_t length = filenameArray->get(exec, JSC::Identifier(exec, "length")).toUInt32(exec); for (uint32_t i=0; i<length; i++) { JSC::JSValue fileValue = filenameArray->get(exec, i); if (fileValue.isObject()) { JSC::JSObject* file = fileValue.toObject(exec); JSC::JSValue pathValue = file->get(exec, JSC::Identifier(exec, "nativePath")); if (pathValue.isString()) { String path = ustringToString(pathValue.toString(exec)); result.append(path); } } } } if (exec->hadException()) exec->clearException(); }
void toArray(JSC::ExecState* exec, JSC::JSValue value, T*& array, int& size) { array = 0; if (!value.isObject()) return; JSC::JSObject* object = asObject(value); int length = object->get(exec, JSC::Identifier(exec, "length")).toInt32(exec); void* tempValues; if (!tryFastMalloc(length * sizeof(T)).getValue(tempValues)) return; T* values = static_cast<T*>(tempValues); for (int i = 0; i < length; ++i) { JSC::JSValue v = object->get(exec, i); if (exec->hadException()) return; values[i] = static_cast<T>(v.toNumber(exec)); } array = values; size = length; }