Reviewers: dcarney,
Message:
I need this to fix the compile error which occurred when I trying to use
As<Boolean>.
https://codereview.chromium.org/986573002/#msg8
Similarly, V8 doesn't provide Cast() for Int32 and Uint32. I assume that we
should use ToInt32() or ToUint32() even when IsInt32() (or IsUint32()) is
true,
given that it seems there is no trivial way to implement
v8::internal::Object::isInt32().
Description:
Add Cast() to Boolean
We should be able to cast a Value to Boolean when IsBoolean() is true.
Please review this at https://codereview.chromium.org/990943003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+19, -0 lines):
M include/v8.h
M src/api.cc
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
76186064524dd005dcef6e119615e564b602988a..765bdae07e6eded5a5e0682694974bfa0d9d6791
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -2007,7 +2007,10 @@ class V8_EXPORT Primitive : public Value { };
class V8_EXPORT Boolean : public Primitive {
public:
bool Value() const;
+ V8_INLINE static Boolean* Cast(v8::Value* obj);
V8_INLINE static Handle<Boolean> New(Isolate* isolate, bool value);
+ private:
+ static void CheckCast(v8::Value* obj);
};
@@ -7287,6 +7290,14 @@ Local<Uint32> Value::ToUint32() const {
Local<Int32> Value::ToInt32() const { return
ToInt32(Isolate::GetCurrent()); }
+Boolean* Boolean::Cast(v8::Value* value) {
+#ifdef V8_ENABLE_CHECKS
+ CheckCast(value);
+#endif
+ return static_cast<Boolean*>(value);
+}
+
+
Name* Name::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
f0c105cffc9817c8e302b9b06f92b771eec3246d..c774c9491757cfe0601021e51d0e7d62001bfee9
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2946,6 +2946,14 @@ void v8::Function::CheckCast(Value* that) {
}
+void v8::Boolean::CheckCast(v8::Value* that) {
+ i::Handle<i::Object> obj = Utils::OpenHandle(that);
+ Utils::ApiCheck(obj->IsBoolean(),
+ "v8::Boolean::Cast()",
+ "Could not convert to boolean");
+}
+
+
void v8::Name::CheckCast(v8::Value* that) {
i::Handle<i::Object> obj = Utils::OpenHandle(that);
Utils::ApiCheck(obj->IsName(),
--
--
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.