2012-10-12 08:12:24 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2015-01-28 11:55:39 +00:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing/
|
2012-10-12 08:12:24 +00:00
|
|
|
**
|
2013-06-24 11:50:51 +00:00
|
|
|
** This file is part of the QtQml module of the Qt Toolkit.
|
2012-10-12 08:12:24 +00:00
|
|
|
**
|
2014-08-22 06:13:59 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL21$
|
2012-10-12 08:12:24 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 11:55:39 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see http://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at http://www.qt.io/contact-us.
|
2012-10-12 08:12:24 +00:00
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-08-22 06:13:59 +00:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-12 08:12:24 +00:00
|
|
|
**
|
2015-01-28 11:55:39 +00:00
|
|
|
** As a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2012-10-12 08:12:24 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-04-15 09:50:16 +00:00
|
|
|
#include "qv4object_p.h"
|
2013-03-05 11:49:35 +00:00
|
|
|
#include "qv4jsir_p.h"
|
2012-11-19 12:15:25 +00:00
|
|
|
#include "qv4isel_p.h"
|
2013-04-15 09:50:16 +00:00
|
|
|
#include "qv4objectproto_p.h"
|
|
|
|
#include "qv4stringobject_p.h"
|
|
|
|
#include "qv4argumentsobject_p.h"
|
2015-02-12 20:16:42 +00:00
|
|
|
#include <private/qv4mm_p.h>
|
2013-04-19 18:25:41 +00:00
|
|
|
#include "qv4lookup_p.h"
|
2013-09-05 11:22:23 +00:00
|
|
|
#include "qv4scopedvalue_p.h"
|
2014-03-31 13:48:02 +00:00
|
|
|
#include "qv4memberdata_p.h"
|
2014-07-25 15:44:14 +00:00
|
|
|
#include "qv4objectiterator_p.h"
|
2014-11-12 19:07:27 +00:00
|
|
|
#include "qv4identifier_p.h"
|
2015-02-14 21:46:41 +00:00
|
|
|
#include "qv4string_p.h"
|
2012-11-16 21:21:34 +00:00
|
|
|
|
2013-05-22 09:58:16 +00:00
|
|
|
#include <stdint.h>
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2013-04-19 11:03:42 +00:00
|
|
|
using namespace QV4;
|
2012-05-04 13:28:04 +00:00
|
|
|
|
2014-04-04 10:22:00 +00:00
|
|
|
DEFINE_OBJECT_VTABLE(Object);
|
2013-01-03 21:17:46 +00:00
|
|
|
|
2014-11-24 14:38:41 +00:00
|
|
|
Heap::Object::Object(InternalClass *internalClass, QV4::Object *prototype)
|
2015-01-13 20:49:09 +00:00
|
|
|
: internalClass(internalClass),
|
2014-11-18 20:22:44 +00:00
|
|
|
prototype(prototype ? prototype->d() : 0)
|
2014-05-08 12:35:30 +00:00
|
|
|
{
|
|
|
|
if (internalClass->size) {
|
|
|
|
Scope scope(internalClass->engine);
|
|
|
|
ScopedObject o(scope, this);
|
2014-11-01 20:44:57 +00:00
|
|
|
o->ensureMemberIndex(internalClass->engine, internalClass->size);
|
2014-05-08 12:35:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-29 12:31:32 +00:00
|
|
|
bool Object::setPrototype(Object *proto)
|
|
|
|
{
|
2014-12-02 13:04:44 +00:00
|
|
|
Heap::Object *pp = proto ? proto->d() : 0;
|
2013-08-29 12:31:32 +00:00
|
|
|
while (pp) {
|
2014-11-24 14:38:41 +00:00
|
|
|
if (pp == d())
|
2013-08-29 12:31:32 +00:00
|
|
|
return false;
|
2014-11-24 14:38:41 +00:00
|
|
|
pp = pp->prototype;
|
2013-08-29 12:31:32 +00:00
|
|
|
}
|
2014-12-02 13:04:44 +00:00
|
|
|
d()->prototype = proto ? proto->d() : 0;
|
2013-08-29 12:31:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-15 10:36:57 +00:00
|
|
|
void Object::put(ExecutionEngine *engine, const QString &name, const Value &value)
|
2012-05-14 14:03:10 +00:00
|
|
|
{
|
2014-11-12 12:32:41 +00:00
|
|
|
Scope scope(engine);
|
|
|
|
ScopedString n(scope, engine->newString(name));
|
2014-12-01 15:13:20 +00:00
|
|
|
put(n, value);
|
2012-05-14 14:03:10 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 10:36:57 +00:00
|
|
|
ReturnedValue Object::getValue(const Value &thisObject, const Property *p, PropertyAttributes attrs)
|
2012-11-10 22:35:06 +00:00
|
|
|
{
|
2013-04-10 08:46:23 +00:00
|
|
|
if (!attrs.isAccessor())
|
2013-09-11 14:28:17 +00:00
|
|
|
return p->value.asReturnedValue();
|
2014-12-03 09:42:07 +00:00
|
|
|
if (!p->getter())
|
2013-09-26 20:07:27 +00:00
|
|
|
return Encode::undefined();
|
2012-11-10 22:35:06 +00:00
|
|
|
|
2014-12-03 09:42:07 +00:00
|
|
|
Scope scope(p->getter()->internalClass->engine);
|
|
|
|
ScopedFunctionObject getter(scope, p->getter());
|
2014-11-28 09:19:11 +00:00
|
|
|
ScopedCallData callData(scope);
|
2015-01-15 10:36:57 +00:00
|
|
|
callData->thisObject = thisObject;
|
2013-09-11 14:28:17 +00:00
|
|
|
return getter->call(callData);
|
2013-03-07 11:25:59 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 10:36:57 +00:00
|
|
|
void Object::putValue(Property *pd, PropertyAttributes attrs, const Value &value)
|
2013-02-12 15:23:52 +00:00
|
|
|
{
|
2014-04-05 18:23:20 +00:00
|
|
|
if (internalClass()->engine->hasException)
|
2013-10-22 11:26:08 +00:00
|
|
|
return;
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs.isAccessor()) {
|
2014-12-03 09:42:07 +00:00
|
|
|
if (Heap::FunctionObject *set = pd->setter()) {
|
|
|
|
Scope scope(set->internalClass->engine);
|
|
|
|
ScopedFunctionObject setter(scope, set);
|
2013-09-11 12:36:01 +00:00
|
|
|
ScopedCallData callData(scope, 1);
|
2015-01-15 10:36:57 +00:00
|
|
|
callData->args[0] = value;
|
2013-09-26 20:07:27 +00:00
|
|
|
callData->thisObject = this;
|
2014-12-03 09:42:07 +00:00
|
|
|
setter->call(callData);
|
2013-04-10 08:46:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-02-12 15:23:52 +00:00
|
|
|
goto reject;
|
2013-03-07 11:55:02 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
if (!attrs.isWritable())
|
2013-03-07 11:55:02 +00:00
|
|
|
goto reject;
|
|
|
|
|
2015-01-15 10:36:57 +00:00
|
|
|
pd->value = value;
|
2013-03-07 11:55:02 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
reject:
|
2014-11-28 08:31:10 +00:00
|
|
|
if (engine()->currentContext()->strictMode)
|
2014-07-28 08:07:57 +00:00
|
|
|
engine()->throwTypeError();
|
2013-03-07 11:55:02 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 10:36:57 +00:00
|
|
|
void Object::defineDefaultProperty(const QString &name, const Value &value)
|
2012-12-12 23:53:04 +00:00
|
|
|
{
|
2013-09-18 10:31:55 +00:00
|
|
|
ExecutionEngine *e = engine();
|
|
|
|
Scope scope(e);
|
|
|
|
ScopedString s(scope, e->newIdentifier(name));
|
2014-12-01 15:13:20 +00:00
|
|
|
defineDefaultProperty(s, value);
|
2012-12-12 23:53:04 +00:00
|
|
|
}
|
|
|
|
|
2013-11-03 14:23:05 +00:00
|
|
|
void Object::defineDefaultProperty(const QString &name, ReturnedValue (*code)(CallContext *), int argumentCount)
|
2013-05-02 19:37:20 +00:00
|
|
|
{
|
2013-09-18 10:31:55 +00:00
|
|
|
ExecutionEngine *e = engine();
|
|
|
|
Scope scope(e);
|
|
|
|
ScopedString s(scope, e->newIdentifier(name));
|
2014-11-28 09:05:24 +00:00
|
|
|
ScopedContext global(scope, e->rootContext());
|
2014-12-31 18:42:15 +00:00
|
|
|
ScopedFunctionObject function(scope, BuiltinFunction::create(global, s, code));
|
2015-04-26 07:22:17 +00:00
|
|
|
function->defineReadonlyProperty(e->id_length(), Primitive::fromInt32(argumentCount));
|
2014-12-01 15:13:20 +00:00
|
|
|
defineDefaultProperty(s, function);
|
2013-05-02 19:37:20 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 11:33:24 +00:00
|
|
|
void Object::defineDefaultProperty(String *name, ReturnedValue (*code)(CallContext *), int argumentCount)
|
2013-09-18 13:34:13 +00:00
|
|
|
{
|
|
|
|
ExecutionEngine *e = engine();
|
|
|
|
Scope scope(e);
|
2014-11-28 09:05:24 +00:00
|
|
|
ScopedContext global(scope, e->rootContext());
|
2014-12-31 18:42:15 +00:00
|
|
|
ScopedFunctionObject function(scope, BuiltinFunction::create(global, name, code));
|
2015-04-26 07:22:17 +00:00
|
|
|
function->defineReadonlyProperty(e->id_length(), Primitive::fromInt32(argumentCount));
|
2013-09-26 11:05:25 +00:00
|
|
|
defineDefaultProperty(name, function);
|
2013-09-18 13:34:13 +00:00
|
|
|
}
|
|
|
|
|
2013-11-03 14:23:05 +00:00
|
|
|
void Object::defineAccessorProperty(const QString &name, ReturnedValue (*getter)(CallContext *), ReturnedValue (*setter)(CallContext *))
|
2013-06-10 14:16:40 +00:00
|
|
|
{
|
2013-09-18 10:31:55 +00:00
|
|
|
ExecutionEngine *e = engine();
|
|
|
|
Scope scope(e);
|
2014-12-31 18:34:52 +00:00
|
|
|
ScopedString s(scope, e->newIdentifier(name));
|
2014-12-01 15:13:20 +00:00
|
|
|
defineAccessorProperty(s, getter, setter);
|
2013-06-10 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 11:33:24 +00:00
|
|
|
void Object::defineAccessorProperty(String *name, ReturnedValue (*getter)(CallContext *), ReturnedValue (*setter)(CallContext *))
|
2013-06-10 14:16:40 +00:00
|
|
|
{
|
|
|
|
ExecutionEngine *v4 = engine();
|
2014-02-06 11:47:43 +00:00
|
|
|
QV4::Scope scope(v4);
|
|
|
|
ScopedProperty p(scope);
|
2014-11-28 09:05:24 +00:00
|
|
|
ScopedContext global(scope, scope.engine->rootContext());
|
2014-12-01 15:13:20 +00:00
|
|
|
p->setGetter(ScopedFunctionObject(scope, (getter ? BuiltinFunction::create(global, name, getter) : 0)));
|
|
|
|
p->setSetter(ScopedFunctionObject(scope, (setter ? BuiltinFunction::create(global, name, setter) : 0)));
|
2014-01-07 15:10:00 +00:00
|
|
|
insertMember(name, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
|
2013-06-10 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 10:36:57 +00:00
|
|
|
void Object::defineReadonlyProperty(const QString &name, const Value &value)
|
2013-01-10 15:06:43 +00:00
|
|
|
{
|
2013-09-18 10:31:55 +00:00
|
|
|
QV4::ExecutionEngine *e = engine();
|
|
|
|
Scope scope(e);
|
|
|
|
ScopedString s(scope, e->newIdentifier(name));
|
2014-12-01 15:13:20 +00:00
|
|
|
defineReadonlyProperty(s, value);
|
2013-01-10 15:06:43 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 10:36:57 +00:00
|
|
|
void Object::defineReadonlyProperty(String *name, const Value &value)
|
2012-12-12 23:53:04 +00:00
|
|
|
{
|
2014-01-07 15:10:00 +00:00
|
|
|
insertMember(name, value, Attr_ReadOnly);
|
2012-12-12 23:53:04 +00:00
|
|
|
}
|
|
|
|
|
2014-11-01 22:04:20 +00:00
|
|
|
void Object::markObjects(Heap::Base *that, ExecutionEngine *e)
|
2012-12-04 12:40:18 +00:00
|
|
|
{
|
2014-11-01 22:50:32 +00:00
|
|
|
Heap::Object *o = static_cast<Heap::Object *>(that);
|
2012-12-04 12:40:18 +00:00
|
|
|
|
2014-11-01 20:44:57 +00:00
|
|
|
if (o->memberData)
|
|
|
|
o->memberData->mark(e);
|
2014-11-01 19:56:47 +00:00
|
|
|
if (o->arrayData)
|
|
|
|
o->arrayData->mark(e);
|
2014-11-24 14:38:41 +00:00
|
|
|
if (o->prototype)
|
|
|
|
o->prototype->mark(e);
|
2012-12-04 12:40:18 +00:00
|
|
|
}
|
|
|
|
|
2013-08-16 08:11:20 +00:00
|
|
|
void Object::ensureMemberIndex(uint idx)
|
2013-02-02 08:52:27 +00:00
|
|
|
{
|
2014-11-01 20:44:57 +00:00
|
|
|
d()->memberData = MemberData::reallocate(engine(), d()->memberData, idx);
|
2013-08-16 08:11:20 +00:00
|
|
|
}
|
|
|
|
|
2014-12-15 07:46:38 +00:00
|
|
|
void Object::insertMember(String *s, const Property *p, PropertyAttributes attributes)
|
2013-08-16 08:11:20 +00:00
|
|
|
{
|
|
|
|
uint idx;
|
2014-05-07 11:33:24 +00:00
|
|
|
InternalClass::addMember(this, s, attributes, &idx);
|
2013-08-16 08:11:20 +00:00
|
|
|
|
|
|
|
|
2014-04-05 18:23:20 +00:00
|
|
|
ensureMemberIndex(internalClass()->size);
|
2013-08-16 08:11:20 +00:00
|
|
|
|
2014-03-06 11:06:36 +00:00
|
|
|
if (attributes.isAccessor()) {
|
2014-03-10 14:18:54 +00:00
|
|
|
Property *pp = propertyAt(idx);
|
2014-12-15 07:46:38 +00:00
|
|
|
pp->value = p->value;
|
|
|
|
pp->set = p->set;
|
2014-03-06 11:06:36 +00:00
|
|
|
} else {
|
2014-12-15 07:46:38 +00:00
|
|
|
d()->memberData->data[idx] = p->value;
|
2014-03-06 11:06:36 +00:00
|
|
|
}
|
2013-02-02 08:52:27 +00:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:56:15 +00:00
|
|
|
// Section 8.12.1
|
2015-04-30 21:29:28 +00:00
|
|
|
void Object::getOwnProperty(String *name, PropertyAttributes *attrs, Property *p)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-01-10 16:33:06 +00:00
|
|
|
uint idx = name->asArrayIndex();
|
2013-02-12 10:05:18 +00:00
|
|
|
if (idx != UINT_MAX)
|
2015-04-30 21:29:28 +00:00
|
|
|
return getOwnProperty(idx, attrs, p);
|
2013-01-10 16:33:06 +00:00
|
|
|
|
2014-04-05 18:23:20 +00:00
|
|
|
uint member = internalClass()->find(name);
|
2013-04-10 08:46:23 +00:00
|
|
|
if (member < UINT_MAX) {
|
2015-04-30 21:29:28 +00:00
|
|
|
*attrs = internalClass()->propertyData[member];
|
|
|
|
if (p)
|
|
|
|
p->copy(propertyAt(member), *attrs);
|
|
|
|
return;
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
2013-02-10 21:22:53 +00:00
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs)
|
|
|
|
*attrs = Attr_Invalid;
|
2015-04-30 21:29:28 +00:00
|
|
|
return;
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2015-04-30 21:29:28 +00:00
|
|
|
void Object::getOwnProperty(uint index, PropertyAttributes *attrs, Property *p)
|
2013-01-10 14:11:32 +00:00
|
|
|
{
|
2015-04-30 21:29:28 +00:00
|
|
|
Property *pd = arrayData() ? arrayData()->getProperty(index) : 0;
|
|
|
|
if (pd) {
|
|
|
|
*attrs = arrayData()->attributes(index);
|
|
|
|
if (p)
|
|
|
|
p->copy(pd, *attrs);
|
|
|
|
return;
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
|
|
|
if (isStringObject()) {
|
2015-04-30 21:29:28 +00:00
|
|
|
*attrs = Attr_NotConfigurable|Attr_NotWritable;
|
|
|
|
if (p)
|
2015-04-30 21:50:50 +00:00
|
|
|
p->value = static_cast<StringObject *>(this)->getIndex(index);
|
2015-04-30 21:29:28 +00:00
|
|
|
return;
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
2013-01-16 12:34:46 +00:00
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs)
|
|
|
|
*attrs = Attr_Invalid;
|
2015-04-30 21:29:28 +00:00
|
|
|
return;
|
2013-01-10 14:11:32 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
// Section 8.12.2
|
2014-05-07 11:33:24 +00:00
|
|
|
Property *Object::__getPropertyDescriptor__(String *name, PropertyAttributes *attrs) const
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2015-04-30 21:50:50 +00:00
|
|
|
Q_ASSERT(name->asArrayIndex() == UINT_MAX);
|
2012-12-18 08:06:03 +00:00
|
|
|
|
2014-11-27 07:56:03 +00:00
|
|
|
const Heap::Object *o = d();
|
2012-12-17 08:52:04 +00:00
|
|
|
while (o) {
|
2014-11-27 07:56:03 +00:00
|
|
|
uint idx = o->internalClass->find(name);
|
2013-04-10 08:46:23 +00:00
|
|
|
if (idx < UINT_MAX) {
|
|
|
|
if (attrs)
|
2014-11-27 07:56:03 +00:00
|
|
|
*attrs = o->internalClass->propertyData[idx];
|
2014-11-01 20:44:57 +00:00
|
|
|
return const_cast<Property *>(o->propertyAt(idx));
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
2013-02-10 21:22:53 +00:00
|
|
|
|
2014-11-27 07:56:03 +00:00
|
|
|
o = o->prototype;
|
2012-12-17 08:52:04 +00:00
|
|
|
}
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs)
|
|
|
|
*attrs = Attr_Invalid;
|
2012-04-16 19:23:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-12 12:43:58 +00:00
|
|
|
Property *Object::__getPropertyDescriptor__(uint index, PropertyAttributes *attrs) const
|
2013-01-10 14:11:32 +00:00
|
|
|
{
|
2014-11-27 07:56:03 +00:00
|
|
|
const Heap::Object *o = d();
|
2013-01-10 14:11:32 +00:00
|
|
|
while (o) {
|
2014-11-27 07:56:03 +00:00
|
|
|
Property *p = o->arrayData ? o->arrayData->getProperty(index) : 0;
|
2013-12-16 08:16:57 +00:00
|
|
|
if (p) {
|
2015-04-30 21:50:50 +00:00
|
|
|
*attrs = o->arrayData->attributes(index);
|
2014-01-07 14:36:28 +00:00
|
|
|
return p;
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
2015-01-10 16:55:29 +00:00
|
|
|
if (o->vtable->type == Type_StringObject) {
|
2015-04-30 21:50:50 +00:00
|
|
|
if (index < static_cast<const Heap::StringObject *>(o)->length()) {
|
|
|
|
// this is an evil hack, but it works, as the method is only ever called from putIndexed,
|
|
|
|
// where we don't use the returned pointer there for non writable attributes
|
|
|
|
*attrs = (Attr_NotWritable|Attr_NotConfigurable);
|
|
|
|
return reinterpret_cast<Property *>(0x1);
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
2013-01-16 12:34:46 +00:00
|
|
|
}
|
2014-11-27 07:56:03 +00:00
|
|
|
o = o->prototype;
|
2013-01-10 14:11:32 +00:00
|
|
|
}
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs)
|
|
|
|
*attrs = Attr_Invalid;
|
2013-01-10 14:11:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-07 11:33:24 +00:00
|
|
|
bool Object::hasProperty(String *name) const
|
2013-05-13 14:11:35 +00:00
|
|
|
{
|
2014-01-08 11:46:53 +00:00
|
|
|
uint idx = name->asArrayIndex();
|
|
|
|
if (idx != UINT_MAX)
|
|
|
|
return hasProperty(idx);
|
2013-08-08 10:52:56 +00:00
|
|
|
|
2014-11-27 07:56:03 +00:00
|
|
|
Scope scope(engine());
|
|
|
|
ScopedObject o(scope, d());
|
2013-08-08 10:52:56 +00:00
|
|
|
while (o) {
|
2014-01-08 11:46:53 +00:00
|
|
|
if (o->hasOwnProperty(name))
|
2013-08-08 10:52:56 +00:00
|
|
|
return true;
|
2014-01-08 11:46:53 +00:00
|
|
|
|
2013-08-29 12:31:32 +00:00
|
|
|
o = o->prototype();
|
2013-08-08 10:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-08 11:46:53 +00:00
|
|
|
bool Object::hasProperty(uint index) const
|
2013-08-08 10:52:56 +00:00
|
|
|
{
|
2014-11-27 07:56:03 +00:00
|
|
|
Scope scope(engine());
|
|
|
|
ScopedObject o(scope, d());
|
2013-08-08 10:52:56 +00:00
|
|
|
while (o) {
|
2014-01-08 11:46:53 +00:00
|
|
|
if (o->hasOwnProperty(index))
|
|
|
|
return true;
|
|
|
|
|
2013-08-29 12:31:32 +00:00
|
|
|
o = o->prototype();
|
2013-08-08 10:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2013-05-13 14:11:35 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 11:33:24 +00:00
|
|
|
bool Object::hasOwnProperty(String *name) const
|
2014-01-04 21:32:13 +00:00
|
|
|
{
|
2014-01-08 11:46:53 +00:00
|
|
|
uint idx = name->asArrayIndex();
|
|
|
|
if (idx != UINT_MAX)
|
|
|
|
return hasOwnProperty(idx);
|
|
|
|
|
2014-04-05 18:23:20 +00:00
|
|
|
if (internalClass()->find(name) < UINT_MAX)
|
2014-01-08 11:46:53 +00:00
|
|
|
return true;
|
|
|
|
if (!query(name).isEmpty())
|
|
|
|
return true;
|
|
|
|
return false;
|
2014-01-04 21:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Object::hasOwnProperty(uint index) const
|
|
|
|
{
|
2014-10-27 07:54:26 +00:00
|
|
|
if (arrayData() && !arrayData()->isEmpty(index))
|
2014-01-08 11:46:53 +00:00
|
|
|
return true;
|
2014-11-17 19:55:41 +00:00
|
|
|
|
2014-01-08 11:46:53 +00:00
|
|
|
if (isStringObject()) {
|
2015-02-13 11:19:04 +00:00
|
|
|
String *s = static_cast<const StringObject *>(this)->d()->value.as<String>();
|
2014-05-09 13:06:29 +00:00
|
|
|
if (index < (uint)s->d()->length())
|
2014-01-08 11:46:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!queryIndexed(index).isEmpty())
|
|
|
|
return true;
|
|
|
|
return false;
|
2014-01-04 21:32:13 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 12:39:20 +00:00
|
|
|
ReturnedValue Object::construct(const Managed *m, CallData *)
|
2014-01-20 12:51:00 +00:00
|
|
|
{
|
2015-02-13 12:39:20 +00:00
|
|
|
return static_cast<const Object *>(m)->engine()->throwTypeError();
|
2014-01-20 12:51:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 12:39:20 +00:00
|
|
|
ReturnedValue Object::call(const Managed *m, CallData *)
|
2014-01-20 12:51:00 +00:00
|
|
|
{
|
2015-02-13 12:39:20 +00:00
|
|
|
return static_cast<const Object *>(m)->engine()->throwTypeError();
|
2014-01-20 12:51:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 09:42:01 +00:00
|
|
|
ReturnedValue Object::get(const Managed *m, String *name, bool *hasProperty)
|
2013-03-07 11:55:02 +00:00
|
|
|
{
|
2015-02-13 09:42:01 +00:00
|
|
|
return static_cast<const Object *>(m)->internalGet(name, hasProperty);
|
2013-03-07 11:55:02 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 09:42:01 +00:00
|
|
|
ReturnedValue Object::getIndexed(const Managed *m, uint index, bool *hasProperty)
|
2013-03-07 11:55:02 +00:00
|
|
|
{
|
2015-02-13 09:42:01 +00:00
|
|
|
return static_cast<const Object *>(m)->internalGetIndexed(index, hasProperty);
|
2013-03-07 11:55:02 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 10:36:57 +00:00
|
|
|
void Object::put(Managed *m, String *name, const Value &value)
|
2013-03-07 11:55:02 +00:00
|
|
|
{
|
2013-09-18 14:36:02 +00:00
|
|
|
static_cast<Object *>(m)->internalPut(name, value);
|
2013-03-07 11:55:02 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 10:36:57 +00:00
|
|
|
void Object::putIndexed(Managed *m, uint index, const Value &value)
|
2013-03-07 11:55:02 +00:00
|
|
|
{
|
2013-06-21 21:42:08 +00:00
|
|
|
static_cast<Object *>(m)->internalPutIndexed(index, value);
|
2013-03-07 11:55:02 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 11:33:24 +00:00
|
|
|
PropertyAttributes Object::query(const Managed *m, String *name)
|
2013-03-07 11:55:02 +00:00
|
|
|
{
|
2013-04-10 08:46:23 +00:00
|
|
|
uint idx = name->asArrayIndex();
|
|
|
|
if (idx != UINT_MAX)
|
2013-06-10 14:29:53 +00:00
|
|
|
return queryIndexed(m, idx);
|
2013-04-10 08:46:23 +00:00
|
|
|
|
2013-06-10 14:29:53 +00:00
|
|
|
const Object *o = static_cast<const Object *>(m);
|
2014-05-07 11:33:24 +00:00
|
|
|
idx = o->internalClass()->find(name);
|
2013-08-08 10:52:56 +00:00
|
|
|
if (idx < UINT_MAX)
|
2014-04-05 18:23:20 +00:00
|
|
|
return o->internalClass()->propertyData[idx];
|
2013-04-10 08:46:23 +00:00
|
|
|
|
|
|
|
return Attr_Invalid;
|
2013-03-07 11:55:02 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 14:29:53 +00:00
|
|
|
PropertyAttributes Object::queryIndexed(const Managed *m, uint index)
|
2013-03-07 11:55:02 +00:00
|
|
|
{
|
2013-06-10 14:29:53 +00:00
|
|
|
const Object *o = static_cast<const Object *>(m);
|
2014-11-17 19:55:41 +00:00
|
|
|
if (o->arrayData() && !o->arrayData()->isEmpty(index))
|
2014-04-05 18:47:36 +00:00
|
|
|
return o->arrayData()->attributes(index);
|
2013-12-16 08:16:57 +00:00
|
|
|
|
2013-08-08 10:52:56 +00:00
|
|
|
if (o->isStringObject()) {
|
2015-02-13 11:19:04 +00:00
|
|
|
String *s = static_cast<const StringObject *>(o)->d()->value.as<String>();
|
2014-05-09 13:06:29 +00:00
|
|
|
if (index < (uint)s->d()->length())
|
2014-01-08 13:57:07 +00:00
|
|
|
return (Attr_NotWritable|Attr_NotConfigurable);
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
|
|
|
return Attr_Invalid;
|
2013-03-07 11:55:02 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 11:33:24 +00:00
|
|
|
bool Object::deleteProperty(Managed *m, String *name)
|
2013-03-07 11:55:02 +00:00
|
|
|
{
|
2013-06-21 18:33:39 +00:00
|
|
|
return static_cast<Object *>(m)->internalDeleteProperty(name);
|
2013-03-07 11:55:02 +00:00
|
|
|
}
|
|
|
|
|
2013-06-21 18:33:39 +00:00
|
|
|
bool Object::deleteIndexedProperty(Managed *m, uint index)
|
2013-03-07 11:55:02 +00:00
|
|
|
{
|
2013-06-21 18:33:39 +00:00
|
|
|
return static_cast<Object *>(m)->internalDeleteIndexedProperty(index);
|
2013-03-07 11:55:02 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 12:39:20 +00:00
|
|
|
ReturnedValue Object::getLookup(const Managed *m, Lookup *l)
|
2013-04-19 18:25:41 +00:00
|
|
|
{
|
2015-02-13 12:39:20 +00:00
|
|
|
const Object *o = static_cast<const Object *>(m);
|
2013-04-19 18:25:41 +00:00
|
|
|
PropertyAttributes attrs;
|
2014-01-07 15:47:44 +00:00
|
|
|
ReturnedValue v = l->lookup(o, &attrs);
|
|
|
|
if (v != Primitive::emptyValue().asReturnedValue()) {
|
2013-04-19 18:25:41 +00:00
|
|
|
if (attrs.isData()) {
|
|
|
|
if (l->level == 0)
|
|
|
|
l->getter = Lookup::getter0;
|
|
|
|
else if (l->level == 1)
|
|
|
|
l->getter = Lookup::getter1;
|
|
|
|
else if (l->level == 2)
|
|
|
|
l->getter = Lookup::getter2;
|
2014-03-13 20:28:30 +00:00
|
|
|
else
|
|
|
|
l->getter = Lookup::getterFallback;
|
2014-01-07 15:47:44 +00:00
|
|
|
return v;
|
2013-04-19 18:25:41 +00:00
|
|
|
} else {
|
|
|
|
if (l->level == 0)
|
|
|
|
l->getter = Lookup::getterAccessor0;
|
|
|
|
else if (l->level == 1)
|
|
|
|
l->getter = Lookup::getterAccessor1;
|
|
|
|
else if (l->level == 2)
|
|
|
|
l->getter = Lookup::getterAccessor2;
|
2014-03-13 20:28:30 +00:00
|
|
|
else
|
|
|
|
l->getter = Lookup::getterFallback;
|
2014-01-07 15:47:44 +00:00
|
|
|
return v;
|
2013-04-19 18:25:41 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-26 20:07:27 +00:00
|
|
|
return Encode::undefined();
|
2013-04-19 18:25:41 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 10:36:57 +00:00
|
|
|
void Object::setLookup(Managed *m, Lookup *l, const Value &value)
|
2013-04-19 18:25:41 +00:00
|
|
|
{
|
2015-01-11 15:30:29 +00:00
|
|
|
Scope scope(static_cast<Object *>(m)->engine());
|
2013-09-18 14:36:02 +00:00
|
|
|
ScopedObject o(scope, static_cast<Object *>(m));
|
2014-11-28 08:31:10 +00:00
|
|
|
ScopedString name(scope, scope.engine->currentContext()->compilationUnit->runtimeStrings[l->nameIndex]);
|
2013-04-19 18:25:41 +00:00
|
|
|
|
2014-04-05 18:23:20 +00:00
|
|
|
InternalClass *c = o->internalClass();
|
2014-11-12 15:07:56 +00:00
|
|
|
uint idx = c->find(name);
|
2014-11-01 22:59:06 +00:00
|
|
|
if (!o->isArrayObject() || idx != Heap::ArrayObject::LengthPropertyIndex) {
|
2014-04-05 18:23:20 +00:00
|
|
|
if (idx != UINT_MAX && o->internalClass()->propertyData[idx].isData() && o->internalClass()->propertyData[idx].isWritable()) {
|
|
|
|
l->classList[0] = o->internalClass();
|
2013-04-19 18:25:41 +00:00
|
|
|
l->index = idx;
|
|
|
|
l->setter = Lookup::setter0;
|
2015-01-15 10:36:57 +00:00
|
|
|
o->memberData()->data[idx] = value;
|
2013-04-19 18:25:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (idx != UINT_MAX) {
|
2014-04-05 18:23:20 +00:00
|
|
|
o->putValue(o->propertyAt(idx), o->internalClass()->propertyData[idx], value);
|
2013-04-19 18:25:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 15:07:56 +00:00
|
|
|
o->put(name, value);
|
2013-08-16 08:11:20 +00:00
|
|
|
|
2014-04-05 18:23:20 +00:00
|
|
|
if (o->internalClass() == c)
|
2013-08-16 08:11:20 +00:00
|
|
|
return;
|
2014-11-12 15:07:56 +00:00
|
|
|
idx = o->internalClass()->find(name);
|
2013-08-16 08:11:20 +00:00
|
|
|
if (idx == UINT_MAX)
|
|
|
|
return;
|
|
|
|
l->classList[0] = c;
|
2014-04-05 18:23:20 +00:00
|
|
|
l->classList[3] = o->internalClass();
|
2013-08-16 08:11:20 +00:00
|
|
|
l->index = idx;
|
2013-08-29 12:31:32 +00:00
|
|
|
if (!o->prototype()) {
|
2013-08-16 08:11:20 +00:00
|
|
|
l->setter = Lookup::setterInsert0;
|
|
|
|
return;
|
|
|
|
}
|
2013-08-29 12:31:32 +00:00
|
|
|
o = o->prototype();
|
2014-04-05 18:23:20 +00:00
|
|
|
l->classList[1] = o->internalClass();
|
2013-08-29 12:31:32 +00:00
|
|
|
if (!o->prototype()) {
|
2013-08-16 08:11:20 +00:00
|
|
|
l->setter = Lookup::setterInsert1;
|
|
|
|
return;
|
|
|
|
}
|
2013-08-29 12:31:32 +00:00
|
|
|
o = o->prototype();
|
2014-04-05 18:23:20 +00:00
|
|
|
l->classList[2] = o->internalClass();
|
2014-03-13 20:28:30 +00:00
|
|
|
if (!o->prototype()) {
|
2013-08-16 08:11:20 +00:00
|
|
|
l->setter = Lookup::setterInsert2;
|
2014-03-13 20:28:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
l->setter = Lookup::setterGeneric;
|
2013-04-19 18:25:41 +00:00
|
|
|
}
|
|
|
|
|
2014-11-28 12:25:56 +00:00
|
|
|
void Object::advanceIterator(Managed *m, ObjectIterator *it, Heap::String **name, uint *index, Property *pd, PropertyAttributes *attrs)
|
2013-06-10 15:11:52 +00:00
|
|
|
{
|
|
|
|
Object *o = static_cast<Object *>(m);
|
2014-11-28 12:25:56 +00:00
|
|
|
*name = 0;
|
2013-06-10 15:11:52 +00:00
|
|
|
*index = UINT_MAX;
|
|
|
|
|
2014-04-05 18:47:36 +00:00
|
|
|
if (o->arrayData()) {
|
2013-12-16 08:16:57 +00:00
|
|
|
if (!it->arrayIndex)
|
|
|
|
it->arrayNode = o->sparseBegin();
|
|
|
|
|
|
|
|
// sparse arrays
|
|
|
|
if (it->arrayNode) {
|
|
|
|
while (it->arrayNode != o->sparseEnd()) {
|
|
|
|
int k = it->arrayNode->key();
|
|
|
|
uint pidx = it->arrayNode->value;
|
2015-02-13 13:17:45 +00:00
|
|
|
Heap::SparseArrayData *sa = o->d()->arrayData.cast<Heap::SparseArrayData>();
|
2014-11-17 19:55:41 +00:00
|
|
|
Property *p = reinterpret_cast<Property *>(sa->arrayData + pidx);
|
2013-12-16 08:16:57 +00:00
|
|
|
it->arrayNode = it->arrayNode->nextNode();
|
2014-11-17 19:55:41 +00:00
|
|
|
PropertyAttributes a = sa->attrs ? sa->attrs[pidx] : Attr_Data;
|
2013-12-16 08:16:57 +00:00
|
|
|
if (!(it->flags & ObjectIterator::EnumerableOnly) || a.isEnumerable()) {
|
|
|
|
it->arrayIndex = k + 1;
|
|
|
|
*index = k;
|
2014-01-08 13:51:33 +00:00
|
|
|
*attrs = a;
|
2014-12-15 07:46:38 +00:00
|
|
|
pd->copy(p, a);
|
2014-01-08 13:51:33 +00:00
|
|
|
return;
|
2013-12-16 08:16:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
it->arrayNode = 0;
|
|
|
|
it->arrayIndex = UINT_MAX;
|
|
|
|
}
|
|
|
|
// dense arrays
|
2014-11-17 19:55:41 +00:00
|
|
|
while (it->arrayIndex < o->d()->arrayData->len) {
|
2015-02-13 13:17:45 +00:00
|
|
|
Heap::SimpleArrayData *sa = o->d()->arrayData.cast<Heap::SimpleArrayData>();
|
2014-10-21 12:54:45 +00:00
|
|
|
Value &val = sa->data(it->arrayIndex);
|
2014-04-05 18:47:36 +00:00
|
|
|
PropertyAttributes a = o->arrayData()->attributes(it->arrayIndex);
|
2013-12-16 08:16:57 +00:00
|
|
|
++it->arrayIndex;
|
2014-10-21 12:54:45 +00:00
|
|
|
if (!val.isEmpty()
|
2013-12-16 08:16:57 +00:00
|
|
|
&& (!(it->flags & ObjectIterator::EnumerableOnly) || a.isEnumerable())) {
|
|
|
|
*index = it->arrayIndex - 1;
|
2014-01-08 13:51:33 +00:00
|
|
|
*attrs = a;
|
2014-10-21 12:54:45 +00:00
|
|
|
pd->value = val;
|
2014-01-08 13:51:33 +00:00
|
|
|
return;
|
2013-06-10 15:11:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-05 18:23:20 +00:00
|
|
|
while (it->memberIndex < o->internalClass()->size) {
|
2014-11-12 19:07:27 +00:00
|
|
|
Identifier *n = o->internalClass()->nameMap.at(it->memberIndex);
|
2014-03-06 09:13:26 +00:00
|
|
|
if (!n) {
|
|
|
|
// accessor properties have a dummy entry with n == 0
|
|
|
|
++it->memberIndex;
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-10 15:11:52 +00:00
|
|
|
|
2014-03-06 11:06:36 +00:00
|
|
|
Property *p = o->propertyAt(it->memberIndex);
|
2014-04-05 18:23:20 +00:00
|
|
|
PropertyAttributes a = o->internalClass()->propertyData[it->memberIndex];
|
2013-06-10 15:11:52 +00:00
|
|
|
++it->memberIndex;
|
|
|
|
if (!(it->flags & ObjectIterator::EnumerableOnly) || a.isEnumerable()) {
|
2015-01-11 15:30:29 +00:00
|
|
|
*name = o->engine()->newString(n->string);
|
2014-01-08 13:51:33 +00:00
|
|
|
*attrs = a;
|
2014-12-15 07:46:38 +00:00
|
|
|
pd->copy(p, a);
|
2014-01-08 13:51:33 +00:00
|
|
|
return;
|
2013-06-10 15:11:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-08 13:51:33 +00:00
|
|
|
*attrs = PropertyAttributes();
|
2013-06-10 15:11:52 +00:00
|
|
|
}
|
2013-03-07 11:55:02 +00:00
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
// Section 8.12.3
|
2015-02-13 09:42:01 +00:00
|
|
|
ReturnedValue Object::internalGet(String *name, bool *hasProperty) const
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-01-10 14:11:32 +00:00
|
|
|
uint idx = name->asArrayIndex();
|
2013-02-12 10:05:18 +00:00
|
|
|
if (idx != UINT_MAX)
|
2013-09-11 19:48:23 +00:00
|
|
|
return getIndexed(idx, hasProperty);
|
2013-01-10 14:11:32 +00:00
|
|
|
|
2014-11-27 07:56:03 +00:00
|
|
|
Scope scope(engine());
|
2015-01-13 16:22:08 +00:00
|
|
|
name->makeIdentifier(scope.engine);
|
|
|
|
|
2014-11-27 07:56:03 +00:00
|
|
|
ScopedObject o(scope, this);
|
2013-01-30 14:43:22 +00:00
|
|
|
while (o) {
|
2014-05-07 11:33:24 +00:00
|
|
|
uint idx = o->internalClass()->find(name);
|
2013-02-10 21:22:53 +00:00
|
|
|
if (idx < UINT_MAX) {
|
|
|
|
if (hasProperty)
|
|
|
|
*hasProperty = true;
|
2014-04-05 18:23:20 +00:00
|
|
|
return getValue(o->propertyAt(idx), o->internalClass()->propertyData.at(idx));
|
2013-01-30 14:43:22 +00:00
|
|
|
}
|
2013-02-10 21:22:53 +00:00
|
|
|
|
2013-08-29 12:31:32 +00:00
|
|
|
o = o->prototype();
|
2012-12-14 08:57:02 +00:00
|
|
|
}
|
2012-11-10 22:35:06 +00:00
|
|
|
|
2012-12-14 08:57:02 +00:00
|
|
|
if (hasProperty)
|
|
|
|
*hasProperty = false;
|
2013-09-18 13:34:13 +00:00
|
|
|
return Encode::undefined();
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 09:42:01 +00:00
|
|
|
ReturnedValue Object::internalGetIndexed(uint index, bool *hasProperty) const
|
2013-01-10 14:11:32 +00:00
|
|
|
{
|
2013-04-10 08:46:23 +00:00
|
|
|
Property *pd = 0;
|
2013-12-16 08:16:57 +00:00
|
|
|
PropertyAttributes attrs;
|
2014-11-27 07:56:03 +00:00
|
|
|
Scope scope(engine());
|
|
|
|
ScopedObject o(scope, this);
|
2013-01-30 14:43:22 +00:00
|
|
|
while (o) {
|
2014-10-27 07:54:26 +00:00
|
|
|
Property *p = o->arrayData() ? o->arrayData()->getProperty(index) : 0;
|
2013-12-16 08:16:57 +00:00
|
|
|
if (p) {
|
2014-01-07 14:36:28 +00:00
|
|
|
pd = p;
|
2014-04-05 18:47:36 +00:00
|
|
|
attrs = o->arrayData()->attributes(index);
|
2014-01-07 14:36:28 +00:00
|
|
|
break;
|
2013-01-30 14:43:22 +00:00
|
|
|
}
|
|
|
|
if (o->isStringObject()) {
|
2015-04-30 21:50:50 +00:00
|
|
|
ScopedString str(scope, static_cast<StringObject *>(o.getPointer())->getIndex(index));
|
|
|
|
if (str) {
|
2013-04-10 08:46:23 +00:00
|
|
|
attrs = (Attr_NotWritable|Attr_NotConfigurable);
|
2015-04-30 21:50:50 +00:00
|
|
|
if (hasProperty)
|
|
|
|
*hasProperty = true;
|
|
|
|
return str.asReturnedValue();
|
2013-01-30 14:43:22 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-29 12:31:32 +00:00
|
|
|
o = o->prototype();
|
2013-01-30 14:43:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pd) {
|
2013-01-10 14:11:32 +00:00
|
|
|
if (hasProperty)
|
|
|
|
*hasProperty = true;
|
2013-09-11 19:48:23 +00:00
|
|
|
return getValue(pd, attrs);
|
2013-01-10 14:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hasProperty)
|
|
|
|
*hasProperty = false;
|
2013-09-26 20:07:27 +00:00
|
|
|
return Encode::undefined();
|
2013-01-10 14:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
// Section 8.12.5
|
2015-01-15 10:36:57 +00:00
|
|
|
void Object::internalPut(String *name, const Value &value)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2014-04-05 18:23:20 +00:00
|
|
|
if (internalClass()->engine->hasException)
|
2013-10-22 11:26:08 +00:00
|
|
|
return;
|
|
|
|
|
2013-01-10 14:11:32 +00:00
|
|
|
uint idx = name->asArrayIndex();
|
2013-02-12 10:05:18 +00:00
|
|
|
if (idx != UINT_MAX)
|
2013-09-19 07:10:42 +00:00
|
|
|
return putIndexed(idx, value);
|
2013-01-10 14:11:32 +00:00
|
|
|
|
2015-01-13 16:22:08 +00:00
|
|
|
name->makeIdentifier(engine());
|
2013-01-30 13:56:40 +00:00
|
|
|
|
2014-05-07 11:33:24 +00:00
|
|
|
uint member = internalClass()->find(name);
|
2013-04-10 08:46:23 +00:00
|
|
|
Property *pd = 0;
|
|
|
|
PropertyAttributes attrs;
|
|
|
|
if (member < UINT_MAX) {
|
2014-03-06 11:06:36 +00:00
|
|
|
pd = propertyAt(member);
|
2014-04-05 18:23:20 +00:00
|
|
|
attrs = internalClass()->propertyData[member];
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
2013-03-08 08:38:46 +00:00
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
// clause 1
|
2013-01-16 23:45:11 +00:00
|
|
|
if (pd) {
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs.isAccessor()) {
|
|
|
|
if (pd->setter())
|
|
|
|
goto cont;
|
|
|
|
goto reject;
|
|
|
|
} else if (!attrs.isWritable())
|
2013-01-16 23:45:11 +00:00
|
|
|
goto reject;
|
2015-04-26 07:22:17 +00:00
|
|
|
else if (isArrayObject() && name->equals(engine()->id_length())) {
|
2013-01-16 23:45:11 +00:00
|
|
|
bool ok;
|
2015-01-15 10:36:57 +00:00
|
|
|
uint l = value.asArrayLength(&ok);
|
2013-10-21 07:57:58 +00:00
|
|
|
if (!ok) {
|
2014-07-28 08:07:57 +00:00
|
|
|
engine()->throwRangeError(value);
|
2013-10-21 07:57:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-02-03 10:36:55 +00:00
|
|
|
ok = setArrayLength(l);
|
2013-01-16 23:45:11 +00:00
|
|
|
if (!ok)
|
|
|
|
goto reject;
|
|
|
|
} else {
|
2015-01-15 10:36:57 +00:00
|
|
|
pd->value = value;
|
2013-01-16 23:45:11 +00:00
|
|
|
}
|
|
|
|
return;
|
2013-08-29 12:31:32 +00:00
|
|
|
} else if (!prototype()) {
|
2014-04-05 18:23:20 +00:00
|
|
|
if (!isExtensible())
|
2013-01-16 23:45:11 +00:00
|
|
|
goto reject;
|
|
|
|
} else {
|
2013-04-12 12:36:41 +00:00
|
|
|
// clause 4
|
2014-11-27 07:56:03 +00:00
|
|
|
Scope scope(engine());
|
|
|
|
if ((pd = ScopedObject(scope, prototype())->__getPropertyDescriptor__(name, &attrs))) {
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs.isAccessor()) {
|
2013-04-12 12:36:41 +00:00
|
|
|
if (!pd->setter())
|
|
|
|
goto reject;
|
2014-04-05 18:23:20 +00:00
|
|
|
} else if (!isExtensible() || !attrs.isWritable()) {
|
2013-01-16 23:45:11 +00:00
|
|
|
goto reject;
|
|
|
|
}
|
2014-04-05 18:23:20 +00:00
|
|
|
} else if (!isExtensible()) {
|
2013-04-12 12:36:41 +00:00
|
|
|
goto reject;
|
2013-01-16 23:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cont:
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2013-01-16 23:45:11 +00:00
|
|
|
// Clause 5
|
2013-04-10 08:46:23 +00:00
|
|
|
if (pd && attrs.isAccessor()) {
|
2015-02-13 08:02:28 +00:00
|
|
|
Q_ASSERT(pd->setter() != 0);
|
2012-10-29 14:37:02 +00:00
|
|
|
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(engine());
|
2014-12-03 09:42:07 +00:00
|
|
|
ScopedFunctionObject setter(scope, pd->setter());
|
2013-09-11 12:36:01 +00:00
|
|
|
ScopedCallData callData(scope, 1);
|
2015-01-15 10:36:57 +00:00
|
|
|
callData->args[0] = value;
|
2013-09-26 20:07:27 +00:00
|
|
|
callData->thisObject = this;
|
2014-12-03 09:42:07 +00:00
|
|
|
setter->call(callData);
|
2013-01-16 23:45:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-10-29 14:37:02 +00:00
|
|
|
|
2014-01-07 15:10:00 +00:00
|
|
|
insertMember(name, value);
|
|
|
|
return;
|
2012-10-29 14:37:02 +00:00
|
|
|
|
|
|
|
reject:
|
2014-11-28 08:31:10 +00:00
|
|
|
if (engine()->currentContext()->strictMode) {
|
2013-06-13 05:46:26 +00:00
|
|
|
QString message = QStringLiteral("Cannot assign to read-only property \"");
|
|
|
|
message += name->toQString();
|
|
|
|
message += QLatin1Char('\"');
|
2014-07-28 08:07:57 +00:00
|
|
|
engine()->throwTypeError(message);
|
2013-06-13 05:46:26 +00:00
|
|
|
}
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 10:36:57 +00:00
|
|
|
void Object::internalPutIndexed(uint index, const Value &value)
|
2013-01-10 14:11:32 +00:00
|
|
|
{
|
2014-04-05 18:23:20 +00:00
|
|
|
if (internalClass()->engine->hasException)
|
2013-10-22 11:26:08 +00:00
|
|
|
return;
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
PropertyAttributes attrs;
|
|
|
|
|
2014-10-27 07:54:26 +00:00
|
|
|
Property *pd = arrayData() ? arrayData()->getProperty(index) : 0;
|
2014-01-07 14:36:28 +00:00
|
|
|
if (pd)
|
2014-04-05 18:47:36 +00:00
|
|
|
attrs = arrayData()->attributes(index);
|
2013-04-10 08:46:23 +00:00
|
|
|
|
|
|
|
if (!pd && isStringObject()) {
|
2015-04-30 21:50:50 +00:00
|
|
|
if (index < static_cast<StringObject *>(this)->length())
|
2013-04-10 08:46:23 +00:00
|
|
|
// not writable
|
|
|
|
goto reject;
|
|
|
|
}
|
2013-03-08 08:38:46 +00:00
|
|
|
|
2013-01-10 14:11:32 +00:00
|
|
|
// clause 1
|
2013-01-16 23:45:11 +00:00
|
|
|
if (pd) {
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs.isAccessor()) {
|
|
|
|
if (pd->setter())
|
|
|
|
goto cont;
|
|
|
|
goto reject;
|
|
|
|
} else if (!attrs.isWritable())
|
2013-01-16 23:45:11 +00:00
|
|
|
goto reject;
|
|
|
|
else
|
2015-01-15 10:36:57 +00:00
|
|
|
pd->value = value;
|
2013-01-16 23:45:11 +00:00
|
|
|
return;
|
2013-08-29 12:31:32 +00:00
|
|
|
} else if (!prototype()) {
|
2014-04-05 18:23:20 +00:00
|
|
|
if (!isExtensible())
|
2013-01-16 23:45:11 +00:00
|
|
|
goto reject;
|
|
|
|
} else {
|
2013-04-12 12:36:41 +00:00
|
|
|
// clause 4
|
2014-11-27 07:56:03 +00:00
|
|
|
Scope scope(engine());
|
|
|
|
if ((pd = ScopedObject(scope, prototype())->__getPropertyDescriptor__(index, &attrs))) {
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs.isAccessor()) {
|
2013-04-12 12:36:41 +00:00
|
|
|
if (!pd->setter())
|
|
|
|
goto reject;
|
2014-04-05 18:23:20 +00:00
|
|
|
} else if (!isExtensible() || !attrs.isWritable()) {
|
2013-01-16 23:45:11 +00:00
|
|
|
goto reject;
|
|
|
|
}
|
2014-04-05 18:23:20 +00:00
|
|
|
} else if (!isExtensible()) {
|
2013-04-12 12:36:41 +00:00
|
|
|
goto reject;
|
2013-01-10 14:11:32 +00:00
|
|
|
}
|
2013-01-16 23:45:11 +00:00
|
|
|
}
|
2013-01-10 14:11:32 +00:00
|
|
|
|
2013-01-16 23:45:11 +00:00
|
|
|
cont:
|
2013-01-10 14:11:32 +00:00
|
|
|
|
2013-01-16 23:45:11 +00:00
|
|
|
// Clause 5
|
2013-04-10 08:46:23 +00:00
|
|
|
if (pd && attrs.isAccessor()) {
|
2015-02-13 08:02:28 +00:00
|
|
|
Q_ASSERT(pd->setter() != 0);
|
2013-01-10 14:11:32 +00:00
|
|
|
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(engine());
|
2014-12-03 09:42:07 +00:00
|
|
|
ScopedFunctionObject setter(scope, pd->setter());
|
2013-09-11 12:36:01 +00:00
|
|
|
ScopedCallData callData(scope, 1);
|
2015-01-15 10:36:57 +00:00
|
|
|
callData->args[0] = value;
|
2013-09-26 20:07:27 +00:00
|
|
|
callData->thisObject = this;
|
2014-12-03 09:42:07 +00:00
|
|
|
setter->call(callData);
|
2013-01-10 14:11:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-19 10:55:36 +00:00
|
|
|
arraySet(index, value);
|
2013-01-16 23:45:11 +00:00
|
|
|
return;
|
|
|
|
|
2013-01-10 14:11:32 +00:00
|
|
|
reject:
|
2014-11-28 08:31:10 +00:00
|
|
|
if (engine()->currentContext()->strictMode)
|
2014-07-28 08:07:57 +00:00
|
|
|
engine()->throwTypeError();
|
2013-01-10 14:11:32 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
// Section 8.12.7
|
2014-05-07 11:33:24 +00:00
|
|
|
bool Object::internalDeleteProperty(String *name)
|
2012-10-29 14:37:02 +00:00
|
|
|
{
|
2014-04-05 18:23:20 +00:00
|
|
|
if (internalClass()->engine->hasException)
|
2013-10-22 11:26:08 +00:00
|
|
|
return false;
|
|
|
|
|
2013-01-10 14:11:32 +00:00
|
|
|
uint idx = name->asArrayIndex();
|
2013-02-12 10:05:18 +00:00
|
|
|
if (idx != UINT_MAX)
|
2013-06-21 18:33:39 +00:00
|
|
|
return deleteIndexedProperty(idx);
|
2013-01-10 14:11:32 +00:00
|
|
|
|
2015-01-13 16:22:08 +00:00
|
|
|
name->makeIdentifier(engine());
|
2013-01-30 13:56:40 +00:00
|
|
|
|
2014-04-05 18:23:20 +00:00
|
|
|
uint memberIdx = internalClass()->find(name);
|
2013-02-10 21:22:53 +00:00
|
|
|
if (memberIdx != UINT_MAX) {
|
2014-04-05 18:23:20 +00:00
|
|
|
if (internalClass()->propertyData[memberIdx].isConfigurable()) {
|
2014-04-05 18:23:43 +00:00
|
|
|
InternalClass::removeMember(this, name->identifier());
|
2013-02-10 21:22:53 +00:00
|
|
|
return true;
|
2012-10-29 14:37:02 +00:00
|
|
|
}
|
2014-11-28 08:31:10 +00:00
|
|
|
if (engine()->currentContext()->strictMode)
|
2014-07-28 08:07:57 +00:00
|
|
|
engine()->throwTypeError();
|
2013-02-10 21:22:53 +00:00
|
|
|
return false;
|
2012-10-29 14:37:02 +00:00
|
|
|
}
|
2013-02-10 21:22:53 +00:00
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-21 18:33:39 +00:00
|
|
|
bool Object::internalDeleteIndexedProperty(uint index)
|
2013-01-10 14:11:32 +00:00
|
|
|
{
|
2014-11-17 19:55:41 +00:00
|
|
|
Scope scope(engine());
|
|
|
|
if (scope.engine->hasException)
|
2013-10-22 11:26:08 +00:00
|
|
|
return false;
|
|
|
|
|
2014-11-17 19:55:41 +00:00
|
|
|
Scoped<ArrayData> ad(scope, arrayData());
|
|
|
|
if (!ad || ad->vtable()->del(this, index))
|
2013-02-05 21:13:27 +00:00
|
|
|
return true;
|
|
|
|
|
2014-11-28 08:31:10 +00:00
|
|
|
if (engine()->currentContext()->strictMode)
|
2014-07-28 08:07:57 +00:00
|
|
|
engine()->throwTypeError();
|
2013-01-10 14:11:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
// Section 8.12.9
|
2014-12-15 07:46:38 +00:00
|
|
|
bool Object::__defineOwnProperty__(ExecutionEngine *engine, String *name, const Property *p, PropertyAttributes attrs)
|
2012-05-20 17:59:47 +00:00
|
|
|
{
|
2013-01-10 14:11:32 +00:00
|
|
|
uint idx = name->asArrayIndex();
|
2013-02-12 10:05:18 +00:00
|
|
|
if (idx != UINT_MAX)
|
2014-11-12 12:32:41 +00:00
|
|
|
return __defineOwnProperty__(engine, idx, p, attrs);
|
2013-01-10 14:11:32 +00:00
|
|
|
|
2014-11-12 12:32:41 +00:00
|
|
|
Scope scope(engine);
|
2015-01-13 16:22:08 +00:00
|
|
|
name->makeIdentifier(scope.engine);
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
Property *current;
|
|
|
|
PropertyAttributes *cattrs;
|
2014-01-09 10:05:08 +00:00
|
|
|
uint memberIndex;
|
2013-01-10 22:22:04 +00:00
|
|
|
|
2015-04-26 07:22:17 +00:00
|
|
|
if (isArrayObject() && name->equals(engine->id_length())) {
|
|
|
|
Q_ASSERT(Heap::ArrayObject::LengthPropertyIndex == internalClass()->find(engine->id_length()));
|
2014-11-01 22:59:06 +00:00
|
|
|
Property *lp = propertyAt(Heap::ArrayObject::LengthPropertyIndex);
|
|
|
|
cattrs = internalClass()->propertyData.constData() + Heap::ArrayObject::LengthPropertyIndex;
|
2014-12-15 07:46:38 +00:00
|
|
|
if (attrs.isEmpty() || p->isSubset(attrs, lp, *cattrs))
|
2013-01-14 21:45:00 +00:00
|
|
|
return true;
|
2013-04-10 08:46:23 +00:00
|
|
|
if (!cattrs->isWritable() || attrs.type() == PropertyAttributes::Accessor || attrs.isConfigurable() || attrs.isEnumerable())
|
2013-01-10 22:22:04 +00:00
|
|
|
goto reject;
|
2013-01-14 21:45:00 +00:00
|
|
|
bool succeeded = true;
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs.type() == PropertyAttributes::Data) {
|
2013-01-11 13:33:10 +00:00
|
|
|
bool ok;
|
2014-12-15 07:46:38 +00:00
|
|
|
uint l = p->value.asArrayLength(&ok);
|
2013-09-25 20:42:58 +00:00
|
|
|
if (!ok) {
|
2014-12-15 07:46:38 +00:00
|
|
|
ScopedValue v(scope, p->value);
|
2014-11-12 12:32:41 +00:00
|
|
|
engine->throwRangeError(v);
|
2013-10-21 07:57:58 +00:00
|
|
|
return false;
|
2013-09-25 20:42:58 +00:00
|
|
|
}
|
2013-02-03 10:36:55 +00:00
|
|
|
succeeded = setArrayLength(l);
|
2013-01-11 13:33:10 +00:00
|
|
|
}
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs.hasWritable() && !attrs.isWritable())
|
|
|
|
cattrs->setWritable(false);
|
2013-01-14 16:41:53 +00:00
|
|
|
if (!succeeded)
|
|
|
|
goto reject;
|
2013-01-11 13:33:10 +00:00
|
|
|
return true;
|
2013-01-10 22:22:04 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
// Clause 1
|
2014-05-07 11:33:24 +00:00
|
|
|
memberIndex = internalClass()->find(name);
|
2014-03-06 11:06:36 +00:00
|
|
|
current = (memberIndex < UINT_MAX) ? propertyAt(memberIndex) : 0;
|
2014-04-05 18:23:20 +00:00
|
|
|
cattrs = internalClass()->propertyData.constData() + memberIndex;
|
2013-03-08 08:38:46 +00:00
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
if (!current) {
|
|
|
|
// clause 3
|
2014-04-05 18:23:20 +00:00
|
|
|
if (!isExtensible())
|
2012-10-28 20:56:15 +00:00
|
|
|
goto reject;
|
2012-10-29 14:37:02 +00:00
|
|
|
// clause 4
|
2014-12-15 07:46:38 +00:00
|
|
|
ScopedProperty pd(scope);
|
|
|
|
pd->copy(p, attrs);
|
|
|
|
pd->fullyPopulated(&attrs);
|
2014-01-07 15:10:00 +00:00
|
|
|
insertMember(name, pd, attrs);
|
2012-10-29 14:37:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 12:32:41 +00:00
|
|
|
return __defineOwnProperty__(engine, memberIndex, name, p, attrs);
|
2013-01-14 22:32:57 +00:00
|
|
|
reject:
|
2014-11-28 08:31:10 +00:00
|
|
|
if (engine->currentContext()->strictMode)
|
2014-11-12 12:32:41 +00:00
|
|
|
engine->throwTypeError();
|
2013-01-14 22:32:57 +00:00
|
|
|
return false;
|
2012-05-25 10:54:36 +00:00
|
|
|
}
|
2012-05-20 17:59:47 +00:00
|
|
|
|
2014-12-15 07:46:38 +00:00
|
|
|
bool Object::__defineOwnProperty__(ExecutionEngine *engine, uint index, const Property *p, PropertyAttributes attrs)
|
2013-01-10 14:11:32 +00:00
|
|
|
{
|
2013-01-14 22:32:57 +00:00
|
|
|
// 15.4.5.1, 4b
|
2014-11-01 22:59:06 +00:00
|
|
|
if (isArrayObject() && index >= getLength() && !internalClass()->propertyData[Heap::ArrayObject::LengthPropertyIndex].isWritable())
|
2013-01-14 22:32:57 +00:00
|
|
|
goto reject;
|
|
|
|
|
2013-12-13 11:15:25 +00:00
|
|
|
if (ArgumentsObject::isNonStrictArgumentsObject(this))
|
2014-11-12 12:32:41 +00:00
|
|
|
return static_cast<ArgumentsObject *>(this)->defineOwnProperty(engine, index, p, attrs);
|
2013-01-22 21:23:59 +00:00
|
|
|
|
2014-11-12 12:32:41 +00:00
|
|
|
return defineOwnProperty2(engine, index, p, attrs);
|
2014-01-03 10:58:03 +00:00
|
|
|
reject:
|
2014-11-28 08:31:10 +00:00
|
|
|
if (engine->currentContext()->strictMode)
|
2014-11-12 12:32:41 +00:00
|
|
|
engine->throwTypeError();
|
2014-01-03 10:58:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-15 07:46:38 +00:00
|
|
|
bool Object::defineOwnProperty2(ExecutionEngine *engine, uint index, const Property *p, PropertyAttributes attrs)
|
2014-01-03 10:58:03 +00:00
|
|
|
{
|
2015-04-30 21:50:50 +00:00
|
|
|
bool hasProperty = 0;
|
2014-01-03 10:58:03 +00:00
|
|
|
|
2013-01-10 14:11:32 +00:00
|
|
|
// Clause 1
|
2014-10-27 07:54:26 +00:00
|
|
|
if (arrayData()) {
|
2015-04-30 21:50:50 +00:00
|
|
|
hasProperty = arrayData()->getProperty(index);
|
|
|
|
if (!hasProperty && isStringObject())
|
|
|
|
hasProperty = (index < static_cast<StringObject *>(this)->length());
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
2013-03-08 08:38:46 +00:00
|
|
|
|
2015-04-30 21:50:50 +00:00
|
|
|
if (!hasProperty) {
|
2013-01-10 14:11:32 +00:00
|
|
|
// clause 3
|
2014-04-05 18:23:20 +00:00
|
|
|
if (!isExtensible())
|
2013-01-10 14:11:32 +00:00
|
|
|
goto reject;
|
|
|
|
// clause 4
|
2014-12-15 07:46:38 +00:00
|
|
|
Scope scope(engine);
|
|
|
|
ScopedProperty pp(scope);
|
|
|
|
pp->copy(p, attrs);
|
|
|
|
pp->fullyPopulated(&attrs);
|
2013-12-16 08:16:57 +00:00
|
|
|
if (attrs == Attr_Data) {
|
2014-12-15 07:46:38 +00:00
|
|
|
ScopedValue v(scope, pp->value);
|
2013-12-16 08:16:57 +00:00
|
|
|
arraySet(index, v);
|
|
|
|
} else {
|
|
|
|
arraySet(index, pp, attrs);
|
|
|
|
}
|
2013-01-10 14:11:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 12:32:41 +00:00
|
|
|
return __defineOwnProperty__(engine, index, 0, p, attrs);
|
2013-01-14 22:32:57 +00:00
|
|
|
reject:
|
2014-11-28 08:31:10 +00:00
|
|
|
if (engine->currentContext()->strictMode)
|
2014-11-12 12:32:41 +00:00
|
|
|
engine->throwTypeError();
|
2013-01-14 22:32:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-15 07:46:38 +00:00
|
|
|
bool Object::__defineOwnProperty__(ExecutionEngine *engine, uint index, String *member, const Property *p, PropertyAttributes attrs)
|
2013-01-14 22:32:57 +00:00
|
|
|
{
|
2013-01-10 14:11:32 +00:00
|
|
|
// clause 5
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs.isEmpty())
|
2013-01-10 14:11:32 +00:00
|
|
|
return true;
|
|
|
|
|
2014-10-27 07:54:26 +00:00
|
|
|
Property *current = 0;
|
2013-12-16 08:16:57 +00:00
|
|
|
PropertyAttributes cattrs;
|
2014-05-07 11:33:24 +00:00
|
|
|
if (member) {
|
2014-03-06 11:06:36 +00:00
|
|
|
current = propertyAt(index);
|
2014-04-05 18:23:20 +00:00
|
|
|
cattrs = internalClass()->propertyData[index];
|
2014-10-27 07:54:26 +00:00
|
|
|
} else if (arrayData()) {
|
2014-04-05 18:47:36 +00:00
|
|
|
current = arrayData()->getProperty(index);
|
|
|
|
cattrs = arrayData()->attributes(index);
|
2014-01-09 10:05:08 +00:00
|
|
|
}
|
2013-04-10 08:46:23 +00:00
|
|
|
|
2013-01-10 14:11:32 +00:00
|
|
|
// clause 6
|
2014-12-15 07:46:38 +00:00
|
|
|
if (p->isSubset(attrs, current, cattrs))
|
2013-01-10 14:11:32 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// clause 7
|
2013-04-10 08:46:23 +00:00
|
|
|
if (!cattrs.isConfigurable()) {
|
|
|
|
if (attrs.isConfigurable())
|
2013-01-10 14:11:32 +00:00
|
|
|
goto reject;
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs.hasEnumerable() && attrs.isEnumerable() != cattrs.isEnumerable())
|
2013-01-10 14:11:32 +00:00
|
|
|
goto reject;
|
|
|
|
}
|
|
|
|
|
|
|
|
// clause 8
|
2013-10-13 20:08:59 +00:00
|
|
|
if (attrs.isGeneric() || current->value.isEmpty())
|
2013-01-10 14:11:32 +00:00
|
|
|
goto accept;
|
|
|
|
|
|
|
|
// clause 9
|
2013-04-10 08:46:23 +00:00
|
|
|
if (cattrs.isData() != attrs.isData()) {
|
2013-01-10 14:11:32 +00:00
|
|
|
// 9a
|
2013-04-10 08:46:23 +00:00
|
|
|
if (!cattrs.isConfigurable())
|
2013-01-10 14:11:32 +00:00
|
|
|
goto reject;
|
2013-04-10 08:46:23 +00:00
|
|
|
if (cattrs.isData()) {
|
2013-01-10 14:11:32 +00:00
|
|
|
// 9b
|
2013-04-10 08:46:23 +00:00
|
|
|
cattrs.setType(PropertyAttributes::Accessor);
|
|
|
|
cattrs.clearWritable();
|
2014-05-07 11:33:24 +00:00
|
|
|
if (!member) {
|
2014-01-09 10:05:08 +00:00
|
|
|
// need to convert the array and the slot
|
|
|
|
initSparseArray();
|
2014-10-27 07:54:26 +00:00
|
|
|
Q_ASSERT(arrayData());
|
2014-01-22 14:25:50 +00:00
|
|
|
setArrayAttributes(index, cattrs);
|
2014-04-05 18:47:36 +00:00
|
|
|
current = arrayData()->getProperty(index);
|
2014-01-09 10:05:08 +00:00
|
|
|
}
|
2013-04-10 08:46:23 +00:00
|
|
|
current->setGetter(0);
|
|
|
|
current->setSetter(0);
|
2013-01-10 14:11:32 +00:00
|
|
|
} else {
|
|
|
|
// 9c
|
2013-04-10 08:46:23 +00:00
|
|
|
cattrs.setType(PropertyAttributes::Data);
|
|
|
|
cattrs.setWritable(false);
|
2014-05-07 11:33:24 +00:00
|
|
|
if (!member) {
|
2014-01-09 10:05:08 +00:00
|
|
|
// need to convert the array and the slot
|
2014-01-22 14:25:50 +00:00
|
|
|
setArrayAttributes(index, cattrs);
|
2014-04-05 18:47:36 +00:00
|
|
|
current = arrayData()->getProperty(index);
|
2014-01-09 10:05:08 +00:00
|
|
|
}
|
2013-09-25 10:24:36 +00:00
|
|
|
current->value = Primitive::undefinedValue();
|
2013-01-10 14:11:32 +00:00
|
|
|
}
|
2013-04-10 08:46:23 +00:00
|
|
|
} else if (cattrs.isData() && attrs.isData()) { // clause 10
|
|
|
|
if (!cattrs.isConfigurable() && !cattrs.isWritable()) {
|
2014-12-15 07:46:38 +00:00
|
|
|
if (attrs.isWritable() || !current->value.sameValue(p->value))
|
2013-01-10 14:11:32 +00:00
|
|
|
goto reject;
|
|
|
|
}
|
|
|
|
} else { // clause 10
|
2014-01-09 10:05:08 +00:00
|
|
|
Q_ASSERT(cattrs.isAccessor() && attrs.isAccessor());
|
2013-04-10 08:46:23 +00:00
|
|
|
if (!cattrs.isConfigurable()) {
|
2014-12-15 07:46:38 +00:00
|
|
|
if (!p->value.isEmpty() && current->value.val != p->value.val)
|
2013-01-16 10:00:56 +00:00
|
|
|
goto reject;
|
2014-12-15 07:46:38 +00:00
|
|
|
if (!p->set.isEmpty() && current->set.val != p->set.val)
|
2013-01-10 14:11:32 +00:00
|
|
|
goto reject;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
accept:
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
current->merge(cattrs, p, attrs);
|
2014-05-07 11:33:24 +00:00
|
|
|
if (member) {
|
|
|
|
InternalClass::changeMember(this, member, cattrs);
|
2013-04-10 08:46:23 +00:00
|
|
|
} else {
|
2014-01-22 14:25:50 +00:00
|
|
|
setArrayAttributes(index, cattrs);
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
2013-01-10 14:11:32 +00:00
|
|
|
return true;
|
|
|
|
reject:
|
2014-11-28 08:31:10 +00:00
|
|
|
if (engine->currentContext()->strictMode)
|
2014-11-12 12:32:41 +00:00
|
|
|
engine->throwTypeError();
|
2013-01-10 14:11:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-14 22:32:57 +00:00
|
|
|
|
2014-12-15 07:46:38 +00:00
|
|
|
bool Object::__defineOwnProperty__(ExecutionEngine *engine, const QString &name, const Property *p, PropertyAttributes attrs)
|
2012-12-11 22:58:40 +00:00
|
|
|
{
|
2014-11-12 12:32:41 +00:00
|
|
|
Scope scope(engine);
|
|
|
|
ScopedString s(scope, engine->newString(name));
|
2014-12-01 15:13:20 +00:00
|
|
|
return __defineOwnProperty__(engine, s, p, attrs);
|
2012-12-11 22:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-03 10:36:55 +00:00
|
|
|
void Object::copyArrayData(Object *other)
|
|
|
|
{
|
2013-08-13 08:43:15 +00:00
|
|
|
Q_ASSERT(isArrayObject());
|
2013-09-19 10:55:36 +00:00
|
|
|
Scope scope(engine());
|
2013-08-13 08:43:15 +00:00
|
|
|
|
2015-01-09 12:13:04 +00:00
|
|
|
if (other->protoHasArray() || ArgumentsObject::isNonStrictArgumentsObject(other) ||
|
|
|
|
(other->arrayType() == Heap::ArrayData::Sparse && other->arrayData()->attrs)) {
|
2013-12-16 08:16:57 +00:00
|
|
|
uint len = other->getLength();
|
2013-08-13 08:43:15 +00:00
|
|
|
Q_ASSERT(len);
|
|
|
|
|
2013-09-19 10:55:36 +00:00
|
|
|
ScopedValue v(scope);
|
2013-08-13 08:43:15 +00:00
|
|
|
for (uint i = 0; i < len; ++i) {
|
2013-09-19 10:55:36 +00:00
|
|
|
arraySet(i, (v = other->getIndexed(i)));
|
2013-08-13 08:43:15 +00:00
|
|
|
}
|
2014-04-05 18:47:36 +00:00
|
|
|
} else if (!other->arrayData()) {
|
2014-01-09 10:05:08 +00:00
|
|
|
;
|
2013-08-13 08:43:15 +00:00
|
|
|
} else {
|
2014-04-05 18:47:36 +00:00
|
|
|
Q_ASSERT(!arrayData() && other->arrayData());
|
2014-11-17 19:55:41 +00:00
|
|
|
ArrayData::realloc(this, other->d()->arrayData->type, other->d()->arrayData->alloc, false);
|
2014-11-01 22:04:20 +00:00
|
|
|
if (other->arrayType() == Heap::ArrayData::Sparse) {
|
2014-11-17 19:55:41 +00:00
|
|
|
Heap::ArrayData *od = other->d()->arrayData;
|
|
|
|
Heap::ArrayData *dd = d()->arrayData;
|
|
|
|
dd->sparse = new SparseArray(*od->sparse);
|
|
|
|
dd->freeList = od->freeList;
|
2014-01-24 13:29:40 +00:00
|
|
|
} else {
|
2014-11-17 19:55:41 +00:00
|
|
|
Heap::ArrayData *dd = d()->arrayData;
|
|
|
|
dd->len = other->d()->arrayData->len;
|
|
|
|
dd->offset = other->d()->arrayData->offset;
|
2014-01-13 08:09:14 +00:00
|
|
|
}
|
2014-11-17 19:55:41 +00:00
|
|
|
memcpy(d()->arrayData->arrayData, other->d()->arrayData->arrayData, d()->arrayData->alloc*sizeof(Value));
|
2013-02-03 21:08:39 +00:00
|
|
|
}
|
2013-12-16 08:16:57 +00:00
|
|
|
setArrayLengthUnchecked(other->getLength());
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
|
2013-12-16 08:16:57 +00:00
|
|
|
uint Object::getLength(const Managed *m)
|
2013-02-03 10:36:55 +00:00
|
|
|
{
|
2015-01-11 15:30:29 +00:00
|
|
|
Scope scope(static_cast<const Object *>(m)->engine());
|
2015-04-26 07:22:17 +00:00
|
|
|
ScopedValue v(scope, static_cast<Object *>(const_cast<Managed *>(m))->get(scope.engine->id_length()));
|
2013-12-16 08:16:57 +00:00
|
|
|
return v->toUInt32();
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
|
2013-12-16 08:16:57 +00:00
|
|
|
bool Object::setArrayLength(uint newLen)
|
2013-02-03 10:36:55 +00:00
|
|
|
{
|
2013-12-16 08:16:57 +00:00
|
|
|
Q_ASSERT(isArrayObject());
|
2014-11-01 22:59:06 +00:00
|
|
|
if (!internalClass()->propertyData[Heap::ArrayObject::LengthPropertyIndex].isWritable())
|
2013-12-16 08:16:57 +00:00
|
|
|
return false;
|
|
|
|
uint oldLen = getLength();
|
|
|
|
bool ok = true;
|
|
|
|
if (newLen < oldLen) {
|
2014-04-05 18:47:36 +00:00
|
|
|
if (!arrayData()) {
|
2014-01-22 14:25:50 +00:00
|
|
|
Q_ASSERT(!newLen);
|
|
|
|
} else {
|
2014-04-05 18:47:36 +00:00
|
|
|
uint l = arrayData()->vtable()->truncate(this, newLen);
|
2014-01-22 14:25:50 +00:00
|
|
|
if (l != newLen)
|
|
|
|
ok = false;
|
|
|
|
newLen = l;
|
|
|
|
}
|
2013-02-03 10:36:55 +00:00
|
|
|
} else {
|
2013-12-16 08:16:57 +00:00
|
|
|
if (newLen >= 0x100000)
|
|
|
|
initSparseArray();
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
setArrayLengthUnchecked(newLen);
|
2013-12-16 08:16:57 +00:00
|
|
|
return ok;
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
|
2013-12-16 08:16:57 +00:00
|
|
|
void Object::initSparseArray()
|
2013-02-03 10:36:55 +00:00
|
|
|
{
|
2014-11-01 22:04:20 +00:00
|
|
|
if (arrayType() == Heap::ArrayData::Sparse)
|
2013-02-03 21:08:39 +00:00
|
|
|
return;
|
|
|
|
|
2014-11-01 22:04:20 +00:00
|
|
|
ArrayData::realloc(this, Heap::ArrayData::Sparse, 0, false);
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-04 10:22:00 +00:00
|
|
|
DEFINE_OBJECT_VTABLE(ArrayObject);
|
2013-09-14 09:25:02 +00:00
|
|
|
|
2014-11-01 22:59:06 +00:00
|
|
|
Heap::ArrayObject::ArrayObject(ExecutionEngine *engine, const QStringList &list)
|
2015-03-25 13:40:35 +00:00
|
|
|
: Heap::Object(engine->arrayClass, engine->arrayPrototype())
|
2013-05-02 20:33:47 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
init();
|
2013-09-19 14:05:25 +00:00
|
|
|
Scope scope(engine);
|
2014-05-09 12:14:02 +00:00
|
|
|
ScopedObject a(scope, this);
|
2013-06-07 12:06:36 +00:00
|
|
|
|
2013-05-02 20:33:47 +00:00
|
|
|
// Converts a QStringList to JS.
|
|
|
|
// The result is a new Array object with length equal to the length
|
|
|
|
// of the QStringList, and the elements being the QStringList's
|
|
|
|
// elements converted to JS Strings.
|
|
|
|
int len = list.count();
|
2014-05-09 12:14:02 +00:00
|
|
|
a->arrayReserve(len);
|
2013-12-16 08:16:57 +00:00
|
|
|
ScopedValue v(scope);
|
2014-01-13 08:09:14 +00:00
|
|
|
for (int ii = 0; ii < len; ++ii)
|
2014-05-09 12:14:02 +00:00
|
|
|
a->arrayPut(ii, (v = engine->newString(list.at(ii))));
|
|
|
|
a->setArrayLengthUnchecked(len);
|
2013-01-11 13:33:10 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 12:39:20 +00:00
|
|
|
ReturnedValue ArrayObject::getLookup(const Managed *m, Lookup *l)
|
2013-12-16 08:16:57 +00:00
|
|
|
{
|
2015-02-13 12:39:20 +00:00
|
|
|
Scope scope(static_cast<const Object *>(m)->engine());
|
2015-01-11 15:30:29 +00:00
|
|
|
ScopedString name(scope, scope.engine->currentContext()->compilationUnit->runtimeStrings[l->nameIndex]);
|
2015-04-26 07:22:17 +00:00
|
|
|
if (name->equals(scope.engine->id_length())) {
|
2013-12-16 08:16:57 +00:00
|
|
|
// special case, as the property is on the object itself
|
|
|
|
l->getter = Lookup::arrayLengthGetter;
|
2015-02-13 12:39:20 +00:00
|
|
|
const ArrayObject *a = static_cast<const ArrayObject *>(m);
|
2014-11-14 08:31:59 +00:00
|
|
|
return a->memberData()->data[Heap::ArrayObject::LengthPropertyIndex].asReturnedValue();
|
2013-12-16 08:16:57 +00:00
|
|
|
}
|
|
|
|
return Object::getLookup(m, l);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint ArrayObject::getLength(const Managed *m)
|
|
|
|
{
|
|
|
|
const ArrayObject *a = static_cast<const ArrayObject *>(m);
|
2014-11-14 08:31:59 +00:00
|
|
|
if (a->memberData()->data[Heap::ArrayObject::LengthPropertyIndex].isInteger())
|
|
|
|
return a->memberData()->data[Heap::ArrayObject::LengthPropertyIndex].integerValue();
|
|
|
|
return Primitive::toUInt32(a->memberData()->data[Heap::ArrayObject::LengthPropertyIndex].doubleValue());
|
2013-12-16 08:16:57 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 20:33:47 +00:00
|
|
|
QStringList ArrayObject::toQStringList() const
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
|
2014-04-05 18:23:20 +00:00
|
|
|
QV4::ExecutionEngine *engine = internalClass()->engine;
|
2013-09-11 19:48:23 +00:00
|
|
|
Scope scope(engine);
|
|
|
|
ScopedValue v(scope);
|
2013-05-02 20:33:47 +00:00
|
|
|
|
2014-11-21 06:16:53 +00:00
|
|
|
uint length = getLength();
|
|
|
|
for (uint i = 0; i < length; ++i) {
|
2013-09-11 19:48:23 +00:00
|
|
|
v = const_cast<ArrayObject *>(this)->getIndexed(i);
|
2013-10-22 11:26:08 +00:00
|
|
|
result.append(v->toQStringNoThrow());
|
2013-09-11 19:48:23 +00:00
|
|
|
}
|
2013-05-02 20:33:47 +00:00
|
|
|
return result;
|
|
|
|
}
|