summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2013-01-26 19:18:31 +0100
committerLudovic Courtès <ludo@gnu.org>2013-01-26 19:18:31 +0100
commited7c4a5d777bcff78512f1f1f9f2847ade90af11 (patch)
tree41f67c43c1008dabc8206968d062286245f221be
parent4ff2133aa16a29347149ff04225fb4649256e9c9 (diff)
downloadguile-ed7c4a5d777bcff78512f1f1f9f2847ade90af11.tar.gz
ecmascript: Fix conversion to boolean for non-numbers.
* module/language/ecmascript/base.scm (->boolean): Call `zero?' and `nan?' only when X is a number. * test-suite/tests/ecmascript.test ("compiler"): Add test case.
-rw-r--r--module/language/ecmascript/base.scm5
-rw-r--r--test-suite/tests/ecmascript.test3
2 files changed, 5 insertions, 3 deletions
diff --git a/module/language/ecmascript/base.scm b/module/language/ecmascript/base.scm
index 6f5c65ba5..ac8493dd0 100644
--- a/module/language/ecmascript/base.scm
+++ b/module/language/ecmascript/base.scm
@@ -1,6 +1,6 @@
;;; ECMAScript for Guile
-;; Copyright (C) 2009 Free Software Foundation, Inc.
+;; Copyright (C) 2009, 2013 Free Software Foundation, Inc.
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -168,7 +168,8 @@
x))
(define (->boolean x)
- (not (or (not x) (null? x) (eq? x *undefined*) (zero? x) (nan? x)
+ (not (or (not x) (null? x) (eq? x *undefined*)
+ (and (number? x) (or (zero? x) (nan? x)))
(and (string? x) (= (string-length x) 0)))))
(define (->number x)
diff --git a/test-suite/tests/ecmascript.test b/test-suite/tests/ecmascript.test
index 8b5dd826f..96b1d6666 100644
--- a/test-suite/tests/ecmascript.test
+++ b/test-suite/tests/ecmascript.test
@@ -1,6 +1,6 @@
;;;; ecmascript.test --- ECMAScript. -*- mode: scheme; coding: utf-8; -*-
;;;;
-;;;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+;;;; Copyright (C) 2010, 2011, 2013 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -78,6 +78,7 @@
(with-test-prefix "compiler"
(ecompile "true;" #t)
+ (ecompile "if (3 > 2) true; else false;" #t)
(ecompile "2 + 2;" 4)
(ecompile "\"hello\";" "hello")
(ecompile "var test = { bar: 1 };")