Commit 83245abb authored by bashi's avatar bashi Committed by Commit bot

Add Cast() for Int32 and Uint32

It should be possible to cast a Value to Int32 without throwing an exception
when IsInt32() is true. Same for Uint32.

BUG=chromium:462402
LOG=Y

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

Cr-Commit-Position: refs/heads/master@{#27156}
parent 40567349
......@@ -2465,8 +2465,11 @@ class V8_EXPORT Integer : public Number {
class V8_EXPORT Int32 : public Integer {
public:
int32_t Value() const;
V8_INLINE static Int32* Cast(v8::Value* obj);
private:
Int32();
static void CheckCast(v8::Value* obj);
};
......@@ -2476,8 +2479,11 @@ class V8_EXPORT Int32 : public Integer {
class V8_EXPORT Uint32 : public Integer {
public:
uint32_t Value() const;
V8_INLINE static Uint32* Cast(v8::Value* obj);
private:
Uint32();
static void CheckCast(v8::Value* obj);
};
......@@ -7364,6 +7370,22 @@ Integer* Integer::Cast(v8::Value* value) {
}
Int32* Int32::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
#endif
return static_cast<Int32*>(value);
}
Uint32* Uint32::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
#endif
return static_cast<Uint32*>(value);
}
Date* Date::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
......
......@@ -2973,6 +2973,18 @@ void v8::Integer::CheckCast(v8::Value* that) {
}
void v8::Int32::CheckCast(v8::Value* that) {
Utils::ApiCheck(that->IsInt32(), "v8::Int32::Cast()",
"Could not convert to 32-bit signed integer");
}
void v8::Uint32::CheckCast(v8::Value* that) {
Utils::ApiCheck(that->IsUint32(), "v8::Uint32::Cast()",
"Could not convert to 32-bit unsigned integer");
}
void v8::Array::CheckCast(Value* that) {
i::Handle<i::Object> obj = Utils::OpenHandle(that);
Utils::ApiCheck(obj->IsJSArray(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment