KJS::JSValue *SlotProxy::callMethod(const QByteArray &methodName, void **_a) { #ifdef DEBUG_SLOTPROXY qDebug() << "SlotProxy::callMethod(" << methodName << ",_a) obj=" << this; #endif KJS::ExecState *exec = m_interpreter->globalExec(); exec->clearException(); // Crash // KJS::Interpreter::globalExec()->context().thisValue() KJS::List args = convertArguments(exec, _a); KJS::Identifier id = KJS::Identifier(KJS::UString(methodName.data())); KJS::JSObject *fun = m_object->get(exec, id)->toObject(exec); KJS::JSValue *retValue; if (!fun->implementsCall()) { #ifdef DEBUG_SLOTPROXY qDebug() << "SlotProxy::callMethod got bad handler"; #endif QString msg = i18n("Bad slot handler: Object %1 Identifier %2 Method %3 Signature: %4.", m_object->className().ascii(), id.ascii(), methodName.data(), QString(m_signature)); retValue = throwError(exec, KJS::TypeError, msg); } else { retValue = fun->call(exec, m_object, args); } if (exec->hadException()) { #ifdef DEBUG_SLOTPROXY qDebug() << "SlotProxy::callMethod had exception"; #endif if (m_interpreter->shouldPrintExceptions()) { KJS::JSLock lock; KJS::JSObject *exceptObj = exec->exception()->toObject(exec);//retValue->toObject(exec); QString message = toQString(exceptObj->toString(exec)); QString sourceURL = toQString(exceptObj->get(exec, "sourceURL")->toString(exec)); int sourceId = exceptObj->get(exec, "sourceId")->toUInt32(exec); // would include the line number, but it's always last line of file int line = exceptObj->get(exec, "line")->toUInt32(exec); (*KJSEmbed::conerr()) << i18n("Exception calling '%1' slot from %2:%3:%4", QString(methodName), !sourceURL.isEmpty() ? sourceURL : QString::number(sourceId), line, message) << endl; } // clear it so it doesn't stop other things exec->clearException(); return KJS::jsNull(); } else { if (retValue->type() == 1 || retValue->type() == 0) { return KJS::jsNull(); } } return retValue; }
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 }
KJS::JSValue *GlobalObject::get(KJS::ExecState *exec, const KJS::Identifier &p) const { kdDebug(26004) << "WebCore::GlobalObject (" << this << ")::get " << p.deprecatedString() << endl; KJS::JSValue *ret = GlobalObject::get(exec, p); if(ret->type() != KJS::UndefinedType) return ret; const KJS::HashEntry *entry = KJS::Lookup::findEntry(&GlobalObject::s_hashTable, p); if(entry) { switch(entry->value) { case GlobalObjectConstants::SVGException: return getSVGExceptionConstructor(exec); case GlobalObjectConstants::SVGLength: return getSVGLengthConstructor(exec); case GlobalObjectConstants::SVGAngle: return getSVGAngleConstructor(exec); case GlobalObjectConstants::SVGColor: return getSVGColorConstructor(exec); case GlobalObjectConstants::SVGPaint: return getSVGPaintConstructor(exec); case GlobalObjectConstants::SVGUnitTypes: return getSVGUnitTypesConstructor(exec); case GlobalObjectConstants::SVGTransform: return getSVGTransformConstructor(exec); case GlobalObjectConstants::SVGGradientElement: return getSVGGradientElementConstructor(exec); case GlobalObjectConstants::SVGPreserveAspectRatio: return getSVGPreserveAspectRatioConstructor(exec); case GlobalObjectConstants::SVGZoomAndPan: return getSVGZoomAndPanConstructor(exec); case GlobalObjectConstants::SVGMarkerElement: return getSVGMarkerElementConstructor(exec); } } // This isn't necessarily a bug. Some code uses if(!window.blah) window.blah=1 // But it can also mean something isn't loaded or implemented... kdDebug(26004) << "GlobalObject::get property not found: " << p.deprecatedString() << endl; return KJS::jsUndefined(); }
JSType JSValueGetType(JSContextRef, JSValueRef value) { KJS::JSValue* jsValue = toJS(value); switch (jsValue->type()) { case KJS::UndefinedType: return kJSTypeUndefined; case KJS::NullType: return kJSTypeNull; case KJS::BooleanType: return kJSTypeBoolean; case KJS::NumberType: return kJSTypeNumber; case KJS::StringType: return kJSTypeString; case KJS::ObjectType: return kJSTypeObject; default: ASSERT(!"JSValueGetType: unknown type code.\n"); return kJSTypeUndefined; } }