source maps parsing is built upon hooks for resolving or loading modules for non-module runs we need to invoke this logic manually
| 1406 | // source maps parsing is built upon hooks for resolving or loading modules |
| 1407 | // for non-module runs we need to invoke this logic manually |
| 1408 | void GjsContextPrivate::register_non_module_sourcemap(const char* script, |
| 1409 | const char* filename) { |
| 1410 | using AutoURI = Gjs::AutoPointer<GUri, GUri, g_uri_unref>; |
| 1411 | Gjs::AutoMainRealm ar{this}; |
| 1412 | |
| 1413 | JS::RootedObject global{m_cx, JS::CurrentGlobalOrNull(m_cx)}; |
| 1414 | JS::RootedValue v_loader{ |
| 1415 | m_cx, gjs_get_global_slot(global, GjsGlobalSlot::MODULE_LOADER)}; |
| 1416 | g_assert(v_loader.isObject()); |
| 1417 | JS::RootedObject v_loader_obj{m_cx, &v_loader.toObject()}; |
| 1418 | |
| 1419 | JS::RootedValueArray<3> args{m_cx}; |
| 1420 | JS::RootedString script_str{m_cx, JS_NewStringCopyZ(m_cx, script)}; |
| 1421 | JS::RootedString file_name_str{m_cx, JS_NewStringCopyZ(m_cx, filename)}; |
| 1422 | args[0].setString(script_str); |
| 1423 | args[1].setString(file_name_str); |
| 1424 | |
| 1425 | // if the file uri is not an absolute uri with a scheme, build one assuming |
| 1426 | // file:// this parameter is used to help locate non-inlined source map file |
| 1427 | AutoURI uri = g_uri_parse(filename, G_URI_FLAGS_NONE, nullptr); |
| 1428 | if (!uri) { |
| 1429 | Gjs::AutoUnref<GFile> file = g_file_new_for_path(filename); |
| 1430 | Gjs::AutoChar file_uri = g_file_get_uri(file); |
| 1431 | JS::RootedString abs_filename_scheme_str{ |
| 1432 | m_cx, JS_NewStringCopyZ(m_cx, file_uri.get())}; |
| 1433 | args[2].setString(abs_filename_scheme_str); |
| 1434 | } |
| 1435 | |
| 1436 | JS::RootedValue ignored{m_cx}; |
| 1437 | JS::Call(m_cx, v_loader_obj, "populateSourceMap", args, &ignored); |
| 1438 | } |
| 1439 | |
| 1440 | GErrorResult<> GjsContextPrivate::eval(const char* script, size_t script_len, |
| 1441 | const char* filename, |
no test coverage detected