summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Lavine <nlavine@haverford.edu>2011-01-03 02:22:35 -0500
committerLudovic Courtès <ludo@gnu.org>2011-01-04 18:36:58 +0100
commit8891bd1b166b7210c241a0c1a730fc3af7f45b8a (patch)
treec037d17df57203eaea848c307be45d000e8ce8d0
parent9dfcd9e2d6fa4fdaae86ce529382d30b27a2cec6 (diff)
downloadguile-8891bd1b166b7210c241a0c1a730fc3af7f45b8a.tar.gz
Fix ECMAScript object creation.
* module/language/ecmascript/compile-tree-il.scm (compile-tree-il): generate correct tree-il for construction of new objects. * test-suite/tests/ecmascript.test (ecompile): Add pattern with EXPECTED omitted. ("compiler"): test whether we generate new objects correctly. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
-rw-r--r--module/language/ecmascript/compile-tree-il.scm20
-rw-r--r--test-suite/tests/ecmascript.test9
2 files changed, 18 insertions, 11 deletions
diff --git a/module/language/ecmascript/compile-tree-il.scm b/module/language/ecmascript/compile-tree-il.scm
index a97e55570..a5276abe3 100644
--- a/module/language/ecmascript/compile-tree-il.scm
+++ b/module/language/ecmascript/compile-tree-il.scm
@@ -366,16 +366,16 @@
`(apply ,(@implv new-array)
,@(map (lambda (x) (comp x e)) args)))
((object . ,args)
- (@impl new-object
- (map (lambda (x)
- (pmatch x
- ((,prop ,val)
- (-> (apply (-> (primitive 'cons))
- (-> (const prop))
- (comp val e))))
- (else
- (error "bad prop-val pair" x))))
- args)))
+ `(apply (@ (language ecmascript impl) new-object)
+ ,@(map (lambda (x)
+ (pmatch x
+ ((,prop ,val)
+ (-> (apply (-> (primitive 'cons))
+ (-> (const prop))
+ (comp val e))))
+ (else
+ (error "bad prop-val pair" x))))
+ args)))
((pref ,obj ,prop)
(@impl pget
(comp obj e)
diff --git a/test-suite/tests/ecmascript.test b/test-suite/tests/ecmascript.test
index 955296de3..b0861bbef 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 Free Software Foundation, Inc.
+;;;; Copyright (C) 2010, 2011 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
@@ -53,6 +53,12 @@
(define-syntax ecompile
(syntax-rules ()
+ ((_ expression)
+ (pass-if expression
+ (not (not
+ (compile (call-with-input-string expression read-ecmascript)
+ #:from 'ecmascript
+ #:to 'value)))))
((_ expression expected)
(pass-if expression
(equal? expected
@@ -65,6 +71,7 @@
(ecompile "true;" #t)
(ecompile "2 + 2;" 4)
(ecompile "\"hello\";" "hello")
+ (ecompile "var test = { bar: 1 };")
;; FIXME: Broken!
;; (ecompile "[1,2,3,4].map(function(x) { return x * x; });"