MCPcopy Create free account
hub / github.com/buke/quickjs-go / js_std_getenviron

Function js_std_getenviron

deps/quickjs/quickjs-libc.c:1041–1076  ·  view source on GitHub ↗

return an object containing the list of the available environment variables. */

Source from the content-addressed store, hash-verified

1039/* return an object containing the list of the available environment
1040 variables. */
1041static 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
1078static JSValue js_std_gc(JSContext *ctx, JSValueConst this_val,
1079 int argc, JSValueConst *argv)

Callers

nothing calls this directly

Calls 2

JS_IsExceptionFunction · 0.85
JS_NewStringFunction · 0.85

Tested by

no test coverage detected