From: Lars Knoll Date: Tue, 11 Dec 2012 22:58:40 +0000 (+0100) Subject: Make the Math constants constant X-Git-Tag: upstream/5.2.1~669^2~659^2~721 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=381ce0e902254f39b411f3b21548943720e3db0c;p=platform%2Fupstream%2Fqtdeclarative.git Make the Math constants constant Mark the Math.pi etc. constants as readonly. Change-Id: I9224400ae48c7f21fc3b0478898c7c78aa7f45df Reviewed-by: Simon Hausmann --- diff --git a/qmljs_objects.cpp b/qmljs_objects.cpp index 6e0af63..c3aafae 100644 --- a/qmljs_objects.cpp +++ b/qmljs_objects.cpp @@ -359,6 +359,12 @@ bool Object::__defineOwnProperty__(ExecutionContext *ctx, String *name, Property return false; } +bool Object::__defineOwnProperty__(ExecutionContext *ctx, const QString &name, PropertyDescriptor *desc) +{ + return __defineOwnProperty__(ctx, ctx->engine->identifier(name), desc); +} + + Value Object::call(ExecutionContext *context, Value , Value *, int) { context->throwTypeError(); diff --git a/qmljs_objects.h b/qmljs_objects.h index 9daa841..51127f6 100644 --- a/qmljs_objects.h +++ b/qmljs_objects.h @@ -452,6 +452,7 @@ struct Object: Managed { virtual bool __hasProperty__(const ExecutionContext *ctx, String *name) const; virtual bool __delete__(ExecutionContext *ctx, String *name); virtual bool __defineOwnProperty__(ExecutionContext *ctx, String *name, PropertyDescriptor *desc); + bool __defineOwnProperty__(ExecutionContext *ctx, const QString &name, PropertyDescriptor *desc); virtual Value call(ExecutionContext *context, Value, Value *, int); diff --git a/qv4ecmaobjects.cpp b/qv4ecmaobjects.cpp index 7932257..c9b9593 100644 --- a/qv4ecmaobjects.cpp +++ b/qv4ecmaobjects.cpp @@ -2954,14 +2954,28 @@ Value ErrorPrototype::method_toString(ExecutionContext *ctx) // MathObject::MathObject(ExecutionContext *ctx) { - __put__(ctx, QStringLiteral("E"), Value::fromDouble(::exp(1.0))); - __put__(ctx, QStringLiteral("LN2"), Value::fromDouble(::log(2.0))); - __put__(ctx, QStringLiteral("LN10"), Value::fromDouble(::log(10.0))); - __put__(ctx, QStringLiteral("LOG2E"), Value::fromDouble(1.0/::log(2.0))); - __put__(ctx, QStringLiteral("LOG10E"), Value::fromDouble(1.0/::log(10.0))); - __put__(ctx, QStringLiteral("PI"), Value::fromDouble(qt_PI)); - __put__(ctx, QStringLiteral("SQRT1_2"), Value::fromDouble(::sqrt(0.5))); - __put__(ctx, QStringLiteral("SQRT2"), Value::fromDouble(::sqrt(2.0))); + PropertyDescriptor desc; + desc.type = PropertyDescriptor::Data; + desc.writable = PropertyDescriptor::Unset; + desc.enumberable = PropertyDescriptor::Unset; + desc.configurable = PropertyDescriptor::Unset; + + desc.value = Value::fromDouble(::exp(1.0)); + __defineOwnProperty__(ctx, QStringLiteral("E"), &desc); + desc.value = Value::fromDouble(::log(2.0)); + __defineOwnProperty__(ctx, QStringLiteral("LN2"), &desc); + desc.value = Value::fromDouble(::log(10.0)); + __defineOwnProperty__(ctx, QStringLiteral("LN10"), &desc); + desc.value = Value::fromDouble(1.0/::log(2.0)); + __defineOwnProperty__(ctx, QStringLiteral("LOG2E"), &desc); + desc.value = Value::fromDouble(1.0/::log(10.0)); + __defineOwnProperty__(ctx, QStringLiteral("LOG10E"), &desc); + desc.value = Value::fromDouble(qt_PI); + __defineOwnProperty__(ctx, QStringLiteral("PI"), &desc); + desc.value = Value::fromDouble(::sqrt(0.5)); + __defineOwnProperty__(ctx, QStringLiteral("SQRT1_2"), &desc); + desc.value = Value::fromDouble(::sqrt(2.0)); + __defineOwnProperty__(ctx, QStringLiteral("SQRT2"), &desc); __put__(ctx, QStringLiteral("abs"), method_abs, 1); __put__(ctx, QStringLiteral("acos"), method_acos, 1);