aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lobject.js10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/lobject.js b/src/lobject.js
index 9263cb1..8754e20 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -411,11 +411,15 @@ const lua_strx2number = function(s) {
};
const lua_str2number = function(s) {
+ try {
+ s = defs.to_jsstring(s);
+ } catch (e) {
+ return null;
+ }
/* parseFloat ignores trailing junk, validate with regex first */
- let str = defs.to_jsstring(s);
- if (!/^[\t\v\f \n\r]*[\+\-]?([0-9]+\.?[0-9]*|\.[0-9]*)([eE][\+\-]?[0-9]+)?[\t\v\f \n\r]*$/.test(str))
+ if (!/^[\t\v\f \n\r]*[\+\-]?([0-9]+\.?[0-9]*|\.[0-9]*)([eE][\+\-]?[0-9]+)?[\t\v\f \n\r]*$/.test(s))
return null;
- let flt = parseFloat(str);
+ let flt = parseFloat(s);
return !isNaN(flt) ? flt : null;
};