diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2017-07-06 18:10:23 +0300 |
---|---|---|
committer | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2017-07-06 18:11:24 +0300 |
commit | fa857ac7bcac67753eb95191f20e2e4af6c314d0 (patch) | |
tree | 4434f45412a9cceb24e70cc05dba670b61f25d46 | |
parent | 0922678fc40fd13e70c32c1543f922962a35bbb7 (diff) | |
download | mpv-fa857ac7bcac67753eb95191f20e2e4af6c314d0.tar.bz2 mpv-fa857ac7bcac67753eb95191f20e2e4af6c314d0.tar.xz |
js: utils.getenv(): fix crash on undefined var
-rw-r--r-- | DOCS/man/javascript.rst | 3 | ||||
-rw-r--r-- | player/javascript.c | 7 |
2 files changed, 8 insertions, 2 deletions
diff --git a/DOCS/man/javascript.rst b/DOCS/man/javascript.rst index 0c099cad0a..74282250b6 100644 --- a/DOCS/man/javascript.rst +++ b/DOCS/man/javascript.rst @@ -196,7 +196,8 @@ Additional utilities Like ``print`` but also expands objects and arrays recursively. ``mp.utils.getenv(name)`` - Returns the value of the host environment variable ``name``, or empty str. + Returns the value of the host environment variable ``name``, or + ``undefined`` if the variable is not defined. ``mp.utils.get_user_path(path)`` Expands (mpv) meta paths like ``~/x``, ``~~/y``, ``~~desktop/z`` etc. diff --git a/player/javascript.c b/player/javascript.c index b00e4eda64..abb1581f86 100644 --- a/player/javascript.c +++ b/player/javascript.c @@ -981,7 +981,12 @@ static void script_write_file(js_State *J, void *af) // args: env var name static void script_getenv(js_State *J) { - js_pushstring(J, getenv(js_tostring(J, 1))); + const char *v = getenv(js_tostring(J, 1)); + if (v) { + js_pushstring(J, v); + } else { + js_pushundefined(J); + } } // args: as-filename, content-string, returns the compiled result as a function |