Commit fdc3a7b6 authored by jl@opera.com's avatar jl@opera.com

In V8Binding.cpp, throw all exceptions via ExceptionState& argument

In those the conversion functions that take an ExceptionState& argument,
always throw via the ExceptionState object, and never directly to V8.
Various existing callers assume this, and fail to detect exceptions that
were thrown directly to V8.

This misbehavior is a regression from
  https://codereview.chromium.org/313033002/
which changed the definition of the TONATIVE_DEFAULT_EXCEPTIONSTATE()
macro, but these functions were somewhat tricky to use even before then,
since exceptions were sometimes thrown to V8 and sometimes not, while
always stored in the ExceptionState object.

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

git-svn-id: svn://svn.chromium.org/blink/trunk@181709 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent af19d4de
...@@ -202,12 +202,15 @@ static inline T toSmallerInt(v8::Handle<v8::Value> value, IntegerConversionConfi ...@@ -202,12 +202,15 @@ static inline T toSmallerInt(v8::Handle<v8::Value> value, IntegerConversionConfi
} }
// Can the value be converted to a number? // Can the value be converted to a number?
TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToNumber(), exceptionState, 0); v8::TryCatch block;
if (numberObject.IsEmpty()) { v8::Local<v8::Number> numberObject(value->ToNumber());
exceptionState.throwTypeError("Not convertible to a number value (of type '" + String(typeName) + "'."); if (block.HasCaught()) {
exceptionState.rethrowV8Exception(block.Exception());
return 0; return 0;
} }
ASSERT(!numberObject.IsEmpty());
if (configuration == EnforceRange) if (configuration == EnforceRange)
return enforceRange(numberObject->Value(), LimitsTrait::minValue, LimitsTrait::maxValue, typeName, exceptionState); return enforceRange(numberObject->Value(), LimitsTrait::minValue, LimitsTrait::maxValue, typeName, exceptionState);
...@@ -239,12 +242,15 @@ static inline T toSmallerUInt(v8::Handle<v8::Value> value, IntegerConversionConf ...@@ -239,12 +242,15 @@ static inline T toSmallerUInt(v8::Handle<v8::Value> value, IntegerConversionConf
} }
// Can the value be converted to a number? // Can the value be converted to a number?
TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToNumber(), exceptionState, 0); v8::TryCatch block;
if (numberObject.IsEmpty()) { v8::Local<v8::Number> numberObject(value->ToNumber());
exceptionState.throwTypeError("Not convertible to a number value (of type '" + String(typeName) + "'."); if (block.HasCaught()) {
exceptionState.rethrowV8Exception(block.Exception());
return 0; return 0;
} }
ASSERT(!numberObject.IsEmpty());
if (configuration == EnforceRange) if (configuration == EnforceRange)
return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typeName, exceptionState); return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typeName, exceptionState);
...@@ -311,12 +317,15 @@ int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf ...@@ -311,12 +317,15 @@ int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
return value->Int32Value(); return value->Int32Value();
// Can the value be converted to a number? // Can the value be converted to a number?
TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToNumber(), exceptionState, 0); v8::TryCatch block;
if (numberObject.IsEmpty()) { v8::Local<v8::Number> numberObject(value->ToNumber());
exceptionState.throwTypeError("Not convertible to a number value (of type 'long'.)"); if (block.HasCaught()) {
exceptionState.rethrowV8Exception(block.Exception());
return 0; return 0;
} }
ASSERT(!numberObject.IsEmpty());
if (configuration == EnforceRange) if (configuration == EnforceRange)
return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, "long", exceptionState); return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, "long", exceptionState);
...@@ -328,8 +337,7 @@ int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf ...@@ -328,8 +337,7 @@ int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
if (configuration == Clamp) if (configuration == Clamp)
return clampTo<int32_t>(numberObject->Value()); return clampTo<int32_t>(numberObject->Value());
TONATIVE_DEFAULT_EXCEPTIONSTATE(int32_t, result, numberObject->Int32Value(), exceptionState, 0); return numberObject->Int32Value();
return result;
} }
int32_t toInt32(v8::Handle<v8::Value> value) int32_t toInt32(v8::Handle<v8::Value> value)
...@@ -357,12 +365,15 @@ uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co ...@@ -357,12 +365,15 @@ uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
} }
// Can the value be converted to a number? // Can the value be converted to a number?
TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToNumber(), exceptionState, 0); v8::TryCatch block;
if (numberObject.IsEmpty()) { v8::Local<v8::Number> numberObject(value->ToNumber());
exceptionState.throwTypeError("Not convertible to a number value (of type 'unsigned long'.)"); if (block.HasCaught()) {
exceptionState.rethrowV8Exception(block.Exception());
return 0; return 0;
} }
ASSERT(!numberObject.IsEmpty());
if (configuration == EnforceRange) if (configuration == EnforceRange)
return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long", exceptionState); return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long", exceptionState);
...@@ -374,8 +385,7 @@ uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co ...@@ -374,8 +385,7 @@ uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
if (configuration == Clamp) if (configuration == Clamp)
return clampTo<uint32_t>(numberObject->Value()); return clampTo<uint32_t>(numberObject->Value());
TONATIVE_DEFAULT(uint32_t, result, numberObject->Uint32Value(), 0); return numberObject->Uint32Value();
return result;
} }
uint32_t toUInt32(v8::Handle<v8::Value> value) uint32_t toUInt32(v8::Handle<v8::Value> value)
...@@ -391,12 +401,15 @@ int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf ...@@ -391,12 +401,15 @@ int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
return value->Int32Value(); return value->Int32Value();
// Can the value be converted to a number? // Can the value be converted to a number?
TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToNumber(), exceptionState, 0); v8::TryCatch block;
if (numberObject.IsEmpty()) { v8::Local<v8::Number> numberObject(value->ToNumber());
exceptionState.throwTypeError("Not convertible to a number value (of type 'long long'.)"); if (block.HasCaught()) {
exceptionState.rethrowV8Exception(block.Exception());
return 0; return 0;
} }
ASSERT(!numberObject.IsEmpty());
double x = numberObject->Value(); double x = numberObject->Value();
if (configuration == EnforceRange) if (configuration == EnforceRange)
...@@ -437,12 +450,15 @@ uint64_t toUInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration co ...@@ -437,12 +450,15 @@ uint64_t toUInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
} }
// Can the value be converted to a number? // Can the value be converted to a number?
TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToNumber(), exceptionState, 0); v8::TryCatch block;
if (numberObject.IsEmpty()) { v8::Local<v8::Number> numberObject(value->ToNumber());
exceptionState.throwTypeError("Not convertible to a number value (of type 'unsigned long long'.)"); if (block.HasCaught()) {
exceptionState.rethrowV8Exception(block.Exception());
return 0; return 0;
} }
ASSERT(!numberObject.IsEmpty());
double x = numberObject->Value(); double x = numberObject->Value();
if (configuration == EnforceRange) if (configuration == EnforceRange)
...@@ -466,7 +482,12 @@ uint64_t toUInt64(v8::Handle<v8::Value> value) ...@@ -466,7 +482,12 @@ uint64_t toUInt64(v8::Handle<v8::Value> value)
float toFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionState) 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(); return numberObject->NumberValue();
} }
...@@ -481,7 +502,13 @@ String toByteString(v8::Handle<v8::Value> value, ExceptionState& exceptionState) ...@@ -481,7 +502,13 @@ String toByteString(v8::Handle<v8::Value> value, ExceptionState& exceptionState)
return String(); return String();
// 1. Let x be ToString(v) // 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); String x = toCoreString(stringObject);
// 2. If the value of any element of x is greater than 255, then throw a TypeError. // 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 ...@@ -605,7 +632,13 @@ String toScalarValueString(v8::Handle<v8::Value> value, ExceptionState& exceptio
// http://encoding.spec.whatwg.org/#type-scalarvaluestring // http://encoding.spec.whatwg.org/#type-scalarvaluestring
if (value.IsEmpty()) if (value.IsEmpty())
return String(); 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 // ScalarValueString is identical to DOMString except that "convert a
// DOMString to a sequence of Unicode characters" is used subsequently // DOMString to a sequence of Unicode characters" is used subsequently
......
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