Chandra
view release on metacpan or search on metacpan
include/chandra/chandra.h view on Meta::CPAN
{
STRLEN mlen;
const char *m = SvPV(msg, mlen);
const char *p;
SV *js = newSVpvs(
"if(window.__chandraDevTools)window.__chandraDevTools.addError('");
for (p = m; p < m + mlen; p++) {
if (*p == '\\') sv_catpvs(js, "\\\\");
else if (*p == '\'') sv_catpvs(js, "\\'");
else if (*p == '\n') sv_catpvs(js, "\\n");
else sv_catpvn(js, p, 1);
}
sv_catpvs(js, "')");
PUSHMARK(SP);
XPUSHs(*app_svp);
XPUSHs(sv_2mortal(js));
PUTBACK;
call_method("dispatch_eval", G_DISCARD | G_EVAL);
if (SvTRUE(ERRSV)) sv_setpvs(ERRSV, "");
}
SvREFCNT_dec(msg);
FREETMPS; LEAVE;
}
}
SvREFCNT_dec(err_copy);
XSRETURN_EMPTY;
}
/* ---- Protocol static XS callback ---- */
typedef struct {
SV *handler;
SV *json_encoder;
} ProtocolBindCtx;
static XS(xs_protocol_bound_callback)
{
dXSARGS;
ProtocolBindCtx *ctx = (ProtocolBindCtx *)CvXSUBANY(cv).any_ptr;
SV *path = (items > 0) ? newSVsv(ST(0)) : newSVsv(&PL_sv_undef);
SV *params_json = (items > 1) ? newSVsv(ST(1)) : newSVsv(&PL_sv_undef);
SV *params;
SV *result = &PL_sv_undef;
params = newRV_noinc((SV *)newHV());
if (SvOK(params_json) && SvCUR(params_json) > 0) {
dSP;
int count;
ENTER; SAVETMPS;
PUSHMARK(SP);
XPUSHs(ctx->json_encoder);
XPUSHs(params_json);
PUTBACK;
count = call_method("decode", G_SCALAR | G_EVAL);
SPAGAIN;
if (count > 0 && !SvTRUE(ERRSV)) {
SV *decoded = POPs;
SvREFCNT_dec(params);
params = newSVsv(decoded);
}
PUTBACK;
FREETMPS; LEAVE;
if (SvTRUE(ERRSV)) sv_setpvs(ERRSV, "");
}
{
dSP;
int count;
ENTER; SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(path));
XPUSHs(sv_2mortal(params));
PUTBACK;
count = call_sv(ctx->handler, G_SCALAR);
SPAGAIN;
if (count > 0) {
result = newSVsv(POPs);
}
PUTBACK;
FREETMPS; LEAVE;
}
SvREFCNT_dec(params_json);
if (result == &PL_sv_undef) {
ST(0) = &PL_sv_undef;
} else {
ST(0) = sv_2mortal(result);
}
XSRETURN(1);
}
/* ---- Shortcut static XS callback ---- */
static XS(xs_shortcut_dispatch_callback)
{
dXSARGS;
SV *shortcut_self = (SV *)CvXSUBANY(cv).any_ptr;
SV *combo_sv = (items > 0) ? ST(0) : &PL_sv_undef;
SV *result = &PL_sv_undef;
/* Check weak ref is still valid */
if (!shortcut_self || !SvOK(shortcut_self) || !SvROK(shortcut_self)) {
ST(0) = &PL_sv_undef;
XSRETURN(1);
}
{
HV *hv = (HV *)SvRV(shortcut_self);
SV **da_svp, **bindings_svp;
const char *combo_str;
STRLEN combo_len;
/* Check global disable */
da_svp = hv_fetchs(hv, "_disabled_all", 0);
if (da_svp && SvIV(*da_svp)) {
ST(0) = &PL_sv_undef;
XSRETURN(1);
}
( run in 0.402 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )