NS_IMETHODIMP nsDOMMultipartFile::Initialize(nsISupports* aOwner, JSContext* aCx, JSObject* aObj, const JS::CallArgs& aArgs) { if (!mIsFile) { return InitBlob(aCx, aArgs.length(), aArgs.array(), GetXPConnectNative); } if (!nsContentUtils::IsCallerChrome()) { return InitFile(aCx, aArgs.length(), aArgs.array()); } if (aArgs.length() > 0) { JS::Value* argv = aArgs.array(); if (argv[0].isObject()) { JS::Rooted<JSObject*> obj(aCx, &argv[0].toObject()); if (JS_IsArrayObject(aCx, obj)) { return InitFile(aCx, aArgs.length(), aArgs.array()); } } } return InitChromeFile(aCx, aArgs.length(), aArgs.array()); }
void CodeInfo::construct(JSContext* cx, JS::CallArgs args) { uassert(ErrorCodes::BadValue, "Code needs 0, 1 or 2 arguments", args.length() == 0 || args.length() == 1 || args.length() == 2); auto scope = getScope(cx); JS::RootedObject thisv(cx); scope->getProto<CodeInfo>().newObject(&thisv); ObjectWrapper o(cx, thisv); if (args.length() == 0) { o.setString(InternedString::code, ""); } else if (args.length() == 1) { JS::HandleValue codeArg = args.get(0); if (!codeArg.isString()) uasserted(ErrorCodes::BadValue, "code must be a string"); o.setValue(InternedString::code, codeArg); } else { if (!args.get(0).isString()) uasserted(ErrorCodes::BadValue, "code must be a string"); if (!args.get(1).isObject()) uasserted(ErrorCodes::BadValue, "scope must be an object"); o.setValue(InternedString::code, args.get(0)); o.setValue(InternedString::scope, args.get(1)); } args.rval().setObjectOrNull(thisv); }
void TimestampInfo::construct(JSContext* cx, JS::CallArgs args) { auto scope = getScope(cx); JS::RootedObject thisv(cx); scope->getProto<TimestampInfo>().newObject(&thisv); ObjectWrapper o(cx, thisv); if (args.length() == 0) { o.setNumber("t", 0); o.setNumber("i", 0); } else if (args.length() == 2) { if (!args.get(0).isNumber()) uasserted(ErrorCodes::BadValue, "Timestamp time must be a number"); if (!args.get(1).isNumber()) uasserted(ErrorCodes::BadValue, "Timestamp increment must be a number"); int64_t t = ValueWriter(cx, args.get(0)).toInt64(); int64_t largestVal = int64_t(Timestamp::max().getSecs()); if (t > largestVal) uasserted(ErrorCodes::BadValue, str::stream() << "The first argument must be in seconds; " << t << " is too large (max " << largestVal << ")"); o.setValue("t", args.get(0)); o.setValue("i", args.get(1)); } else { uasserted(ErrorCodes::BadValue, "Timestamp needs 0 or 2 arguments"); } args.rval().setObjectOrNull(thisv); }
void DBInfo::construct(JSContext* cx, JS::CallArgs args) { auto scope = getScope(cx); if (args.length() != 2) uasserted(ErrorCodes::BadValue, "db constructor requires 2 arguments"); for (unsigned i = 0; i < args.length(); ++i) { uassert(ErrorCodes::BadValue, "db initializer called with undefined argument", !args.get(i).isUndefined()); } JS::RootedObject thisv(cx); scope->getProto<DBInfo>().newObject(&thisv); ObjectWrapper o(cx, thisv); o.setValue(InternedString::_mongol, args.get(0)); o.setValue(InternedString::_name, args.get(1)); std::string dbName = ValueWriter(cx, args.get(1)).toString(); if (!NamespaceString::validDBName(dbName)) uasserted(ErrorCodes::BadValue, str::stream() << "[" << dbName << "] is not a valid database name"); args.rval().setObjectOrNull(thisv); }
NS_IMETHODIMP nsDOMMultipartFile::Initialize(nsISupports* aOwner, JSContext* aCx, JSObject* aObj, const JS::CallArgs& aArgs) { if (!mIsFile) { return InitBlob(aCx, aArgs.length(), aArgs.array(), GetXPConnectNative); } return InitFile(aCx, aArgs.length(), aArgs.array()); }
bool XPC_WN_CallMethod(JSContext* cx, unsigned argc, Value* vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); MOZ_ASSERT(JS_TypeOfValue(cx, args.calleev()) == JSTYPE_FUNCTION, "bad function"); RootedObject funobj(cx, &args.callee()); RootedObject obj(cx, JS_THIS_OBJECT(cx, vp)); if (!obj) return false; obj = FixUpThisIfBroken(obj, funobj); XPCCallContext ccx(cx, obj, funobj, JSID_VOIDHANDLE, args.length(), args.array(), vp); XPCWrappedNative* wrapper = ccx.GetWrapper(); THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper); RefPtr<XPCNativeInterface> iface; XPCNativeMember* member; if (!XPCNativeMember::GetCallInfo(funobj, &iface, &member)) return Throw(NS_ERROR_XPC_CANT_GET_METHOD_INFO, cx); ccx.SetCallInfo(iface, member, false); return XPCWrappedNative::CallMethod(ccx); }
bool FieldSetterImpl(JSContext *cx, JS::CallArgs args) { const JS::Value &thisv = args.thisv(); MOZ_ASSERT(ValueHasISupportsPrivate(thisv)); JS::Rooted<JSObject*> thisObj(cx, &thisv.toObject()); // We should be in the compartment of |this|. If we got here via nativeCall, // |this| is not same-compartment with |callee|, and it's possible via // asymmetric security semantics that |args.calleev()| is actually a security // wrapper. In this case, we know we want to do an unsafe unwrap, and // InstallXBLField knows how to handle cross-compartment pointers. bool installed = false; JS::Rooted<JSObject*> callee(cx, js::UncheckedUnwrap(&args.calleev().toObject())); JS::Rooted<jsid> id(cx); if (!InstallXBLField(cx, callee, thisObj, &id, &installed)) { return false; } if (installed) { JS::Rooted<JS::Value> v(cx, args.length() > 0 ? args[0] : JS::UndefinedValue()); if (!::JS_SetPropertyById(cx, thisObj, id, v.address())) { return false; } } args.rval().setUndefined(); return true; }
static JSBool AfxGlobal_modReplaceOnGlEnd(JSContext *cx, unsigned argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if(4 > args.length()) return JS_FALSE; GLint oldActiveTextureArb; GLboolean oldTexture2d; GLint oldTextureBinding2d; GLint oldTextureEnvMode; if(!JS::ToInt32(cx, args[0], &oldActiveTextureArb)) return JS_FALSE; oldTexture2d = JS::ToBoolean(args[1]); if(!JS::ToInt32(cx, args[2], &oldTextureBinding2d)) return JS_FALSE; if(!JS::ToInt32(cx, args[3], &oldTextureEnvMode)) return JS_FALSE; glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, oldTextureEnvMode); glBindTexture(GL_TEXTURE_2D, oldTextureBinding2d); if(!oldTexture2d) glDisable(GL_TEXTURE_2D); glActiveTextureARB(oldActiveTextureArb); args.rval().set(JSVAL_VOID); return JS_TRUE; }
static JSBool AfxGlobal_hlCvarSetValue(JSContext *cx, unsigned argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if(2 > args.length()) return JS_FALSE; JSString *str = JS_ValueToString(cx, args[0]); if (!str) return JS_FALSE; char * cvar = JS_EncodeString(cx, str); if(!cvar) return JS_FALSE; std::string strCvar(cvar); JS_free(cx, cvar); double value; if(!JS::ToNumber(cx, args[1], &value)) return JS_FALSE; pEngfuncs->Cvar_SetValue(const_cast<char *>(strCvar.c_str()), (float)value); args.rval().set(JSVAL_VOID); return JS_TRUE; }
static JSBool AfxGlobal_load(JSContext *cx, unsigned argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if(1 > args.length()) return JS_FALSE; JSString *str = JS_ValueToString(cx, args[0]); if (!str) return JS_FALSE; char *filename = JS_EncodeString(cx, str); if(!filename) return JS_FALSE; std::string strFile(filename); JS_free(cx, filename); JS::RootedObject thisobj(cx, JS_THIS_OBJECT(cx, vp)); if (!thisobj) return false; JSScript *script = JS::Compile(cx, thisobj, JS::CompileOptions(cx), strFile.c_str()); if(!script) return JS_FALSE; jsval result; if(!JS_ExecuteScript(cx, thisobj, script, &result)) return JS_FALSE; args.rval().set(result); return JS_TRUE; }
static JSBool AfxGlobal_glGenTextures(JSContext *cx, unsigned argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if(1 > args.length()) return JS_FALSE; uint32_t length; if(!JS::ToUint32(cx, args[0], &length)) return JS_FALSE; GLuint * textures = new GLuint[length]; jsval * jsTextures = new jsval[length]; glGenTextures(length, textures); for(uint32_t i=0; i<length; i++) { jsTextures[i] = JS_NumberValue(textures[i]); } delete textures; JSObject * retObj = JS_NewArrayObject(cx, length, jsTextures); delete jsTextures; if(!retObj) return JS_FALSE; args.rval().set(OBJECT_TO_JSVAL(retObj)); return JS_TRUE; }
static JSBool AfxGlobal_createPath(JSContext *cx, unsigned argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if(1 > args.length()) return JS_FALSE; JSString *str = JS_ValueToString(cx, args[0]); if (!str) return JS_FALSE; char *c_str = JS_EncodeString(cx, str); if(!c_str) return JS_FALSE; bool bOk = false; std::wstring wPath; std::string path; if(AnsiStringToWideString(c_str, wPath) && CreatePath(wPath.c_str(), wPath) && WideStringToAnsiString(wPath.c_str(), path)) { JSString * str = JS_NewStringCopyZ(cx, path.c_str()); args.rval().set(STRING_TO_JSVAL(str)); } else args.rval().set(JSVAL_NULL); JS_free(cx, c_str); return JS_TRUE; }
static JSBool AfxGlImage_writeBitmap(JSContext *cx, unsigned argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if(1 > args.length()) return JS_FALSE; JSObject * jsObj; if(!JS_ValueToObject(cx, args.thisv(), &jsObj)) return JS_FALSE; AfxGlImage *afxGlImage = (AfxGlImage *)JS_GetPrivate(jsObj); JSString *str = JS_ValueToString(cx, args[0]); if (!str) return JS_FALSE; char *c_str = JS_EncodeString(cx, str); if(!c_str) return JS_FALSE; std::wstring wFileName; bool bOk = AnsiStringToWideString(c_str, wFileName); JS_free(cx, c_str); if(!(bOk && AfxImageUtils::WriteBitmap(afxGlImage, wFileName.c_str()))) return JS_FALSE; args.rval().set(JSVAL_VOID); return JS_TRUE; }
static JSBool AfxGlImage_sliceFloatDepthBuffer(JSContext *cx, unsigned argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if(2 > args.length()) return JS_FALSE; JSObject * jsObj; if(!JS_ValueToObject(cx, args.thisv(), &jsObj)) return JS_FALSE; AfxGlImage *afxGlImage = (AfxGlImage *)JS_GetPrivate(jsObj); GLdouble sliceLo; GLdouble sliceHi; if(!( JS::ToNumber(cx, args[0], &sliceLo) && JS::ToNumber(cx, args[1], &sliceHi) )) return JS_FALSE; if(!AfxImageUtils::SliceFloatDepthBuffer(afxGlImage, sliceLo, sliceHi)) return JS_FALSE; args.rval().set(JSVAL_VOID); return JS_TRUE; }
static JSBool AfxGlobal_soundRecStart(JSContext *cx, unsigned argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if(2 > args.length()) return JS_FALSE; double volume; if(!JS::ToNumber(cx, args[1], &volume)) return JS_FALSE; JSString *str = JS_ValueToString(cx, args[0]); if (!str) return JS_FALSE; char *c_str = JS_EncodeString(cx, str); if(!c_str) return JS_FALSE; std::wstring wPath; if(!AnsiStringToWideString(c_str, wPath)) { JS_free(cx, c_str); return JS_FALSE; } JS_free(cx, c_str); bool result = g_Filming.GetFilmSound()->Start(wPath.c_str(), 0, (float)volume); args.rval().set(BOOLEAN_TO_JSVAL(result)); return JS_TRUE; }
JS_BINDED_FUNC_IMPL(FakeAudio, removeEventListener) { JS::CallArgs args = CallArgsFromVp(argc, vp); if (args.length() >= 2) { // need to think this through } return JS_TRUE; }
static bool RegisterAppManifest(JSContext* cx, unsigned argc, jsval* vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (args.length() != 1) { JS_ReportError(cx, "Wrong number of arguments"); return false; } if (!args[0].isObject()) { JS_ReportError(cx, "Expected object as argument 1 to registerAppManifest"); return false; } Rooted<JSObject*> arg1(cx, &args[0].toObject()); nsCOMPtr<nsIFile> file; nsresult rv = nsXPConnect::XPConnect()-> WrapJS(cx, arg1, NS_GET_IID(nsIFile), getter_AddRefs(file)); if (NS_FAILED(rv)) { XPCThrower::Throw(rv, cx); return false; } rv = XRE_AddManifestLocation(NS_APP_LOCATION, file); if (NS_FAILED(rv)) { XPCThrower::Throw(rv, cx); return false; } return true; }
void SessionInfo::Functions::getTxnNumber::call(JSContext* cx, JS::CallArgs args) { auto holder = getHolder(args); invariant(holder); uassert(ErrorCodes::BadValue, "getTxnNumber takes no arguments", args.length() == 0); ValueReader(cx, args.rval()).fromInt64(holder->txnNumber); }
void SessionInfo::Functions::getTxnState::call(JSContext* cx, JS::CallArgs args) { auto holder = getHolder(args); invariant(holder); uassert(ErrorCodes::BadValue, "getTxnState takes no arguments", args.length() == 0); ValueReader(cx, args.rval()).fromStringData(transactionStateName(holder->txnState)); }
static bool SetInterruptCallback(JSContext* cx, unsigned argc, jsval* vp) { MOZ_ASSERT(sScriptedInterruptCallback.initialized()); // Sanity-check args. JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (args.length() != 1) { JS_ReportError(cx, "Wrong number of arguments"); return false; } // Allow callers to remove the interrupt callback by passing undefined. if (args[0].isUndefined()) { sScriptedInterruptCallback = UndefinedValue(); return true; } // Otherwise, we should have a callable object. if (!args[0].isObject() || !JS::IsCallable(&args[0].toObject())) { JS_ReportError(cx, "Argument must be callable"); return false; } sScriptedInterruptCallback = args[0]; return true; }
static bool Options(JSContext* cx, unsigned argc, jsval* vp) { JS::CallArgs args = CallArgsFromVp(argc, vp); RuntimeOptions oldRuntimeOptions = RuntimeOptionsRef(cx); for (unsigned i = 0; i < args.length(); ++i) { JSString* str = ToString(cx, args[i]); if (!str) return false; JSAutoByteString opt(cx, str); if (!opt) return false; if (strcmp(opt.ptr(), "strict") == 0) RuntimeOptionsRef(cx).toggleExtraWarnings(); else if (strcmp(opt.ptr(), "werror") == 0) RuntimeOptionsRef(cx).toggleWerror(); else if (strcmp(opt.ptr(), "strict_mode") == 0) RuntimeOptionsRef(cx).toggleStrictMode(); else { JS_ReportError(cx, "unknown option name '%s'. The valid names are " "strict, werror, and strict_mode.", opt.ptr()); return false; } } char* names = nullptr; if (oldRuntimeOptions.extraWarnings()) { names = JS_sprintf_append(names, "%s", "strict"); if (!names) { JS_ReportOutOfMemory(cx); return false; } } if (oldRuntimeOptions.werror()) { names = JS_sprintf_append(names, "%s%s", names ? "," : "", "werror"); if (!names) { JS_ReportOutOfMemory(cx); return false; } } if (names && oldRuntimeOptions.strictMode()) { names = JS_sprintf_append(names, "%s%s", names ? "," : "", "strict_mode"); if (!names) { JS_ReportOutOfMemory(cx); return false; } } JSString* str = JS_NewStringCopyZ(cx, names); free(names); if (!str) return false; args.rval().setString(str); return true; }
void SessionInfo::Functions::incrementTxnNumber::call(JSContext* cx, JS::CallArgs args) { auto holder = getHolder(args); invariant(holder); uassert(ErrorCodes::BadValue, "incrementTxnNumber takes no arguments", args.length() == 0); ++holder->txnNumber; args.rval().setUndefined(); }
static bool Censor(JSContext* cx, unsigned argc, JS::Value* vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); MOZ_RELEASE_ASSERT(args.length() == 2); MOZ_RELEASE_ASSERT(args[0].isString()); args.rval().setNull(); return true; }
void SessionInfo::Functions::setTxnNumber::call(JSContext* cx, JS::CallArgs args) { auto holder = getHolder(args); invariant(holder); uassert(ErrorCodes::BadValue, "setTxnNumber takes 1 argument", args.length() == 1); auto arg = args.get(0); holder->txnNumber = ValueWriter(cx, arg).toInt64(); args.rval().setUndefined(); }
void SessionInfo::Functions::setTxnState::call(JSContext* cx, JS::CallArgs args) { auto holder = getHolder(args); invariant(holder); uassert(ErrorCodes::BadValue, "setTxnState takes 1 argument", args.length() == 1); auto arg = args.get(0); holder->txnState = transactionStateEnum(ValueWriter(cx, arg).toString().c_str()); args.rval().setUndefined(); }
static bool constructHook(JSContext *cx, unsigned argc, jsval *vp) { JS::CallArgs args = CallArgsFromVp(argc, vp); // Check that arguments were passed properly from JS_New. JS::RootedObject obj(cx, JS_NewObject(cx, js::Jsvalify(&JSObject::class_), JS::NullPtr(), JS::NullPtr())); if (!obj) { JS_ReportError(cx, "test failed, could not construct object"); return false; } if (strcmp(JS_GetClass(obj)->name, "Object") != 0) { JS_ReportError(cx, "test failed, wrong class for 'this'"); return false; } if (args.length() != 3) { JS_ReportError(cx, "test failed, argc == %d", args.length()); return false; } if (!args[0].isInt32() || args[2].toInt32() != 2) { JS_ReportError(cx, "test failed, wrong value in args[2]"); return false; } if (!args.isConstructing()) { JS_ReportError(cx, "test failed, not constructing"); return false; } // Perform a side-effect to indicate that this hook was actually called. JS::RootedValue value(cx, args[0]); JS::RootedObject callee(cx, &args.callee()); if (!JS_SetElement(cx, callee, 0, value)) return false; args.rval().setObject(*obj); // trash the argv, perversely args[0].setUndefined(); args[1].setUndefined(); args[2].setUndefined(); return true; }
void TimestampInfo::construct(JSContext* cx, JS::CallArgs args) { auto scope = getScope(cx); JS::RootedObject thisv(cx); scope->getProto<TimestampInfo>().newObject(&thisv); ObjectWrapper o(cx, thisv); if (args.length() == 0) { o.setNumber(InternedString::t, 0); o.setNumber(InternedString::i, 0); } else if (args.length() == 2) { o.setNumber(InternedString::t, getTimestampArg(cx, args, 0, "Timestamp time (seconds)")); o.setNumber(InternedString::i, getTimestampArg(cx, args, 1, "Timestamp increment")); } else { uasserted(ErrorCodes::BadValue, "Timestamp needs 0 or 2 arguments"); } args.rval().setObjectOrNull(thisv); }
void BinDataInfo::Functions::HexData::call(JSContext* cx, JS::CallArgs args) { if (args.length() != 2) uasserted(ErrorCodes::BadValue, "HexData needs 2 arguments"); JS::RootedValue type(cx, args.get(0)); if (!type.isNumber() || type.toInt32() < 0 || type.toInt32() > 255) uasserted(ErrorCodes::BadValue, "HexData subtype must be a Number between 0 and 255 inclusive"); hexToBinData(cx, type.toInt32(), args.get(1), args.rval()); }
void BinDataInfo::Functions::MD5::call(JSContext* cx, JS::CallArgs args) { if (args.length() != 1) uasserted(ErrorCodes::BadValue, "MD5 needs 1 argument"); auto arg = args.get(0); auto str = ValueWriter(cx, arg).toString(); if (str.length() != 32) uasserted(ErrorCodes::BadValue, "MD5 string must have 32 characters"); hexToBinData(cx, MD5Type, arg, args.rval()); }
static bool SimulateActivityCallback(JSContext* cx, unsigned argc, jsval* vp) { // Sanity-check args. JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (args.length() != 1 || !args[0].isBoolean()) { JS_ReportError(cx, "Wrong number of arguments"); return false; } xpc::SimulateActivityCallback(args[0].toBoolean()); return true; }