static JSValue js_sys_load_script(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
    const char *filename;
    u8 *data=NULL;
    u32 data_size;
    JSValue res;
    GF_Err e;
	char *full_url = NULL;

	if (!argc || !JS_IsString(argv[0])) return GF_JS_EXCEPTION(ctx);
    filename = JS_ToCString(ctx, argv[0]);
    if (!filename) return GF_JS_EXCEPTION(ctx);

	if ((argc>1) && JS_ToBool(ctx, argv[1]) ) {
		const char *par_url = jsf_get_script_filename(ctx);
		full_url = gf_url_concatenate(par_url, filename);
		JS_FreeCString(ctx, filename);
		filename = full_url;
	}

	e = gf_file_load_data(filename, &data, &data_size);
	if (e) {
		res = js_throw_err_msg(ctx, e, "Failed to load file %s", filename);
	} else if (data) {
		if (!gf_utf8_is_legal(data, data_size)) {
			res = js_throw_err_msg(ctx, e, "Script file %s is not UTF-8", filename);
		} else {
			res = JS_Eval(ctx, (char *)data, data_size, filename, JS_EVAL_TYPE_GLOBAL);
		}
	} else {
		res = JS_UNDEFINED;
	}
    if (data) gf_free(data);

    if (full_url)
		gf_free(full_url);
    else
		JS_FreeCString(ctx, filename);
    return res;
}
static JSValue js_sys_load_script(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
    const char *filename;
    u8 *data=NULL;
    u32 data_size;
    JSValue res;
    GF_Err e;
	char *full_url = NULL;

	if (!argc || !JS_IsString(argv[0])) return GF_JS_EXCEPTION(ctx);
    filename = JS_ToCString(ctx, argv[0]);
    if (!filename) return GF_JS_EXCEPTION(ctx);

	if ((argc>1) && JS_ToBool(ctx, argv[1]) ) {
		const char *par_url = jsf_get_script_filename(ctx);
		full_url = gf_url_concatenate(par_url, filename);
		JS_FreeCString(ctx, filename);
		filename = full_url;
	}

	e = gf_file_load_data(filename, &data, &data_size);
	if (e) {
		res = js_throw_err_msg(ctx, e, "Failed to load file %s", filename);
	} else if (data) {
		if (!gf_utf8_is_legal(data, data_size)) {
			res = js_throw_err_msg(ctx, e, "Script file %s is not UTF-8", filename);
		} else {
			res = JS_Eval(ctx, (char *)data, data_size, filename, JS_EVAL_TYPE_GLOBAL);
		}
	} else {
		res = JS_UNDEFINED;
	}
    if (data) gf_free(data);

    if (full_url)
		gf_free(full_url);
    else
		JS_FreeCString(ctx, filename);
    return res;
}