Esempio n. 1
0
Vector<String> Dictionary::getPropertyNames(
    ExceptionState& exceptionState) const {
  if (m_dictionaryObject.IsEmpty())
    return Vector<String>();

  v8::TryCatch tryCatch(isolate());
  v8::Local<v8::Array> propertyNames;
  if (!m_dictionaryObject->GetPropertyNames(v8Context())
           .ToLocal(&propertyNames)) {
    exceptionState.rethrowV8Exception(tryCatch.Exception());
    return Vector<String>();
  }

  Vector<String> names;
  for (uint32_t i = 0; i < propertyNames->Length(); ++i) {
    v8::Local<v8::String> key;
    if (!getStringValueInArray(v8Context(), propertyNames, i).ToLocal(&key)) {
      exceptionState.rethrowV8Exception(tryCatch.Exception());
      return Vector<String>();
    }
    V8StringResource<> stringKey(key);
    if (!stringKey.prepare(isolate(), exceptionState))
      return Vector<String>();

    names.push_back(stringKey);
  }

  return names;
}
Esempio n. 2
0
bool Dictionary::getOwnPropertiesAsStringHashMap(
    HashMap<String, String>& hashMap) const {
  v8::Local<v8::Object> object;
  if (!toObject(object))
    return false;

  v8::Local<v8::Array> properties;
  if (!object->GetOwnPropertyNames(v8Context()).ToLocal(&properties))
    return false;
  for (uint32_t i = 0; i < properties->Length(); ++i) {
    v8::Local<v8::String> key;
    if (!propertyKey(v8Context(), properties, i, key))
      continue;
    if (!v8CallBoolean(object->Has(v8Context(), key)))
      continue;

    v8::Local<v8::Value> value;
    if (!object->Get(v8Context(), key).ToLocal(&value))
      continue;
    TOSTRING_DEFAULT(V8StringResource<>, stringKey, key, false);
    TOSTRING_DEFAULT(V8StringResource<>, stringValue, value, false);
    if (!static_cast<const String&>(stringKey).isEmpty())
      hashMap.set(stringKey, stringValue);
  }

  return true;
}
Esempio n. 3
0
bool Dictionary::getInternal(const v8::Local<v8::Value>& key,
                             v8::Local<v8::Value>& result) const {
  v8::Local<v8::Object> object;
  if (!toObject(object))
    return false;

  DCHECK(m_isolate);
  DCHECK_EQ(m_isolate, v8::Isolate::GetCurrent());
  if (!v8CallBoolean(object->Has(v8Context(), key)))
    return false;
  return object->Get(v8Context(), key).ToLocal(&result);
}
Esempio n. 4
0
bool Dictionary::getKey(const String& key, v8::Local<v8::Value>& value) const
{
    v8::Local<v8::Object> object;
    if (!toObject(object))
        return false;

    ASSERT(m_isolate);
    ASSERT(m_isolate == v8::Isolate::GetCurrent());
    ASSERT(m_exceptionState);
    v8::Local<v8::String> v8Key = v8String(m_isolate, key);
    if (!v8CallBoolean(object->Has(v8Context(), v8Key)))
        return false;
    return object->Get(v8Context(), v8Key).ToLocal(&value);
}
Esempio n. 5
0
bool Dictionary::getInternal(const v8::Local<v8::Value>& key,
                             v8::Local<v8::Value>& result) const {
  if (m_dictionaryObject.IsEmpty())
    return false;

  if (!v8CallBoolean(m_dictionaryObject->Has(v8Context(), key)))
    return false;

  // Swallow a possible exception in v8::Object::Get().
  // TODO(bashi,yukishiino): Should rethrow the exception.
  // http://crbug.com/666661
  v8::TryCatch tryCatch(isolate());
  return m_dictionaryObject->Get(v8Context(), key).ToLocal(&result);
}
Esempio n. 6
0
bool Dictionary::hasProperty(const StringView& key) const {
  v8::Local<v8::Object> object;
  if (!toObject(object))
    return false;

  DCHECK(m_isolate);
  DCHECK_EQ(m_isolate, v8::Isolate::GetCurrent());
  return v8CallBoolean(object->Has(v8Context(), v8String(m_isolate, key)));
}
Esempio n. 7
0
bool Dictionary::getPropertyNames(Vector<String>& names) const {
  v8::Local<v8::Object> object;
  if (!toObject(object))
    return false;

  v8::Local<v8::Array> properties;
  if (!object->GetPropertyNames(v8Context()).ToLocal(&properties))
    return false;
  for (uint32_t i = 0; i < properties->Length(); ++i) {
    v8::Local<v8::String> key;
    if (!propertyKey(v8Context(), properties, i, key))
      continue;
    if (!v8CallBoolean(object->Has(v8Context(), key)))
      continue;
    TOSTRING_DEFAULT(V8StringResource<>, stringKey, key, false);
    names.append(stringKey);
  }

  return true;
}
Esempio n. 8
0
bool Dictionary::hasProperty(const String& key) const
{
    v8::Local<v8::Object> object;
    if (!toObject(object))
        return false;

    ASSERT(m_isolate);
    ASSERT(m_isolate == v8::Isolate::GetCurrent());
    ASSERT(m_exceptionState);
    v8::Local<v8::String> v8Key = v8String(m_isolate, key);
    return v8CallBoolean(object->Has(v8Context(), v8Key));
}
Esempio n. 9
0
HashMap<String, String> Dictionary::getOwnPropertiesAsStringHashMap(
    ExceptionState& exceptionState) const {
  if (m_dictionaryObject.IsEmpty())
    return HashMap<String, String>();

  v8::TryCatch tryCatch(isolate());
  v8::Local<v8::Array> propertyNames;
  if (!m_dictionaryObject->GetOwnPropertyNames(v8Context())
           .ToLocal(&propertyNames)) {
    exceptionState.rethrowV8Exception(tryCatch.Exception());
    return HashMap<String, String>();
  }

  HashMap<String, String> ownProperties;
  for (uint32_t i = 0; i < propertyNames->Length(); ++i) {
    v8::Local<v8::String> key;
    if (!getStringValueInArray(v8Context(), propertyNames, i).ToLocal(&key)) {
      exceptionState.rethrowV8Exception(tryCatch.Exception());
      return HashMap<String, String>();
    }
    V8StringResource<> stringKey(key);
    if (!stringKey.prepare(isolate(), exceptionState))
      return HashMap<String, String>();

    v8::Local<v8::Value> value;
    if (!m_dictionaryObject->Get(v8Context(), key).ToLocal(&value)) {
      exceptionState.rethrowV8Exception(tryCatch.Exception());
      return HashMap<String, String>();
    }
    V8StringResource<> stringValue(value);
    if (!stringValue.prepare(isolate(), exceptionState))
      return HashMap<String, String>();

    if (!static_cast<const String&>(stringKey).isEmpty())
      ownProperties.set(stringKey, stringValue);
  }

  return ownProperties;
}
Esempio n. 10
0
bool Dictionary::hasProperty(const StringView& key,
                             ExceptionState& exceptionState) const {
  if (m_dictionaryObject.IsEmpty())
    return false;

  v8::TryCatch tryCatch(m_isolate);
  bool hasKey = false;
  if (!m_dictionaryObject->Has(v8Context(), v8String(m_isolate, key))
           .To(&hasKey)) {
    exceptionState.rethrowV8Exception(tryCatch.Exception());
    return false;
  }

  return hasKey;
}
Esempio n. 11
0
bool Dictionary::toObject(v8::Local<v8::Object>& object) const {
  return !isUndefinedOrNull() &&
         m_options->ToObject(v8Context()).ToLocal(&object);
}