void SVGScriptElement::executeScript(Document *document, StringImpl *jsCode) { if(!document || !jsCode) return; #if 0 Ecma *ecmaEngine = document->ecmaEngine(); if(!ecmaEngine) return; KJS::Interpreter::lock(); // Run script KJS::Completion comp = ecmaEngine->evaluate(jsCode.deprecatedString(), ecmaEngine->globalObject()); if(comp.complType() == KJS::Throw) { KJS::ExecState *exec = ecmaEngine->globalExec(); KJS::JSValue *exVal = comp.value(); int lineno = -1; if(exVal->isObject()) { KJS::JSValue *lineVal = static_cast<KJS::JSObject *>(exVal)->get(exec, "line"); if(lineVal->type() == KJS::NumberType) lineno = int(lineVal->toNumber(exec)); } // Fire ERROR_EVENT upon errors... SVGDocument *svgDocument = static_cast<SVGDocument *>(document); if(svgDocument && document->hasListenerType(ERROR_EVENT)) { RefPtr<Event> event = svgDocument->createEvent("SVGEvents"); event->initEvent(EventNames::errorEvent, false, false); svgDocument->dispatchRecursiveEvent(event.get(), svgDocument->lastChild()); } kdDebug() << "[SVGScriptElement] Evaluation error, line " << (lineno != -1 ? DeprecatedString::number(lineno) : DeprecatedString::fromLatin1("N/A")) << " " << exVal->toString(exec).deprecatedString() << endl; } else if(comp.complType() == KJS::ReturnValue) kdDebug() << "[SVGScriptElement] Return value: " << comp.value()->toString(ecmaEngine->globalExec()).deprecatedString() << endl; else if(comp.complType() == KJS::Normal) kdDebug() << "[SVGScriptElement] Evaluated ecma script!" << endl; KJS::Interpreter::unlock(); #else if (jsCode) // Hack to close memory leak due to #if 0 String(jsCode); #endif }
// from khtml/ecma/debugger/debugwindow.cpp static QString exceptionToString(KJS::ExecState* exec, KJS::JSValue* exceptionObj) { QString exceptionMsg = valueToString(exceptionObj); // Since we purposefully bypass toString, we need to figure out // string serialization ourselves. //### might be easier to export class info for ErrorInstance --- KJS::JSObject* valueObj = exceptionObj->getObject(); KJS::JSValue* protoObj = valueObj ? valueObj->prototype() : 0; bool exception = false; bool syntaxError = false; if (protoObj == exec->lexicalInterpreter()->builtinSyntaxErrorPrototype()) { exception = true; syntaxError = true; } if (protoObj == exec->lexicalInterpreter()->builtinErrorPrototype() || protoObj == exec->lexicalInterpreter()->builtinEvalErrorPrototype() || protoObj == exec->lexicalInterpreter()->builtinReferenceErrorPrototype() || protoObj == exec->lexicalInterpreter()->builtinRangeErrorPrototype() || protoObj == exec->lexicalInterpreter()->builtinTypeErrorPrototype() || protoObj == exec->lexicalInterpreter()->builtinURIErrorPrototype()) { exception = true; } if (!exception) return exceptionMsg; // Clear exceptions temporarily so we can get/call a few things. // We memorize the old exception first, of course. Note that // This is not always the same as exceptionObj since we may be // asked to translate a non-active exception KJS::JSValue* oldExceptionObj = exec->exception(); exec->clearException(); // We want to serialize the syntax errors ourselves, to provide the line number. // The URL is in "sourceURL" and the line is in "line" // ### TODO: Perhaps we want to use 'sourceId' in case of eval contexts. if (syntaxError) { KJS::JSValue* lineValue = valueObj->get(exec, "line"); KJS::JSValue* urlValue = valueObj->get(exec, "sourceURL"); int line = lineValue->toNumber(exec); QString url = urlValue->toString(exec).qstring(); exceptionMsg = i18n("Parse error at %1 line %2", url, line + 1); } else { // ### it's still not 100% safe to call toString here, even on // native exception objects, since someone might have changed the toString property // of the exception prototype, but I'll punt on this case for now. exceptionMsg = exceptionObj->toString(exec).qstring(); } exec->setException(oldExceptionObj); return exceptionMsg; }