static nsresult GetAlgorithmName(JSContext* aCx, const OOS& aAlgorithm, /* out */ nsString& aName) { MOZ_ASSERT(aAlgorithm.IsString()); // TODO: remove assertion when we coerce. if (aAlgorithm.IsString()) { // If string, then treat as algorithm name aName.Assign(aAlgorithm.GetAsString()); } else { // TODO: Coerce to string and extract name. See WebCryptoTask.cpp } if (!NormalizeToken(aName, aName)) { return NS_ERROR_DOM_SYNTAX_ERR; } return NS_OK; }
static nsresult GetAlgorithmName(JSContext* aCx, const OOS& aAlgorithm, nsString& aName) { ClearException ce(aCx); if (aAlgorithm.IsString()) { // If string, then treat as algorithm name aName.Assign(aAlgorithm.GetAsString()); } else { // Coerce to algorithm and extract name JS::RootedValue value(aCx, JS::ObjectValue(*aAlgorithm.GetAsObject())); Algorithm alg; if (!alg.Init(aCx, value) || !alg.mName.WasPassed()) { return NS_ERROR_DOM_SYNTAX_ERR; } aName.Assign(alg.mName.Value()); } return NS_OK; }