Commit cb7e1062 authored by vivek.vg@samsung.com's avatar vivek.vg@samsung.com

[bindings] Split toUInt32 into faster inline and non-inline slower path.

R=haraken@chromium.org, jl@opera.com

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

git-svn-id: svn://svn.chromium.org/blink/trunk@190741 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent c5058451
...@@ -351,14 +351,11 @@ int32_t toInt32(v8::Handle<v8::Value> value) ...@@ -351,14 +351,11 @@ int32_t toInt32(v8::Handle<v8::Value> value)
return toInt32(value, NormalConversion, exceptionState); return toInt32(value, NormalConversion, exceptionState);
} }
uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) uint32_t toUInt32Slow(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
{ {
// Fast case. The value is already a 32-bit unsigned integer. ASSERT(!value->IsUint32());
if (value->IsUint32())
return value->Uint32Value();
// Fast case. The value is a 32-bit signed integer - possibly positive?
if (value->IsInt32()) { if (value->IsInt32()) {
ASSERT(configuration != NormalConversion);
int32_t result = value->Int32Value(); int32_t result = value->Int32Value();
if (result >= 0) if (result >= 0)
return result; return result;
...@@ -366,23 +363,17 @@ uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co ...@@ -366,23 +363,17 @@ uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
exceptionState.throwTypeError("Value is outside the 'unsigned long' value range."); exceptionState.throwTypeError("Value is outside the 'unsigned long' value range.");
return 0; return 0;
} }
if (configuration == Clamp) ASSERT(configuration == Clamp);
return clampTo<uint32_t>(result); return clampTo<uint32_t>(result);
return result;
} }
v8::Local<v8::Number> numberObject; v8::Isolate* isolate = v8::Isolate::GetCurrent();
if (value->IsNumber()) { // Can the value be converted to a number?
numberObject = value.As<v8::Number>(); v8::TryCatch block(isolate);
} else { v8::Local<v8::Number> numberObject = value->ToNumber(isolate);
v8::Isolate* isolate = v8::Isolate::GetCurrent(); if (block.HasCaught()) {
// Can the value be converted to a number? exceptionState.rethrowV8Exception(block.Exception());
v8::TryCatch block(isolate); return 0;
numberObject = value->ToNumber(isolate);
if (block.HasCaught()) {
exceptionState.rethrowV8Exception(block.Exception());
return 0;
}
} }
ASSERT(!numberObject.IsEmpty()); ASSERT(!numberObject.IsEmpty());
......
...@@ -432,7 +432,20 @@ int32_t toInt32(v8::Handle<v8::Value>); ...@@ -432,7 +432,20 @@ int32_t toInt32(v8::Handle<v8::Value>);
// Convert a value to a 32-bit unsigned integer. The conversion fails if the // Convert a value to a 32-bit unsigned integer. The conversion fails if the
// value cannot be converted to a number or the range violated per WebIDL: // value cannot be converted to a number or the range violated per WebIDL:
// http://www.w3.org/TR/WebIDL/#es-unsigned-long // http://www.w3.org/TR/WebIDL/#es-unsigned-long
uint32_t toUInt32(v8::Handle<v8::Value>, IntegerConversionConfiguration, ExceptionState&); uint32_t toUInt32Slow(v8::Handle<v8::Value>, IntegerConversionConfiguration, ExceptionState&);
inline uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
{
// Fast case. The value is already a 32-bit unsigned integer.
if (value->IsUint32())
return value->Uint32Value();
// Fast case. The value is a 32-bit signed integer with NormalConversion configuration.
if (value->IsInt32() && configuration == NormalConversion)
return value->Int32Value();
return toUInt32Slow(value, configuration, exceptionState);
}
inline uint32_t toUInt32(v8::Handle<v8::Value> value, ExceptionState& exceptionState) inline uint32_t toUInt32(v8::Handle<v8::Value> value, ExceptionState& exceptionState)
{ {
return toUInt32(value, NormalConversion, exceptionState); return toUInt32(value, NormalConversion, exceptionState);
......
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