本文整理汇总了C++中Completion::complType方法的典型用法代码示例。如果您正苦于以下问题:C++ Completion::complType方法的具体用法?C++ Completion::complType怎么用?C++ Completion::complType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Completion
的用法示例。
在下文中一共展示了Completion::complType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: evaluate
ScriptValue WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode)
{
{
MutexLocker lock(m_sharedDataMutex);
if (m_executionForbidden)
return noValue();
}
initScriptIfNeeded();
JSLock lock(false);
ExecState* exec = m_workerContextWrapper->globalExec();
m_workerContextWrapper->startTimeoutCheck();
Completion comp = JSC::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), sourceCode.jsSourceCode(), m_workerContextWrapper);
m_workerContextWrapper->stopTimeoutCheck();
m_workerContext->thread()->messagingProxy()->reportWorkerThreadActivity(m_workerContext->hasPendingActivity());
if (comp.complType() == Normal || comp.complType() == ReturnValue)
return comp.value();
if (comp.complType() == Throw)
reportException(exec, comp.value());
return noValue();
}
示例2: evaluate
JSValue* KJSProxy::evaluate(const String& filename, int baseLine, const String& str, Node* n)
{
// evaluate code. Returns the JS return value or 0
// if there was none, an error occured or the type couldn't be converted.
initScriptIfNeeded();
// inlineCode is true for <a href="javascript:doSomething()">
// and false for <script>doSomething()</script>. Check if it has the
// expected value in all cases.
// See smart window.open policy for where this is used.
bool inlineCode = filename.isNull();
m_script->setInlineCode(inlineCode);
JSLock lock;
JSValue* thisNode = n ? Window::retrieve(m_frame) : toJS(m_script->globalExec(), n);
m_script->startTimeoutCheck();
Completion comp = m_script->evaluate(filename, baseLine, reinterpret_cast<const KJS::UChar*>(str.characters()), str.length(), thisNode);
m_script->stopTimeoutCheck();
if (comp.complType() == Normal || comp.complType() == ReturnValue)
return comp.value();
if (comp.complType() == Throw) {
UString errorMessage = comp.value()->toString(m_script->globalExec());
int lineNumber = comp.value()->toObject(m_script->globalExec())->get(m_script->globalExec(), "line")->toInt32(m_script->globalExec());
UString sourceURL = comp.value()->toObject(m_script->globalExec())->get(m_script->globalExec(), "sourceURL")->toString(m_script->globalExec());
if (Page* page = m_frame->page())
page->chrome()->addMessageToConsole(errorMessage, lineNumber, sourceURL);
}
return 0;
}
示例3: evaluate
QVariant KJSProxyImpl::evaluate(QString filename, int baseLine,
const QString&str, const DOM::Node &n, Completion *completion) {
// evaluate code. Returns the JS return value or an invalid QVariant
// if there was none, an error occured or the type couldn't be converted.
initScript();
// inlineCode is true for <a href="javascript:doSomething()">
// and false for <script>doSomething()</script>. Check if it has the
// expected value in all cases.
// See smart window.open policy for where this is used.
bool inlineCode = filename.isNull();
//kdDebug(6070) << "KJSProxyImpl::evaluate inlineCode=" << inlineCode << endl;
#ifdef KJS_DEBUGGER
if (inlineCode)
filename = "(unknown file)";
if (KJSDebugWin::instance()) {
KJSDebugWin::instance()->attach(m_script);
KJSDebugWin::instance()->setNextSourceInfo(filename,baseLine);
// KJSDebugWin::instance()->setMode(KJSDebugWin::Step);
}
#else
Q_UNUSED(baseLine);
#endif
m_script->setInlineCode(inlineCode);
Window* window = Window::retrieveWindow( m_part );
KJS::Value thisNode = n.isNull() ? Window::retrieve( m_part ) : getDOMNode(m_script->globalExec(),n);
UString code( str );
KJSCPUGuard guard;
guard.start();
Completion comp = m_script->evaluate(code, thisNode);
guard.stop();
bool success = ( comp.complType() == Normal ) || ( comp.complType() == ReturnValue );
if (completion)
*completion = comp;
#ifdef KJS_DEBUGGER
// KJSDebugWin::instance()->setCode(QString::null);
#endif
window->afterScriptExecution();
// let's try to convert the return value
if (success && !comp.value().isNull())
return ValueToVariant( m_script->globalExec(), comp.value());
else
{
if ( comp.complType() == Throw )
{
UString msg = comp.value().toString(m_script->globalExec());
kdWarning(6070) << "Script threw exception: " << msg.qstring() << endl;
}
return QVariant();
}
}
示例4: execute
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 ?
}
示例5: evaluateInWorld
ScriptValue ScriptController::evaluateInWorld(const ScriptSourceCode& sourceCode, DOMWrapperWorld* world, ShouldAllowXSS shouldAllowXSS)
{
const SourceCode& jsSourceCode = sourceCode.jsSourceCode();
String sourceURL = ustringToString(jsSourceCode.provider()->url());
if (shouldAllowXSS == DoNotAllowXSS && !m_XSSAuditor->canEvaluate(sourceCode.source())) {
// This script is not safe to be evaluated.
return JSValue();
}
// evaluate code. Returns the JS return value or 0
// if there was none, an error occurred or the type couldn't be converted.
// inlineCode is true for <a href="javascript:doSomething()">
// and false for <script>doSomething()</script>. Check if it has the
// expected value in all cases.
// See smart window.open policy for where this is used.
JSDOMWindowShell* shell = windowShell(world);
ExecState* exec = shell->window()->globalExec();
const String* savedSourceURL = m_sourceURL;
m_sourceURL = &sourceURL;
JSLock lock(SilenceAssertionsOnly);
RefPtr<Frame> protect = m_frame;
#if ENABLE(INSPECTOR)
if (InspectorTimelineAgent* timelineAgent = m_frame->page() ? m_frame->page()->inspectorTimelineAgent() : 0)
timelineAgent->willEvaluateScript(sourceURL, sourceCode.startLine());
#endif
exec->globalData().timeoutChecker.start();
Completion comp = JSMainThreadExecState::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), jsSourceCode, shell);
exec->globalData().timeoutChecker.stop();
#if ENABLE(INSPECTOR)
if (InspectorTimelineAgent* timelineAgent = m_frame->page() ? m_frame->page()->inspectorTimelineAgent() : 0)
timelineAgent->didEvaluateScript();
#endif
// Evaluating the JavaScript could cause the frame to be deallocated
// so we start the keep alive timer here.
m_frame->keepAlive();
if (comp.complType() == Normal || comp.complType() == ReturnValue) {
m_sourceURL = savedSourceURL;
return comp.value();
}
if (comp.complType() == Throw || comp.complType() == Interrupted)
reportException(exec, comp.value());
m_sourceURL = savedSourceURL;
return JSValue();
}
示例6: runWithScripts
static bool runWithScripts(GlobalObject* globalObject, const Vector<Script>& scripts, bool dump)
{
UString script;
UString fileName;
Vector<char> scriptBuffer;
if (dump)
BytecodeGenerator::setDumpsGeneratedCode(true);
JSGlobalData& globalData = globalObject->globalData();
#if ENABLE(SAMPLING_FLAGS)
SamplingFlags::start();
#endif
bool success = true;
for (size_t i = 0; i < scripts.size(); i++) {
if (scripts[i].isFile) {
fileName = scripts[i].argument;
if (!fillBufferWithContentsOfFile(fileName, scriptBuffer))
return false; // fail early so we can catch missing files
script = scriptBuffer.data();
} else {
script = scripts[i].argument;
fileName = "[Command Line]";
}
globalData.startSampling();
Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(script, fileName));
success = success && completion.complType() != Throw;
if (dump) {
if (completion.complType() == Throw)
printf("Exception: %s\n", completion.value().toString(globalObject->globalExec()).utf8().data());
else
printf("End: %s\n", completion.value().toString(globalObject->globalExec()).utf8().data());
}
globalData.stopSampling();
globalObject->globalExec()->clearException();
}
#if ENABLE(SAMPLING_FLAGS)
SamplingFlags::stop();
#endif
globalData.dumpSampleData(globalObject->globalExec());
#if ENABLE(SAMPLING_COUNTERS)
AbstractSamplingCounter::dump();
#endif
#if ENABLE(REGEXP_TRACING)
globalData.dumpRegExpTrace();
#endif
return success;
}
示例7: evaluate
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();
}
示例8: 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;
}
示例9: 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");
}
示例10: evaluateString
static ExitCode evaluateString(Interpreter *interp, const char *fileName,
const UString &code,
bool printResult = false)
{
ExecState *exec = interp->globalExec();
Completion res = interp->evaluate(fileName, 0, code);
if (res.complType() == Throw) {
CString msg = res.value()->toString(exec).UTF8String();
JSObject *resObj = res.value()->toObject(exec);
CString message = resObj->toString(exec).UTF8String();
int line = resObj->toObject(exec)->get(exec, "line")->toUInt32(exec);
if (fileName) {
fprintf(stderr, "%s (line %d): ", fileName, line);
}
fprintf(stderr, "%s\n", msg.c_str());
return ErrorEval;
} else if (printResult) {
if (res.isValueCompletion() && !res.value()->isUndefined()) {
CString s8 = res.value()->toString(exec).UTF8String();
if (s8.size() != 0) {
fprintf(stdout, "%s\n", s8.c_str());
}
}
}
return ErrorNone;
}
示例11: 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;
}
示例12: 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;
}
示例13: 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());
}
示例14: 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");
}
示例15: evaluate
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;
}