本文整理汇总了C++中JS_LeaveCompartment函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_LeaveCompartment函数的具体用法?C++ JS_LeaveCompartment怎么用?C++ JS_LeaveCompartment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JS_LeaveCompartment函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:mvarie,项目名称:Spidermonkey,代码行数:52,代码来源:jsd_val.cpp
示例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;
}
开发者ID:mvarie,项目名称:Spidermonkey,代码行数:33,代码来源:jsd_val.cpp
示例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;
}
开发者ID:mvarie,项目名称:Spidermonkey,代码行数:32,代码来源:jsd_val.cpp
示例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;
}
开发者ID:RickEyre,项目名称:mozilla-central,代码行数:29,代码来源:jsd_scpt.cpp
示例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;
}
开发者ID:mvarie,项目名称:Spidermonkey,代码行数:28,代码来源:jsd_val.cpp
示例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;
}
开发者ID:RickEyre,项目名称:mozilla-central,代码行数:34,代码来源:jsd_scpt.cpp
示例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);
}
开发者ID:mvarie,项目名称:Spidermonkey,代码行数:25,代码来源:jsd_val.cpp
示例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);
}
开发者ID:victoryang,项目名称:gjs,代码行数:27,代码来源:gjs-tests.cpp
示例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;
}
开发者ID:RickEyre,项目名称:mozilla-central,代码行数:30,代码来源:jsd_scpt.cpp
示例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;
}
开发者ID:mvarie,项目名称:Spidermonkey,代码行数:29,代码来源:jsd_val.cpp
示例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;
}
开发者ID:mvarie,项目名称:Spidermonkey,代码行数:28,代码来源:jsd_val.cpp
示例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;
}
开发者ID:RickEyre,项目名称:mozilla-central,代码行数:58,代码来源:jsd_scpt.cpp
示例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);
}
开发者ID:Rektosauros,项目名称:0ad,代码行数:9,代码来源:ScriptInterface.cpp
示例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);
}
开发者ID:mvarie,项目名称:Spidermonkey,代码行数:43,代码来源:jsd_val.cpp
示例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;
}
}
开发者ID:ashishrana7,项目名称:firefox,代码行数:21,代码来源:tests.cpp
示例16: jsd_EnableSingleStepInterrupts
JSBool
jsd_EnableSingleStepInterrupts(JSDContext* jsdc, JSDScript* jsdscript, JSBool enable)
{
JSCompartment* oldCompartment;
JSBool rv;
oldCompartment = JS_EnterCompartmentOfScript(jsdc->dumbContext, jsdscript->script);
JSD_LOCK();
rv = JS_SetSingleStepMode(jsdc->dumbContext, jsdscript->script, enable);
JSD_UNLOCK();
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
return rv;
}
开发者ID:RickEyre,项目名称:mozilla-central,代码行数:12,代码来源:jsd_scpt.cpp
示例17: jsd_GetValueClassName
const char*
jsd_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval)
{
jsval val = jsdval->val;
JSCompartment* oldCompartment = NULL;
if(!jsdval->className && !JSVAL_IS_PRIMITIVE(val))
{
JSObject* obj = JSVAL_TO_OBJECT(val);
JS_BeginRequest(jsdc->dumbContext);
oldCompartment = JS_EnterCompartment(jsdc->dumbContext, obj);
jsdval->className = JS_GetDebugClassName(obj);
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
JS_EndRequest(jsdc->dumbContext);
}
return jsdval->className;
}
开发者ID:JSilver99,项目名称:mozilla-central,代码行数:17,代码来源:jsd_val.cpp
示例18: jsd_GetValueFunction
/*
* Retrieve a JSFunction* from a JSDValue*. This differs from
* JS_ValueToFunction by fully unwrapping the object first.
*/
JSFunction*
jsd_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval)
{
JSObject *obj;
JSFunction *fun;
JSCompartment* oldCompartment = NULL;
if (JSVAL_IS_PRIMITIVE(jsdval->val))
return NULL;
obj = JS_UnwrapObject(JSVAL_TO_OBJECT(jsdval->val));
oldCompartment = JS_EnterCompartment(jsdc->dumbContext, obj);
fun = JS_ValueToFunction(jsdc->dumbContext, OBJECT_TO_JSVAL(obj));
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
return fun;
}
开发者ID:JSilver99,项目名称:mozilla-central,代码行数:21,代码来源:jsd_val.cpp
示例19: jsd_GetValueFunction
/*
* Retrieve a JSFunction* from a JSDValue*. This differs from
* JS_ValueToFunction by fully unwrapping the object first.
*/
JSFunction*
jsd_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval)
{
JSContext* cx = jsdc->dumbContext;
JS::RootedObject obj(cx);
JS::RootedFunction fun(cx);
JSCompartment* oldCompartment = NULL;
if (JSVAL_IS_PRIMITIVE(jsdval->val))
return NULL;
obj = js::UncheckedUnwrap(JSVAL_TO_OBJECT(jsdval->val));
oldCompartment = JS_EnterCompartment(cx, obj);
fun = JS_ValueToFunction(cx, OBJECT_TO_JSVAL(obj));
JS_LeaveCompartment(cx, oldCompartment);
return fun;
}
开发者ID:mvarie,项目名称:Spidermonkey,代码行数:23,代码来源:jsd_val.cpp
示例20: 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);
}
}
开发者ID:mvarie,项目名称:Spidermonkey,代码行数:20,代码来源:jsd_val.cpp
注:本文中的JS_LeaveCompartment函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论