Exemplo n.º 1
0
void KstBindWindow::setWindowName(KJS::ExecState *exec, const KJS::Value& value) {
  if (value.type() != KJS::StringType) {
    return createPropertyTypeError(exec);
  }
  KstViewWindow *w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(value.toString(exec).qstring()));
  if (w) {
    return createPropertyGeneralError(exec, i18n("A window of this name already exists."));
  }
  _d->setCaption(value.toString(exec).qstring());
}
Exemplo n.º 2
0
// Variant value must be released with NPReleaseVariantValue()
void coerceValueToNPVariantStringType (KJS::ExecState *exec, const KJS::Value &value, NPVariant *result)
{
    UString ustring = value.toString(exec);
    CString cstring = ustring.UTF8String();
    NPString string = { (const NPUTF8 *)cstring.c_str(), cstring.size() };
    NPN_InitializeVariantWithStringCopy (result, &string);
}
void KstBindDocument::setName(KJS::ExecState *exec, const KJS::Value& value) {
  if (value.type() != KJS::StringType) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
    exec->setException(eobj);
    return;
  }
  KstApp::inst()->document()->setTitle(value.toString(exec).qstring());
}
Exemplo n.º 4
0
// Variant value must be released with NPReleaseVariantValue()
void convertValueToNPVariant (KJS::ExecState *exec, const KJS::Value &value, NPVariant *result)
{
    Type type = value.type();

    if (type == StringType) {
        UString ustring = value.toString(exec);
        CString cstring = ustring.UTF8String();
        NPString string = { (const NPUTF8 *)cstring.c_str(), cstring.size() };
        NPN_InitializeVariantWithStringCopy (result, &string );
    }
    else if (type == NumberType) {
        NPN_InitializeVariantWithDouble (result, value.toNumber(exec));
    }
    else if (type == BooleanType) {
        NPN_InitializeVariantWithBool (result, value.toBoolean(exec));
    }
    else if (type == UnspecifiedType) {
        NPN_InitializeVariantAsUndefined(result);
    }
    else if (type == NullType) {
        NPN_InitializeVariantAsNull(result);
    }
    else if (type == ObjectType) {
        KJS::ObjectImp *objectImp = static_cast<KJS::ObjectImp*>(value.imp());
        if (objectImp->classInfo() == &KJS::RuntimeObjectImp::info) {
            KJS::RuntimeObjectImp *imp = static_cast<KJS::RuntimeObjectImp *>(value.imp());
            CInstance *instance = static_cast<CInstance*>(imp->getInternalInstance());
            NPN_InitializeVariantWithObject (result, instance->getObject());
        }
        else {

            KJS::Interpreter *originInterpreter = exec->interpreter();
            const Bindings::RootObject *originExecutionContext = rootForInterpreter(originInterpreter);

            KJS::Interpreter *interpreter = 0;
            if (originInterpreter->isGlobalObject(value)) {
                interpreter = originInterpreter->interpreterForGlobalObject (value.imp());
            }

            if (!interpreter)
                interpreter = originInterpreter;

            const Bindings::RootObject *executionContext = rootForInterpreter(interpreter);
            if (!executionContext) {
                Bindings::RootObject *newExecutionContext = new KJS::Bindings::RootObject(0);
                newExecutionContext->setInterpreter (interpreter);
                executionContext = newExecutionContext;
            }

            NPObject *obj = (NPObject *)exec->interpreter()->createLanguageInstanceForValue (exec, Instance::CLanguage, value.toObject(exec), originExecutionContext, executionContext);
            NPN_InitializeVariantWithObject (result, obj);
            _NPN_ReleaseObject (obj);
        }
    }
    else
        NPN_InitializeVariantAsUndefined(result);
}
Exemplo n.º 5
0
void KstBindPlot::setTopLabel(KJS::ExecState *exec, const KJS::Value& value) {
  if (value.type() != KJS::StringType) {
    return createPropertyTypeError(exec);
  }
  Kst2DPlotPtr d = makePlot(_d);
  if (d) {
    KstWriteLocker wl(d);
    d->topLabel()->setText(value.toString(exec).qstring());
  }
}
Exemplo n.º 6
0
void KstBindLegend::setTitle(KJS::ExecState *exec, const KJS::Value& value) {
  if (value.type() != KJS::StringType) {
    return createPropertyTypeError(exec);
  }
  KstViewLegendPtr d = makeLegend(_d);
  if (d) {
    KstWriteLocker wl(d);
    d->setTitle(value.toString(exec).qstring());
    KstApp::inst()->paintAll(KstPainter::P_PAINT);
  }
}
Exemplo n.º 7
0
void KstBindPlotLabel::setFont(KJS::ExecState *exec, const KJS::Value& value) {
  if (!_d) {
    return createPropertyInternalError(exec);
  }
  if (value.type() != KJS::StringType) {
    return createPropertyTypeError(exec);
  }
  KstWriteLocker wl(_d);
  _d->topLabel()->setFontName(value.toString(exec).qstring());
  _d->setDirty();
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
}
void KstBindPowerSpectrum::setRUnits(KJS::ExecState *exec, const KJS::Value& value) {
  if (value.type() != KJS::StringType) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
    exec->setException(eobj);
    return;
  }
  KstPSDPtr d = makePSD(_d);
  if (d) {
    KstWriteLocker wl(d);
    d->setRUnits(value.toString(exec).qstring());
  }
}
QStringList KJSEmbedPart::constructorNames() const
{
    QStringList classes;

    KJS::List cons = constructorList();
    KJS::ListIterator it = cons.begin();
    while ( it != cons.end() ) {
	KJS::Value v = *it;
	classes += v.toString( js->globalExec() ).qstring();
	it++;
    }

    return classes;
}
bool JSConsoleWidget::execute( const QString &cmd, const KJS::Value &self )
{
    KJS::Completion jsres;
    bool ok = js->execute( jsres, cmd, self );

    // Executed ok
    if ( ok ) {

	// No return value
	if ( !jsres.isValueCompletion() )
	    return ok;

	// Return value
	KJS::Value ret = jsres.value();
	KJS::UString s = ret.toString( js->globalExec() );

	if ( s.isNull() ) {
	    warn( i18n("Success, but return value cannot be displayed") );
	    return ok;
	}

	QString txt = s.qstring();
	txt = txt.replace( QChar('\n'), "<br>" );
	println( txt );

	return ok;
    }

    // Handle errors
    KJS::ComplType ct = jsres.complType();
    if ( (ct == KJS::Throw) || (ct == KJS::Break) || ct == KJS::Continue ) {

	KJS::UString s = jsres.value().toString( js->globalExec() );
	if ( !s.isNull() )
	    warn( s.qstring() );
	else
	    warn( i18n("Unspecified error") );
    }
    else {
	kdDebug(80001) << "jsconsolewidget: Unknown completion error, " << ct << endl;
	warn( i18n("Unknown error returned, completion type %1").arg(ct) );
    }

    return ok;
}
Exemplo n.º 11
0
jvalue KJS::Bindings::convertValueToJValue (KJS::ExecState *exec, KJS::Value value, JNIType _JNIType, const char *javaClassName)
{
    jvalue result;
    double d = 0;
   
    d = value.toNumber(exec);
    switch (_JNIType){
        case object_type: {
            result.l = (jobject)0;
            
            // First see if we have a Java instance.
            if (value.type() == KJS::ObjectType){
                KJS::ObjectImp *objectImp = static_cast<KJS::ObjectImp*>(value.imp());
                if (strcmp(objectImp->classInfo()->className, "RuntimeObject") == 0) {
                    KJS::RuntimeObjectImp *imp = static_cast<KJS::RuntimeObjectImp *>(value.imp());
                    JavaInstance *instance = static_cast<JavaInstance*>(imp->getInternalInstance());
                    result.l = instance->javaInstance();
                }
                else if (strcmp(objectImp->classInfo()->className, "RuntimeArray") == 0) {
                    KJS::RuntimeArrayImp *imp = static_cast<KJS::RuntimeArrayImp *>(value.imp());
                    JavaArray *array = static_cast<JavaArray*>(imp->getConcreteArray());
                    result.l = array->javaArray();
                }
            }
            
            // Now convert value to a string if the target type is a java.lang.string.
            if (result.l == 0 && strcmp(javaClassName, "java.lang.String") == 0) {
                KJS::UString stringValue = value.toString(exec);
                JNIEnv *env = getJNIEnv();
                jobject javaString = env->functions->NewString (env, (const jchar *)stringValue.data(), stringValue.size());
                result.l = javaString;
            }
        }
        break;
        
        case boolean_type: {
            result.z = (jboolean)d;
        }
        break;
            
        case byte_type: {
            result.b = (jbyte)d;
        }
        break;
        
        case char_type: {
            result.c = (jchar)d;
        }
        break;

        case short_type: {
            result.s = (jshort)d;
        }
        break;

        case int_type: {
            result.i = (jint)d;
        }
        break;

        case long_type: {
            result.j = (jlong)d;
        }
        break;

        case float_type: {
            result.f = (jfloat)d;
        }
        break;

        case double_type: {
            result.d = (jdouble)d;
        }
        break;
            
        break;

        case invalid_type:
        default:
        case void_type: {
            //bzero (&result, sizeof(jvalue));
            memset(&result, 0, sizeof(jvalue));
        }
        break;
    }
    return result;
}