Function: js--js-encode-value
js--js-encode-value is a byte-compiled function defined in js.el.gz.
Signature
(js--js-encode-value X)
Documentation
Marshall the given value for JS.
Strings and numbers are JSON-encoded. Lists (including nil) are
made into JavaScript array literals and their contents encoded
with js--js-encode-value.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/js.el.gz
(defun js--js-encode-value (x)
"Marshall the given value for JS.
Strings and numbers are JSON-encoded. Lists (including nil) are
made into JavaScript array literals and their contents encoded
with `js--js-encode-value'."
(cond ((or (stringp x) (numberp x)) (json-encode x))
((symbolp x) (format "{objid:%S}" (symbol-name x)))
((js--js-handle-p x)
(when (js--js-handle-expired-p x)
(error "Stale JS handle"))
(format "{objid:%s}" (js--js-handle-id x)))
((sequencep x)
(if (eq (car-safe x) 'js--funcall)
(format "{funcall:[%s]}"
(mapconcat #'js--js-encode-value (cdr x) ","))
(concat
"[" (mapconcat #'js--js-encode-value x ",") "]")))
(t
(error "Unrecognized item: %S" x))))