aboutsummaryrefslogtreecommitdiffstats
path: root/qmljs_objects.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2012-12-13 00:53:04 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2012-12-12 16:07:18 +0100
commitc28f8c7b409fdd7214bb721c4192374786ec682f (patch)
tree7df99ac24c439f6349593d2723af5e40ace6ba0a /qmljs_objects.cpp
parent949303cd7da0edcab235bc19d5fad7d4af7eaed3 (diff)
Fix access rights for builtin properties
According to the spec all builtin properties have writable: true, enumerable: false and configurable:true by default. This is what is now being used. Some constants have all attributes set to false, and there is an extra method for setting these readonly properties. Change-Id: If5ba875bcc9f1644aa8a07a2d9b37716bf228e12 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'qmljs_objects.cpp')
-rw-r--r--qmljs_objects.cpp46
1 files changed, 38 insertions, 8 deletions
diff --git a/qmljs_objects.cpp b/qmljs_objects.cpp
index 12269f2030..8ab6e50178 100644
--- a/qmljs_objects.cpp
+++ b/qmljs_objects.cpp
@@ -95,13 +95,6 @@ void Object::__put__(ExecutionContext *ctx, const QString &name, const Value &va
__put__(ctx, ctx->engine->identifier(name), value);
}
-void Object::__put__(ExecutionContext *ctx, const QString &name, Value (*code)(ExecutionContext *), int count)
-{
- Q_UNUSED(count);
- String *nameStr = ctx->engine->newString(name);
- __put__(ctx, name, Value::fromObject(ctx->engine->newNativeFunction(ctx, nameStr, code)));
-}
-
Value Object::getValue(ExecutionContext *ctx, PropertyDescriptor *p) const
{
if (p->isData())
@@ -130,6 +123,43 @@ bool Object::inplaceBinOp(Value rhs, Value index, BinOp op, ExecutionContext *ct
return inplaceBinOp(rhs, name, op, ctx);
}
+void Object::defineDefaultProperty(String *name, Value value)
+{
+ if (!members)
+ members = new PropertyTable();
+ PropertyDescriptor *pd = members->insert(name);
+ pd->type = PropertyDescriptor::Data;
+ pd->writable = PropertyDescriptor::Set;
+ pd->enumberable = PropertyDescriptor::Unset;
+ pd->configurable = PropertyDescriptor::Set;
+ pd->value = value;
+}
+
+void Object::defineDefaultProperty(ExecutionContext *context, const QString &name, Value value)
+{
+ defineDefaultProperty(context->engine->identifier(name), value);
+}
+
+void Object::defineDefaultProperty(ExecutionContext *context, const QString &name, Value (*code)(ExecutionContext *), int count)
+{
+ Q_UNUSED(count);
+ // ### FIX count
+ String *s = context->engine->identifier(name);
+ defineDefaultProperty(s, Value::fromObject(context->engine->newNativeFunction(context, s, code)));
+}
+
+void Object::defineReadonlyProperty(ExecutionEngine *engine, const QString &name, Value value)
+{
+ if (!members)
+ members = new PropertyTable();
+ PropertyDescriptor *pd = members->insert(engine->identifier(name));
+ pd->type = PropertyDescriptor::Data;
+ pd->writable = PropertyDescriptor::Unset;
+ pd->enumberable = PropertyDescriptor::Unset;
+ pd->configurable = PropertyDescriptor::Unset;
+ pd->value = value;
+}
+
void Object::getCollectables(QVector<Object *> &objects)
{
if (prototype)
@@ -724,7 +754,7 @@ Value ErrorObject::__get__(ExecutionContext *ctx, String *name)
void ErrorObject::setNameProperty(ExecutionContext *ctx)
{
- __put__(ctx, QLatin1String("name"), Value::fromString(ctx, className()));
+ defineDefaultProperty(ctx, QLatin1String("name"), Value::fromString(ctx, className()));
}
void ErrorObject::getCollectables(QVector<Object *> &objects)