diff options
author | hajimehoshi@chromium.org <hajimehoshi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-14 14:45:13 +0000 |
---|---|---|
committer | hajimehoshi@chromium.org <hajimehoshi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-14 14:45:13 +0000 |
commit | 7812cea037087dd48055829b20b4e722f97db444 (patch) | |
tree | 80a0c4a76d1631540f456607fb09d5bd2d0ee6dd /gin | |
parent | d887774412e383d172c0e1b67ac073c08dba9cf0 (diff) | |
download | chromium_src-7812cea037087dd48055829b20b4e722f97db444.zip chromium_src-7812cea037087dd48055829b20b4e722f97db444.tar.gz chromium_src-7812cea037087dd48055829b20b4e722f97db444.tar.bz2 |
gin: Automatic conversion from JS number to intger
Now gin doesn't convert JavaScript double to an integer. This means that
gin::Arguments::GetNext() with a pointer of an integer fails when the
next arguments is double, and nothing is set to the vairable. IMO this
can cause bugs which are hard to understand. It is because on JavaScript
side we can't distinguish integer and double, and GetNext() with an
integer variable and JS number produces unstable results.
For example, In [1], EventSender's mouseMoveTo is called with arguments
which can be doubles, not integers, but EventSender::mouseToMove excepts
integers. Now EventSender is implemented by CppBoundClass and toInt32 is
used explicitly, but now EventSender is being moved to gin, and using
GetNext with integer vairables simply will fail.
[1] https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/LayoutTests/fast/events/5056619.html&sq=package:chromium
BUG=331301
TEST=gin_unittests --gtest_filter=ConverterTest.Int32
Review URL: https://codereview.chromium.org/195893017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257105 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin')
-rw-r--r-- | gin/converter.cc | 4 | ||||
-rw-r--r-- | gin/converter_unittest.cc | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/gin/converter.cc b/gin/converter.cc index 07437b7..29da322 100644 --- a/gin/converter.cc +++ b/gin/converter.cc @@ -35,7 +35,7 @@ Handle<Value> Converter<int32_t>::ToV8(Isolate* isolate, int32_t val) { bool Converter<int32_t>::FromV8(Isolate* isolate, Handle<Value> val, int32_t* out) { - if (!val->IsInt32()) + if (!val->IsNumber()) return false; *out = val->Int32Value(); return true; @@ -47,7 +47,7 @@ Handle<Value> Converter<uint32_t>::ToV8(Isolate* isolate, uint32_t val) { bool Converter<uint32_t>::FromV8(Isolate* isolate, Handle<Value> val, uint32_t* out) { - if (!val->IsUint32()) + if (!val->IsNumber()) return false; *out = val->Uint32Value(); return true; diff --git a/gin/converter_unittest.cc b/gin/converter_unittest.cc index 791d7e6..cf1affc 100644 --- a/gin/converter_unittest.cc +++ b/gin/converter_unittest.cc @@ -89,7 +89,7 @@ TEST_F(ConverterTest, Int32) { { Integer::New(instance_->isolate(), 0).As<Value>(), true, 0 }, { Integer::New(instance_->isolate(), 1).As<Value>(), true, 1 }, { Number::New(instance_->isolate(), -1).As<Value>(), true, -1 }, - { Number::New(instance_->isolate(), 1.1).As<Value>(), false, 0 }, + { Number::New(instance_->isolate(), 1.1).As<Value>(), true, 1 }, { String::NewFromUtf8(instance_->isolate(), "42").As<Value>(), false, 0 }, { String::NewFromUtf8(instance_->isolate(), "foo").As<Value>(), false, 0 }, { Object::New(instance_->isolate()).As<Value>(), false, 0 }, |