Make the Math constants constant
authorLars Knoll <lars.knoll@digia.com>
Tue, 11 Dec 2012 22:58:40 +0000 (23:58 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Tue, 11 Dec 2012 14:08:28 +0000 (15:08 +0100)
Mark the Math.pi etc. constants as readonly.

Change-Id: I9224400ae48c7f21fc3b0478898c7c78aa7f45df
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
qmljs_objects.cpp
qmljs_objects.h
qv4ecmaobjects.cpp

index 6e0af63..c3aafae 100644 (file)
@@ -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();
index 9daa841..51127f6 100644 (file)
@@ -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);
 
index 7932257..c9b9593 100644 (file)
@@ -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);