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

Unified Diff: Source/bindings/core/v8/V8Binding.cpp

Issue 559553003: In V8Binding.cpp, throw all exceptions via ExceptionState& argument (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/v8/V8Binding.cpp
diff --git a/Source/bindings/core/v8/V8Binding.cpp b/Source/bindings/core/v8/V8Binding.cpp
index b1e36c0770e75469d2b5ca77c8109eb2dabbcc69..ff24e6097cd89c7778d7b286a186b719378850dd 100644
--- a/Source/bindings/core/v8/V8Binding.cpp
+++ b/Source/bindings/core/v8/V8Binding.cpp
@@ -202,12 +202,15 @@ static inline T toSmallerInt(v8::Handle<v8::Value> value, IntegerConversionConfi
}
// Can the value be converted to a number?
- TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToNumber(), exceptionState, 0);
- if (numberObject.IsEmpty()) {
- exceptionState.throwTypeError("Not convertible to a number value (of type '" + String(typeName) + "'.");
+ v8::TryCatch block;
+ v8::Local<v8::Number> numberObject(value->ToNumber());
+ if (block.HasCaught()) {
+ exceptionState.rethrowV8Exception(block.Exception());
return 0;
}
+ ASSERT(!numberObject.IsEmpty());
+
if (configuration == EnforceRange)
return enforceRange(numberObject->Value(), LimitsTrait::minValue, LimitsTrait::maxValue, typeName, exceptionState);
@@ -239,12 +242,15 @@ static inline T toSmallerUInt(v8::Handle<v8::Value> value, IntegerConversionConf
}
// Can the value be converted to a number?
- TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToNumber(), exceptionState, 0);
- if (numberObject.IsEmpty()) {
- exceptionState.throwTypeError("Not convertible to a number value (of type '" + String(typeName) + "'.");
+ v8::TryCatch block;
+ v8::Local<v8::Number> numberObject(value->ToNumber());
+ if (block.HasCaught()) {
+ exceptionState.rethrowV8Exception(block.Exception());
return 0;
}
+ ASSERT(!numberObject.IsEmpty());
+
if (configuration == EnforceRange)
return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typeName, exceptionState);
@@ -311,12 +317,15 @@ int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
return value->Int32Value();
// Can the value be converted to a number?
- TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToNumber(), exceptionState, 0);
- if (numberObject.IsEmpty()) {
- exceptionState.throwTypeError("Not convertible to a number value (of type 'long'.)");
+ v8::TryCatch block;
+ v8::Local<v8::Number> numberObject(value->ToNumber());
+ if (block.HasCaught()) {
+ exceptionState.rethrowV8Exception(block.Exception());
return 0;
}
+ ASSERT(!numberObject.IsEmpty());
+
if (configuration == EnforceRange)
return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, "long", exceptionState);
@@ -328,8 +337,7 @@ int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
if (configuration == Clamp)
return clampTo<int32_t>(numberObject->Value());
- TONATIVE_DEFAULT_EXCEPTIONSTATE(int32_t, result, numberObject->Int32Value(), exceptionState, 0);
- return result;
+ return numberObject->Int32Value();
}
int32_t toInt32(v8::Handle<v8::Value> value)
@@ -357,12 +365,15 @@ uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
}
// Can the value be converted to a number?
- TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToNumber(), exceptionState, 0);
- if (numberObject.IsEmpty()) {
- exceptionState.throwTypeError("Not convertible to a number value (of type 'unsigned long'.)");
+ v8::TryCatch block;
+ v8::Local<v8::Number> numberObject(value->ToNumber());
+ if (block.HasCaught()) {
+ exceptionState.rethrowV8Exception(block.Exception());
return 0;
}
+ ASSERT(!numberObject.IsEmpty());
+
if (configuration == EnforceRange)
return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long", exceptionState);
@@ -374,8 +385,7 @@ uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
if (configuration == Clamp)
return clampTo<uint32_t>(numberObject->Value());
- TONATIVE_DEFAULT(uint32_t, result, numberObject->Uint32Value(), 0);
- return result;
+ return numberObject->Uint32Value();
}
uint32_t toUInt32(v8::Handle<v8::Value> value)
@@ -391,12 +401,15 @@ int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
return value->Int32Value();
// Can the value be converted to a number?
- TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToNumber(), exceptionState, 0);
- if (numberObject.IsEmpty()) {
- exceptionState.throwTypeError("Not convertible to a number value (of type 'long long'.)");
+ v8::TryCatch block;
+ v8::Local<v8::Number> numberObject(value->ToNumber());
+ if (block.HasCaught()) {
+ exceptionState.rethrowV8Exception(block.Exception());
return 0;
}
+ ASSERT(!numberObject.IsEmpty());
+
double x = numberObject->Value();
if (configuration == EnforceRange)
@@ -437,12 +450,15 @@ uint64_t toUInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
}
// Can the value be converted to a number?
- TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToNumber(), exceptionState, 0);
- if (numberObject.IsEmpty()) {
- exceptionState.throwTypeError("Not convertible to a number value (of type 'unsigned long long'.)");
+ v8::TryCatch block;
+ v8::Local<v8::Number> numberObject(value->ToNumber());
+ if (block.HasCaught()) {
+ exceptionState.rethrowV8Exception(block.Exception());
return 0;
}
+ ASSERT(!numberObject.IsEmpty());
+
double x = numberObject->Value();
if (configuration == EnforceRange)
@@ -466,7 +482,12 @@ uint64_t toUInt64(v8::Handle<v8::Value> value)
float toFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionState)
{
- TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToNumber(), exceptionState, 0);
+ v8::TryCatch block;
+ v8::Local<v8::Number> numberObject(value->ToNumber());
+ if (block.HasCaught()) {
+ exceptionState.rethrowV8Exception(block.Exception());
+ return 0;
+ }
return numberObject->NumberValue();
}
@@ -481,7 +502,13 @@ String toByteString(v8::Handle<v8::Value> value, ExceptionState& exceptionState)
return String();
// 1. Let x be ToString(v)
- TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::String>, stringObject, value->ToString(), exceptionState, String());
+ v8::TryCatch block;
+ v8::Local<v8::String> stringObject(value->ToString());
+ if (block.HasCaught()) {
+ exceptionState.rethrowV8Exception(block.Exception());
+ return String();
+ }
+
String x = toCoreString(stringObject);
// 2. If the value of any element of x is greater than 255, then throw a TypeError.
@@ -605,7 +632,13 @@ String toScalarValueString(v8::Handle<v8::Value> value, ExceptionState& exceptio
// http://encoding.spec.whatwg.org/#type-scalarvaluestring
if (value.IsEmpty())
return String();
- TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::String>, stringObject, value->ToString(), exceptionState, String());
+
+ v8::TryCatch block;
+ v8::Local<v8::String> stringObject(value->ToString());
+ if (block.HasCaught()) {
+ exceptionState.rethrowV8Exception(block.Exception());
+ return String();
+ }
// ScalarValueString is identical to DOMString except that "convert a
// DOMString to a sequence of Unicode characters" is used subsequently
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698