return an object containing the list of the available environment variables. */
| 1039 | /* return an object containing the list of the available environment |
| 1040 | variables. */ |
| 1041 | static JSValue js_std_getenviron(JSContext *ctx, JSValueConst this_val, |
| 1042 | int argc, JSValueConst *argv) |
| 1043 | { |
| 1044 | char **envp; |
| 1045 | const char *name, *p, *value; |
| 1046 | JSValue obj; |
| 1047 | uint32_t idx; |
| 1048 | size_t name_len; |
| 1049 | JSAtom atom; |
| 1050 | int ret; |
| 1051 | |
| 1052 | obj = JS_NewObject(ctx); |
| 1053 | if (JS_IsException(obj)) |
| 1054 | return JS_EXCEPTION; |
| 1055 | envp = environ; |
| 1056 | for(idx = 0; envp[idx] != NULL; idx++) { |
| 1057 | name = envp[idx]; |
| 1058 | p = strchr(name, '='); |
| 1059 | name_len = p - name; |
| 1060 | if (!p) |
| 1061 | continue; |
| 1062 | value = p + 1; |
| 1063 | atom = JS_NewAtomLen(ctx, name, name_len); |
| 1064 | if (atom == JS_ATOM_NULL) |
| 1065 | goto fail; |
| 1066 | ret = JS_DefinePropertyValue(ctx, obj, atom, JS_NewString(ctx, value), |
| 1067 | JS_PROP_C_W_E); |
| 1068 | JS_FreeAtom(ctx, atom); |
| 1069 | if (ret < 0) |
| 1070 | goto fail; |
| 1071 | } |
| 1072 | return obj; |
| 1073 | fail: |
| 1074 | JS_FreeValue(ctx, obj); |
| 1075 | return JS_EXCEPTION; |
| 1076 | } |
| 1077 | |
| 1078 | static JSValue js_std_gc(JSContext *ctx, JSValueConst this_val, |
| 1079 | int argc, JSValueConst *argv) |
nothing calls this directly
no test coverage detected