本文整理汇总了C++中JS_CallFunctionName函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_CallFunctionName函数的具体用法?C++ JS_CallFunctionName怎么用?C++ JS_CallFunctionName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JS_CallFunctionName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: invokeDelegate
void invokeDelegate(const char* fName, const char* name, int intVal, int argc) {
if (!s_cx) {
return;
}
//cocos2d::CCDirector::getInstance()->getScheduler()->performFunctionInCocosThread([=](){
JSContext* cx = s_cx;
const char* func_name = fName;
JS::RootedObject obj(cx, mJsDelegate);
JSAutoCompartment ac(cx, obj);
#if defined(MOZJS_MAJOR_VERSION)
#if MOZJS_MAJOR_VERSION >= 33
bool hasAction;
JS::RootedValue retval(cx);
JS::RootedValue func_handle(cx);
#else
bool hasAction;
jsval retval;
JS::RootedValue func_handle(cx);
#endif
#elif defined(JS_VERSION)
JSBool hasAction;
jsval retval;
jsval func_handle;
#endif
jsval dataVal[2];
if (2 == argc) {
dataVal[0] = c_string_to_jsval(cx, name);
dataVal[1] = INT_TO_JSVAL(intVal);
} else if (1 == argc) {
dataVal[0] = c_string_to_jsval(cx, name);
}
if (JS_HasProperty(cx, obj, func_name, &hasAction) && hasAction) {
if(!JS_GetProperty(cx, obj, func_name, &func_handle)) {
return;
}
if(func_handle == JSVAL_VOID) {
return;
}
#if MOZJS_MAJOR_VERSION >= 31
if (0 == argc) {
JS_CallFunctionName(cx, obj, func_name, JS::HandleValueArray::empty(), &retval);
} else {
JS_CallFunctionName(cx, obj, func_name, JS::HandleValueArray::fromMarkedLocation(argc, dataVal), &retval);
}
#else
if (0 == argc) {
JS_CallFunctionName(cx, obj, func_name, 0, nullptr, &retval);
} else {
JS_CallFunctionName(cx, obj, func_name, argc, dataVal, &retval);
}
#endif
}
//});
}
示例2: invokeJS
void invokeJS(const char* func, IMCallbackJS* cb) {
if (!s_cx) {
return;
}
JSContext* cx = s_cx;
const char* func_name = func;
JS::RootedObject obj(cx, _JSDelegate);
JSAutoCompartment ac(cx, obj);
#if defined(MOZJS_MAJOR_VERSION)
#if MOZJS_MAJOR_VERSION >= 33
bool hasAction;
JS::RootedValue retval(cx);
JS::RootedValue func_handle(cx);
#else
bool hasAction;
jsval retval;
JS::RootedValue func_handle(cx);
#endif
#elif defined(JS_VERSION)
JSBool hasAction;
jsval retval;
jsval func_handle;
#endif
int valueSize = 0;
jsval* pVals = nullptr;
valueSize = cb->transParams(&pVals);
if (JS_HasProperty(cx, obj, func_name, &hasAction) && hasAction) {
if(!JS_GetProperty(cx, obj, func_name, &func_handle)) {
return;
}
if(func_handle == JSVAL_VOID) {
return;
}
#if MOZJS_MAJOR_VERSION >= 31
if (0 == valueSize) {
JS_CallFunctionName(cx, obj, func_name, JS::HandleValueArray::empty(), &retval);
} else {
JS_CallFunctionName(cx, obj, func_name, JS::HandleValueArray::fromMarkedLocation(valueSize, pVals), &retval);
}
#else
if (0 == valueSize) {
JS_CallFunctionName(cx, obj, func_name, 0, nullptr, &retval);
} else {
JS_CallFunctionName(cx, obj, func_name, valueSize, pVals, &retval);
}
#endif
}
}
示例3: UnwrapJSObject
nsresult abpListener::HandleEvent(nsIDOMEvent* event) {
nsresult rv;
abpJSContextHolder holder;
JSObject* overlay = UnwrapJSObject(fakeBrowserWindow);
JSContext* cx = holder.get();
if (cx == nsnull || overlay == nsnull)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID());
if (xpc == nsnull)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIXPConnectJSObjectHolder> wrapperHolder;
rv = xpc->WrapNative(cx, JS_GetParent(cx, overlay), event, NS_GET_IID(nsIDOMEvent), getter_AddRefs(wrapperHolder));
if (NS_FAILED(rv))
return rv;
JSObject* jsObj;
rv = wrapperHolder->GetJSObject(&jsObj);
if (NS_FAILED(rv))
return rv;
jsval arg = OBJECT_TO_JSVAL(jsObj);
jsval retval;
JS_CallFunctionName(cx, overlay, "onEvent", 1, &arg, &retval);
return NS_OK;
}
示例4: DriverManager_getDriver
static JSBool DriverManager_getDriver(JSContext *cx, unsigned argc, jsval *vp)
{
jsval drivers;
JS_LookupProperty(cx, JS_THIS_OBJECT(cx, vp), "drivers", &drivers);
// FIXME check return code; check that drivers is an array
JSObject *obj = JSVAL_TO_OBJECT(drivers);
uint32_t len, i;
JS_GetArrayLength(cx, obj, &len);
for (i = 0; i < len; i++) {
jsval driver, rval;
jsval acceptsURL_argv[] = {JS_ARGV(cx, vp)[0]};
JS_GetElement(cx, obj, i, &driver);
JS_CallFunctionName(cx, JSVAL_TO_OBJECT(driver), "acceptsURL", 1, &acceptsURL_argv[0], &rval); // FIXME check return value
JSBool acceptsURL;
JS_ValueToBoolean(cx, rval, &acceptsURL); // FIXME check ret val
if (acceptsURL) {
JS_SET_RVAL(cx, vp, driver);
return JS_TRUE;
}
}
JS_ReportError(cx, "No suitable driver");
JS_SET_RVAL(cx, vp, JSVAL_NULL);
return JS_FALSE;
}
示例5: dispatch
Result dispatch(JSContext *cx, JSObject *thisobj, const char *dataPropName,
const char *methodName, Result noHandler)
{
if (!data)
return fail;
JSBool found;
if (!JS_HasProperty(cx, thisobj, methodName, &found))
return fail;
if (!found)
return noHandler;
// Create event object.
jsval v;
if (!deserializeData(cx, &v))
return fail;
JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
if (!obj || !JS_DefineProperty(cx, obj, dataPropName, v, NULL, NULL, 0))
return fail;
// Call event handler.
jsval argv[1] = { OBJECT_TO_JSVAL(obj) };
jsval rval = JSVAL_VOID;
return Result(JS_CallFunctionName(cx, thisobj, methodName, 1, argv, &rval));
}
示例6: test_fn2
static bool
test_fn2(JSContext* cx, unsigned argc, JS::Value* vp)
{
JS::RootedValue r(cx);
JS::RootedObject global(cx, JS::CurrentGlobalOrNull(cx));
return JS_CallFunctionName(cx, global, "d", JS::HandleValueArray::empty(), &r);
}
示例7: OBJECT_TO_JSVAL
int
Stage::DrawScreen(int h) {
jsval rval;
int x, y, ytimesw;
if (SDL_MUSTLOCK(screen)) {
if (SDL_LockSurface(screen) < 0) {
return 0;
}
}
jsval argv[5];
argv[0] = OBJECT_TO_JSVAL(screenArrayBuffer);
argv[1] = INT_TO_JSVAL(WIDTH);
argv[2] = INT_TO_JSVAL(HEIGHT);
argv[3] = INT_TO_JSVAL(screen->pitch);
argv[4] = INT_TO_JSVAL(BPP);
JSBool ok = JS_CallFunctionName(cx, global, "paint", 5, argv, &rval);
Blit((char *)screen->pixels, screenBuffer, screenBufferSize);
if (SDL_MUSTLOCK(screen))
SDL_UnlockSurface(screen);
SDL_Flip(screen);
}
示例8: delegateToResolver
static JSBool
delegateToResolver(JSContext *cx, JSObject *obj, const char *name,
uintN argc, jsval *argv, jsval *rval)
{
jsval resolver;
if (!JS_GetReservedSlot(cx, obj, SLOT_RESOLVER, &resolver))
return JS_FALSE;
JSObject *resolverObj = JSVAL_TO_OBJECT(resolver);
jsval *allArgv;
uintN allArgc = argc + 2;
allArgv = (jsval *)PR_Malloc(allArgc * sizeof(jsval));
if (!JS_GetReservedSlot(cx, obj, SLOT_WRAPPEE, allArgv)) {
PR_Free(allArgv);
return JS_FALSE;
}
allArgv[1] = OBJECT_TO_JSVAL(obj);
for (unsigned int i = 0; i < argc; i++)
allArgv[i + 2] = argv[i];
if (!JS_CallFunctionName(cx, resolverObj, name, allArgc, allArgv, rval)) {
PR_Free(allArgv);
return JS_FALSE;
}
PR_Free(allArgv);
return JS_TRUE;
}
示例9: callJSDelegate
bool callJSDelegate(TableView* table, ssize_t idx, std::string jsFunctionName, jsval& retVal)
{
js_proxy_t * p = jsb_get_native_proxy(table);
if (!p) return false;
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
bool hasAction;
JS::RootedValue temp_retval(cx);
jsval dataVal[2];
dataVal[0] = OBJECT_TO_JSVAL(p->obj);
dataVal[1] = ssize_to_jsval(cx,idx);
JSObject* obj = _JSTableViewDataSource;
JSAutoCompartment ac(cx, obj);
if (JS_HasProperty(cx, obj, jsFunctionName.c_str(), &hasAction) && hasAction)
{
if(!JS_GetProperty(cx, obj, jsFunctionName.c_str(), &temp_retval))
{
return false;
}
if(temp_retval == JSVAL_VOID)
{
return false;
}
bool ret = JS_CallFunctionName(cx, obj, jsFunctionName.c_str(),
2, dataVal, &retVal);
return ret == true ? true : false;
}
return false;
}
示例10: test_fn2
static bool
test_fn2(JSContext *cx, unsigned argc, jsval *vp)
{
jsval r;
JS::RootedObject global(cx, JS::CurrentGlobalOrNull(cx));
return JS_CallFunctionName(cx, global, "d", 0, nullptr, &r);
}
示例11: callJSDelegate
bool callJSDelegate(TableView* table, std::string jsFunctionName, jsval& retVal)
{
js_proxy_t * p = jsb_get_native_proxy(table);
if (!p) return false;
JSBool hasAction;
jsval temp_retval;
jsval dataVal = OBJECT_TO_JSVAL(p->obj);
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
JSObject* obj = _JSTableViewDataSource;
if (JS_HasProperty(cx, obj, jsFunctionName.c_str(), &hasAction) && hasAction) {
if(!JS_GetProperty(cx, obj, jsFunctionName.c_str(), &temp_retval)) {
return false;
}
if(temp_retval == JSVAL_VOID) {
return false;
}
JSAutoCompartment ac(cx, obj);
JS_CallFunctionName(cx, obj, jsFunctionName.c_str(),
1, &dataVal, &retVal);
return true;
}
return false;
}
示例12: callJSDelegate
bool callJSDelegate(TableView* table, std::string jsFunctionName, JS::MutableHandleValue retVal)
{
js_proxy_t * p = jsb_get_native_proxy(table);
if (!p) return false;
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
bool hasAction;
JS::RootedValue temp_retval(cx);
jsval dataVal = OBJECT_TO_JSVAL(p->obj);
JS::RootedObject obj(cx, _JSTableViewDataSource);
JSAutoCompartment ac(cx, obj);
if (JS_HasProperty(cx, obj, jsFunctionName.c_str(), &hasAction) && hasAction)
{
if(!JS_GetProperty(cx, obj, jsFunctionName.c_str(), &temp_retval))
{
return false;
}
if(temp_retval == JSVAL_VOID)
{
return false;
}
JS_CallFunctionName(cx, obj, jsFunctionName.c_str(),
JS::HandleValueArray::fromMarkedLocation(1, &dataVal), retVal);
return true;
}
return false;
}
示例13: m_runtime
ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, const shared_ptr<ScriptRuntime>& runtime) :
m_runtime(runtime), m_glob(runtime->m_rt), m_nativeScope(runtime->m_rt)
{
bool ok;
m_cx = JS_NewContext(m_runtime->m_rt, STACK_CHUNK_SIZE);
ENSURE(m_cx);
JS_SetParallelIonCompilationEnabled(m_runtime->m_rt, true);
// For GC debugging:
// JS_SetGCZeal(m_cx, 2);
JS_SetContextPrivate(m_cx, NULL);
JS_SetErrorReporter(m_cx, ErrorReporter);
JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_ION_ENABLE, 1);
JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_BASELINE_ENABLE, 1);
JS::ContextOptionsRef(m_cx).setExtraWarnings(1)
.setWerror(0)
.setVarObjFix(1)
.setStrictMode(1);
JS::CompartmentOptions opt;
opt.setVersion(JSVERSION_LATEST);
JSAutoRequest rq(m_cx);
JS::RootedObject globalRootedVal(m_cx, JS_NewGlobalObject(m_cx, &global_class, NULL, JS::OnNewGlobalHookOption::FireOnNewGlobalHook, opt));
m_comp = JS_EnterCompartment(m_cx, globalRootedVal);
ok = JS_InitStandardClasses(m_cx, globalRootedVal);
ENSURE(ok);
m_glob = globalRootedVal.get();
// Use the testing functions to globally enable gcPreserveCode. This brings quite a
// big performance improvement. In future SpiderMonkey versions, we should probably
// use the functions implemented here: https://bugzilla.mozilla.org/show_bug.cgi?id=1068697
JS::RootedObject testingFunctionsObj(m_cx, js::GetTestingFunctions(m_cx));
ENSURE(testingFunctionsObj);
JS::RootedValue ret(m_cx);
JS_CallFunctionName(m_cx, testingFunctionsObj, "gcPreserveCode", JS::HandleValueArray::empty(), &ret);
JS_DefineProperty(m_cx, m_glob, "global", globalRootedVal, JSPROP_ENUMERATE | JSPROP_READONLY
| JSPROP_PERMANENT);
m_nativeScope = JS_DefineObject(m_cx, m_glob, nativeScopeName, NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY
| JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "print", ::print, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "log", ::logmsg, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "warn", ::warn, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "error", ::error, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "deepcopy", ::deepcopy, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
Register("ProfileStart", ::ProfileStart, 1);
Register("ProfileStop", ::ProfileStop, 0);
runtime->RegisterContext(m_cx);
}
示例14: rq
bool ScriptInterface::ParseJSON(const std::string& string_utf8, JS::MutableHandleValue out)
{
JSAutoRequest rq(m->m_cx);
std::wstring attrsW = wstring_from_utf8(string_utf8);
utf16string string(attrsW.begin(), attrsW.end());
if (JS_ParseJSON(m->m_cx, reinterpret_cast<const jschar*>(string.c_str()), (u32)string.size(), out))
return true;
LOGERROR("JS_ParseJSON failed!");
if (!JS_IsExceptionPending(m->m_cx))
return false;
JS::RootedValue exc(m->m_cx);
if (!JS_GetPendingException(m->m_cx, &exc))
return false;
JS_ClearPendingException(m->m_cx);
// We expect an object of type SyntaxError
if (!exc.isObject())
return false;
JS::RootedValue rval(m->m_cx);
JS::RootedObject excObj(m->m_cx, &exc.toObject());
if (!JS_CallFunctionName(m->m_cx, excObj, "toString", JS::HandleValueArray::empty(), &rval))
return false;
std::wstring error;
ScriptInterface::FromJSVal(m->m_cx, rval, error);
LOGERROR("%s", utf8_from_wstring(error));
return false;
}
示例15: ac
bool Context::realCall(const char* fn, int n, JS::Value* args,
JS::Value* val) const
{
JSAutoCompartment ac(_jsctx, _global);
bool ok = JS_CallFunctionName(_jsctx, _global, fn, n, args, val);
return ok;
}