本文整理汇总了C++中JS_GetContextPrivate函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_GetContextPrivate函数的具体用法?C++ JS_GetContextPrivate怎么用?C++ JS_GetContextPrivate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JS_GetContextPrivate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nidium_sm_timer
bool JSGlobal::JS_setInterval(JSContext *cx, JS::CallArgs &args)
{
struct nidium_sm_timer *params;
int ms = 0, i;
int argc = args.length();
params = new nidium_sm_timer(cx);
if (!params) {
JS_ReportOutOfMemory(cx);
return false;
}
params->cx = cx;
params->global = m_Instance;
params->argc = nidium_max(0, argc - 2);
params->argv = new JS::PersistentRootedValue *[params->argc];
for (i = 0; i < argc - 2; i++) {
params->argv[i] = new JS::PersistentRootedValue(cx);
}
if (!JSUtils::ReportIfNotFunction(cx, args[0])) {
delete[] params->argv;
delete params;
return false;
}
params->func = args[0];
if (argc > 1 && !JS::ToInt32(cx, args[1], &ms)) {
ms = 0;
}
params->ms = nidium_max(8, ms);
for (i = 0; i < static_cast<int>(argc) - 2; i++) {
*params->argv[i] = args.array()[i + 2];
}
ape_timer_t *timer = APE_timer_create(
static_cast<ape_global *>(JS_GetContextPrivate(cx)), params->ms,
nidium_timerng_wrapper, static_cast<void *>(params));
APE_timer_unprotect(timer);
APE_timer_setclearfunc(timer, nidium_timer_deleted);
args.rval().setNumber(static_cast<double>(APE_timer_getid(timer)));
return true;
}
示例2: APE_timer_clearbyid
bool JSGlobal::JS_clearTimeout(JSContext *cx, JS::CallArgs &args)
{
double identifier;
if (!JS_ConvertArguments(cx, args, "d", &identifier)) {
return false;
}
APE_timer_clearbyid(static_cast<ape_global *>(JS_GetContextPrivate(cx)),
static_cast<uint64_t>(identifier), 0);
return true;
}
示例3: setContentType
JSBool JsHttpServerResponse::setContentType(JSContext *cx,JSObject *obj,uintN argc,jsval *argv,jsval *rval)
{
char *contentType = {0};
if ( !JS_ConvertArguments(cx,argc,argv,"s",&contentType) ) {
return Engine::throwUsageError(cx,argv);
}
ContextPrivate *cxPrivate = (ContextPrivate*)JS_GetContextPrivate(cx);
cxPrivate->getHttpResponse().setContentType(contentType);
return JS_TRUE;
}
示例4: write
JSBool JsHttpServerResponse::write(JSContext *cx,JSObject *obj,uintN argc,jsval *argv,jsval *rval)
{
char *output = {0};
if ( !JS_ConvertArguments(cx,argc,argv,"s",&output) ) {
return Engine::throwUsageError(cx,argv);
}
ContextPrivate *cxPrivate = (ContextPrivate*)JS_GetContextPrivate(cx);
cxPrivate->getHttpResponse().write(output,strlen(output));
return JS_TRUE;
}
示例5: gjs_on_context_gc
static JSBool
gjs_on_context_gc (JSContext *cx,
JSGCStatus status)
{
GjsContext *gjs_context = JS_GetContextPrivate(cx);
if (status == JSGC_END) {
if (gjs_context->idle_emit_gc_id == 0)
gjs_context->idle_emit_gc_id = g_idle_add (gjs_context_idle_emit_gc, gjs_context);
}
return TRUE;
}
示例6: error_reporter
static void
error_reporter(JSContext *ctx, const char *message, JSErrorReport *report)
{
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
struct session *ses = interpreter->vs->doc_view->session;
struct terminal *term;
unsigned char *strict, *exception, *warning, *error;
struct string msg;
assert(interpreter && interpreter->vs && interpreter->vs->doc_view
&& ses && ses->tab);
if_assert_failed goto reported;
term = ses->tab->term;
#ifdef CONFIG_LEDS
set_led_value(ses->status.ecmascript_led, 'J');
#endif
if (!get_opt_bool("ecmascript.error_reporting", ses)
|| !init_string(&msg))
goto reported;
strict = JSREPORT_IS_STRICT(report->flags) ? " strict" : "";
exception = JSREPORT_IS_EXCEPTION(report->flags) ? " exception" : "";
warning = JSREPORT_IS_WARNING(report->flags) ? " warning" : "";
error = !report->flags ? " error" : "";
add_format_to_string(&msg, _("A script embedded in the current "
"document raised the following%s%s%s%s", term),
strict, exception, warning, error);
add_to_string(&msg, ":\n\n");
add_to_string(&msg, message);
if (report->linebuf && report->tokenptr) {
int pos = report->tokenptr - report->linebuf;
add_format_to_string(&msg, "\n\n%s\n.%*s^%*s.",
report->linebuf,
pos - 2, " ",
strlen(report->linebuf) - pos - 1, " ");
}
info_box(term, MSGBOX_FREE_TEXT, N_("JavaScript Error"), ALIGN_CENTER,
msg.source);
reported:
/* Im clu'les. --pasky */
JS_ClearPendingException(ctx);
}
示例7: js_saveline
static JSBool
js_saveline(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
sbbs_t* sbbs;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
sbbs->slatr[sbbs->slcnt]=sbbs->latr;
sprintf(sbbs->slbuf[sbbs->slcnt<SAVE_LINES ? sbbs->slcnt++ : sbbs->slcnt]
,"%.*s",sbbs->lbuflen,sbbs->lbuf);
sbbs->lbuflen=0;
return(JS_TRUE);
}
示例8: js_restoreline
static JSBool
js_restoreline(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
sbbs_t* sbbs;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
sbbs->lbuflen=0;
sbbs->attr(sbbs->slatr[--sbbs->slcnt]);
sbbs->rputs(sbbs->slbuf[sbbs->slcnt]);
sbbs->curatr=LIGHTGRAY;
return(JS_TRUE);
}
示例9: js_cursor_left
static JSBool
js_cursor_left(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
int32 val=1;
sbbs_t* sbbs;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
if(argc)
JS_ValueToInt32(cx,argv[0],&val);
sbbs->cursor_left(val);
return(JS_TRUE);
}
示例10: go_func_callback
/* The function callback. */
JSBool go_func_callback(JSContext *cx, uintN argc, jsval *vp) {
JSObject *callee = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
jsval name;
JS_GetProperty(cx, callee, "name", &name);
char* cname = JS_EncodeString(cx, JS_ValueToString(cx, name));
JSBool result = call_go_func(JS_GetContextPrivate(cx), cname, argc, vp);
JS_free(cx, (void*)cname);
return result;
}
示例11: xgg_pbar_propop_xn_set
/** set numeric property (xn).
*/
JSBool xgg_pbar_propop_xn_set(JSContext *pcxa, JSObject *pobja, jsval id, jsval *vp)
{
XGGPRIVHDR* phdr = JS_GetPrivate(pcxa, pobja);
XGG_PBAR_PRIV* pv0 = JS_GetPrivate(pcxa, pobja);
XJSEXADGELEM* pelem0 = phdr->pxadgelem;
XJSECTX* pjsectx = (XJSECTX*)JS_GetContextPrivate(pcxa);
XJSE_ASSERT(pelem0 != 0); // basicelement inheritances must have this
xjse_result_t xr1;
xjse_int_t nid = 0;//, nvalue = 0;//, n1;
char* psz0;
JS_ValueToInt32(pcxa, id, &nid);
//JS_ValueToInt32(pcxa, vp[0], &nvalue);
//XJSE_TRACE("xgg_pbar_propop_xn_set. [%d](%d)", nid, nvalue);
switch(nid) {
case PBAR_TID_EMPTYIMAGE:
psz0 = JS_GetStringBytes(JS_ValueToString(pcxa, vp[0]));
xr1 = xgg_xadget_reload_img(pjsectx, &(pv0->ppbempty), psz0, 0, 0);
if(xr1 != XJSE_SUCCESS)
goto failed;
if(pelem0->fcx == 0.0f)
pelem0->fcx = (xjse_float_t)(pv0->ppbempty->nimgwidth);
if(pelem0->fcy == 0.0f)
pelem0->fcy = (xjse_float_t)(pv0->ppbempty->nimgheight);
break;
case PBAR_TID_FULLIMAGE:
psz0 = JS_GetStringBytes(JS_ValueToString(pcxa, vp[0]));
xr1 = xgg_xadget_reload_img(pjsectx, &(pv0->ppbfull), psz0, 0, 0);
if(xr1 != XJSE_SUCCESS)
goto failed;
break;
case PBAR_TID_MAX:
JS_ValueToInt32(pcxa, vp[0], &(pv0->nmax));
break;
case PBAR_TID_MIN:
JS_ValueToInt32(pcxa, vp[0], &(pv0->nmin));
break;
case PBAR_TID_VALUE:
JS_ValueToInt32(pcxa, vp[0], &(pv0->nvalue));
break;
default:
XJSE_TRACE("(E) unknown xn prop [property id: %d]", nid);
}
return JS_TRUE;
failed:
return JS_FALSE;
}
示例12: js_cleartoeol
static JSBool
js_cleartoeol(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
sbbs_t* sbbs;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
if(argc)
js_set_attr(cx, sbbs, argv[0]);
sbbs->cleartoeol();
return(JS_TRUE);
}
示例13: branch_cb
JSBool
branch_cb(JSContext* jscx, JSScript* script)
{
Context* pycx = (Context*) JS_GetContextPrivate(jscx);
time_t now = time(NULL);
if(pycx == NULL)
{
JS_ReportError(jscx, "Failed to find Python context.");
return JS_FALSE;
}
// Get out quick if we don't have any quotas.
if(pycx->max_time == 0 && pycx->max_heap == 0)
{
return JS_TRUE;
}
// Only check occasionally for resource usage.
pycx->branch_count++;
if((pycx->branch_count > 0x3FFF) != 1)
{
return JS_TRUE;
}
pycx->branch_count = 0;
if(pycx->max_heap > 0 && jscx->runtime->gcBytes > pycx->max_heap)
{
// First see if garbage collection gets under the threshold.
JS_GC(jscx);
if(jscx->runtime->gcBytes > pycx->max_heap)
{
PyErr_NoMemory();
return JS_FALSE;
}
}
if(
pycx->max_time > 0
&& pycx->start_time > 0
&& pycx->max_time < now - pycx->start_time
)
{
PyErr_SetNone(PyExc_SystemError);
return JS_FALSE;
}
return JS_TRUE;
}
示例14: MOZ_ASSERT
~WorkletJSContext() override
{
MOZ_ASSERT(!NS_IsMainThread());
JSContext* cx = MaybeContext();
if (!cx) {
return; // Initialize() must have failed
}
delete static_cast<WorkletThreadContextPrivate*>(JS_GetContextPrivate(cx));
JS_SetContextPrivate(cx, nullptr);
nsCycleCollector_shutdown();
}
示例15: resolve
JSBool
resolve(JSContext* jscx, JSObject* jsobj, jsval key)
{
Context* pycx = NULL;
PyObject* pykey = NULL;
jsid pid;
JSBool ret = JS_FALSE;
pycx = (Context*) JS_GetContextPrivate(jscx);
if(pycx == NULL)
{
JS_ReportError(jscx, "Failed to get Python context.");
goto done;
}
// Bail if there's no registered global handler.
if(pycx->global == NULL)
{
ret = JS_TRUE;
goto done;
}
pykey = js2py(pycx, key);
if(pykey == NULL) goto done;
if(!PyMapping_HasKey(pycx->global, pykey))
{
ret = JS_TRUE;
goto done;
}
if(!JS_ValueToId(jscx, key, &pid))
{
JS_ReportError(jscx, "Failed to convert property id.");
goto done;
}
if(!js_DefineProperty(jscx, pycx->root, pid, JSVAL_VOID, NULL, NULL,
JSPROP_SHARED, NULL))
{
JS_ReportError(jscx, "Failed to define property.");
goto done;
}
ret = JS_TRUE;
done:
Py_XDECREF(pykey);
return ret;
}