Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: src/api.cc

Issue 13977018: Add Value::Is* methods for typed arrays and ArrayBuffer (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 4352ef3301e2f56a44689bc27459219b8cf1961e..c2ae74f64c73e7bcbfb46b8fb2bab0bd9e51bd0b 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2408,6 +2408,43 @@ bool Value::IsArray() const {
return Utils::OpenHandle(this)->IsJSArray();
}
rossberg 2013/04/30 13:46:48 Nit: extra line
+bool Value::IsArrayBuffer() const {
+ if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArrayBuffer()"))
+ return false;
+ return Utils::OpenHandle(this)->IsJSArrayBuffer();
+}
+
+
+bool Value::IsTypedArray() const {
+ if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArrayBuffer()"))
+ return false;
+ return Utils::OpenHandle(this)->IsJSTypedArray();
+}
+
rossberg 2013/04/30 13:46:48 Same here
+#define TYPED_ARRAY_LIST(F) \
+F(Uint8Array, kExternalUnsignedByteArray) \
+F(Int8Array, kExternalByteArray) \
+F(Uint16Array, kExternalUnsignedShortArray) \
+F(Int16Array, kExternalShortArray) \
+F(Uint32Array, kExternalUnsignedIntArray) \
+F(Int32Array, kExternalIntArray) \
+F(Float32Array, kExternalFloatArray) \
+F(Float64Array, kExternalDoubleArray)
+
+
+#define VALUE_IS_TYPED_ARRAY(TypedArray, type_const) \
+ bool Value::Is##TypedArray() const { \
+ if (IsDeadCheck(i::Isolate::Current(), "v8::Value::Is" #TypedArray "()")) \
+ return false; \
+ i::Handle<i::Object> obj = Utils::OpenHandle(this); \
+ if (!obj->IsJSTypedArray()) return false; \
+ return i::JSTypedArray::cast(*obj)->type() == type_const; \
+ }
+
+TYPED_ARRAY_LIST(VALUE_IS_TYPED_ARRAY)
+
+#undef VALUE_IS_TYPED_ARRAY
+
bool Value::IsObject() const {
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsObject()")) return false;
@@ -2776,14 +2813,7 @@ void v8::TypedArray::CheckCast(Value* that) {
}
-CHECK_TYPED_ARRAY_CAST(Uint8Array, kExternalUnsignedByteArray)
-CHECK_TYPED_ARRAY_CAST(Int8Array, kExternalByteArray)
-CHECK_TYPED_ARRAY_CAST(Uint16Array, kExternalUnsignedShortArray)
-CHECK_TYPED_ARRAY_CAST(Int16Array, kExternalShortArray)
-CHECK_TYPED_ARRAY_CAST(Uint32Array, kExternalUnsignedIntArray)
-CHECK_TYPED_ARRAY_CAST(Int32Array, kExternalIntArray)
-CHECK_TYPED_ARRAY_CAST(Float32Array, kExternalFloatArray)
-CHECK_TYPED_ARRAY_CAST(Float64Array, kExternalDoubleArray)
+TYPED_ARRAY_LIST(CHECK_TYPED_ARRAY_CAST)
#undef CHECK_TYPED_ARRAY_CAST
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698