Revision: 23338
Author: [email protected]
Date: Mon Aug 25 08:56:31 2014 UTC
Log: Expose Value::IsMap, IsSet, IsWeakMap, IsWeakSet in V8 API.
These checks will be needed for DevTools.
[email protected], [email protected]
Review URL: https://codereview.chromium.org/464413002
https://code.google.com/p/v8/source/detail?r=23338
Modified:
/branches/bleeding_edge/include/v8.h
/branches/bleeding_edge/src/api.cc
/branches/bleeding_edge/src/heap/heap.h
/branches/bleeding_edge/test/cctest/test-api.cc
=======================================
--- /branches/bleeding_edge/include/v8.h Thu Aug 21 12:39:33 2014 UTC
+++ /branches/bleeding_edge/include/v8.h Mon Aug 25 08:56:31 2014 UTC
@@ -1472,6 +1472,30 @@
*/
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.
=======================================
--- /branches/bleeding_edge/src/api.cc Wed Aug 20 15:25:13 2014 UTC
+++ /branches/bleeding_edge/src/api.cc Mon Aug 25 08:56:31 2014 UTC
@@ -2412,13 +2412,27 @@
}
-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 {
return Utils::OpenHandle(this)->IsBoolean();
@@ -2452,38 +2466,6 @@
}
return false;
}
-
-
-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,
@@ -2515,14 +2497,6 @@
return false;
}
}
-
-
-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 {
=======================================
--- /branches/bleeding_edge/src/heap/heap.h Fri Aug 22 09:18:10 2014 UTC
+++ /branches/bleeding_edge/src/heap/heap.h Mon Aug 25 08:56:31 2014 UTC
@@ -294,6 +294,10 @@
V(String_string, "String") \
V(symbol_string, "symbol") \
V(Symbol_string, "Symbol") \
+ V(Map_string, "Map") \
+ V(Set_string, "Set") \
+ V(WeakMap_string, "WeakMap") \
+ V(WeakSet_string, "WeakSet") \
V(for_string, "for") \
V(for_api_string, "for_api") \
V(for_intern_string, "for_intern") \
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Thu Aug 21 11:55:46
2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-api.cc Mon Aug 25 08:56:31
2014 UTC
@@ -1554,6 +1554,42 @@
v8::Handle<Value> object = CompileRun("{a:42}");
CHECK(!object->IsArgumentsObject());
}
+
+
+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) {
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.