本文整理汇总了C++中createError函数的典型用法代码示例。如果您正苦于以下问题:C++ createError函数的具体用法?C++ createError怎么用?C++ createError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createError
Expected<T, DatabaseError> InMemoryDatabase::getValue(const std::string& domain,
const std::string& key) {
debug_only::verifyTrue(is_open_, "database is not open");
if (!is_open_) {
return createError(DatabaseError::DbIsNotOpen, "Database is closed");
}
auto storage_iter = storage_.find(domain);
if (storage_iter == storage_.end()) {
return domainNotFoundError(domain);
}
std::lock_guard<std::mutex> lock(storage_iter->second->getMutex());
auto result = storage_iter->second->get(key);
if (result) {
DataType value = result.take();
if (value.type() == typeid(T)) {
return boost::get<T>(value);
} else {
auto error =
createError(DatabaseError::KeyNotFound, "Requested wrong type for: ")
<< domain << ":" << key << " stored type: " << value.type().name()
<< " requested type " << boost::core::demangle(typeid(T).name());
LOG(ERROR) << error.getFullMessageRecursive();
debug_only::fail(error.getFullMessageRecursive().c_str());
return std::move(error);
}
}
return result.takeError();
}
示例2: parseVersion
// VERSION major[.minor]
Error parseVersion(uint32_t *Major, uint32_t *Minor) {
read();
if (Tok.K != Identifier)
return createError("identifier expected, but got " + Tok.Value);
StringRef V1, V2;
std::tie(V1, V2) = Tok.Value.split('.');
if (V1.getAsInteger(10, *Major))
return createError("integer expected, but got " + Tok.Value);
if (V2.empty())
*Minor = 0;
else if (V2.getAsInteger(10, *Minor))
return createError("integer expected, but got " + Tok.Value);
return Error::success();
}
示例3: createAesCbcParams
static RefPtr<CryptoAlgorithmParameters> createAesCbcParams(ExecState* exec, JSValue value)
{
if (!value.isObject()) {
throwTypeError(exec);
return nullptr;
}
JSValue iv = getProperty(exec, value.getObject(), "iv");
if (exec->hadException())
return nullptr;
auto result = adoptRef(*new CryptoAlgorithmAesCbcParams);
CryptoOperationData ivData;
if (!cryptoOperationDataFromJSValue(exec, iv, ivData)) {
ASSERT(exec->hadException());
return nullptr;
}
if (ivData.second != 16) {
exec->vm().throwException(exec, createError(exec, "AES-CBC initialization data must be 16 bytes"));
return nullptr;
}
memcpy(result->iv.data(), ivData.first, ivData.second);
return WTFMove(result);
}
示例4: initScriptIfNeeded
void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, ScriptValue* exception)
{
if (isExecutionForbidden())
return;
initScriptIfNeeded();
JSLock lock(SilenceAssertionsOnly);
ExecState* exec = m_workerContextWrapper->globalExec();
m_workerContextWrapper->globalData().timeoutChecker.start();
JSValue evaluationException;
JSC::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), sourceCode.jsSourceCode(), m_workerContextWrapper.get(), &evaluationException);
m_workerContextWrapper->globalData().timeoutChecker.stop();
if ((evaluationException && isTerminatedExecutionException(evaluationException)) || m_workerContextWrapper->globalData().terminator.shouldTerminate()) {
forbidExecution();
return;
}
if (evaluationException) {
String errorMessage;
int lineNumber = 0;
String sourceURL = sourceCode.url().string();
if (m_workerContext->sanitizeScriptError(errorMessage, lineNumber, sourceURL))
*exception = ScriptValue(*m_globalData, throwError(exec, createError(exec, errorMessage.impl())));
else
*exception = ScriptValue(*m_globalData, evaluationException);
}
}
示例5: throwError
// Shared implementation used by test and exec.
bool RegExpObject::match(ExecState* exec)
{
RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
UString input = !exec->argumentCount() ? regExpConstructor->input() : exec->argument(0).toString(exec);
if (input.isNull()) {
throwError(exec, createError(exec, makeString("No input to ", toString(exec), ".")));
return false;
}
if (!regExp()->global()) {
int position;
int length;
regExpConstructor->performMatch(d->regExp.get(), input, 0, position, length);
return position >= 0;
}
if (d->lastIndex < 0 || d->lastIndex > input.length()) {
d->lastIndex = 0;
return false;
}
int position;
int length = 0;
regExpConstructor->performMatch(d->regExp.get(), input, static_cast<int>(d->lastIndex), position, length);
if (position < 0) {
d->lastIndex = 0;
return false;
}
d->lastIndex = position + length;
return true;
}
示例6: createStackOverflowError
JSValue* createStackOverflowError(ExecState* exec)
{
//Note by Arpit Baldeva:07/16/09. Added this assert to indicate to the users that the JavaScript has exceeded
//statck size. This is because EAWebkit users can explicitly set the stack size for JavaScript usage.
ASSERT_WITH_MESSAGE(false, "JavaScript Stack overflowed. Please increase the stack size");
return createError(exec, RangeError, "Maximum call stack size exceeded.");
}
示例7: DECLARE_THROW_SCOPE
JSValue IntlNumberFormat::formatNumber(ExecState& state, double number)
{
VM& vm = state.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// 11.3.4 FormatNumber abstract operation (ECMA-402 2.0)
if (!m_initializedNumberFormat)
return throwTypeError(&state, scope, "Intl.NumberFormat.prototype.format called on value that's not an object initialized as a NumberFormat"_s);
// Map negative zero to positive zero.
if (!number)
number = 0.0;
UErrorCode status = U_ZERO_ERROR;
Vector<UChar, 32> buffer(32);
auto length = unum_formatDouble(m_numberFormat.get(), number, buffer.data(), buffer.size(), nullptr, &status);
if (status == U_BUFFER_OVERFLOW_ERROR) {
buffer.grow(length);
status = U_ZERO_ERROR;
unum_formatDouble(m_numberFormat.get(), number, buffer.data(), length, nullptr, &status);
}
if (U_FAILURE(status))
return throwException(&state, scope, createError(&state, "Failed to format a number."_s));
return jsString(&state, String(buffer.data(), length));
}
示例8: jsUndefined
JSValue QtField::valueFromInstance(ExecState* exec, const Instance* inst) const
{
const QtInstance* instance = static_cast<const QtInstance*>(inst);
QObject* obj = instance->getObject();
if (obj) {
QVariant val;
if (m_type == MetaProperty) {
if (m_property.isReadable())
val = m_property.read(obj);
else
return jsUndefined();
} else if (m_type == ChildObject)
val = QVariant::fromValue((QObject*) m_childObject.data());
#ifndef QT_NO_PROPERTIES
else if (m_type == DynamicProperty)
val = obj->property(m_dynamicProperty);
#endif
JSValueRef exception = 0;
JSValueRef jsValue = convertQVariantToValue(toRef(exec), inst->rootObject(), val, &exception);
if (exception)
return exec->vm().throwException(exec, toJS(exec, exception));
return toJS(exec, jsValue);
}
QString msg = QString(QLatin1String("cannot access member `%1' of deleted QObject")).arg(QLatin1String(name()));
return exec->vm().throwException(exec, createError(exec, msg.toLatin1().constData()));
}
示例9: initScriptIfNeeded
void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, NakedPtr<JSC::Exception>& returnedException)
{
if (isExecutionForbidden())
return;
initScriptIfNeeded();
ExecState* exec = m_workerGlobalScopeWrapper->globalExec();
JSLockHolder lock(exec);
JSC::evaluate(exec, sourceCode.jsSourceCode(), m_workerGlobalScopeWrapper->globalThis(), returnedException);
VM& vm = exec->vm();
if ((returnedException && isTerminatedExecutionException(returnedException)) || isTerminatingExecution()) {
forbidExecution();
return;
}
if (returnedException) {
String errorMessage;
int lineNumber = 0;
int columnNumber = 0;
String sourceURL = sourceCode.url().string();
if (m_workerGlobalScope->sanitizeScriptError(errorMessage, lineNumber, columnNumber, sourceURL, sourceCode.cachedScript())) {
vm.throwException(exec, createError(exec, errorMessage.impl()));
returnedException = vm.exception();
vm.clearException();
}
}
}
示例10: getDynamicStrTab
static Expected<StringRef> getDynamicStrTab(const ELFFile<ELFT> *Elf) {
auto DynamicEntriesOrError = Elf->dynamicEntries();
if (!DynamicEntriesOrError)
return DynamicEntriesOrError.takeError();
for (const typename ELFT::Dyn &Dyn : *DynamicEntriesOrError) {
if (Dyn.d_tag == ELF::DT_STRTAB) {
auto MappedAddrOrError = Elf->toMappedAddr(Dyn.getPtr());
if (!MappedAddrOrError)
consumeError(MappedAddrOrError.takeError());
return StringRef(reinterpret_cast<const char *>(*MappedAddrOrError));
}
}
// If the dynamic segment is not present, we fall back on the sections.
auto SectionsOrError = Elf->sections();
if (!SectionsOrError)
return SectionsOrError.takeError();
for (const typename ELFT::Shdr &Sec : *SectionsOrError) {
if (Sec.sh_type == ELF::SHT_DYNSYM)
return Elf->getStringTableForSymtab(Sec);
}
return createError("dynamic string table not found");
}
示例11: ASSERT
// ECMA 8.6.2.2
void JSObject::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
{
ASSERT(value);
ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
if (propertyName == exec->propertyNames().underscoreProto) {
// Setting __proto__ to a non-object, non-null value is silently ignored to match Mozilla.
if (!value.isObject() && !value.isNull())
return;
if (!setPrototypeWithCycleCheck(value))
throwError(exec, createError(exec, "cyclic __proto__ value"));
return;
}
// Check if there are any setters or getters in the prototype chain
JSValue prototype;
for (JSObject* obj = this; !obj->structure()->hasGetterSetterProperties(); obj = asObject(prototype)) {
prototype = obj->prototype();
if (prototype.isNull()) {
putDirectInternal(exec->globalData(), propertyName, value, 0, true, slot);
return;
}
}
unsigned attributes;
JSCell* specificValue;
if ((m_structure->get(propertyName, attributes, specificValue) != WTF::notFound) && attributes & ReadOnly)
return;
for (JSObject* obj = this; ; obj = asObject(prototype)) {
if (JSValue gs = obj->getDirect(propertyName)) {
if (gs.isGetterSetter()) {
JSObject* setterFunc = asGetterSetter(gs)->setter();
if (!setterFunc) {
throwSetterError(exec);
return;
}
CallData callData;
CallType callType = setterFunc->getCallData(callData);
MarkedArgumentBuffer args;
args.append(value);
call(exec, setterFunc, callType, callData, this, args);
return;
}
// If there's an existing property on the object or one of its
// prototypes it should be replaced, so break here.
break;
}
prototype = obj->prototype();
if (prototype.isNull())
break;
}
putDirectInternal(exec->globalData(), propertyName, value, 0, true, slot);
return;
}
示例12: GTEST_TEST
GTEST_TEST(ExpectedTest, nested_errors_example) {
const auto msg = std::string{"Write a good error message"};
auto firstFailureSource = [&msg]() -> Expected<std::vector<int>, TestError> {
return createError(TestError::Semantic, msg);
};
auto giveMeNestedError = [&]() -> Expected<std::vector<int>, TestError> {
auto ret = firstFailureSource();
ret.isError();
return createError(TestError::Runtime, msg, ret.takeError());
};
auto ret = giveMeNestedError();
EXPECT_FALSE(ret);
ASSERT_TRUE(ret.isError());
EXPECT_EQ(ret.getErrorCode(), TestError::Runtime);
ASSERT_TRUE(ret.getError().hasUnderlyingError());
EXPECT_PRED2(stringContains, ret.getError().getFullMessage(), msg);
}
示例13: createCollator
JSValue IntlCollator::compareStrings(ExecState& state, StringView x, StringView y)
{
// 10.3.4 CompareStrings abstract operation (ECMA-402 2.0)
if (!m_collator) {
createCollator(state);
if (!m_collator)
return state.vm().throwException(&state, createError(&state, ASCIILiteral("Failed to compare strings.")));
}
UErrorCode status = U_ZERO_ERROR;
UCharIterator iteratorX = createIterator(x);
UCharIterator iteratorY = createIterator(y);
auto result = ucol_strcollIter(m_collator, &iteratorX, &iteratorY, &status);
if (U_FAILURE(status))
return state.vm().throwException(&state, createError(&state, ASCIILiteral("Failed to compare strings.")));
return jsNumber(result);
}
示例14: createError
GitCredentialResponse GitCredentialResponse::createForDefault()
{
git_cred *cred;
if (git_cred_default_new(&cred) < 0) {
return createError();
} else {
return GitCredentialResponse(cred);
}
}
示例15: lock
void NPRuntimeObjectMap::moveGlobalExceptionToExecState(ExecState* exec)
{
if (globalExceptionString().isNull())
return;
{
JSLockHolder lock(exec);
exec->vm().throwException(exec, createError(exec, globalExceptionString()));
}
globalExceptionString() = String();
}