[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash/server as_value.cpp
From: |
Martin Guy |
Subject: |
[Gnash-commit] gnash/server as_value.cpp |
Date: |
Sat, 03 Mar 2007 11:35:32 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Martin Guy <martinwguy> 07/03/03 11:35:32
Modified files:
server : as_value.cpp
Log message:
Return NAN for bad types and bad string conversions.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_value.cpp?cvsroot=gnash&r1=1.17&r2=1.18
Patches:
Index: as_value.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/as_value.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- as_value.cpp 1 Feb 2007 13:40:08 -0000 1.17
+++ as_value.cpp 3 Mar 2007 11:35:32 -0000 1.18
@@ -30,6 +30,8 @@
#include "gstring.h" // for automatic as_value::STRING => String as object
#include "Number.h" // for automatic as_value::NUMBER => Number as object
+#include <cmath>
+
using namespace std;
#ifdef WIN32
@@ -38,6 +40,13 @@
namespace gnash {
+#ifndef NAN
+ // Pre-C99 compilers
+# define NAN (0.0/0.0)
+// If this makes your compiler die with div by zero,
+// use "static double zzzero = 0.0;" and "(zzzero/zzzero)"
+#endif
+
//
// as_value -- ActionScript value type
//
@@ -264,25 +273,22 @@
// gets converted; otherwise it is set to NaN.
//
// Also, "Infinity", "-Infinity", and "NaN"
- // are recognized.
+ // are recognized by strtod() but not by Flash Player.
char* tail=0;
m_number_value = strtod(m_string_value.c_str(), &tail);
if ( tail == m_string_value.c_str() || *tail != 0 )
{
// Failed conversion to Number.
-
- // avoid divide by zero compiler warning by using a variable
- double temp = 0.0;
-
- // this division by zero creates a NaN value in the double
- m_number_value = temp / temp;
+ m_number_value = NAN;
}
return m_number_value;
} else if (m_type == NULLTYPE) {
- // Evan: from my tests
- return 0;
+ // Evan says: from my tests 0
+ // Martin tries var foo = new Number(null) and gets NaN
+ return NAN;
} else if (m_type == BOOLEAN) {
// Evan: from my tests
+ // Martin: confirmed
return (this->m_boolean_value) ? 1 : 0;
} else if (m_type == NUMBER) {
return m_number_value;
@@ -302,7 +308,7 @@
return 0.0;
} else {
- return 0.0;
+ return NAN;
}
}
- [Gnash-commit] gnash/server as_value.cpp,
Martin Guy <=