aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-05-25 14:32:31 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2013-05-26 02:49:30 +0200
commitd7b5b7756849e8c056cedc602502d1d8af5a66bb (patch)
tree2545b0dba8b45ce2b439beaa28cb2dcf05a05f6f /src/qml
parent82be884e2f8fe38c23476cd7e03a410225dfd42f (diff)
Remove template argument from MemberAccessorGetterSetter class
Like this we don't need to have the call method inline. This is bad, as the method uses try/catch, and leads to compile errors with clang if the header is included from libs compiled without exceptions enabled. Change-Id: I801e21aafafc255836dfa19b81c84f884de0b395 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/qml/qqmllocale.cpp79
-rw-r--r--src/qml/qml/v4/qv4functionobject.cpp31
-rw-r--r--src/qml/qml/v4/qv4functionobject_p.h32
-rw-r--r--src/qml/qml/v4/qv4sequenceobject.cpp14
-rw-r--r--src/qml/qml/v4/qv4sequenceobject_p.h4
-rwxr-xr-xsrc/qml/qml/v4/v4classgen11
-rw-r--r--src/qml/qml/v8/qv8engine_p.h2
7 files changed, 96 insertions, 77 deletions
diff --git a/src/qml/qml/qqmllocale.cpp b/src/qml/qml/qqmllocale.cpp
index 6e149703db..5db82c9e96 100644
--- a/src/qml/qml/qqmllocale.cpp
+++ b/src/qml/qml/qqmllocale.cpp
@@ -67,35 +67,42 @@ public:
QLocale locale;
+ static QLocale &getThisLocale(QV4::SimpleCallContext *ctx) {
+ QQmlLocaleData *thisObject = ctx->thisObject.asObject()->asQmlLocale();
+ if (!thisObject)
+ ctx->throwTypeError();
+ return thisObject->locale;
+ }
+
static void initClass(QV4::ExecutionEngine *engine, const QV4::Value &obj);
- QV4::Value method_currencySymbol(QV4::SimpleCallContext *ctx);
- QV4::Value method_dateTimeFormat(QV4::SimpleCallContext *ctx);
- QV4::Value method_timeFormat(QV4::SimpleCallContext *ctx);
- QV4::Value method_dateFormat(QV4::SimpleCallContext *ctx);
- QV4::Value method_monthName(QV4::SimpleCallContext *ctx);
- QV4::Value method_standaloneMonthName(QV4::SimpleCallContext *ctx);
- QV4::Value method_dayName(QV4::SimpleCallContext *ctx);
- QV4::Value method_standaloneDayName(QV4::SimpleCallContext *ctx);
-
- QV4::Value method_get_firstDayOfWeek(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_measurementSystem(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_textDirection(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_weekDays(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_uiLanguages(QV4::SimpleCallContext *ctx);
-
- QV4::Value method_get_name(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_nativeLanguageName(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_nativeCountryName(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_decimalPoint(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_groupSeparator(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_percent(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_zeroDigit(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_negativeSign(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_positiveSign(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_exponential(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_amText(QV4::SimpleCallContext *ctx);
- QV4::Value method_get_pmText(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_currencySymbol(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_dateTimeFormat(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_timeFormat(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_dateFormat(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_monthName(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_standaloneMonthName(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_dayName(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_standaloneDayName(QV4::SimpleCallContext *ctx);
+
+ static QV4::Value method_get_firstDayOfWeek(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_measurementSystem(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_textDirection(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_weekDays(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_uiLanguages(QV4::SimpleCallContext *ctx);
+
+ static QV4::Value method_get_name(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_nativeLanguageName(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_nativeCountryName(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_decimalPoint(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_groupSeparator(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_percent(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_zeroDigit(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_negativeSign(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_positiveSign(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_exponential(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_amText(QV4::SimpleCallContext *ctx);
+ static QV4::Value method_get_pmText(QV4::SimpleCallContext *ctx);
private:
static void destroy(Managed *that)
@@ -498,26 +505,30 @@ QV4::Value QQmlNumberExtension::fromLocaleString(QV4::SimpleCallContext *ctx)
//--------------
// Locale object
-QV4::Value QQmlLocaleData::method_get_firstDayOfWeek(QV4::SimpleCallContext*)
+QV4::Value QQmlLocaleData::method_get_firstDayOfWeek(QV4::SimpleCallContext *ctx)
{
+ QLocale locale = getThisLocale(ctx);
int fdow = int(locale.firstDayOfWeek());
if (fdow == 7)
fdow = 0; // Qt::Sunday = 7, but Sunday is 0 in JS Date
return QV4::Value::fromInt32(fdow);
}
-QV4::Value QQmlLocaleData::method_get_measurementSystem(QV4::SimpleCallContext*)
+QV4::Value QQmlLocaleData::method_get_measurementSystem(QV4::SimpleCallContext *ctx)
{
+ QLocale locale = getThisLocale(ctx);
return QV4::Value::fromInt32(locale.measurementSystem());
}
-QV4::Value QQmlLocaleData::method_get_textDirection(QV4::SimpleCallContext*)
+QV4::Value QQmlLocaleData::method_get_textDirection(QV4::SimpleCallContext *ctx)
{
+ QLocale locale = getThisLocale(ctx);
return QV4::Value::fromInt32(locale.textDirection());
}
-QV4::Value QQmlLocaleData::method_get_weekDays(QV4::SimpleCallContext* ctx)
+QV4::Value QQmlLocaleData::method_get_weekDays(QV4::SimpleCallContext *ctx)
{
+ QLocale locale = getThisLocale(ctx);
QList<Qt::DayOfWeek> days = locale.weekdays();
QV4::ArrayObject *result = ctx->engine->newArrayObject();
@@ -535,6 +546,7 @@ QV4::Value QQmlLocaleData::method_get_weekDays(QV4::SimpleCallContext* ctx)
QV4::Value QQmlLocaleData::method_get_uiLanguages(QV4::SimpleCallContext *ctx)
{
+ QLocale locale = getThisLocale(ctx);
QStringList langs = locale.uiLanguages();
QV4::ArrayObject *result = ctx->engine->newArrayObject();
result->arrayReserve(langs.size());
@@ -547,6 +559,7 @@ QV4::Value QQmlLocaleData::method_get_uiLanguages(QV4::SimpleCallContext *ctx)
QV4::Value QQmlLocaleData::method_currencySymbol(QV4::SimpleCallContext *ctx)
{
+ QLocale locale = getThisLocale(ctx);
if (ctx->argumentCount > 1)
V4THROW_ERROR("Locale: currencySymbol(): Invalid arguments");
@@ -561,6 +574,7 @@ QV4::Value QQmlLocaleData::method_currencySymbol(QV4::SimpleCallContext *ctx)
#define LOCALE_FORMAT(FUNC) \
QV4::Value QQmlLocaleData::method_ ##FUNC (QV4::SimpleCallContext *ctx) { \
+ QLocale locale = getThisLocale(ctx); \
if (ctx->argumentCount > 1) \
V4THROW_ERROR("Locale: " #FUNC "(): Invalid arguments"); \
QLocale::FormatType format = QLocale::LongFormat;\
@@ -578,6 +592,7 @@ LOCALE_FORMAT(dateFormat)
// +1 added to idx because JS is 0-based, whereas QLocale months begin at 1.
#define LOCALE_FORMATTED_MONTHNAME(VARIABLE) \
QV4::Value QQmlLocaleData::method_ ## VARIABLE (QV4::SimpleCallContext *ctx) {\
+ QLocale locale = getThisLocale(ctx); \
if (ctx->argumentCount < 1 || ctx->argumentCount > 2) \
V4THROW_ERROR("Locale: " #VARIABLE "(): Invalid arguments"); \
QLocale::FormatType enumFormat = QLocale::LongFormat; \
@@ -602,6 +617,7 @@ QV4::Value QQmlLocaleData::method_ ## VARIABLE (QV4::SimpleCallContext *ctx) {\
// 0 -> 7 as Qt::Sunday is 7, but Sunday is 0 in JS Date
#define LOCALE_FORMATTED_DAYNAME(VARIABLE) \
QV4::Value QQmlLocaleData::method_ ## VARIABLE (QV4::SimpleCallContext *ctx) {\
+ QLocale locale = getThisLocale(ctx); \
if (ctx->argumentCount < 1 || ctx->argumentCount > 2) \
V4THROW_ERROR("Locale: " #VARIABLE "(): Invalid arguments"); \
QLocale::FormatType enumFormat = QLocale::LongFormat; \
@@ -631,6 +647,7 @@ LOCALE_FORMATTED_DAYNAME(standaloneDayName)
#define LOCALE_STRING_PROPERTY(VARIABLE) QV4::Value QQmlLocaleData::method_get_ ## VARIABLE (QV4::SimpleCallContext* ctx) \
{ \
+ QLocale locale = getThisLocale(ctx); \
return QV4::Value::fromString(ctx, locale. VARIABLE());\
}
diff --git a/src/qml/qml/v4/qv4functionobject.cpp b/src/qml/qml/v4/qv4functionobject.cpp
index 6f3254eae8..7fde827e6d 100644
--- a/src/qml/qml/v4/qv4functionobject.cpp
+++ b/src/qml/qml/v4/qv4functionobject.cpp
@@ -510,3 +510,34 @@ void BoundFunction::markObjects(Managed *that)
m->mark();
FunctionObject::markObjects(that);
}
+
+
+Value MemberAccessorGetterSetter::call(Managed *that, ExecutionContext *context, const Value &thisObject, Value *args, int argc)
+{
+ MemberAccessorGetterSetter *getterSetter = static_cast<MemberAccessorGetterSetter *>(that);
+
+ Object *thisO = thisObject.asObject();
+ if (!thisO || thisO->internalType() != getterSetter->managedType)
+ context->throwTypeError();
+
+ QV4::SimpleCallContext ctx;
+ ctx.initSimpleCallContext(context->engine);
+ ctx.strictMode = true;
+ ctx.thisObject = thisObject;
+ ctx.arguments = args;
+ ctx.argumentCount = argc;
+ context->engine->pushContext(&ctx);
+
+ QV4::Value result = QV4::Value::undefinedValue();
+ try {
+ result = getterSetter->getterSetter(&ctx);
+ } catch (QV4::Exception &ex) {
+ ex.partiallyUnwindContext(context);
+ throw;
+ }
+ context->engine->popContext();
+ return result;
+}
+
+
+DEFINE_MANAGED_VTABLE(MemberAccessorGetterSetter);
diff --git a/src/qml/qml/v4/qv4functionobject_p.h b/src/qml/qml/v4/qv4functionobject_p.h
index f9a7e596d9..7e43e41561 100644
--- a/src/qml/qml/v4/qv4functionobject_p.h
+++ b/src/qml/qml/v4/qv4functionobject_p.h
@@ -198,11 +198,10 @@ struct BoundFunction: FunctionObject {
static bool hasInstance(Managed *that, ExecutionContext *ctx, const Value &value);
};
-template <typename T>
class MemberAccessorGetterSetter : public FunctionObject
{
public:
- typedef Value (T::*GetterSetterFunction)(QV4::SimpleCallContext *ctx);
+ typedef Value (* GetterSetterFunction)(QV4::SimpleCallContext *ctx);
MemberAccessorGetterSetter(ExecutionContext *scope, GetterSetterFunction getterSetter, int managedType)
: FunctionObject(scope)
@@ -212,34 +211,7 @@ public:
this->getterSetter = getterSetter;
}
- static QV4::Value call(Managed *that, ExecutionContext *context, const QV4::Value &thisObject, QV4::Value *args, int argc)
- {
- MemberAccessorGetterSetter<T> *getterSetter = static_cast<MemberAccessorGetterSetter<T> *>(that);
-
- Object *thisO = thisObject.asObject();
- if (!thisO || thisO->internalType() != getterSetter->managedType)
- context->throwTypeError();
-
- T *o = static_cast<T *>(thisO);
-
- QV4::SimpleCallContext ctx;
- ctx.initSimpleCallContext(context->engine);
- ctx.strictMode = true;
- ctx.thisObject = thisObject;
- ctx.arguments = args;
- ctx.argumentCount = argc;
- context->engine->pushContext(&ctx);
-
- QV4::Value result = QV4::Value::undefinedValue();
- try {
- result = (o->* getterSetter->getterSetter)(&ctx);
- } catch (QV4::Exception &ex) {
- ex.partiallyUnwindContext(context);
- throw;
- }
- context->engine->popContext();
- return result;
- }
+ static QV4::Value call(Managed *that, ExecutionContext *context, const QV4::Value &thisObject, QV4::Value *args, int argc);
protected:
GetterSetterFunction getterSetter;
const int managedType;
diff --git a/src/qml/qml/v4/qv4sequenceobject.cpp b/src/qml/qml/v4/qv4sequenceobject.cpp
index ee36ea2742..16b9ce7cb3 100644
--- a/src/qml/qml/v4/qv4sequenceobject.cpp
+++ b/src/qml/qml/v4/qv4sequenceobject.cpp
@@ -498,10 +498,13 @@ QV4::Value SequencePrototype::method_sort(QV4::SimpleCallContext *ctx)
QV4::Value QQmlSequenceBase::method_get_length(QV4::SimpleCallContext* ctx) QV4_ANNOTATE(attributes QV4::Attr_ReadOnly)
{
+ QV4::Object *o = ctx->thisObject.asObject();
+ if (!o)
+ ctx->throwTypeError();
#define CALL_LENGTH_GETTER(SequenceElementType, SequenceElementTypeName, SequenceType, DefaultValue) \
- case QV4::Managed::Type_Qml##SequenceElementTypeName##List: return asQml##SequenceElementTypeName##List()->lengthGetter(ctx);
+ case QV4::Managed::Type_Qml##SequenceElementTypeName##List: return o->asQml##SequenceElementTypeName##List()->lengthGetter(ctx);
- switch (internalType()) {
+ switch (o->internalType()) {
FOREACH_QML_SEQUENCE_TYPE(CALL_LENGTH_GETTER)
default: QV4::Value::undefinedValue();
}
@@ -511,10 +514,13 @@ QV4::Value QQmlSequenceBase::method_get_length(QV4::SimpleCallContext* ctx) QV4_
QV4::Value QQmlSequenceBase::method_set_length(QV4::SimpleCallContext* ctx)
{
+ QV4::Object *o = ctx->thisObject.asObject();
+ if (!o)
+ ctx->throwTypeError();
#define CALL_LENGTH_SETTER(SequenceElementType, SequenceElementTypeName, SequenceType, DefaultValue) \
- case QV4::Managed::Type_Qml##SequenceElementTypeName##List: asQml##SequenceElementTypeName##List()->lengthSetter(ctx); break;
+ case QV4::Managed::Type_Qml##SequenceElementTypeName##List: o->asQml##SequenceElementTypeName##List()->lengthSetter(ctx); break;
- switch (internalType()) {
+ switch (o->internalType()) {
FOREACH_QML_SEQUENCE_TYPE(CALL_LENGTH_SETTER)
default: break;
}
diff --git a/src/qml/qml/v4/qv4sequenceobject_p.h b/src/qml/qml/v4/qv4sequenceobject_p.h
index 0461c296e7..d2514c66db 100644
--- a/src/qml/qml/v4/qv4sequenceobject_p.h
+++ b/src/qml/qml/v4/qv4sequenceobject_p.h
@@ -72,9 +72,9 @@ public:
void initClass(QV4::ExecutionEngine *engine);
- QV4::Value method_get_length(QV4::SimpleCallContext* ctx) QV4_ANNOTATE(attributes QV4::Attr_ReadOnly);
+ static QV4::Value method_get_length(QV4::SimpleCallContext* ctx) QV4_ANNOTATE(attributes QV4::Attr_ReadOnly);
- QV4::Value method_set_length(QV4::SimpleCallContext* ctx);
+ static QV4::Value method_set_length(QV4::SimpleCallContext* ctx);
};
struct QV4_JS_CLASS(SequencePrototype) : public QV4::Object
diff --git a/src/qml/qml/v4/v4classgen b/src/qml/qml/v4/v4classgen
index 8726717475..614124f036 100755
--- a/src/qml/qml/v4/v4classgen
+++ b/src/qml/qml/v4/v4classgen
@@ -89,9 +89,9 @@ class Accessor():
out.write(" QV4::FunctionObject *wrappedSetter = 0;\n")
out.write("\n")
if self.getter:
- out.write(" wrappedGetter = new (engine->memoryManager) %s_AccessorGetterSetter(engine->rootContext, &%s::%s, %s);\n" % (parsedClass.name, parsedClass.name, self.getter.fullMethodName(), managedType))
+ out.write(" wrappedGetter = new (engine->memoryManager) QV4::MemberAccessorGetterSetter(engine->rootContext, &%s::%s, %s);\n" % (parsedClass.name, self.getter.fullMethodName(), managedType))
if self.setter:
- out.write(" wrappedSetter = new (engine->memoryManager) %s_AccessorGetterSetter(engine->rootContext, &%s::%s, %s);\n" % (parsedClass.name, parsedClass.name, self.setter.fullMethodName(), managedType))
+ out.write(" wrappedSetter = new (engine->memoryManager) QV4::MemberAccessorGetterSetter(engine->rootContext, &%s::%s, %s);\n" % (parsedClass.name, self.setter.fullMethodName(), managedType))
attributes = ["QV4::Attr_Accessor"];
@@ -212,13 +212,6 @@ def generateBinding(out, parsedClass, vtableEntries):
out.write(" return new (scope->engine->memoryManager) %s(scope);\n" % ctorClass)
out.write("}\n\n")
- if len(parsedClass.accessors) > 0:
- typename = "%s_AccessorGetterSetter" % parsedClass.name
- out.write("typedef QV4::MemberAccessorGetterSetter<%s> %s;\n" % (parsedClass.name, typename))
- out.write("template<>\n")
- out.write("DEFINE_MANAGED_VTABLE(%s);" % typename)
- out.write("\n\n")
-
for method in parsedClass.methods.values():
if not method.isClassMethod():
method.generateMemberFunctionWrapper(out, parsedClass)
diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h
index 24435e2f05..283706778e 100644
--- a/src/qml/qml/v8/qv8engine_p.h
+++ b/src/qml/qml/v8/qv8engine_p.h
@@ -185,7 +185,7 @@ public:
QV8Engine *engine() const { return e; }
private:
friend class QV8QObjectWrapper;
- friend class QV4::QObjectMethod;
+ friend struct QV4::QObjectMethod;
QQmlV4Function();
QQmlV4Function(const QQmlV4Function &);
QQmlV4Function &operator=(const QQmlV4Function &);