bool IsPromise() const;
/**
+ * Returns true if this value is a Map.
+ * This is an experimental feature.
+ */
+ bool IsMap() const;
+
+ /**
+ * Returns true if this value is a Set.
+ * This is an experimental feature.
+ */
+ bool IsSet() const;
+
+ /**
+ * Returns true if this value is a WeakMap.
+ * This is an experimental feature.
+ */
+ bool IsWeakMap() const;
+
+ /**
+ * Returns true if this value is a WeakSet.
+ * This is an experimental feature.
+ */
+ bool IsWeakSet() const;
+
+ /**
* Returns true if this value is an ArrayBuffer.
* This is an experimental feature.
*/
}
-bool Value::IsArgumentsObject() const {
- i::Handle<i::Object> obj = Utils::OpenHandle(this);
- if (!obj->IsHeapObject()) return false;
- i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
- return obj->HasSpecificClassOf(isolate->heap()->Arguments_string());
-}
+#define VALUE_IS_SPECIFIC_TYPE(Type, Class) \
+ bool Value::Is##Type() const { \
+ i::Handle<i::Object> obj = Utils::OpenHandle(this); \
+ if (!obj->IsHeapObject()) return false; \
+ i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); \
+ return obj->HasSpecificClassOf(isolate->heap()->Class##_string()); \
+ }
+
+VALUE_IS_SPECIFIC_TYPE(ArgumentsObject, Arguments)
+VALUE_IS_SPECIFIC_TYPE(BooleanObject, Boolean)
+VALUE_IS_SPECIFIC_TYPE(NumberObject, Number)
+VALUE_IS_SPECIFIC_TYPE(StringObject, String)
+VALUE_IS_SPECIFIC_TYPE(SymbolObject, Symbol)
+VALUE_IS_SPECIFIC_TYPE(Date, Date)
+VALUE_IS_SPECIFIC_TYPE(Map, Map)
+VALUE_IS_SPECIFIC_TYPE(Set, Set)
+VALUE_IS_SPECIFIC_TYPE(WeakMap, WeakMap)
+VALUE_IS_SPECIFIC_TYPE(WeakSet, WeakSet)
+
+#undef VALUE_IS_SPECIFIC_TYPE
bool Value::IsBoolean() const {
}
-bool Value::IsDate() const {
- i::Handle<i::Object> obj = Utils::OpenHandle(this);
- if (!obj->IsHeapObject()) return false;
- i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
- return obj->HasSpecificClassOf(isolate->heap()->Date_string());
-}
-
-
-bool Value::IsStringObject() const {
- i::Handle<i::Object> obj = Utils::OpenHandle(this);
- if (!obj->IsHeapObject()) return false;
- i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
- return obj->HasSpecificClassOf(isolate->heap()->String_string());
-}
-
-
-bool Value::IsSymbolObject() const {
- i::Handle<i::Object> obj = Utils::OpenHandle(this);
- if (!obj->IsHeapObject()) return false;
- i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
- return obj->HasSpecificClassOf(isolate->heap()->Symbol_string());
-}
-
-
-bool Value::IsNumberObject() const {
- i::Handle<i::Object> obj = Utils::OpenHandle(this);
- if (!obj->IsHeapObject()) return false;
- i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
- return obj->HasSpecificClassOf(isolate->heap()->Number_string());
-}
-
-
static bool CheckConstructor(i::Isolate* isolate,
i::Handle<i::JSObject> obj,
const char* class_name) {
}
-bool Value::IsBooleanObject() const {
- i::Handle<i::Object> obj = Utils::OpenHandle(this);
- if (!obj->IsHeapObject()) return false;
- i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
- return obj->HasSpecificClassOf(isolate->heap()->Boolean_string());
-}
-
-
bool Value::IsRegExp() const {
i::Handle<i::Object> obj = Utils::OpenHandle(this);
return obj->IsJSRegExp();
}
+THREADED_TEST(IsMapOrSet) {
+ LocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+ v8::Handle<Value> map = CompileRun("new Map()");
+ v8::Handle<Value> set = CompileRun("new Set()");
+ v8::Handle<Value> weak_map = CompileRun("new WeakMap()");
+ v8::Handle<Value> weak_set = CompileRun("new WeakSet()");
+ CHECK(map->IsMap());
+ CHECK(set->IsSet());
+ CHECK(weak_map->IsWeakMap());
+ CHECK(weak_set->IsWeakSet());
+
+ CHECK(!map->IsSet());
+ CHECK(!map->IsWeakMap());
+ CHECK(!map->IsWeakSet());
+
+ CHECK(!set->IsMap());
+ CHECK(!set->IsWeakMap());
+ CHECK(!set->IsWeakSet());
+
+ CHECK(!weak_map->IsMap());
+ CHECK(!weak_map->IsSet());
+ CHECK(!weak_map->IsWeakSet());
+
+ CHECK(!weak_set->IsMap());
+ CHECK(!weak_set->IsSet());
+ CHECK(!weak_set->IsWeakMap());
+
+ v8::Handle<Value> object = CompileRun("{a:42}");
+ CHECK(!object->IsMap());
+ CHECK(!object->IsSet());
+ CHECK(!object->IsWeakMap());
+ CHECK(!object->IsWeakSet());
+}
+
+
THREADED_TEST(StringObject) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());