21#include <unordered_map>
24#include "quickjs/quickjs.h"
37 IOProp convert_js_to_io_prop(JSContext* ctx, JSValueConst obj_val );
38 void dump_exception_details( JSContext* ctx );
40 void safe_function_call(JSContext* ctx, JSValueConst obj, JSValueConst func,
41 int argc = 0, JSValueConst* argv =
nullptr );
42 void safe_function_call_by_name(JSContext* ctx,
const char* func_name,
43 int argc = 0, JSValue* argv =
nullptr );
45 void debug_function_call( JSContext* ctx,
const char* func_name );
49 std::vector<std::string> search_paths;
52 const std::string js_search_paths_object =
"__load_search_paths";
57 std::vector<JSValue > vals;
59 explicit JsArgs(JSContext* c) : ctx(c) {}
69 vals.push_back(JS_NewInt64(ctx, x));
75 vals.push_back(JS_NewString(ctx, s));
81 return (
int)vals.size();
92 JSModuleDef* module_loader_with_path( JSContext* ctx,
const char* module_name,
void* opaque );
93 JSValue js_load_file_with_data( JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv );
94 std::string find_file(
const std::string filename,
const std::vector<std::string>& search_paths );
95 JSModuleDef* qjs_module_loader(JSContext* ctx,
const char* module_name,
void* opaque);
96 char* qjs_module_normalize(JSContext* ctx,
const char* base_name,
const char* name,
void* opaque);
103 JSValueGuard(JSContext* ctx, JSValue val) : ctx(ctx), value(val) {}
106 if( ctx && !JS_IsUndefined(value) && !JS_IsNull(value) )
107 JS_FreeValue(ctx, value);
120 std::vector<T> js_array_to_vector(JSContext* ctx, JSValueConst array_val,
121 std::function<T(JSContext*, JSValue)> converter)
123 std::vector<T> result;
125 if (!JS_IsArray(ctx, array_val))
130 JSValue length_val = JS_GetPropertyStr(ctx, array_val,
"length");
132 JS_ToInt32(ctx, &length, length_val);
133 JS_FreeValue(ctx, length_val);
135 for(
int i = 0; i < length; i++ )
137 JSValue item_val = JS_GetPropertyUint32(ctx, array_val, i);
138 T item = converter(ctx, item_val);
139 result.push_back(item);
140 JS_FreeValue(ctx, item_val);
149 static std::unordered_map<JSRuntime*, std::set<std::string>> loaded_modules;
152 static void mark_module_loaded(JSRuntime* rt,
const std::string& module_name);
153 static bool is_module_loaded(JSRuntime* rt,
const std::string& module_name);
154 static std::vector<std::string> get_loaded_modules(JSRuntime* rt);
157 bool is_module_loaded(JSContext* ctx,
const std::string& module_name);
Definition JSHelpers.h:99
Definition JSHelpers.h:147
Definition AccessConfig.h:30
Definition JSHelpers.h:32
Definition JSHelpers.h:48
Definition JSHelpers.h:55