mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-09 23:40:29 +02:00
add scheme integration to js via `require'
* module/language/ecmascript/impl.scm: Add <js-module-object>, that wraps a module. Add js-require, a javascript-happy function that returns an object that wraps a Guile module. Bind it to `require' in the default environment.
This commit is contained in:
parent
a3e34104db
commit
143177ed9e
1 changed files with 26 additions and 0 deletions
|
@ -57,10 +57,36 @@
|
|||
(define-method (prop-attrs (o <js-global-object>) (p <string>))
|
||||
(prop-attrs o (string->symbol p)))
|
||||
|
||||
(define-class <js-module-object> (<js-object>)
|
||||
(module #:init-form (js-module o) #:init-keyword #:module
|
||||
#:getter js-module))
|
||||
(define-method (pget (o <js-module-object>) (p <string>))
|
||||
(pget o (string->symbol p)))
|
||||
(define-method (pget (o <js-module-object>) (p <symbol>))
|
||||
(let ((v (module-variable (js-module o) p)))
|
||||
(if v
|
||||
(variable-ref v)
|
||||
(next-method))))
|
||||
(define-method (pput (o <js-module-object>) (p <string>) v)
|
||||
(pput o (string->symbol p) v))
|
||||
(define-method (pput (o <js-module-object>) (p <symbol>) v)
|
||||
(module-define! (js-module o) p v))
|
||||
(define-method (prop-attrs (o <js-module-object>) (p <symbol>))
|
||||
(cond ((module-variable (js-module o) p) '())
|
||||
(else (next-method))))
|
||||
(define-method (prop-attrs (o <js-module-object>) (p <string>))
|
||||
(prop-attrs o (string->symbol p)))
|
||||
|
||||
;; we could make a renamer, but having obj['foo-bar'] should be enough
|
||||
(define (js-require modstr)
|
||||
(make <js-module-object> #:module
|
||||
(resolve-interface (map string->symbol (string-split modstr #\.)))))
|
||||
|
||||
(define (init-js-bindings! mod)
|
||||
(module-define! mod 'NaN +nan.0)
|
||||
(module-define! mod 'Infinity +inf.0)
|
||||
(module-define! mod 'undefined *undefined*)
|
||||
(module-define! mod 'require js-require)
|
||||
;; isNAN, isFinite, parseFloat, parseInt, eval
|
||||
;; decodeURI, decodeURIComponent, encodeURI, encodeURIComponent
|
||||
;; Object Function Array String Boolean Number Date RegExp Error EvalError
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue