Skip to content

Commit 9eb0650

Browse files
committed
add a util to check if a polyglot value is javascript undefined
1 parent 20808c0 commit 9eb0650

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/net/coruscation/js4clj/api/converting.clj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,12 @@
7676
;; polyglot time, date, time zone, instant, duration
7777
:else
7878
value))
79+
80+
(defn js-undefined-raw?
81+
"Check if an value is an instance of `org.graalvm.polyglot.Value` and of JavaScript `undefined` value"
82+
[value]
83+
(and (instance? org.graalvm.polyglot.Value value)
84+
(= (some-> value
85+
(.getMetaObject)
86+
(.getMetaQualifiedName))
87+
"undefined")))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(ns net.coruscation.js4clj.api.converting-test
2+
(:require
3+
[clojure.test :refer [deftest is use-fixtures]]
4+
[net.coruscation.js4clj.api.converting :as subject]
5+
[net.coruscation.js4clj.context :as context]
6+
[net.coruscation.js4clj.test-utils :refer [fresh-context]]))
7+
8+
(deftest js-undefined-raw?-test
9+
(is (true?
10+
(subject/js-undefined-raw?
11+
(.eval @context/*context* "js" "undefined"))))
12+
(is (false?
13+
(subject/js-undefined-raw?
14+
(.eval @context/*context* "js" "null"))))
15+
(is (false?
16+
(subject/js-undefined-raw?
17+
(.eval @context/*context* "js" "[]")))))
18+
19+
(use-fixtures :each #'fresh-context)
20+

0 commit comments

Comments
 (0)