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

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

Issue 567503002: Add toDouble() helper, and use toFloat()/toDouble() for conversions (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
Index: Source/bindings/core/v8/V8Binding.cpp
diff --git a/Source/bindings/core/v8/V8Binding.cpp b/Source/bindings/core/v8/V8Binding.cpp
index ae76dca6218a539d32c75224a033ead250f7cadc..54eb709dfd0ed28de7083e9d7f9b7e25b5599d18 100644
--- a/Source/bindings/core/v8/V8Binding.cpp
+++ b/Source/bindings/core/v8/V8Binding.cpp
@@ -482,12 +482,21 @@ uint64_t toUInt64(v8::Handle<v8::Value> value)
float toFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionState)
{
+ return static_cast<float>(toDouble(value, exceptionState));
+}
+
+double toDouble(v8::Handle<v8::Value> value, ExceptionState& exceptionState)
+{
+ if (value->IsNumber())
+ return value->NumberValue();
+
v8::TryCatch block;
v8::Local<v8::Number> numberObject(value->ToNumber());
if (block.HasCaught()) {
exceptionState.rethrowV8Exception(block.Exception());
return 0;
}
+
return numberObject->NumberValue();
}

Powered by Google App Engine
This is Rietveld 408576698