Loads JS code from a file and imports it
| 147 | |
| 148 | // Loads JS code from a file and imports it |
| 149 | GJS_JSAPI_RETURN_CONVENTION |
| 150 | bool import_file(JSContext* cx, JS::HandleObject module, GFile* file) { |
| 151 | Gjs::AutoError error; |
| 152 | Gjs::AutoChar script; |
| 153 | size_t script_len = 0; |
| 154 | |
| 155 | if (!(g_file_load_contents(file, nullptr, script.out(), &script_len, |
| 156 | nullptr, &error))) |
| 157 | return gjs_throw_gerror_message(cx, error); |
| 158 | g_assert(script); |
| 159 | |
| 160 | Gjs::AutoChar full_path{g_file_get_parse_name(file)}; |
| 161 | Gjs::AutoChar uri{g_file_get_uri(file)}; |
| 162 | return evaluate_import(cx, module, script, script_len, full_path, uri); |
| 163 | } |
| 164 | |
| 165 | // JSClass operations |
| 166 |
no test coverage detected