
static JSValue js_color_get_component(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
	const char *str;
	u32 comp_idx, color;
	Double comp;
	if (argc!=2)
		return GF_JS_EXCEPTION(ctx);

	str = JS_ToCString(ctx, argv[0]);
	if (!str) return GF_JS_EXCEPTION(ctx);
	color = gf_color_parse(str);
	JS_FreeCString(ctx, str);

	if (JS_ToInt32(ctx, &comp_idx, argv[1]))
		return GF_JS_EXCEPTION(ctx);

	switch (comp_idx) {
	case 0: comp = GF_COL_A(color); break;
	case 1: comp = GF_COL_R(color); break;
	case 2: comp = GF_COL_G(color); break;
	case 3: comp = GF_COL_B(color); break;
	default: return GF_JS_EXCEPTION(ctx);
	}
	comp /= 255.0;
	return JS_NewFloat64(ctx, comp);

static JSValue js_color_get_component(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
	const char *str;
	u32 comp_idx, color;
	Double comp;
	if (argc!=2)
		return GF_JS_EXCEPTION(ctx);

	str = JS_ToCString(ctx, argv[0]);
	if (!str) return GF_JS_EXCEPTION(ctx);
	color = gf_color_parse(str);
	JS_FreeCString(ctx, str);

	if (JS_ToInt32(ctx, &comp_idx, argv[1]))
		return GF_JS_EXCEPTION(ctx);

	switch (comp_idx) {
	case 0: comp = GF_COL_A(color); break;
	case 1: comp = GF_COL_R(color); break;
	case 2: comp = GF_COL_G(color); break;
	case 3: comp = GF_COL_B(color); break;
	default: return GF_JS_EXCEPTION(ctx);
	}
	comp /= 255.0;
	return JS_NewFloat64(ctx, comp);