1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

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.
This commit is contained in:
Ludovic Courtès 2013-01-26 19:18:31 +01:00
parent 4ff2133aa1
commit ed7c4a5d77
2 changed files with 5 additions and 3 deletions

View file

@ -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)

View file

@ -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 };")