File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -301,7 +301,19 @@ dom::Value Value::getDom() const
301301
302302std::string Value::getString () const { return std::string (getDom ().getString ()); }
303303bool Value::getBool () const { return getDom ().getBool (); }
304- std::int64_t Value::getInteger () const { return getDom ().getInteger (); }
304+ std::int64_t Value::getInteger () const
305+ {
306+ auto lock = lockContext (impl_);
307+ double d = jerry_value_as_number (to_js (val_));
308+
309+ // Mirror legacy behavior: convert any JS number to an integer by
310+ // truncating toward zero instead of requiring an integral DOM value.
311+ if (d >= (double )std::numeric_limits<std::int64_t >::max ())
312+ return std::numeric_limits<std::int64_t >::max ();
313+ if (d <= (double )std::numeric_limits<std::int64_t >::min ())
314+ return std::numeric_limits<std::int64_t >::min ();
315+ return static_cast <std::int64_t >(d);
316+ }
305317double Value::getDouble () const
306318{
307319 auto lock = lockContext (impl_);
You can’t perform that action at this time.
0 commit comments