JSBool js_PluginOneSignalJS_PluginOneSignal_setListener(JSContext *cx, uint32_t argc, jsval *vp) #endif { s_cx = cx; JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { if (!args.get(0).isObject()) { ok = false; } JSB_PRECONDITION2(ok, cx, false, "js_PluginOneSignalJS_PluginOneSignal_setIAPListener : Error processing arguments"); OneSignalListenerJS* wrapper = new OneSignalListenerJS(); wrapper->setJSDelegate(cx, args.get(0)); sdkbox::PluginOneSignal::setListener(wrapper); args.rval().setUndefined(); return true; } JS_ReportErrorUTF8(cx, "js_PluginOneSignalJS_PluginOneSignal_setIAPListener : wrong number of arguments"); return false; }
bool js_PluginAppnextJS_PluginAppnext_hideAd(JSContext *cx, uint32_t argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { sdkbox::PluginAppnext::hideAd(); args.rval().setUndefined(); return true; } JS_ReportErrorUTF8(cx, "js_PluginAppnextJS_PluginAppnext_hideAd : wrong number of arguments"); return false; }
bool js_PluginAppnextJS_PluginAppnext_init(JSContext *cx, uint32_t argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { bool ret = sdkbox::PluginAppnext::init(); JS::RootedValue jsret(cx); jsret = JS::BooleanValue(ret); args.rval().set(jsret); return true; } JS_ReportErrorUTF8(cx, "js_PluginAppnextJS_PluginAppnext_init : wrong number of arguments"); return false; }
bool js_PluginAppnextJS_PluginAppnext_setRewardsAmountRewarded(JSContext *cx, uint32_t argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { std::string arg0; ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_PluginAppnextJS_PluginAppnext_setRewardsAmountRewarded : Error processing arguments"); sdkbox::PluginAppnext::setRewardsAmountRewarded(arg0); args.rval().setUndefined(); return true; } JS_ReportErrorUTF8(cx, "js_PluginAppnextJS_PluginAppnext_setRewardsAmountRewarded : wrong number of arguments"); return false; }
bool js_PluginAppnextJS_PluginAppnext_isVideoReady(JSContext *cx, uint32_t argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 1) { std::string arg0; ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_PluginAppnextJS_PluginAppnext_isVideoReady : Error processing arguments"); bool ret = sdkbox::PluginAppnext::isVideoReady(arg0); JS::RootedValue jsret(cx); jsret = JS::BooleanValue(ret); args.rval().set(jsret); return true; } JS_ReportErrorUTF8(cx, "js_PluginAppnextJS_PluginAppnext_isVideoReady : wrong number of arguments"); return false; }
JSObject* Library::Create(JSContext* cx, HandleValue path, const JSCTypesCallbacks* callbacks) { RootedObject libraryObj(cx, JS_NewObject(cx, &sLibraryClass)); if (!libraryObj) return nullptr; // initialize the library JS_SetReservedSlot(libraryObj, SLOT_LIBRARY, PrivateValue(nullptr)); // attach API functions if (!JS_DefineFunctions(cx, libraryObj, sLibraryFunctions)) return nullptr; if (!path.isString()) { JS_ReportErrorASCII(cx, "open takes a string argument"); return nullptr; } PRLibSpec libSpec; RootedFlatString pathStr(cx, JS_FlattenString(cx, path.toString())); if (!pathStr) return nullptr; AutoStableStringChars pathStrChars(cx); if (!pathStrChars.initTwoByte(cx, pathStr)) return nullptr; #ifdef XP_WIN // On Windows, converting to native charset may corrupt path string. // So, we have to use Unicode path directly. char16ptr_t pathChars = pathStrChars.twoByteChars(); libSpec.value.pathname_u = pathChars; libSpec.type = PR_LibSpec_PathnameU; #else // Convert to platform native charset if the appropriate callback has been // provided. char* pathBytes; if (callbacks && callbacks->unicodeToNative) { pathBytes = callbacks->unicodeToNative(cx, pathStrChars.twoByteChars(), pathStr->length()); if (!pathBytes) return nullptr; } else { // Fallback: assume the platform native charset is UTF-8. This is true // for Mac OS X, Android, and probably Linux. size_t nbytes = GetDeflatedUTF8StringLength(cx, pathStrChars.twoByteChars(), pathStr->length()); if (nbytes == (size_t) -1) return nullptr; pathBytes = static_cast<char*>(JS_malloc(cx, nbytes + 1)); if (!pathBytes) return nullptr; ASSERT_OK(DeflateStringToUTF8Buffer(cx, pathStrChars.twoByteChars(), pathStr->length(), pathBytes, &nbytes)); pathBytes[nbytes] = 0; } libSpec.value.pathname = pathBytes; libSpec.type = PR_LibSpec_Pathname; #endif PRLibrary* library = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW); #ifndef XP_WIN JS_free(cx, pathBytes); #endif if (!library) { #define MAX_ERROR_LEN 1024 char error[MAX_ERROR_LEN] = "Cannot get error from NSPR."; uint32_t errorLen = PR_GetErrorTextLength(); if (errorLen && errorLen < MAX_ERROR_LEN) PR_GetErrorText(error); #undef MAX_ERROR_LEN if (JS::StringIsASCII(error)) { JSAutoByteString pathCharsUTF8; if (pathCharsUTF8.encodeUtf8(cx, pathStr)) JS_ReportErrorUTF8(cx, "couldn't open library %s: %s", pathCharsUTF8.ptr(), error); } else { JSAutoByteString pathCharsLatin1; if (pathCharsLatin1.encodeLatin1(cx, pathStr)) JS_ReportErrorLatin1(cx, "couldn't open library %s: %s", pathCharsLatin1.ptr(), error); } return nullptr; } // stash the library JS_SetReservedSlot(libraryObj, SLOT_LIBRARY, PrivateValue(library)); return libraryObj; }
static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS_ReportErrorUTF8(cx, "Constructor for the requested class is not available, please refer to the API reference."); return false; }