Add Cast() to Boolean

We should be able to cast a Value to Boolean when IsBoolean() is true.

Review URL: https://codereview.chromium.org/990943003

Cr-Commit-Position: refs/heads/master@{#27124}
This commit is contained in:
bashi 2015-03-10 16:40:11 -07:00 committed by Commit bot
parent 0c12ff2db4
commit 8bdac10631
2 changed files with 19 additions and 0 deletions

View File

@ -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);
};
@ -7314,6 +7317,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);

View File

@ -2933,6 +2933,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(),