本文整理汇总了C++中JS_LeaveCompartment函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_LeaveCompartment函数的具体用法?C++ JS_LeaveCompartment怎么用?C++ JS_LeaveCompartment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JS_LeaveCompartment函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: jsd_GetValueString
JSString*
jsd_GetValueString(JSDContext* jsdc, JSDValue* jsdval)
{
JSContext* cx = jsdc->dumbContext;
JSExceptionState* exceptionState;
JSCompartment* oldCompartment = NULL;
jsval stringval;
JS::RootedString string(cx);
JS::RootedObject scopeObj(cx);
if(jsdval->string)
return jsdval->string;
/* Reuse the string without copying or re-rooting it */
if(JSVAL_IS_STRING(jsdval->val)) {
jsdval->string = JSVAL_TO_STRING(jsdval->val);
return jsdval->string;
}
JS_BeginRequest(cx);
/* Objects call JS_ValueToString in their own compartment. */
scopeObj = !JSVAL_IS_PRIMITIVE(jsdval->val) ? JSVAL_TO_OBJECT(jsdval->val) : jsdc->glob;
oldCompartment = JS_EnterCompartment(cx, scopeObj);
exceptionState = JS_SaveExceptionState(cx);
string = JS_ValueToString(cx, jsdval->val);
JS_RestoreExceptionState(cx, exceptionState);
JS_LeaveCompartment(cx, oldCompartment);
oldCompartment = NULL;
if(string) {
stringval = STRING_TO_JSVAL(string);
oldCompartment = JS_EnterCompartment(cx, jsdc->glob);
}
if(!string || !JS_WrapValue(cx, &stringval)) {
if(oldCompartment)
JS_LeaveCompartment(cx, oldCompartment);
JS_EndRequest(cx);
return NULL;
}
jsdval->string = JSVAL_TO_STRING(stringval);
if(!JS_AddNamedStringRoot(cx, &jsdval->string, "ValueString"))
jsdval->string = NULL;
JS_LeaveCompartment(cx, oldCompartment);
JS_EndRequest(cx);
return jsdval->string;
}
示例2: jsd_GetValueConstructor
JSDValue*
jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval)
{
JSCompartment* oldCompartment = NULL;
JSContext* cx = jsdc->dumbContext;
if(!(CHECK_BIT_FLAG(jsdval->flags, GOT_CTOR)))
{
JS::RootedObject obj(cx);
JS::RootedObject proto(cx);
JS::RootedObject ctor(cx);
JS_ASSERT(!jsdval->ctor);
SET_BIT_FLAG(jsdval->flags, GOT_CTOR);
if(JSVAL_IS_PRIMITIVE(jsdval->val))
return NULL;
obj = JSVAL_TO_OBJECT(jsdval->val);
if(!JS_GetPrototype(cx, obj, proto.address()))
return NULL;
if(!proto)
return NULL;
JS_BeginRequest(jsdc->dumbContext);
oldCompartment = JS_EnterCompartment(jsdc->dumbContext, obj);
ctor = JS_GetConstructor(jsdc->dumbContext,proto);
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
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;
}
示例3: jsd_GetScriptForValue
JSDScript*
jsd_GetScriptForValue(JSDContext* jsdc, JSDValue* jsdval)
{
JSContext* cx = jsdc->dumbContext;
JS::RootedValue val(cx, jsdval->val);
JSFunction* fun = NULL;
JSExceptionState* exceptionState;
JS::RootedScript script(cx);
JSDScript* jsdscript;
JSCompartment* oldCompartment = NULL;
if (!jsd_IsValueFunction(jsdc, jsdval))
return NULL;
JS_BeginRequest(cx);
oldCompartment = JS_EnterCompartment(cx, JSVAL_TO_OBJECT(val));
exceptionState = JS_SaveExceptionState(cx);
fun = JSD_GetValueFunction(jsdc, jsdval);
JS_RestoreExceptionState(cx, exceptionState);
if (fun)
script = JS_GetFunctionScript(cx, fun);
JS_LeaveCompartment(cx, oldCompartment);
JS_EndRequest(cx);
if (!script)
return NULL;
JSD_LOCK_SCRIPTS(jsdc);
jsdscript = jsd_FindJSDScript(jsdc, script);
JSD_UNLOCK_SCRIPTS(jsdc);
return jsdscript;
}
示例4: jsd_GetClosestLine
unsigned
jsd_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, uintptr_t pc)
{
JSCompartment* oldCompartment;
unsigned first = jsdscript->lineBase;
unsigned last = first + jsd_GetScriptLineExtent(jsdc, jsdscript) - 1;
unsigned line = 0;
oldCompartment = JS_EnterCompartmentOfScript(jsdc->dumbContext, jsdscript->script);
if (pc)
line = JS_PCToLineNumber(jsdc->dumbContext, jsdscript->script, (jsbytecode*)pc);
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
if( line < first )
return first;
if( line > last )
return last;
#ifdef LIVEWIRE
if( jsdscript && jsdscript->lwscript )
{
unsigned newline;
jsdlw_ProcessedToRawLineNumber(jsdc, jsdscript, line, &newline);
line = newline;
}
#endif
return line;
}
示例5: jsd_GetValueFunctionId
JSString*
jsd_GetValueFunctionId(JSDContext* jsdc, JSDValue* jsdval)
{
JSContext* cx = jsdc->dumbContext;
JS::RootedFunction fun(cx);
JSExceptionState* exceptionState;
JSCompartment* oldCompartment = NULL;
if(!jsdval->funName && jsd_IsValueFunction(jsdc, jsdval))
{
JS_BeginRequest(cx);
oldCompartment = JS_EnterCompartment(jsdc->dumbContext, JSVAL_TO_OBJECT(jsdval->val));
exceptionState = JS_SaveExceptionState(cx);
fun = JSD_GetValueFunction(jsdc, jsdval);
JS_RestoreExceptionState(cx, exceptionState);
JS_LeaveCompartment(cx, oldCompartment);
JS_EndRequest(cx);
if(!fun)
return NULL;
jsdval->funName = JS_GetFunctionId(fun);
/* For compatibility we return "anonymous", not an empty string here. */
if (!jsdval->funName)
jsdval->funName = JS_GetAnonymousString(jsdc->jsrt);
}
return jsdval->funName;
}
示例6: jsd_GetLinePCs
JSBool
jsd_GetLinePCs(JSDContext* jsdc, JSDScript* jsdscript,
unsigned startLine, unsigned maxLines,
unsigned* count, unsigned** retLines, uintptr_t** retPCs)
{
JSCompartment* oldCompartment;
unsigned first = jsdscript->lineBase;
unsigned last = first + jsd_GetScriptLineExtent(jsdc, jsdscript) - 1;
JSBool ok;
jsbytecode **pcs;
unsigned i;
if (last < startLine)
return JS_TRUE;
oldCompartment = JS_EnterCompartmentOfScript(jsdc->dumbContext, jsdscript->script);
ok = JS_GetLinePCs(jsdc->dumbContext, jsdscript->script,
startLine, maxLines,
count, retLines, &pcs);
if (ok) {
if (retPCs) {
for (i = 0; i < *count; ++i) {
(*retPCs)[i] = (*pcs)[i];
}
}
JS_free(jsdc->dumbContext, pcs);
}
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
return ok;
}
示例7: jsd_IsValueNative
JSBool
jsd_IsValueNative(JSDContext* jsdc, JSDValue* jsdval)
{
JSContext* cx = jsdc->dumbContext;
JS::RootedFunction fun(cx);
JSExceptionState* exceptionState;
JSCompartment* oldCompartment = NULL;
if(jsd_IsValueFunction(jsdc, jsdval))
{
JSBool ok = JS_FALSE;
JS_BeginRequest(cx);
oldCompartment = JS_EnterCompartment(cx, JSVAL_TO_OBJECT(jsdval->val));
exceptionState = JS_SaveExceptionState(cx);
fun = JSD_GetValueFunction(jsdc, jsdval);
JS_RestoreExceptionState(cx, exceptionState);
if(fun)
ok = JS_GetFunctionScript(cx, fun) ? JS_FALSE : JS_TRUE;
JS_LeaveCompartment(cx, oldCompartment);
JS_EndRequest(cx);
JS_ASSERT(fun);
return ok;
}
return !JSVAL_IS_PRIMITIVE(jsdval->val);
}
示例8: gjstest_test_func_gjs_jsapi_util_string_js_string_utf8
static void
gjstest_test_func_gjs_jsapi_util_string_js_string_utf8(void)
{
GjsUnitTestFixture fixture;
JSContext *context;
JSObject *global;
const char *utf8_string = "\303\211\303\226 foobar \343\203\237";
char *utf8_result;
jsval js_string;
_gjs_unit_test_fixture_begin(&fixture);
context = fixture.context;
global = JS_GetGlobalObject(context);
JSCompartment *oldCompartment = JS_EnterCompartment(context, global);
g_assert(gjs_string_from_utf8(context, utf8_string, -1, &js_string) == JS_TRUE);
g_assert(JSVAL_IS_STRING(js_string));
g_assert(gjs_string_to_utf8(context, js_string, &utf8_result) == JS_TRUE);
JS_LeaveCompartment(context, oldCompartment);
_gjs_unit_test_fixture_finish(&fixture);
g_assert(g_str_equal(utf8_string, utf8_result));
g_free(utf8_result);
}
示例9: jsd_ClearExecutionHook
JSBool
jsd_ClearExecutionHook(JSDContext* jsdc,
JSDScript* jsdscript,
uintptr_t pc)
{
JSCompartment* oldCompartment;
JSDExecHook* jsdhook;
JSD_LOCK();
jsdhook = _findHook(jsdc, jsdscript, pc);
if( ! jsdhook )
{
JSD_UNLOCK();
return JS_FALSE;
}
oldCompartment = JS_EnterCompartmentOfScript(jsdc->dumbContext, jsdscript->script);
JS_ClearTrap(jsdc->dumbContext, jsdscript->script,
(jsbytecode*)pc, NULL, NULL );
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
JS_REMOVE_LINK(&jsdhook->links);
free(jsdhook);
JSD_UNLOCK();
return JS_TRUE;
}
示例10: jsd_GetValueParent
JSDValue*
jsd_GetValueParent(JSDContext* jsdc, JSDValue* jsdval)
{
JSCompartment* oldCompartment = NULL;
if(!(CHECK_BIT_FLAG(jsdval->flags, GOT_PARENT)))
{
JSContext* cx = jsdc->dumbContext;
JS::RootedObject obj(cx);
JS::RootedObject parent(cx);
JS_ASSERT(!jsdval->parent);
SET_BIT_FLAG(jsdval->flags, GOT_PARENT);
if(JSVAL_IS_PRIMITIVE(jsdval->val))
return NULL;
obj = JSVAL_TO_OBJECT(jsdval->val);
JS_BeginRequest(jsdc->dumbContext);
oldCompartment = JS_EnterCompartment(jsdc->dumbContext, obj);
parent = JS_GetParentOrScopeChain(jsdc->dumbContext,obj);
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
JS_EndRequest(jsdc->dumbContext);
if(!parent)
return NULL;
jsdval->parent = jsd_NewValue(jsdc, OBJECT_TO_JSVAL(parent));
}
if(jsdval->parent)
jsdval->parent->nref++;
return jsdval->parent;
}
示例11: jsd_RefreshValue
void
jsd_RefreshValue(JSDContext* jsdc, JSDValue* jsdval)
{
JSContext* cx = jsdc->dumbContext;
JSCompartment* oldCompartment = NULL;
if(jsdval->string)
{
/* if the jsval is a string, then we didn't need to root the string */
if(!JSVAL_IS_STRING(jsdval->val))
{
JS_BeginRequest(cx);
oldCompartment = JS_EnterCompartment(cx, jsdc->glob);
JS_RemoveStringRoot(cx, &jsdval->string);
JS_LeaveCompartment(cx, oldCompartment);
JS_EndRequest(cx);
}
jsdval->string = NULL;
}
jsdval->funName = NULL;
jsdval->className = NULL;
DROP_CLEAR_VALUE(jsdc, jsdval->proto);
DROP_CLEAR_VALUE(jsdc, jsdval->parent);
DROP_CLEAR_VALUE(jsdc, jsdval->ctor);
_freeProps(jsdc, jsdval);
jsdval->flags = 0;
}
示例12: jsd_SetExecutionHook
JSBool
jsd_SetExecutionHook(JSDContext* jsdc,
JSDScript* jsdscript,
uintptr_t pc,
JSD_ExecutionHookProc hook,
void* callerdata)
{
JSDExecHook* jsdhook;
JSBool rv;
JSCompartment* oldCompartment;
JSD_LOCK();
if( ! hook )
{
jsd_ClearExecutionHook(jsdc, jsdscript, pc);
JSD_UNLOCK();
return JS_TRUE;
}
jsdhook = _findHook(jsdc, jsdscript, pc);
if( jsdhook )
{
jsdhook->hook = hook;
jsdhook->callerdata = callerdata;
JSD_UNLOCK();
return JS_TRUE;
}
/* else... */
jsdhook = (JSDExecHook*)calloc(1, sizeof(JSDExecHook));
if( ! jsdhook ) {
JSD_UNLOCK();
return JS_FALSE;
}
jsdhook->jsdscript = jsdscript;
jsdhook->pc = pc;
jsdhook->hook = hook;
jsdhook->callerdata = callerdata;
oldCompartment = JS_EnterCompartmentOfScript(jsdc->dumbContext, jsdscript->script);
rv = JS_SetTrap(jsdc->dumbContext, jsdscript->script,
(jsbytecode*)pc, jsd_TrapHandler,
PRIVATE_TO_JSVAL(jsdhook));
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
if ( ! rv ) {
free(jsdhook);
JSD_UNLOCK();
return JS_FALSE;
}
JS_APPEND_LINK(&jsdhook->links, &jsdscript->hooks);
JSD_UNLOCK();
return JS_TRUE;
}
示例13: rq
ScriptInterface_impl::~ScriptInterface_impl()
{
m_runtime->UnRegisterContext(m_cx);
{
JSAutoRequest rq(m_cx);
JS_LeaveCompartment(m_cx, m_comp);
}
JS_DestroyContext(m_cx);
}
示例14: _buildProps
static JSBool _buildProps(JSDContext* jsdc, JSDValue* jsdval)
{
JSContext* cx = jsdc->dumbContext;
JS::RootedObject obj(cx);
JSPropertyDescArray pda;
unsigned i;
JSCompartment* oldCompartment = NULL;
JS_ASSERT(JS_CLIST_IS_EMPTY(&jsdval->props));
JS_ASSERT(!(CHECK_BIT_FLAG(jsdval->flags, GOT_PROPS)));
JS_ASSERT(!JSVAL_IS_PRIMITIVE(jsdval->val));
if(JSVAL_IS_PRIMITIVE(jsdval->val))
return JS_FALSE;
obj = JSVAL_TO_OBJECT(jsdval->val);
JS_BeginRequest(cx);
oldCompartment = JS_EnterCompartment(jsdc->dumbContext, obj);
if(!JS_GetPropertyDescArray(cx, obj, &pda))
{
JS_EndRequest(cx);
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
return JS_FALSE;
}
for(i = 0; i < pda.length; i++)
{
JSDProperty* prop = _newProperty(jsdc, &pda.array[i], 0);
if(!prop)
{
_freeProps(jsdc, jsdval);
break;
}
JS_APPEND_LINK(&prop->links, &jsdval->props);
}
JS_PutPropertyDescArray(cx, &pda);
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
JS_EndRequest(cx);
SET_BIT_FLAG(jsdval->flags, GOT_PROPS);
return !JS_CLIST_IS_EMPTY(&jsdval->props);
}
示例15: JS_LeaveCompartment
void JSAPITest::uninit()
{
if (oldCompartment) {
JS_LeaveCompartment(cx, oldCompartment);
oldCompartment = nullptr;
}
if (global) {
JS_LeaveCompartment(cx, nullptr);
JS::RemoveObjectRoot(cx, &global);
global = nullptr;
}
if (cx) {
JS_EndRequest(cx);
JS_DestroyContext(cx);
cx = nullptr;
}
if (rt) {
destroyRuntime();
rt = nullptr;
}
}