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(); }
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; }
ScriptObject InjectedScriptHost::createInjectedScript(const String& source, ScriptState* scriptState, long id) { SourceCode sourceCode = makeSource(stringToUString(source)); JSLock lock(SilenceAssertionsOnly); JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject()); JSValue globalThisValue = scriptState->globalThisValue(); Completion comp = JSMainThreadExecState::evaluate(scriptState, globalObject->globalScopeChain(), sourceCode, globalThisValue); if (comp.complType() != JSC::Normal && comp.complType() != JSC::ReturnValue) return ScriptObject(); JSValue functionValue = comp.value(); CallData callData; CallType callType = functionValue.getCallData(callData); if (callType == CallTypeNone) return ScriptObject(); MarkedArgumentBuffer args; args.append(toJS(scriptState, globalObject, this)); args.append(globalThisValue); args.append(jsNumber(scriptState, id)); args.append(jsString(scriptState, String("JSC"))); JSValue result = JSC::call(scriptState, functionValue, callType, callData, globalThisValue, args); if (result.isObject()) return ScriptObject(scriptState, result.getObject()); return ScriptObject(); }
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(); } }
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 ? }
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(); }
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; }
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(); }
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; }
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"); }
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; }
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; }
/* 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; }
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()); }
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"); }
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; }
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; }
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; }
ScriptValue ScriptController::evaluateInWorld(const ScriptSourceCode& sourceCode, DOMWrapperWorld* world) { const SourceCode& jsSourceCode = sourceCode.jsSourceCode(); String sourceURL = ustringToString(jsSourceCode.provider()->url()); // 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; InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvaluateScript(m_frame, sourceURL, sourceCode.startLine()); exec->globalData().timeoutChecker.start(); Completion comp = JSMainThreadExecState::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), jsSourceCode, shell); exec->globalData().timeoutChecker.stop(); InspectorInstrumentation::didEvaluateScript(cookie); // 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 ScriptValue(exec->globalData(), comp.value()); } if (comp.complType() == Throw || comp.complType() == Interrupted) reportException(exec, comp.value()); m_sourceURL = savedSourceURL; return ScriptValue(); }
static bool runWithScripts(GlobalObject* globalObject, const Vector<UString>& fileNames, bool dump) { Vector<char> script; if (dump) BytecodeGenerator::setDumpsGeneratedCode(true); #if ENABLE(OPCODE_SAMPLING) Interpreter* interpreter = globalObject->globalData()->interpreter; interpreter->setSampler(new SamplingTool(interpreter)); #endif 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 ENABLE(OPCODE_SAMPLING) interpreter->sampler()->start(); #endif Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(script.data(), fileName)); success = success && completion.complType() != Throw; if (dump) { if (completion.complType() == Throw) printf("Exception: %s\n", completion.value()->toString(globalObject->globalExec()).ascii()); else printf("End: %s\n", completion.value()->toString(globalObject->globalExec()).ascii()); } globalObject->globalExec()->clearException(); #if ENABLE(OPCODE_SAMPLING) interpreter->sampler()->stop(); #endif } #if ENABLE(OPCODE_SAMPLING) interpreter->sampler()->dump(globalObject->globalExec()); delete interpreter->sampler(); #endif return success; }
JSValue* ScriptController::evaluate(const String& filename, int baseLine, const String& str) { // 11/09/09 CSidhall - Added notify process start to user NOTIFY_PROCESS_STATUS(EA::WebKit::kVProcessTypeScript, EA::WebKit::kVProcessStatusStarted); // 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. ExecState* exec = m_windowShell->window()->globalExec(); m_processingInlineCode = filename.isNull(); JSLock lock; // Evaluating the JavaScript could cause the frame to be deallocated // so we start the keep alive timer here. m_frame->keepAlive(); m_windowShell->window()->startTimeoutCheck(); Completion comp = Interpreter::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), filename, baseLine, StringSourceProvider::create(str), m_windowShell); m_windowShell->window()->stopTimeoutCheck(); NOTIFY_PROCESS_STATUS(EA::WebKit::kVProcessTypeScript, EA::WebKit::kVProcessStatusEnded); if (comp.complType() == Normal || comp.complType() == ReturnValue) { m_processingInlineCode = false; return comp.value(); } if (comp.complType() == Throw) { UString errorMessage = comp.value()->toString(exec); int lineNumber = comp.value()->toObject(exec)->get(exec, Identifier(exec, "line"))->toInt32(exec); UString sourceURL = comp.value()->toObject(exec)->get(exec, Identifier(exec, "sourceURL"))->toString(exec); m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, errorMessage, lineNumber, sourceURL); } m_processingInlineCode = false; return 0; }
static bool runWithScripts(GlobalObject* globalObject, const Vector<UString>& fileNames, bool prettyPrint, bool dump) { Vector<char> script; if (dump) CodeGenerator::setDumpsGeneratedCode(true); #if ENABLE(SAMPLING_TOOL) Machine* machine = globalObject->globalData()->machine; machine->m_sampler = new SamplingTool(); machine->m_sampler->start(); #endif 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 (completion.complType() == Throw) printf("Exception: %s\n", completion.value()->toString(globalObject->globalExec()).ascii()); else printf("End: %s\n", completion.value()->toString(globalObject->globalExec()).ascii()); } globalObject->globalExec()->clearException(); } } #if ENABLE(SAMPLING_TOOL) machine->m_sampler->stop(); machine->m_sampler->dump(globalObject->globalExec()); delete machine->m_sampler; #endif return success; }
EncodedJSValue JSC_HOST_CALL functionLoad(ExecState* exec) { UString fileName = exec->argument(0).toString(exec); Vector<char> script; if (!fillBufferWithContentsOfFile(fileName, script)) return JSValue::encode(throwError(exec, createError(exec, "Could not open file."))); JSGlobalObject* globalObject = exec->lexicalGlobalObject(); Completion result = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(script.data(), fileName)); if (result.complType() == Throw) throwError(exec, result.value()); return JSValue::encode(result.value()); }
ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode) { // evaluate code. Returns the JS return value or 0 // if there was none, an error occured or the type couldn't be converted. const SourceCode& jsSourceCode = sourceCode.jsSourceCode(); 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. ExecState* exec = m_windowShell->window()->globalExec(); const String* savedSourceURL = m_sourceURL; String sourceURL = jsSourceCode.provider()->url(); m_sourceURL = &sourceURL; JSLock lock(false); // Evaluating the JavaScript could cause the frame to be deallocated // so we start the keep alive timer here. m_frame->keepAlive(); m_windowShell->window()->startTimeoutCheck(); Completion comp = JSC::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), jsSourceCode, m_windowShell); m_windowShell->window()->stopTimeoutCheck(); if (comp.complType() == Normal || comp.complType() == ReturnValue) { m_sourceURL = savedSourceURL; return comp.value(); } if (comp.complType() == Throw) reportException(exec, comp.value()); m_sourceURL = savedSourceURL; return noValue(); }
ScriptValue WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, ScriptValue* exception) { { MutexLocker lock(m_sharedDataMutex); if (m_executionForbidden) return JSValue(); } 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); m_workerContextWrapper->globalData().timeoutChecker.stop(); if (comp.complType() == Normal || comp.complType() == ReturnValue) return comp.value(); if (comp.complType() == Throw) *exception = comp.value(); return JSValue(); }
AJValue JSC_HOST_CALL functionCheckSyntax(ExecState* exec, AJObject* o, AJValue v, const ArgList& args) { UNUSED_PARAM(o); UNUSED_PARAM(v); UString fileName = args.at(0).toString(exec); Vector<char> script; if (!fillBufferWithContentsOfFile(fileName, script)) return throwError(exec, GeneralError, "Could not open file."); AJGlobalObject* globalObject = exec->lexicalGlobalObject(); Completion result = checkSyntax(globalObject->globalExec(), makeSource(script.data(), fileName)); if (result.complType() == Throw) exec->setException(result.value()); return result.value(); }
bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) { ExecState* exec = toJS(ctx); exec->globalData().heap.registerThread(); JSLock lock(exec); SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber); Completion completion = checkSyntax(exec->dynamicGlobalObject()->globalExec(), source); if (completion.complType() == Throw) { if (exception) *exception = toRef(completion.value()); return false; } return true; }
bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) { JSLock lock; ExecState* exec = toJS(ctx); UString::Rep* scriptRep = toJS(script); UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null; Completion completion = Interpreter::checkSyntax(exec->dynamicGlobalObject()->globalExec(), UString(sourceURLRep), startingLineNumber, UString(scriptRep)); if (completion.complType() == Throw) { if (exception) *exception = toRef(completion.value()); return false; } return true; }
EncodedJSValue JSC_HOST_CALL functionCheckSyntax(ExecState* exec) { UString fileName = exec->argument(0).toString(exec); Vector<char> script; if (!fillBufferWithContentsOfFile(fileName, script)) return JSValue::encode(throwError(exec, createError(exec, "Could not open file."))); JSGlobalObject* globalObject = exec->lexicalGlobalObject(); StopWatch stopWatch; stopWatch.start(); Completion result = checkSyntax(globalObject->globalExec(), makeSource(script.data(), fileName)); stopWatch.stop(); if (result.complType() == Throw) throwError(exec, result.value()); return JSValue::encode(jsNumber(stopWatch.getElapsedMS())); }
Completion Interpreter::evaluate(const UString &sourceURL, int startingLineNumber, const UString &code, const Value &thisV) { Completion comp = rep->evaluate(code,thisV, sourceURL, startingLineNumber); #if APPLE_CHANGES if (shouldPrintExceptions() && comp.complType() == Throw) { lock(); ExecState *exec = rep->globalExec(); char *f = strdup(sourceURL.ascii()); const char *message = comp.value().toObject(exec).toString(exec).ascii(); printf("[%d] %s:%s\n", getpid(), f, message); free(f); unlock(); } #endif return comp; }