本文整理汇总了C++中JS_BeginRequest函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_BeginRequest函数的具体用法?C++ JS_BeginRequest怎么用?C++ JS_BeginRequest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JS_BeginRequest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: jsd_NewValue
/*
* Create a new JSD value referring to a jsval. Copy string values into the
* JSD compartment. Leave all other GCTHINGs in their native compartments
* and access them through cross-compartment calls.
*/
JSDValue*
jsd_NewValue(JSDContext* jsdc, jsval val)
{
JSDValue* jsdval;
JSCrossCompartmentCall *call = NULL;
if(!(jsdval = (JSDValue*) calloc(1, sizeof(JSDValue))))
return NULL;
if(JSVAL_IS_GCTHING(val))
{
JSBool ok;
JS_BeginRequest(jsdc->dumbContext);
call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, jsdc->glob);
if(!call) {
JS_EndRequest(jsdc->dumbContext);
free(jsdval);
return NULL;
}
ok = JS_AddNamedValueRoot(jsdc->dumbContext, &jsdval->val, "JSDValue");
if(ok && JSVAL_IS_STRING(val)) {
if(!JS_WrapValue(jsdc->dumbContext, &val)) {
ok = JS_FALSE;
}
}
JS_LeaveCrossCompartmentCall(call);
JS_EndRequest(jsdc->dumbContext);
if(!ok)
{
free(jsdval);
return NULL;
}
}
jsdval->val = val;
jsdval->nref = 1;
JS_INIT_CLIST(&jsdval->props);
return jsdval;
}
示例2: def_timestep_view_set_filterColor
CEXPORT JSBool def_timestep_view_set_filterColor(JSContext *cx, JSHandleObject obj, JSHandleId id, JSBool strict, JSMutableHandleValue vp) {
JS_BeginRequest(cx);
timestep_view *thiz = (timestep_view*)JS_GetPrivate(obj.get());
if (thiz) {
if (vp.isString()) {
JSString *jstr = vp.toString();
JSTR_TO_CSTR(cx, jstr, cstr);
rgba color;
rgba_parse(&color, cstr);
thiz->filter_color = color;
}
}
JS_EndRequest(cx);
return JS_TRUE;
}
示例3: round_js_sm_removeregistry
JSBool round_js_sm_removeregistry(JSContext *cx, unsigned argc, jsval *vp) {
if (argc < 1)
return JS_FALSE;
Round::LocalNode *node = dynamic_cast<Round::LocalNode *>(round_js_sm_getlocalnode());
if (!node)
return JS_FALSE;
JS_BeginRequest(cx);
std::string key;
JSSTRING_TO_STDSTRING(cx, vp, 0, &key);
bool isSuccess = node->removeRegistry(key);
JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(JSBool(isSuccess)));
JS_EndRequest(cx);
return JS_TRUE;
}
示例4: jsd_DropValue
void
jsd_DropValue(JSDContext* jsdc, JSDValue* jsdval)
{
JSCompartment* oldCompartment = NULL;
JS_ASSERT(jsdval->nref > 0);
if(0 == --jsdval->nref)
{
jsd_RefreshValue(jsdc, jsdval);
if(JSVAL_IS_GCTHING(jsdval->val))
{
JS_BeginRequest(jsdc->dumbContext);
oldCompartment = JS_EnterCompartment(jsdc->dumbContext, jsdc->glob);
JS_RemoveValueRoot(jsdc->dumbContext, &jsdval->val);
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
JS_EndRequest(jsdc->dumbContext);
}
free(jsdval);
}
}
示例5: gjs_keep_alive_remove_global_child
void
gjs_keep_alive_remove_global_child(JSContext *context,
GjsUnrootedFunc notify,
JSObject *child,
void *data)
{
JSObject *keep_alive;
JS_BeginRequest(context);
keep_alive = gjs_keep_alive_get_global(context);
if (!keep_alive)
g_error("no keep_alive property on the global object, have you "
"previously added this child?");
gjs_keep_alive_remove_child(keep_alive, notify, child, data);
JS_EndRequest(context);
}
示例6: round_js_sm_getnodestate
JSBool round_js_sm_getnodestate(JSContext* cx, unsigned argc, jsval* vp)
{
RoundLocalNode* node = round_js_sm_getlocalnode();
if (!node)
return JS_FALSE;
JS_BeginRequest(cx);
/*
RoundLocalNodeResponse nodeRes;
Round::SystemGetNodeInfoResponse sysRes(&nodeRes);
sysRes.setNode(node);
JS_SET_NODERESPONSE_RVAL(cx, vp, nodeRes);
*/
JS_EndRequest(cx);
return JS_TRUE;
}
示例7: jsd_GetValueFunctionName
const char*
jsd_GetValueFunctionName(JSDContext* jsdc, JSDValue* jsdval)
{
JSContext* cx = jsdc->dumbContext;
JSFunction* fun;
JSExceptionState* exceptionState;
if(!jsdval->funName && jsd_IsValueFunction(jsdc, jsdval))
{
JS_BeginRequest(cx);
exceptionState = JS_SaveExceptionState(cx);
fun = JS_ValueToFunction(cx, jsdval->val);
JS_RestoreExceptionState(cx, exceptionState);
JS_EndRequest(cx);
if(!fun)
return NULL;
jsdval->funName = JS_GetFunctionName(fun);
}
return jsdval->funName;
}
示例8: Core_initialize
JSObject*
Core_initialize (JSContext *cx, const char* path)
{
JS_BeginRequest(cx);
JS_SetOptions(cx, JSOPTION_VAROBJFIX|JSOPTION_JIT|JSOPTION_XML);
JS_SetVersion(cx, JS_StringToVersion("1.8"));
JSObject* object = JS_NewObject(cx, &Core_class, NULL, NULL);
if (object && JS_InitStandardClasses(cx, object)) {
JS_DefineFunctions(cx, object, Core_methods);
JS_EnterLocalRootScope(cx);
// Properties
jsval property;
std::string rootPath = __Core_getRootPath(cx, path);
jsval paths[] = {
STRING_TO_JSVAL(JS_NewString(cx, JS_strdup(cx, rootPath.c_str()), rootPath.length())),
STRING_TO_JSVAL(JS_NewString(cx, JS_strdup(cx, __LJS_LIBRARY_PATH__), strlen(__LJS_LIBRARY_PATH__)))
};
property = OBJECT_TO_JSVAL(JS_NewArrayObject(cx, 2, paths));
JS_SetProperty(cx, object, "__PATH__", &property);
property = STRING_TO_JSVAL(JS_NewString(cx, JS_strdup(cx, __LJS_VERSION__), strlen(__LJS_VERSION__)));
JS_SetProperty(cx, object, "__VERSION__", &property);
property = OBJECT_TO_JSVAL(object);
JS_SetProperty(cx, object, "Program", &property);
JS_LeaveLocalRootScope(cx);
JS_EndRequest(cx);
if (__Core_include(cx, __LJS_LIBRARY_PATH__ "/Core")) {
return object;
}
}
return NULL;
}
示例9: gjs_string_from_utf8
JSBool
gjs_string_from_utf8(JSContext *context,
const char *utf8_string,
gssize n_bytes,
jsval *value_p)
{
jschar *u16_string;
glong u16_string_length;
JSString *str;
GError *error;
/* intentionally using n_bytes even though glib api suggests n_chars; with
* n_chars (from g_utf8_strlen()) the result appears truncated
*/
error = NULL;
u16_string = g_utf8_to_utf16(utf8_string,
n_bytes,
NULL,
&u16_string_length,
&error);
if (!u16_string) {
gjs_throw(context,
"Failed to convert UTF-8 string to "
"JS string: %s",
error->message);
g_error_free(error);
return JS_FALSE;
}
JS_BeginRequest(context);
/* Avoid a copy - assumes that g_malloc == js_malloc == malloc */
str = JS_NewUCString(context, u16_string, u16_string_length);
if (str && value_p)
*value_p = STRING_TO_JSVAL(str);
JS_EndRequest(context);
return str != NULL;
}
示例10: __Core_getPath
std::string
__Core_getPath (JSContext* cx, std::string fileName)
{
/*
* Getting the dirname of the file from the other file is included
* then copying it and getting the path to the dir.
*/
const char* scriptName = __Core_getScriptName(cx);
char* from = strdup(scriptName ? scriptName : "");
char* dir = dirname(from);
std::string path = std::string(dir) + "/" + fileName;
free(from);
JS_BeginRequest(cx);
struct stat test;
if (stat(path.c_str(), &test) != 0) {
JSObject* lPath; JS_ValueToObject(cx, JS_EVAL(cx, "Program.__PATH__"), &lPath);
if (lPath) {
jsuint length;
JS_GetArrayLength(cx, lPath, &length);
size_t i;
for (i = 0; i < length; i++) {
jsval pathFile;
JS_GetElement(cx, lPath, i, &pathFile);
path = std::string(JS_GetStringBytes(JSVAL_TO_STRING(pathFile))) + "/" + fileName;
if (stat(path.c_str(), &test) == 0) {
break;
}
}
}
}
JS_EndRequest(cx);
return path;
}
示例11: jsd_GetValueConstructor
JSDValue*
jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval)
{
JSCrossCompartmentCall *call = NULL;
if(!(CHECK_BIT_FLAG(jsdval->flags, GOT_CTOR)))
{
JSObject* obj;
JSObject* proto;
JSObject* ctor;
JS_ASSERT(!jsdval->ctor);
SET_BIT_FLAG(jsdval->flags, GOT_CTOR);
if(!JSVAL_IS_OBJECT(jsdval->val))
return NULL;
if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
return NULL;
JS_BeginRequest(jsdc->dumbContext);
call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
if(!call) {
JS_EndRequest(jsdc->dumbContext);
return NULL;
}
proto = JS_GetPrototype(jsdc->dumbContext,obj);
if(!proto)
{
JS_LeaveCrossCompartmentCall(call);
JS_EndRequest(jsdc->dumbContext);
return NULL;
}
ctor = JS_GetConstructor(jsdc->dumbContext,proto);
JS_LeaveCrossCompartmentCall(call);
JS_EndRequest(jsdc->dumbContext);
if(!ctor)
return NULL;
jsdval->ctor = jsd_NewValue(jsdc, OBJECT_TO_JSVAL(ctor));
}
if(jsdval->ctor)
jsdval->ctor->nref++;
return jsdval->ctor;
}
示例12: Embed
static int Embed(int argc, char **argv)
{
Core::Context *ncx = initNidiumJS();
JSContext *cx = ncx->getNJS()->getJSContext();
if (argc <= 1) {
printf("$ %s <path> [prefix] [> out]\n", argv[0]);
return 1;
}
DIR *dir = opendir(argv[1]);
if (!dir) {
fprintf(stderr, "Can't open dir %s\n", argv[1]);
}
JS_BeginRequest(cx);
JSNFS *nfs = new JSNFS(cx);
bool ok;
if (argc == 3) {
std::string prefix = "/";
prefix += argv[2];
fprintf(stderr, "Create prefix %s...\n", prefix.c_str());
nfs->mkdir(prefix.c_str(), strlen(prefix.c_str()));
ok = listdir(nfs, dir, argv[1], strlen(argv[1]));
} else {
ok = listdir(nfs, dir, argv[1], strlen(argv[1]));
}
nfs->save(DIR2NFS_OUTPUT);
JS_EndRequest(cx);
delete ncx;
return ok ? 0 : 1;
}
示例13: jsd_GetThisForStackFrame
JSDValue*
jsd_GetThisForStackFrame(JSDContext* jsdc,
JSDThreadState* jsdthreadstate,
JSDStackFrameInfo* jsdframe)
{
JSObject* obj;
JSDValue* jsdval = NULL;
JSD_LOCK_THREADSTATES(jsdc);
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
{
JS_BeginRequest(jsdthreadstate->context);
obj = JS_GetFrameThis(jsdthreadstate->context, jsdframe->fp);
JS_EndRequest(jsdthreadstate->context);
if(obj)
jsdval = JSD_NewValue(jsdc, OBJECT_TO_JSVAL(obj));
}
JSD_UNLOCK_THREADSTATES(jsdc);
return jsdval;
}
示例14: __declspec
BOOL __declspec(dllexport) InitExports(JSContext * cx, JSObject * global)
{
JSFunctionSpec xdeployFunctions[] = {
{ "SetComputerName", setcomputername, 2, 0 },
{ "NetJoinDomain", netjoindomain, 6, 0 },
{ "NetLocalGroupAddMembers", netlocalgroupaddmembers, 2, 0 },
{ "NetGetLastErrorMessage", GetLastNetErrorMessage, 1, 0 },
{ "NetGetJoinableOUs", netgetjoinableous, 3, 0 },
{ "HideFirstUXWnd", close_FirstUXWnd, 0, 0 },
{ 0 },
};
JS_BeginRequest(cx);
JS_DefineFunctions(cx, global, xdeployFunctions);
JS_DefineConstDoubles(cx, global, xdeployConsts);
InitCrypto(cx, global);
InitMsi(cx, global);
InitProgressDlg(cx, global);
JS_EndRequest(cx);
return TRUE;
}
示例15: TCP_initialize
JSBool
TCP_initialize (JSContext* cx)
{
JS_BeginRequest(cx);
JS_EnterLocalRootScope(cx);
JSObject* parent = JSVAL_TO_OBJECT(JS_EVAL(cx, "System.Network.Sockets"));
JSObject* object = JS_InitClass(
cx, parent, JSVAL_TO_OBJECT(JS_EVAL(cx, "System.Network.Sockets.prototype")), &TCP_class,
TCP_constructor, 1, TCP_attributes, TCP_methods, NULL, TCP_static_methods
);
if (object) {
JS_LeaveLocalRootScope(cx);
JS_EndRequest(cx);
return JS_TRUE;
}
return JS_FALSE;
}