mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-01 20:30:28 +02:00
support foo["bar"] in addition to foo.bar
* module/language/ecmascript/parse.scm (parse-ecmascript): And update the function declaration forms for the new var syntax. * module/language/ecmascript/compile-ghil.scm (comp): Support foo["bar"] in addition to foo.bar. * module/language/ecmascript/impl.scm (pget, pput): Some fixes for when we get non-symbols -- it can happen, yo. I suppose we should allow for non-string keys too..
This commit is contained in:
parent
b72880eb17
commit
cdad2166e7
3 changed files with 28 additions and 25 deletions
|
@ -114,10 +114,14 @@
|
||||||
args)))
|
args)))
|
||||||
((pref ,obj ,prop)
|
((pref ,obj ,prop)
|
||||||
(@impl e l pget (list (comp obj e) (make-ghil-quote e l prop))))
|
(@impl e l pget (list (comp obj e) (make-ghil-quote e l prop))))
|
||||||
|
((aref ,obj ,index)
|
||||||
|
(@impl e l pget (list (comp obj e) (comp index e))))
|
||||||
((= (ref ,name) ,val)
|
((= (ref ,name) ,val)
|
||||||
(make-ghil-set e l (ghil-var-for-set! e name) (comp val e)))
|
(make-ghil-set e l (ghil-var-for-set! e name) (comp val e)))
|
||||||
((= (pref ,obj ,prop) ,val)
|
((= (pref ,obj ,prop) ,val)
|
||||||
(@impl e l pput (list (comp obj e) (make-ghil-quote e l prop) (comp val e))))
|
(@impl e l pput (list (comp obj e) (make-ghil-quote e l prop) (comp val e))))
|
||||||
|
((= (aref ,obj ,prop) ,val)
|
||||||
|
(@impl e l pput (list (comp obj e) (comp prop e) (comp val e))))
|
||||||
(else
|
(else
|
||||||
(error "compilation not yet implemented:" x)))))
|
(error "compilation not yet implemented:" x)))))
|
||||||
|
|
||||||
|
|
|
@ -47,13 +47,14 @@
|
||||||
(value #:getter js-value #:init-value #f #:init-keyword #:value))
|
(value #:getter js-value #:init-value #f #:init-keyword #:value))
|
||||||
|
|
||||||
(define-method (pget (o <js-object>) p)
|
(define-method (pget (o <js-object>) p)
|
||||||
(let ((h (hashq-get-handle (js-props o) p)))
|
(let ((p (if (string? p) (string->symbol p) p)))
|
||||||
(if h
|
(let ((h (hashq-get-handle (js-props o) p)))
|
||||||
(cdr h)
|
(if h
|
||||||
(let ((proto (js-prototype o)))
|
(cdr h)
|
||||||
(if proto
|
(let ((proto (js-prototype o)))
|
||||||
(pget proto p)
|
(if proto
|
||||||
*undefined*)))))
|
(pget proto p)
|
||||||
|
*undefined*))))))
|
||||||
|
|
||||||
(define-method (prop-attrs (o <js-object>) p)
|
(define-method (prop-attrs (o <js-object>) p)
|
||||||
(or (let ((attrs (js-prop-attrs o)))
|
(or (let ((attrs (js-prop-attrs o)))
|
||||||
|
@ -67,22 +68,18 @@
|
||||||
(memq attr (prop-attrs o p)))
|
(memq attr (prop-attrs o p)))
|
||||||
|
|
||||||
(define-method (pput (o <js-object>) p v)
|
(define-method (pput (o <js-object>) p v)
|
||||||
(if (prop-has-attr? o p 'ReadOnly)
|
(let ((p (if (string? p) (string->symbol p) p)))
|
||||||
(throw 'ReferenceError o p)
|
(if (prop-has-attr? o p 'ReadOnly)
|
||||||
(hashq-set! (js-props o) p v)))
|
(throw 'ReferenceError o p)
|
||||||
|
(hashq-set! (js-props o) p v))))
|
||||||
;; what the hell is this
|
|
||||||
(define-method (has-property? (o <js-object>) p v)
|
|
||||||
(if (prop-has-attr? o p 'ReadOnly)
|
|
||||||
(throw 'ReferenceError o p)
|
|
||||||
(hashq-set! (js-props o) p v)))
|
|
||||||
|
|
||||||
(define-method (pdel (o <js-object>) p)
|
(define-method (pdel (o <js-object>) p)
|
||||||
(if (prop-has-attr? o p 'DontDelete)
|
(let ((p (if (string? p) (string->symbol p) p)))
|
||||||
#f
|
(if (prop-has-attr? o p 'DontDelete)
|
||||||
(begin
|
#f
|
||||||
(pput o p *undefined*)
|
(begin
|
||||||
#t)))
|
(pput o p *undefined*)
|
||||||
|
#t))))
|
||||||
|
|
||||||
(define (object->string o error?)
|
(define (object->string o error?)
|
||||||
(let ((toString (pget o 'toString)))
|
(let ((toString (pget o 'toString)))
|
||||||
|
@ -197,7 +194,8 @@
|
||||||
(if (< p (vector-length v))
|
(if (< p (vector-length v))
|
||||||
(vector-ref v p)
|
(vector-ref v p)
|
||||||
(next-method))))
|
(next-method))))
|
||||||
((eq? p 'length)
|
((or (and (symbol? p) (eq? p 'length))
|
||||||
|
(and (string? p) (string=? p "length")))
|
||||||
(vector-length (js-array-vector o)))
|
(vector-length (js-array-vector o)))
|
||||||
(else (next-method))))
|
(else (next-method))))
|
||||||
|
|
||||||
|
@ -211,7 +209,8 @@
|
||||||
(vector-move-left! vect 0 (vector-length vect) new 0)
|
(vector-move-left! vect 0 (vector-length vect) new 0)
|
||||||
(set! (js-array-vector o) new)
|
(set! (js-array-vector o) new)
|
||||||
(vector-set! new p)))))
|
(vector-set! new p)))))
|
||||||
((eq? p 'length)
|
((or (and (symbol? p) (eq? p 'length))
|
||||||
|
(and (string? p) (string=? p "length")))
|
||||||
(let ((vect (js-array-vector o)))
|
(let ((vect (js-array-vector o)))
|
||||||
(let ((new (make-vector (->uint32 v) 0)))
|
(let ((new (make-vector (->uint32 v) 0)))
|
||||||
(vector-move-left! vect 0 (min (vector-length vect) (->uint32 v))
|
(vector-move-left! vect 0 (min (vector-length vect) (->uint32 v))
|
||||||
|
|
|
@ -58,8 +58,8 @@
|
||||||
(SourceElement (Statement) -> $1
|
(SourceElement (Statement) -> $1
|
||||||
(FunctionDeclaration) -> $1)
|
(FunctionDeclaration) -> $1)
|
||||||
|
|
||||||
(FunctionDeclaration (function Identifier lparen rparen lbrace FunctionBody rbrace) -> `(var ,$2 (lambda () ,$6))
|
(FunctionDeclaration (function Identifier lparen rparen lbrace FunctionBody rbrace) -> `(var (,$2 (lambda () ,$6)))
|
||||||
(function Identifier lparen FormalParameterList rparen lbrace FunctionBody rbrace) -> `(var ,$2 (lambda ,$4 ,$7)))
|
(function Identifier lparen FormalParameterList rparen lbrace FunctionBody rbrace) -> `(var (,$2 (lambda ,$4 ,$7))))
|
||||||
(FunctionExpression (function lparen rparen lbrace FunctionBody rbrace) -> `(lambda () ,$5)
|
(FunctionExpression (function lparen rparen lbrace FunctionBody rbrace) -> `(lambda () ,$5)
|
||||||
(function Identifier lparen rparen lbrace FunctionBody rbrace) -> `(lambda () ,$6)
|
(function Identifier lparen rparen lbrace FunctionBody rbrace) -> `(lambda () ,$6)
|
||||||
(function lparen FormalParameterList rparen lbrace FunctionBody rbrace) -> `(lambda ,$3 ,$6)
|
(function lparen FormalParameterList rparen lbrace FunctionBody rbrace) -> `(lambda ,$3 ,$6)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue