本文整理汇总了C++中Completion类的典型用法代码示例。如果您正苦于以下问题:C++ Completion类的具体用法?C++ Completion怎么用?C++ Completion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Completion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runInteractive
static void runInteractive(GlobalObject* globalObject)
{
//abaldeva: Put it here instead of it being static. Otherwise it allocates memory before the
//user has a chance to set the allocator.
const UString interpreterName("Interpreter");
while (true) {
#if HAVE(READLINE)
char* line = readline(interactivePrompt);
if (!line)
break;
if (line[0])
add_history(line);
Completion completion = Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), interpreterName, 1, line);
free(line);
#else
puts(interactivePrompt);
Vector<char, 256> line;
int c;
while ((c = getchar()) != EOF) {
// FIXME: Should we also break on \r?
if (c == '\n')
break;
line.append(c);
}
line.append('\0');
Completion completion = Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), interpreterName, 1, line.data());
#endif
if (completion.isValueCompletion())
printf("%s\n", completion.value()->toString(globalObject->globalExec()).UTF8String().c_str());
}
printf("\n");
}
示例2: runWithScripts
static bool runWithScripts(GlobalObject* globalObject, const Vector<UString>& fileNames, bool prettyPrint, bool dump)
{
Vector<char> script;
if (dump)
CodeGenerator::setDumpsGeneratedCode(true);
bool success = true;
for (size_t i = 0; i < fileNames.size(); i++) {
UString fileName = fileNames[i];
if (!fillBufferWithContentsOfFile(fileName, script))
return false; // fail early so we can catch missing files
if (prettyPrint)
prettyPrintScript(globalObject->globalExec(), fileName, script);
else {
Completion completion = Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), fileName, 1, script.data());
success = success && completion.complType() != Throw;
if (dump) {
if (success)
printf("End: %s\n", completion.value()->toString(globalObject->globalExec()).ascii());
else
printf("Exception: %s\n", completion.value()->toString(globalObject->globalExec()).ascii());
}
}
}
return success;
}
示例3: JSEvaluateScript
JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
ExecState* exec = toJS(ctx);
exec->globalData().heap.registerThread();
JSLock lock(exec);
JSObject* jsThisObject = toJS(thisObject);
// evaluate sets "this" to the global object if it is NULL
JSGlobalObject* globalObject = exec->dynamicGlobalObject();
SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber);
Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), source, jsThisObject);
if (completion.complType() == Throw) {
if (exception)
*exception = toRef(completion.value());
return 0;
}
if (completion.value())
return toRef(completion.value());
// happens, for example, when the only statement is an empty (';') statement
return toRef(jsUndefined());
}
示例4: doIt
bool doIt(int argc, char** argv)
{
bool success = true;
bool prettyPrint = false;
GlobalImp* global = new GlobalImp();
// create interpreter
RefPtr<Interpreter> interp = new Interpreter(global);
// add debug() function
global->put(interp->globalExec(), "debug", new TestFunctionImp(TestFunctionImp::Debug, 1));
// add "print" for compatibility with the mozilla js shell
global->put(interp->globalExec(), "print", new TestFunctionImp(TestFunctionImp::Print, 1));
// add "quit" for compatibility with the mozilla js shell
global->put(interp->globalExec(), "quit", new TestFunctionImp(TestFunctionImp::Quit, 0));
// add "gc" for compatibility with the mozilla js shell
global->put(interp->globalExec(), "gc", new TestFunctionImp(TestFunctionImp::GC, 0));
// add "version" for compatibility with the mozilla js shell
global->put(interp->globalExec(), "version", new TestFunctionImp(TestFunctionImp::Version, 1));
global->put(interp->globalExec(), "run", new TestFunctionImp(TestFunctionImp::Run, 1));
Interpreter::setShouldPrintExceptions(true);
for (int i = 1; i < argc; i++) {
const char* fileName = argv[i];
if (strcmp(fileName, "-f") == 0) // mozilla test driver script uses "-f" prefix for files
continue;
if (strcmp(fileName, "-p") == 0) {
prettyPrint = true;
continue;
}
char* script = createStringWithContentsOfFile(fileName);
if (!script) {
success = false;
break; // fail early so we can catch missing files
}
if (prettyPrint) {
int errLine = 0;
UString errMsg;
UString s = Parser::prettyPrint(script, &errLine, &errMsg);
if (s.isNull()) {
fprintf(stderr, "%s:%d: %s.\n", fileName, errLine, errMsg.UTF8String().c_str());
success = false;
free(script);
break;
}
printf("%s\n", s.UTF8String().c_str());
} else {
Completion completion = interp->evaluate(fileName, 0, script);
success = success && completion.complType() != Throw;
}
free(script);
}
return success;
}
示例5: runInteractive
static void runInteractive(GlobalObject* globalObject)
{
while (true) {
#if HAVE(READLINE) && !RUNNING_FROM_XCODE
char* line = readline(interactivePrompt);
if (!line)
break;
if (line[0])
add_history(line);
Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(line, interpreterName));
free(line);
#else
printf("%s", interactivePrompt);
Vector<char, 256> line;
int c;
while ((c = getchar()) != EOF) {
// FIXME: Should we also break on \r?
if (c == '\n')
break;
line.append(c);
}
if (line.isEmpty())
break;
line.append('\0');
Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(line.data(), interpreterName));
#endif
if (completion.complType() == Throw)
printf("Exception: %s\n", completion.value().toString(globalObject->globalExec()).utf8().data());
else
printf("%s\n", completion.value().toString(globalObject->globalExec()).utf8().data());
globalObject->globalExec()->clearException();
}
printf("\n");
}
示例6: _NPN_Evaluate
bool _NPN_Evaluate(NPP, NPObject* o, NPString* s, NPVariant* variant)
{
if (o->_class == NPScriptObjectClass) {
JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o);
RootObject* rootObject = obj->rootObject;
if (!rootObject || !rootObject->isValid())
return false;
ExecState* exec = rootObject->globalObject()->globalExec();
JSLock lock(false);
String scriptString = convertNPStringToUTF16(s);
rootObject->globalObject()->startTimeoutCheck();
Completion completion = Interpreter::evaluate(rootObject->globalObject()->globalExec(), rootObject->globalObject()->globalScopeChain(), UString(), 1, scriptString);
rootObject->globalObject()->stopTimeoutCheck();
ComplType type = completion.complType();
JSValue* result;
if (type == Normal) {
result = completion.value();
if (!result)
result = jsUndefined();
} else
result = jsUndefined();
convertValueToNPVariant(exec, result, variant);
exec->clearException();
return true;
}
VOID_TO_NPVARIANT(*variant);
return false;
}
示例7: TestHasPrefix
void
TestHasPrefix(const _Fragment& aFragment, bool aExpectedHas, bool aExpectedComplete)
{
_PrefixArray array = { GeneratePrefix(_Fragment("bravo.com/"), 32),
GeneratePrefix(_Fragment("browsing.com/"), 8),
GeneratePrefix(_Fragment("gound.com/"), 5),
GeneratePrefix(_Fragment("small.com/"), 4)
};
RunTestInNewThread([&] () -> void {
UniquePtr<LookupCache> cache = SetupLookupCache<LookupCacheV4>(array);
Completion lookupHash;
lookupHash.FromPlaintext(aFragment);
bool has, confirmed;
uint32_t matchLength;
// Freshness is not used in V4 so we just put dummy values here.
TableFreshnessMap dummy;
nsresult rv =
cache->Has(lookupHash, &has, &matchLength, &confirmed);
EXPECT_EQ(rv, NS_OK);
EXPECT_EQ(has, aExpectedHas);
EXPECT_EQ(matchLength == COMPLETE_SIZE, aExpectedComplete);
EXPECT_EQ(confirmed, false);
cache->ClearAll();
});
}
示例8: TestCache
void
TestCache(const Completion aCompletion,
bool aExpectedHas,
bool aExpectedConfirmed,
bool aExpectedInCache,
T* aCache = nullptr)
{
bool has, inCache, confirmed;
uint32_t matchLength;
if (aCache) {
aCache->Has(aCompletion, &has, &matchLength, &confirmed);
inCache = aCache->IsInCache(aCompletion.ToUint32());
} else {
_PrefixArray array = { GeneratePrefix(_Fragment("cache.notexpired.com/"), 10),
GeneratePrefix(_Fragment("cache.expired.com/"), 8),
GeneratePrefix(_Fragment("gound.com/"), 5),
GeneratePrefix(_Fragment("small.com/"), 4)
};
UniquePtr<T> cache = SetupLookupCache<T>(array);
// Create an expired entry and a non-expired entry
SetupCacheEntry(cache.get(), _Fragment("cache.notexpired.com/"));
SetupCacheEntry(cache.get(), _Fragment("cache.expired.com/"), true, true);
cache->Has(aCompletion, &has, &matchLength, &confirmed);
inCache = cache->IsInCache(aCompletion.ToUint32());
}
EXPECT_EQ(has, aExpectedHas);
EXPECT_EQ(confirmed, aExpectedConfirmed);
EXPECT_EQ(inCache, aExpectedInCache);
}
示例9: JSRunEvaluate
/*
JSRunEvaluate
*/
JSObjectRef JSRunEvaluate(JSRunRef ref)
{
JSObjectRef result = 0;
JSRun* ptr = (JSRun*)ref;
if (ptr)
{
Completion completion = ptr->Evaluate();
if (completion.isValueCompletion())
{
result = (JSObjectRef)KJSValueToJSObject(completion.value(), ptr->GetInterpreter()->globalExec());
}
if (completion.complType() == Throw)
{
JSFlags flags = ptr->Flags();
if (flags & kJSFlagDebug)
{
CFTypeRef error = JSObjectCopyCFValue(result);
if (error)
{
CFShow(error);
CFRelease(error);
}
}
}
}
return result;
}
示例10: TestHasPrefix
void
TestHasPrefix(const _Fragment& aFragment, bool aExpectedHas, bool aExpectedComplete)
{
_PrefixArray array = { GeneratePrefix(_Fragment("bravo.com/"), 32),
GeneratePrefix(_Fragment("browsing.com/"), 8),
GeneratePrefix(_Fragment("gound.com/"), 5),
GeneratePrefix(_Fragment("small.com/"), 4)
};
RunTestInNewThread([&] () -> void {
UniquePtr<LookupCache> cache = SetupLookupCacheV4(array);
Completion lookupHash;
nsCOMPtr<nsICryptoHash> cryptoHash = do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID);
lookupHash.FromPlaintext(aFragment, cryptoHash);
bool has, complete;
nsresult rv = cache->Has(lookupHash, &has, &complete);
EXPECT_EQ(rv, NS_OK);
EXPECT_EQ(has, aExpectedHas);
EXPECT_EQ(complete, aExpectedComplete);
cache->ClearAll();
});
}
示例11: globalObject
bool NPRuntimeObjectMap::evaluate(NPObject* npObject, const String&scriptString, NPVariant* result)
{
Global<JSGlobalObject> globalObject(this->globalObject()->globalData(), this->globalObject());
if (!globalObject)
return false;
ExecState* exec = globalObject->globalExec();
JSLock lock(SilenceAssertionsOnly);
JSValue thisValue = getOrCreateJSObject(globalObject.get(), npObject);
globalObject->globalData().timeoutChecker.start();
Completion completion = JSC::evaluate(exec, globalObject->globalScopeChain(), makeSource(UString(scriptString.impl())), thisValue);
globalObject->globalData().timeoutChecker.stop();
ComplType completionType = completion.complType();
JSValue resultValue;
if (completionType == Normal) {
resultValue = completion.value();
if (!resultValue)
resultValue = jsUndefined();
} else
resultValue = jsUndefined();
exec->clearException();
convertJSValueToNPVariant(exec, resultValue, *result);
return true;
}
示例12: ScriptValue
ScriptValue WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, ScriptValue* exception)
{
if (isExecutionForbidden())
return ScriptValue();
initScriptIfNeeded();
JSLock lock(SilenceAssertionsOnly);
ExecState* exec = m_workerContextWrapper->globalExec();
m_workerContextWrapper->globalData().timeoutChecker.start();
Completion comp = JSC::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), sourceCode.jsSourceCode(), m_workerContextWrapper.get());
m_workerContextWrapper->globalData().timeoutChecker.stop();
ComplType completionType = comp.complType();
if (completionType == Terminated || m_workerContextWrapper->globalData().terminator.shouldTerminate()) {
forbidExecution();
return ScriptValue();
}
if (completionType == JSC::Normal || completionType == ReturnValue)
return ScriptValue(*m_globalData, comp.value());
if (completionType == Throw) {
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, comp.value());
}
return ScriptValue();
}
示例13: runInteractive
static void runInteractive(GlobalObject* globalObject)
{
while (true) {
#if HAVE(READLINE)
char* line = readline(interactivePrompt);
if (!line)
break;
if (line[0])
add_history(line);
Completion completion = Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), interpreterName, 1, line);
free(line);
#else
puts(interactivePrompt);
Vector<char, 256> line;
int c;
while ((c = getchar()) != EOF) {
// FIXME: Should we also break on \r?
if (c == '\n')
break;
line.append(c);
}
line.append('\0');
Completion completion = Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), interpreterName, 1, line.data());
#endif
if (completion.complType() == Throw)
printf("Exception: %s\n", completion.value()->toString(globalObject->globalExec()).ascii());
else
printf("%s\n", completion.value()->toString(globalObject->globalExec()).UTF8String().c_str());
globalObject->globalExec()->clearException();
}
printf("\n");
}
示例14: _NPN_Evaluate
bool _NPN_Evaluate(NPP, NPObject* o, NPString* s, NPVariant* variant)
{
if (o->_class == NPScriptObjectClass) {
JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o);
RootObject* rootObject = obj->rootObject;
if (!rootObject || !rootObject->isValid())
return false;
ExecState* exec = rootObject->globalObject()->globalExec();
JSLock lock(SilenceAssertionsOnly);
String scriptString = convertNPStringToUTF16(s);
ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject();
globalObject->globalData()->timeoutChecker.start();
Completion completion = JSC::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(scriptString), JSC::JSValue());
globalObject->globalData()->timeoutChecker.stop();
ComplType type = completion.complType();
JSValue result;
if (type == Normal) {
result = completion.value();
if (!result)
result = jsUndefined();
} else
result = jsUndefined();
convertValueToNPVariant(exec, result, variant);
exec->clearException();
return true;
}
VOID_TO_NPVARIANT(*variant);
return false;
}
示例15: Completion
Completion DeclaredFunctionImp::execute(ExecState *exec)
{
Completion result = body->execute(exec);
if (result.complType() == Throw || result.complType() == ReturnValue)
return result;
return Completion(Normal, Undefined()); // TODO: or ReturnValue ?
}