Index: Source/bindings/core/v8/V8Binding.cpp |
diff --git a/Source/bindings/core/v8/V8Binding.cpp b/Source/bindings/core/v8/V8Binding.cpp |
index 9d52428fd65061187f4d4bac23574645fca3a314..258be4435f595d1f34c9a5f3fe4583aed5fc4ee0 100644 |
--- a/Source/bindings/core/v8/V8Binding.cpp |
+++ b/Source/bindings/core/v8/V8Binding.cpp |
@@ -177,9 +177,15 @@ static inline T toSmallerInt(v8::Handle<v8::Value> value, IntegerConversionConfi |
{ |
typedef IntTypeLimits<T> LimitsTrait; |
+ v8::Isolate* isolate = exceptionState.isolate(); |
+ v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
// Fast case. The value is already a 32-bit integer in the right range. |
if (value->IsInt32()) { |
- int32_t result = value->Int32Value(); |
+ int32_t result; |
bashi
2015/03/11 10:30:37
As seen below, there are some code which look almo
|
+ if (!getValueFromMaybe(value->Int32Value(context), result)) { |
+ exceptionState.throwTypeError("Cannot convert to a 32 bit integer."); |
+ return 0; |
+ } |
if (result >= LimitsTrait::minValue && result <= LimitsTrait::maxValue) |
return static_cast<T>(result); |
if (configuration == EnforceRange) { |
@@ -196,12 +202,13 @@ static inline T toSmallerInt(v8::Handle<v8::Value> value, IntegerConversionConfi |
if (value->IsNumber()) { |
numberObject = value.As<v8::Number>(); |
} else { |
- v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
// Can the value be converted to a number? |
v8::TryCatch block(isolate); |
- numberObject = value->ToNumber(isolate); |
- if (block.HasCaught()) { |
- exceptionState.rethrowV8Exception(block.Exception()); |
+ if (!value->ToNumber(context).ToLocal(&numberObject)) { |
Yuki
2015/03/11 13:11:53
It looks to me that either of ToNumber or ToLocal
|
+ if (block.HasCaught()) |
+ exceptionState.rethrowV8Exception(block.Exception()); |
+ else |
+ exceptionState.throwTypeError("Cannot convert to a number."); |
return 0; |
} |
} |
@@ -231,9 +238,15 @@ static inline T toSmallerUInt(v8::Handle<v8::Value> value, IntegerConversionConf |
{ |
typedef IntTypeLimits<T> LimitsTrait; |
+ v8::Isolate* isolate = exceptionState.isolate(); |
+ v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
// Fast case. The value is a 32-bit signed integer - possibly positive? |
if (value->IsInt32()) { |
int32_t result = value->Int32Value(); |
+ if (!getValueFromMaybe(value->Int32Value(context), result)) { |
+ exceptionState.throwTypeError("Cannot convert to a 32 bit integer."); |
+ return 0; |
+ } |
if (result >= 0 && result <= LimitsTrait::maxValue) |
return static_cast<T>(result); |
if (configuration == EnforceRange) { |
@@ -249,12 +262,13 @@ static inline T toSmallerUInt(v8::Handle<v8::Value> value, IntegerConversionConf |
if (value->IsNumber()) { |
numberObject = value.As<v8::Number>(); |
} else { |
- v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
// Can the value be converted to a number? |
v8::TryCatch block(isolate); |
- numberObject = value->ToNumber(isolate); |
- if (block.HasCaught()) { |
- exceptionState.rethrowV8Exception(block.Exception()); |
+ if (!value->ToNumber(context).ToLocal(&numberObject)) { |
+ if (block.HasCaught()) |
+ exceptionState.rethrowV8Exception(block.Exception()); |
+ else |
+ exceptionState.throwTypeError("Cannot convert to a number."); |
return 0; |
} |
} |
@@ -324,20 +338,29 @@ uint16_t toUInt16(v8::Handle<v8::Value> value) |
int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) |
{ |
+ v8::Isolate* isolate = exceptionState.isolate(); |
+ v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
// Fast case. The value is already a 32-bit integer. |
- if (value->IsInt32()) |
- return value->Int32Value(); |
+ if (value->IsInt32()) { |
+ int32_t result; |
+ if (!getValueFromMaybe(value->Int32Value(context), result)) { |
+ exceptionState.throwTypeError("Cannot convert to a 32 bit integer."); |
+ return 0; |
+ } |
+ return result; |
+ } |
v8::Local<v8::Number> numberObject; |
if (value->IsNumber()) { |
numberObject = value.As<v8::Number>(); |
} else { |
- v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
// Can the value be converted to a number? |
v8::TryCatch block(isolate); |
- numberObject = value->ToNumber(isolate); |
- if (block.HasCaught()) { |
- exceptionState.rethrowV8Exception(block.Exception()); |
+ if (!value->ToNumber(context).ToLocal(&numberObject)) { |
+ if (block.HasCaught()) |
+ exceptionState.rethrowV8Exception(block.Exception()); |
+ else |
+ exceptionState.throwTypeError("Cannot convert to a number."); |
return 0; |
} |
} |
@@ -357,7 +380,12 @@ int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf |
if (std::isinf(numberValue)) |
return 0; |
- return numberObject->Int32Value(); |
+ int32_t result; |
+ if (!getValueFromMaybe(numberObject->Int32Value(context), result)) { |
+ exceptionState.throwTypeError("Cannot convert to a 32 bit integer."); |
+ return 0; |
+ } |
+ return result; |
} |
int32_t toInt32(v8::Handle<v8::Value> value) |
@@ -369,9 +397,15 @@ int32_t toInt32(v8::Handle<v8::Value> value) |
uint32_t toUInt32Slow(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) |
{ |
ASSERT(!value->IsUint32()); |
+ v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
+ v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
if (value->IsInt32()) { |
ASSERT(configuration != NormalConversion); |
- int32_t result = value->Int32Value(); |
+ int32_t result; |
+ if (!getValueFromMaybe(value->Int32Value(context), result)) { |
+ exceptionState.throwTypeError("Cannot convert to a 32 bit integer."); |
+ return 0; |
+ } |
if (result >= 0) |
return result; |
if (configuration == EnforceRange) { |
@@ -382,12 +416,14 @@ uint32_t toUInt32Slow(v8::Handle<v8::Value> value, IntegerConversionConfiguratio |
return clampTo<uint32_t>(result); |
} |
- v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
// Can the value be converted to a number? |
v8::TryCatch block(isolate); |
- v8::Local<v8::Number> numberObject = value->ToNumber(isolate); |
- if (block.HasCaught()) { |
- exceptionState.rethrowV8Exception(block.Exception()); |
+ v8::Local<v8::Number> numberObject; |
+ if (!value->ToNumber(context).ToLocal(&numberObject)) { |
+ if (block.HasCaught()) |
+ exceptionState.rethrowV8Exception(block.Exception()); |
+ else |
+ exceptionState.throwTypeError("Cannot convert to a number."); |
return 0; |
} |
ASSERT(!numberObject.IsEmpty()); |
@@ -406,7 +442,12 @@ uint32_t toUInt32Slow(v8::Handle<v8::Value> value, IntegerConversionConfiguratio |
if (std::isinf(numberValue)) |
return 0; |
- return numberObject->Uint32Value(); |
+ uint32_t result; |
+ if (!getValueFromMaybe(numberObject->Uint32Value(context), result)) { |
+ exceptionState.throwTypeError("Cannot convert to a 32 bit unsigned integer."); |
+ return 0; |
+ } |
+ return result; |
} |
uint32_t toUInt32(v8::Handle<v8::Value> value) |
@@ -420,20 +461,29 @@ int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf |
// Clamping not supported for int64_t/long long int. See Source/wtf/MathExtras.h. |
ASSERT(configuration != Clamp); |
+ v8::Isolate* isolate = exceptionState.isolate(); |
+ v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
// Fast case. The value is a 32-bit integer. |
- if (value->IsInt32()) |
- return value->Int32Value(); |
+ if (value->IsInt32()) { |
+ int32_t result; |
+ if (!getValueFromMaybe(value->Int32Value(context), result)) { |
+ exceptionState.throwTypeError("Cannot convert to a 32 bit integer."); |
+ return 0; |
+ } |
+ return result; |
+ } |
v8::Local<v8::Number> numberObject; |
if (value->IsNumber()) { |
numberObject = value.As<v8::Number>(); |
} else { |
- v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
// Can the value be converted to a number? |
v8::TryCatch block(isolate); |
- numberObject = value->ToNumber(isolate); |
- if (block.HasCaught()) { |
- exceptionState.rethrowV8Exception(block.Exception()); |
+ if (!value->ToNumber(context).ToLocal(&numberObject)) { |
+ if (block.HasCaught()) |
+ exceptionState.rethrowV8Exception(block.Exception()); |
+ else |
+ exceptionState.throwTypeError("Cannot convert to a number."); |
return 0; |
} |
} |
@@ -461,13 +511,26 @@ int64_t toInt64(v8::Handle<v8::Value> value) |
uint64_t toUInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) |
{ |
+ v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
+ v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
+ |
// Fast case. The value is a 32-bit unsigned integer. |
- if (value->IsUint32()) |
- return value->Uint32Value(); |
+ if (value->IsUint32()) { |
+ uint32_t result; |
+ if (!getValueFromMaybe(value->Uint32Value(context), result)) { |
+ exceptionState.throwTypeError("Cannot convert to a 32 bit unsigned integer."); |
+ return 0; |
+ } |
+ return result; |
+ } |
// Fast case. The value is a 32-bit integer. |
if (value->IsInt32()) { |
- int32_t result = value->Int32Value(); |
+ int32_t result; |
+ if (!getValueFromMaybe(value->Int32Value(context), result)) { |
+ exceptionState.throwTypeError("Cannot convert to a 32 bit integer."); |
+ return 0; |
+ } |
if (result >= 0) |
return result; |
if (configuration == EnforceRange) { |
@@ -483,12 +546,13 @@ uint64_t toUInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration co |
if (value->IsNumber()) { |
numberObject = value.As<v8::Number>(); |
} else { |
- v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
// Can the value be converted to a number? |
v8::TryCatch block(isolate); |
- numberObject = value->ToNumber(isolate); |
- if (block.HasCaught()) { |
- exceptionState.rethrowV8Exception(block.Exception()); |
+ if (!value->ToNumber(context).ToLocal(&numberObject)) { |
+ if (block.HasCaught()) |
+ exceptionState.rethrowV8Exception(block.Exception()); |
+ else |
+ exceptionState.throwTypeError("Cannot convert to a number."); |
return 0; |
} |
} |
@@ -535,11 +599,14 @@ float toRestrictedFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionSt |
double toDoubleSlow(v8::Handle<v8::Value> value, ExceptionState& exceptionState) |
{ |
ASSERT(!value->IsNumber()); |
- v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
+ v8::Isolate* isolate = exceptionState.isolate(); |
v8::TryCatch block(isolate); |
- double doubleValue = value->NumberValue(); |
- if (block.HasCaught()) { |
- exceptionState.rethrowV8Exception(block.Exception()); |
+ double doubleValue; |
+ if (!getValueFromMaybe(value->NumberValue(isolate->GetCurrentContext()), doubleValue)) { |
+ if (block.HasCaught()) |
+ exceptionState.rethrowV8Exception(block.Exception()); |
+ else |
+ exceptionState.throwTypeError("Cannot convert to a number."); |
return 0; |
} |
return doubleValue; |
@@ -572,11 +639,14 @@ String toByteString(v8::Handle<v8::Value> value, ExceptionState& exceptionState) |
if (value->IsString()) { |
stringObject = value.As<v8::String>(); |
} else { |
- v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
+ v8::Isolate* isolate = exceptionState.isolate(); |
v8::TryCatch block(isolate); |
stringObject = value->ToString(isolate); |
- if (block.HasCaught()) { |
- exceptionState.rethrowV8Exception(block.Exception()); |
+ if (!value->ToString(isolate->GetCurrentContext()).ToLocal(&stringObject)) { |
+ if (block.HasCaught()) |
+ exceptionState.rethrowV8Exception(block.Exception()); |
+ else |
+ exceptionState.throwTypeError("Cannot convert to a string."); |
return String(); |
} |
} |
@@ -708,9 +778,13 @@ String toUSVString(v8::Handle<v8::Value> value, ExceptionState& exceptionState) |
if (value->IsString()) { |
stringObject = value.As<v8::String>(); |
} else { |
- v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
+ v8::Isolate* isolate = exceptionState.isolate(); |
v8::TryCatch block(isolate); |
stringObject = value->ToString(isolate); |
+ if (!value->ToString(isolate->GetCurrentContext()).ToLocal(&stringObject)) { |
+ exceptionState.throwTypeError("Cannot convert to a string."); |
+ return String(); |
+ } |
if (block.HasCaught()) { |
exceptionState.rethrowV8Exception(block.Exception()); |
return String(); |