2012-10-12 08:12:24 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2013-06-24 11:50:51 +00:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-12 08:12:24 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
**
|
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
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** 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
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3.0 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU General Public License version 3.0 requirements will be
|
|
|
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** $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"
|
|
|
|
#include "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"
|
2012-11-16 21:21:34 +00:00
|
|
|
|
|
|
|
#include <private/qqmljsengine_p.h>
|
|
|
|
#include <private/qqmljslexer_p.h>
|
|
|
|
#include <private/qqmljsparser_p.h>
|
|
|
|
#include <private/qqmljsast_p.h>
|
2013-03-05 11:49:35 +00:00
|
|
|
#include <qv4jsir_p.h>
|
2012-11-16 21:21:34 +00:00
|
|
|
#include <qv4codegen_p.h>
|
2013-01-09 13:37:55 +00:00
|
|
|
#include "private/qlocale_tools_p.h"
|
2012-11-16 21:21:34 +00:00
|
|
|
|
2012-05-18 08:10:36 +00:00
|
|
|
#include <QtCore/qmath.h>
|
2012-05-07 14:05:05 +00:00
|
|
|
#include <QtCore/QDebug>
|
2012-04-16 19:23:25 +00:00
|
|
|
#include <cassert>
|
2012-05-25 15:45:15 +00:00
|
|
|
#include <typeinfo>
|
2012-11-16 21:21:34 +00:00
|
|
|
#include <iostream>
|
2013-05-22 09:58:16 +00:00
|
|
|
#include <stdint.h>
|
2013-02-08 08:30:40 +00:00
|
|
|
#include "qv4alloca_p.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
|
|
|
|
2013-02-14 13:07:57 +00:00
|
|
|
DEFINE_MANAGED_VTABLE(Object);
|
2013-01-03 21:17:46 +00:00
|
|
|
|
2013-02-10 21:22:53 +00:00
|
|
|
Object::Object(ExecutionEngine *engine)
|
2013-08-29 19:23:04 +00:00
|
|
|
: Managed(engine->objectClass)
|
2013-04-15 08:31:35 +00:00
|
|
|
, memberDataAlloc(InlinePropertySize), memberData(inlineProperties)
|
2013-04-10 08:46:23 +00:00
|
|
|
, arrayOffset(0), arrayDataLen(0), arrayAlloc(0), arrayAttributes(0), arrayData(0), sparseArray(0)
|
2013-02-10 21:22:53 +00:00
|
|
|
{
|
2013-02-13 22:00:10 +00:00
|
|
|
vtbl = &static_vtbl;
|
2013-02-10 21:22:53 +00:00
|
|
|
type = Type_Object;
|
2013-10-13 19:03:44 +00:00
|
|
|
flags = SimpleArray;
|
2013-06-21 19:28:11 +00:00
|
|
|
memset(memberData, 0, sizeof(Property)*memberDataAlloc);
|
2013-02-10 21:22:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 11:06:22 +00:00
|
|
|
Object::Object(InternalClass *internalClass)
|
2013-05-06 09:37:53 +00:00
|
|
|
: Managed(internalClass)
|
2013-04-23 05:31:02 +00:00
|
|
|
, memberDataAlloc(InlinePropertySize), memberData(inlineProperties)
|
|
|
|
, arrayOffset(0), arrayDataLen(0), arrayAlloc(0), arrayAttributes(0), arrayData(0), sparseArray(0)
|
|
|
|
{
|
|
|
|
vtbl = &static_vtbl;
|
|
|
|
type = Type_Object;
|
2013-10-13 19:03:44 +00:00
|
|
|
flags = SimpleArray;
|
2013-04-23 05:31:02 +00:00
|
|
|
|
|
|
|
if (internalClass->size >= memberDataAlloc) {
|
|
|
|
memberDataAlloc = internalClass->size;
|
|
|
|
memberData = new Property[memberDataAlloc];
|
|
|
|
}
|
2013-06-21 19:28:11 +00:00
|
|
|
memset(memberData, 0, sizeof(Property)*memberDataAlloc);
|
2013-04-23 05:31:02 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 13:12:37 +00:00
|
|
|
Object::~Object()
|
|
|
|
{
|
2013-04-15 08:31:35 +00:00
|
|
|
if (memberData != inlineProperties)
|
|
|
|
delete [] memberData;
|
2013-02-03 21:08:39 +00:00
|
|
|
delete [] (arrayData - (sparseArray ? 0 : arrayOffset));
|
2013-04-10 08:46:23 +00:00
|
|
|
if (arrayAttributes)
|
|
|
|
delete [] (arrayAttributes - (sparseArray ? 0 : arrayOffset));
|
2013-02-03 10:36:55 +00:00
|
|
|
delete sparseArray;
|
2013-02-14 14:00:06 +00:00
|
|
|
_data = 0;
|
|
|
|
}
|
|
|
|
|
2013-08-29 12:31:32 +00:00
|
|
|
bool Object::setPrototype(Object *proto)
|
|
|
|
{
|
|
|
|
Object *pp = proto;
|
|
|
|
while (pp) {
|
|
|
|
if (pp == this)
|
|
|
|
return false;
|
|
|
|
pp = pp->prototype();
|
|
|
|
}
|
|
|
|
internalClass = internalClass->changePrototype(proto);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-14 14:00:06 +00:00
|
|
|
void Object::destroy(Managed *that)
|
|
|
|
{
|
|
|
|
static_cast<Object *>(that)->~Object();
|
2012-05-04 13:12:37 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 14:36:02 +00:00
|
|
|
void Object::put(ExecutionContext *ctx, const QString &name, const ValueRef value)
|
2012-05-14 14:03:10 +00:00
|
|
|
{
|
2013-09-18 14:36:02 +00:00
|
|
|
Scope scope(ctx);
|
|
|
|
ScopedString n(scope, ctx->engine->newString(name));
|
|
|
|
put(n, value);
|
2012-05-14 14:03:10 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 11:17:55 +00:00
|
|
|
ReturnedValue Object::getValue(const ValueRef 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();
|
2013-04-10 08:46:23 +00:00
|
|
|
FunctionObject *getter = p->getter();
|
|
|
|
if (!getter)
|
2013-09-26 20:07:27 +00:00
|
|
|
return Encode::undefined();
|
2012-11-10 22:35:06 +00:00
|
|
|
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(getter->engine());
|
2013-09-11 12:36:01 +00:00
|
|
|
ScopedCallData callData(scope, 0);
|
2013-09-19 11:17:55 +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
|
|
|
}
|
|
|
|
|
2013-09-19 11:17:55 +00:00
|
|
|
void Object::putValue(Property *pd, PropertyAttributes attrs, const ValueRef value)
|
2013-02-12 15:23:52 +00:00
|
|
|
{
|
2013-10-22 11:26:08 +00:00
|
|
|
if (internalClass->engine->hasException)
|
|
|
|
return;
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs.isAccessor()) {
|
|
|
|
if (pd->set) {
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(pd->set->engine());
|
2013-09-11 12:36:01 +00:00
|
|
|
ScopedCallData callData(scope, 1);
|
2013-09-19 11:17:55 +00:00
|
|
|
callData->args[0] = *value;
|
2013-09-26 20:07:27 +00:00
|
|
|
callData->thisObject = this;
|
2013-09-05 11:22:23 +00:00
|
|
|
pd->set->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;
|
|
|
|
|
2013-09-19 11:17:55 +00:00
|
|
|
pd->value = *value;
|
2013-03-07 11:55:02 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
reject:
|
2013-06-21 22:52:47 +00:00
|
|
|
if (engine()->current->strictMode)
|
|
|
|
engine()->current->throwTypeError();
|
2013-03-07 11:55:02 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 11:05:25 +00:00
|
|
|
void Object::defineDefaultProperty(const StringRef name, ValueRef value)
|
2012-12-12 23:53:04 +00:00
|
|
|
{
|
2013-09-18 09:00:38 +00:00
|
|
|
Property *pd = insertMember(name, Attr_Data|Attr_NotEnumerable);
|
2013-09-26 11:05:25 +00:00
|
|
|
pd->value = *value;
|
2012-12-12 23:53:04 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 11:05:25 +00:00
|
|
|
void Object::defineDefaultProperty(const QString &name, ValueRef 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));
|
2013-09-18 08:02:04 +00:00
|
|
|
defineDefaultProperty(s, value);
|
2012-12-12 23:53:04 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 10:31:55 +00:00
|
|
|
void Object::defineDefaultProperty(const QString &name, ReturnedValue (*code)(SimpleCallContext *), 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));
|
|
|
|
Scoped<FunctionObject> function(scope, e->newBuiltinFunction(e->rootContext, s, code));
|
2013-09-25 10:24:36 +00:00
|
|
|
function->defineReadonlyProperty(e->id_length, Primitive::fromInt32(argumentCount));
|
2013-09-26 11:05:25 +00:00
|
|
|
defineDefaultProperty(s, function);
|
2013-05-02 19:37:20 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 13:34:13 +00:00
|
|
|
void Object::defineDefaultProperty(const StringRef name, ReturnedValue (*code)(SimpleCallContext *), int argumentCount)
|
|
|
|
{
|
|
|
|
ExecutionEngine *e = engine();
|
|
|
|
Scope scope(e);
|
|
|
|
Scoped<FunctionObject> function(scope, e->newBuiltinFunction(e->rootContext, name, code));
|
2013-09-25 10:24:36 +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-09-18 10:31:55 +00:00
|
|
|
void Object::defineAccessorProperty(const QString &name, ReturnedValue (*getter)(SimpleCallContext *), ReturnedValue (*setter)(SimpleCallContext *))
|
2013-06-10 14:16:40 +00:00
|
|
|
{
|
2013-09-18 10:31:55 +00:00
|
|
|
ExecutionEngine *e = engine();
|
|
|
|
Scope scope(e);
|
|
|
|
Scoped<String> s(scope, e->newIdentifier(name));
|
2013-09-18 08:02:04 +00:00
|
|
|
defineAccessorProperty(s, getter, setter);
|
2013-06-10 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 08:02:04 +00:00
|
|
|
void Object::defineAccessorProperty(const StringRef name, ReturnedValue (*getter)(SimpleCallContext *), ReturnedValue (*setter)(SimpleCallContext *))
|
2013-06-10 14:16:40 +00:00
|
|
|
{
|
|
|
|
ExecutionEngine *v4 = engine();
|
2013-09-18 09:00:38 +00:00
|
|
|
Property *p = insertMember(name, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
|
2013-09-18 07:30:45 +00:00
|
|
|
|
2013-06-10 14:16:40 +00:00
|
|
|
if (getter)
|
2013-09-18 08:02:04 +00:00
|
|
|
p->setGetter(v4->newBuiltinFunction(v4->rootContext, name, getter)->getPointer());
|
2013-06-10 14:16:40 +00:00
|
|
|
if (setter)
|
2013-09-18 08:02:04 +00:00
|
|
|
p->setSetter(v4->newBuiltinFunction(v4->rootContext, name, setter)->getPointer());
|
2013-06-10 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 11:05:25 +00:00
|
|
|
void Object::defineReadonlyProperty(const QString &name, ValueRef 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));
|
|
|
|
defineReadonlyProperty(s, value);
|
2013-01-10 15:06:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 11:05:25 +00:00
|
|
|
void Object::defineReadonlyProperty(const StringRef name, ValueRef value)
|
2012-12-12 23:53:04 +00:00
|
|
|
{
|
2013-09-18 10:31:55 +00:00
|
|
|
Property *pd = insertMember(name, Attr_ReadOnly);
|
2013-09-26 11:05:25 +00:00
|
|
|
pd->value = *value;
|
2012-12-12 23:53:04 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 22:00:10 +00:00
|
|
|
void Object::markObjects(Managed *that)
|
2012-12-04 12:40:18 +00:00
|
|
|
{
|
2013-02-13 22:00:10 +00:00
|
|
|
Object *o = static_cast<Object *>(that);
|
2012-12-04 12:40:18 +00:00
|
|
|
|
2013-10-15 20:27:10 +00:00
|
|
|
if (!o->hasAccessorProperty) {
|
2013-11-01 11:38:32 +00:00
|
|
|
for (uint i = 0; i < o->internalClass->size; ++i)
|
2013-10-15 20:27:10 +00:00
|
|
|
o->memberData[i].value.mark();
|
|
|
|
} else {
|
2013-11-01 11:38:32 +00:00
|
|
|
for (uint i = 0; i < o->internalClass->size; ++i) {
|
2013-10-15 20:27:10 +00:00
|
|
|
const Property &pd = o->memberData[i];
|
|
|
|
if (o->internalClass->propertyData[i].isAccessor()) {
|
|
|
|
if (pd.getter())
|
|
|
|
pd.getter()->mark();
|
|
|
|
if (pd.setter())
|
|
|
|
pd.setter()->mark();
|
|
|
|
} else {
|
|
|
|
pd.value.mark();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (o->flags & SimpleArray) {
|
|
|
|
for (uint i = 0; i < o->arrayDataLen; ++i)
|
|
|
|
o->arrayData[i].value.mark();
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
for (uint i = 0; i < o->arrayDataLen; ++i) {
|
|
|
|
const Property &pd = o->arrayData[i];
|
|
|
|
if (o->arrayAttributes && o->arrayAttributes[i].isAccessor()) {
|
|
|
|
if (pd.getter())
|
|
|
|
pd.getter()->mark();
|
|
|
|
if (pd.setter())
|
|
|
|
pd.setter()->mark();
|
|
|
|
} else {
|
|
|
|
pd.value.mark();
|
|
|
|
}
|
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
|
|
|
{
|
2013-02-10 21:22:53 +00:00
|
|
|
if (idx >= memberDataAlloc) {
|
|
|
|
memberDataAlloc = qMax((uint)8, 2*memberDataAlloc);
|
2013-04-10 08:46:23 +00:00
|
|
|
Property *newMemberData = new Property[memberDataAlloc];
|
|
|
|
memcpy(newMemberData, memberData, sizeof(Property)*idx);
|
2013-05-31 07:41:54 +00:00
|
|
|
memset(newMemberData + idx, 0, sizeof(Property)*(memberDataAlloc - idx));
|
2013-04-15 08:31:35 +00:00
|
|
|
if (memberData != inlineProperties)
|
|
|
|
delete [] memberData;
|
2013-02-10 21:22:53 +00:00
|
|
|
memberData = newMemberData;
|
2013-02-02 08:52:27 +00:00
|
|
|
}
|
2013-08-16 08:11:20 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 09:00:38 +00:00
|
|
|
Property *Object::insertMember(const StringRef s, PropertyAttributes attributes)
|
2013-08-16 08:11:20 +00:00
|
|
|
{
|
|
|
|
uint idx;
|
2013-09-18 09:00:38 +00:00
|
|
|
internalClass = internalClass->addMember(s.getPointer(), attributes, &idx);
|
2013-08-16 08:11:20 +00:00
|
|
|
|
|
|
|
if (attributes.isAccessor())
|
|
|
|
hasAccessorProperty = 1;
|
|
|
|
|
|
|
|
ensureMemberIndex(idx);
|
|
|
|
|
2013-02-10 21:22:53 +00:00
|
|
|
return memberData + idx;
|
2013-02-02 08:52:27 +00:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:56:15 +00:00
|
|
|
// Section 8.12.1
|
2013-09-18 12:30:53 +00:00
|
|
|
Property *Object::__getOwnProperty__(const StringRef name, PropertyAttributes *attrs)
|
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)
|
2013-04-12 12:43:58 +00:00
|
|
|
return __getOwnProperty__(idx, attrs);
|
2013-01-10 16:33:06 +00:00
|
|
|
|
2013-02-10 21:22:53 +00:00
|
|
|
uint member = internalClass->find(name);
|
2013-04-10 08:46:23 +00:00
|
|
|
if (member < UINT_MAX) {
|
|
|
|
if (attrs)
|
|
|
|
*attrs = internalClass->propertyData[member];
|
2013-02-10 21:22:53 +00:00
|
|
|
return memberData + member;
|
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;
|
2012-04-16 19:23:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-12 12:43:58 +00:00
|
|
|
Property *Object::__getOwnProperty__(uint index, PropertyAttributes *attrs)
|
2013-01-10 14:11:32 +00:00
|
|
|
{
|
2013-04-10 08:46:23 +00:00
|
|
|
uint pidx = propertyIndexFromArrayIndex(index);
|
|
|
|
if (pidx < UINT_MAX) {
|
|
|
|
Property *p = arrayData + pidx;
|
2013-10-13 20:08:59 +00:00
|
|
|
if (!p->value.isEmpty() && !(arrayAttributes && arrayAttributes[pidx].isGeneric())) {
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs)
|
|
|
|
*attrs = arrayAttributes ? arrayAttributes[pidx] : PropertyAttributes(Attr_Data);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isStringObject()) {
|
|
|
|
if (attrs)
|
|
|
|
*attrs = Attr_NotConfigurable|Attr_NotWritable;
|
2013-04-12 12:43:58 +00:00
|
|
|
return static_cast<StringObject *>(this)->getIndex(index);
|
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;
|
2013-01-10 14:11:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
// Section 8.12.2
|
2013-09-18 12:30:53 +00:00
|
|
|
Property *Object::__getPropertyDescriptor__(const StringRef name, PropertyAttributes *attrs) const
|
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)
|
2013-04-12 12:43:58 +00:00
|
|
|
return __getPropertyDescriptor__(idx);
|
2013-01-10 16:33:06 +00:00
|
|
|
|
2012-12-18 08:06:03 +00:00
|
|
|
|
2013-03-07 09:57:48 +00:00
|
|
|
const Object *o = this;
|
2012-12-17 08:52:04 +00:00
|
|
|
while (o) {
|
2013-09-18 12:30:53 +00:00
|
|
|
uint idx = o->internalClass->find(name.getPointer());
|
2013-04-10 08:46:23 +00:00
|
|
|
if (idx < UINT_MAX) {
|
|
|
|
if (attrs)
|
|
|
|
*attrs = o->internalClass->propertyData[idx];
|
2013-02-10 21:22:53 +00:00
|
|
|
return o->memberData + idx;
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
2013-02-10 21:22:53 +00:00
|
|
|
|
2013-08-29 12:31:32 +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
|
|
|
{
|
2013-03-07 09:57:48 +00:00
|
|
|
const Object *o = this;
|
2013-01-10 14:11:32 +00:00
|
|
|
while (o) {
|
2013-04-10 08:46:23 +00:00
|
|
|
uint pidx = o->propertyIndexFromArrayIndex(index);
|
|
|
|
if (pidx < UINT_MAX) {
|
|
|
|
Property *p = o->arrayData + pidx;
|
2013-10-13 20:08:59 +00:00
|
|
|
if (!p->value.isEmpty()) {
|
2013-04-10 08:46:23 +00:00
|
|
|
if (attrs)
|
|
|
|
*attrs = o->arrayAttributes ? o->arrayAttributes[pidx] : PropertyAttributes(Attr_Data);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 12:41:37 +00:00
|
|
|
if (o->isStringObject()) {
|
2013-04-12 12:43:58 +00:00
|
|
|
Property *p = static_cast<const StringObject *>(o)->getIndex(index);
|
2013-04-10 08:46:23 +00:00
|
|
|
if (p) {
|
|
|
|
if (attrs)
|
|
|
|
*attrs = (Attr_NotWritable|Attr_NotConfigurable);
|
2013-01-16 12:34:46 +00:00
|
|
|
return p;
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
2013-01-16 12:34:46 +00:00
|
|
|
}
|
2013-08-29 12:31:32 +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;
|
|
|
|
}
|
|
|
|
|
2013-09-18 12:30:53 +00:00
|
|
|
bool Object::__hasProperty__(const StringRef name) const
|
2013-05-13 14:11:35 +00:00
|
|
|
{
|
|
|
|
if (__getPropertyDescriptor__(name))
|
|
|
|
return true;
|
2013-08-08 10:52:56 +00:00
|
|
|
|
|
|
|
const Object *o = this;
|
|
|
|
while (o) {
|
2013-09-19 07:58:50 +00:00
|
|
|
if (!o->query(name).isEmpty())
|
2013-08-08 10:52:56 +00:00
|
|
|
return true;
|
2013-08-29 12:31:32 +00:00
|
|
|
o = o->prototype();
|
2013-08-08 10:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Object::__hasProperty__(uint index) const
|
|
|
|
{
|
|
|
|
if (__getPropertyDescriptor__(index))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const Object *o = this;
|
|
|
|
while (o) {
|
|
|
|
if (!o->queryIndexed(index).isEmpty())
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-09-18 13:34:13 +00:00
|
|
|
ReturnedValue Object::get(Managed *m, const StringRef name, bool *hasProperty)
|
2013-03-07 11:55:02 +00:00
|
|
|
{
|
2013-06-21 21:26:11 +00:00
|
|
|
return static_cast<Object *>(m)->internalGet(name, hasProperty);
|
2013-03-07 11:55:02 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 19:48:23 +00:00
|
|
|
ReturnedValue Object::getIndexed(Managed *m, uint index, bool *hasProperty)
|
2013-03-07 11:55:02 +00:00
|
|
|
{
|
2013-06-21 20:55:13 +00:00
|
|
|
return static_cast<Object *>(m)->internalGetIndexed(index, hasProperty);
|
2013-03-07 11:55:02 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 14:36:02 +00:00
|
|
|
void Object::put(Managed *m, const StringRef name, const ValueRef 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
|
|
|
}
|
|
|
|
|
2013-09-19 07:10:42 +00:00
|
|
|
void Object::putIndexed(Managed *m, uint index, const ValueRef 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
|
|
|
}
|
|
|
|
|
2013-09-19 07:58:50 +00:00
|
|
|
PropertyAttributes Object::query(const Managed *m, StringRef 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);
|
2013-09-19 07:58:50 +00:00
|
|
|
idx = o->internalClass->find(name.getPointer());
|
2013-08-08 10:52:56 +00:00
|
|
|
if (idx < UINT_MAX)
|
|
|
|
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);
|
2013-08-08 10:52:56 +00:00
|
|
|
uint pidx = o->propertyIndexFromArrayIndex(index);
|
|
|
|
if (pidx < UINT_MAX) {
|
|
|
|
if (o->arrayAttributes)
|
|
|
|
return o->arrayAttributes[pidx];
|
2013-10-13 20:08:59 +00:00
|
|
|
if (!o->arrayData[pidx].value.isEmpty())
|
|
|
|
return Attr_Data;
|
2013-08-08 10:52:56 +00:00
|
|
|
}
|
|
|
|
if (o->isStringObject()) {
|
|
|
|
Property *p = static_cast<const StringObject *>(o)->getIndex(index);
|
|
|
|
if (p)
|
2013-04-10 08:46:23 +00:00
|
|
|
return Attr_Data;
|
|
|
|
}
|
|
|
|
return Attr_Invalid;
|
2013-03-07 11:55:02 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 07:58:50 +00:00
|
|
|
bool Object::deleteProperty(Managed *m, const StringRef 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
|
|
|
}
|
|
|
|
|
2013-09-11 20:45:47 +00:00
|
|
|
ReturnedValue Object::getLookup(Managed *m, Lookup *l)
|
2013-04-19 18:25:41 +00:00
|
|
|
{
|
|
|
|
Object *o = static_cast<Object *>(m);
|
|
|
|
PropertyAttributes attrs;
|
|
|
|
Property *p = l->lookup(o, &attrs);
|
|
|
|
if (p) {
|
|
|
|
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;
|
2013-09-11 20:45:47 +00:00
|
|
|
return p->value.asReturnedValue();
|
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;
|
2013-09-11 20:45:47 +00:00
|
|
|
return o->getValue(p, attrs);
|
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
|
|
|
}
|
|
|
|
|
2013-09-18 14:36:02 +00:00
|
|
|
void Object::setLookup(Managed *m, Lookup *l, const ValueRef value)
|
2013-04-19 18:25:41 +00:00
|
|
|
{
|
2013-09-18 14:36:02 +00:00
|
|
|
Scope scope(m->engine());
|
|
|
|
ScopedObject o(scope, static_cast<Object *>(m));
|
2013-04-19 18:25:41 +00:00
|
|
|
|
2013-08-16 08:11:20 +00:00
|
|
|
InternalClass *c = o->internalClass;
|
|
|
|
uint idx = c->find(l->name);
|
2013-04-19 18:25:41 +00:00
|
|
|
if (!o->isArrayObject() || idx != ArrayObject::LengthPropertyIndex) {
|
|
|
|
if (idx != UINT_MAX && o->internalClass->propertyData[idx].isData() && o->internalClass->propertyData[idx].isWritable()) {
|
|
|
|
l->classList[0] = o->internalClass;
|
|
|
|
l->index = idx;
|
|
|
|
l->setter = Lookup::setter0;
|
2013-09-18 14:36:02 +00:00
|
|
|
o->memberData[idx].value = *value;
|
2013-04-19 18:25:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (idx != UINT_MAX) {
|
2013-09-19 11:17:55 +00:00
|
|
|
o->putValue(o->memberData + idx, o->internalClass->propertyData[idx], value);
|
2013-04-19 18:25:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-18 14:36:02 +00:00
|
|
|
ScopedString s(scope, l->name);
|
|
|
|
o->put(s, value);
|
2013-08-16 08:11:20 +00:00
|
|
|
|
|
|
|
if (o->internalClass == c)
|
|
|
|
return;
|
|
|
|
idx = o->internalClass->find(l->name);
|
|
|
|
if (idx == UINT_MAX)
|
|
|
|
return;
|
|
|
|
l->classList[0] = c;
|
|
|
|
l->classList[3] = o->internalClass;
|
|
|
|
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();
|
2013-08-16 08:11: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();
|
2013-08-16 08:11:20 +00:00
|
|
|
l->classList[2] = o->internalClass;
|
2013-08-29 12:31:32 +00:00
|
|
|
if (!o->prototype())
|
2013-08-16 08:11:20 +00:00
|
|
|
l->setter = Lookup::setterInsert2;
|
2013-04-19 18:25:41 +00:00
|
|
|
}
|
|
|
|
|
2013-09-30 11:48:05 +00:00
|
|
|
Property *Object::advanceIterator(Managed *m, ObjectIterator *it, StringRef name, uint *index, PropertyAttributes *attrs)
|
2013-06-10 15:11:52 +00:00
|
|
|
{
|
|
|
|
Object *o = static_cast<Object *>(m);
|
2013-09-30 11:48:05 +00:00
|
|
|
name = (String *)0;
|
2013-06-10 15:11:52 +00:00
|
|
|
*index = UINT_MAX;
|
|
|
|
|
|
|
|
if (!it->arrayIndex)
|
|
|
|
it->arrayNode = o->sparseArrayBegin();
|
|
|
|
|
|
|
|
// sparse arrays
|
|
|
|
if (it->arrayNode) {
|
|
|
|
while (it->arrayNode != o->sparseArrayEnd()) {
|
|
|
|
int k = it->arrayNode->key();
|
|
|
|
uint pidx = it->arrayNode->value;
|
|
|
|
Property *p = o->arrayData + pidx;
|
|
|
|
it->arrayNode = it->arrayNode->nextNode();
|
|
|
|
PropertyAttributes a = o->arrayAttributes ? o->arrayAttributes[pidx] : PropertyAttributes(Attr_Data);
|
|
|
|
if (!(it->flags & ObjectIterator::EnumerableOnly) || a.isEnumerable()) {
|
|
|
|
it->arrayIndex = k + 1;
|
|
|
|
*index = k;
|
|
|
|
if (attrs)
|
|
|
|
*attrs = a;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
it->arrayNode = 0;
|
|
|
|
it->arrayIndex = UINT_MAX;
|
|
|
|
}
|
|
|
|
// dense arrays
|
|
|
|
while (it->arrayIndex < o->arrayDataLen) {
|
|
|
|
uint pidx = o->propertyIndexFromArrayIndex(it->arrayIndex);
|
|
|
|
Property *p = o->arrayData + pidx;
|
|
|
|
PropertyAttributes a = o->arrayAttributes ? o->arrayAttributes[pidx] : PropertyAttributes(Attr_Data);
|
|
|
|
++it->arrayIndex;
|
2013-10-13 20:08:59 +00:00
|
|
|
if (!p->value.isEmpty()
|
2013-06-10 15:11:52 +00:00
|
|
|
&& (!(it->flags & ObjectIterator::EnumerableOnly) || a.isEnumerable())) {
|
|
|
|
*index = it->arrayIndex - 1;
|
|
|
|
if (attrs)
|
|
|
|
*attrs = a;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (it->memberIndex < o->internalClass->size) {
|
|
|
|
String *n = o->internalClass->nameMap.at(it->memberIndex);
|
|
|
|
assert(n);
|
|
|
|
|
|
|
|
Property *p = o->memberData + it->memberIndex;
|
|
|
|
PropertyAttributes a = o->internalClass->propertyData[it->memberIndex];
|
|
|
|
++it->memberIndex;
|
|
|
|
if (!(it->flags & ObjectIterator::EnumerableOnly) || a.isEnumerable()) {
|
2013-09-30 11:48:05 +00:00
|
|
|
name = n;
|
2013-06-10 15:11:52 +00:00
|
|
|
if (attrs)
|
|
|
|
*attrs = a;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-03-07 11:55:02 +00:00
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
// Section 8.12.3
|
2013-09-18 13:34:13 +00:00
|
|
|
ReturnedValue Object::internalGet(const StringRef name, bool *hasProperty)
|
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
|
|
|
|
2013-06-21 22:16:40 +00:00
|
|
|
name->makeIdentifier();
|
2013-01-30 13:56:40 +00:00
|
|
|
|
2013-01-30 14:43:22 +00:00
|
|
|
Object *o = this;
|
|
|
|
while (o) {
|
2013-09-18 13:34:13 +00:00
|
|
|
uint idx = o->internalClass->find(name.getPointer());
|
2013-02-10 21:22:53 +00:00
|
|
|
if (idx < UINT_MAX) {
|
|
|
|
if (hasProperty)
|
|
|
|
*hasProperty = true;
|
2013-06-21 22:52:47 +00:00
|
|
|
return getValue(o->memberData + 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
|
|
|
}
|
|
|
|
|
2013-09-11 19:48:23 +00:00
|
|
|
ReturnedValue Object::internalGetIndexed(uint index, bool *hasProperty)
|
2013-01-10 14:11:32 +00:00
|
|
|
{
|
2013-04-10 08:46:23 +00:00
|
|
|
Property *pd = 0;
|
|
|
|
PropertyAttributes attrs = Attr_Data;
|
2013-01-30 14:43:22 +00:00
|
|
|
Object *o = this;
|
|
|
|
while (o) {
|
2013-04-10 08:46:23 +00:00
|
|
|
uint pidx = o->propertyIndexFromArrayIndex(index);
|
|
|
|
if (pidx < UINT_MAX) {
|
2013-10-13 20:08:59 +00:00
|
|
|
if (!o->arrayData[pidx].value.isEmpty()) {
|
2013-04-10 08:46:23 +00:00
|
|
|
pd = o->arrayData + pidx;
|
|
|
|
if (o->arrayAttributes)
|
|
|
|
attrs = o->arrayAttributes[pidx];
|
|
|
|
break;
|
|
|
|
}
|
2013-01-30 14:43:22 +00:00
|
|
|
}
|
|
|
|
if (o->isStringObject()) {
|
2013-04-12 12:43:58 +00:00
|
|
|
pd = static_cast<StringObject *>(o)->getIndex(index);
|
2013-04-10 08:46:23 +00:00
|
|
|
if (pd) {
|
|
|
|
attrs = (Attr_NotWritable|Attr_NotConfigurable);
|
2013-01-30 14:43:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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
|
2013-09-18 14:36:02 +00:00
|
|
|
void Object::internalPut(const StringRef name, const ValueRef value)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-10-22 11:26:08 +00:00
|
|
|
if (internalClass->engine->hasException)
|
|
|
|
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
|
|
|
|
2013-06-21 22:16:40 +00:00
|
|
|
name->makeIdentifier();
|
2013-01-30 13:56:40 +00:00
|
|
|
|
2013-09-18 12:30:53 +00:00
|
|
|
uint member = internalClass->find(name.getPointer());
|
2013-04-10 08:46:23 +00:00
|
|
|
Property *pd = 0;
|
|
|
|
PropertyAttributes attrs;
|
|
|
|
if (member < UINT_MAX) {
|
|
|
|
pd = memberData + member;
|
|
|
|
attrs = internalClass->propertyData[member];
|
|
|
|
}
|
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;
|
2013-10-01 14:11:55 +00:00
|
|
|
else if (isArrayObject() && name->equals(engine()->id_length)) {
|
2013-01-16 23:45:11 +00:00
|
|
|
bool ok;
|
2013-09-18 14:36:02 +00:00
|
|
|
uint l = value->asArrayLength(&ok);
|
2013-10-21 07:57:58 +00:00
|
|
|
if (!ok) {
|
2013-09-25 20:42:58 +00:00
|
|
|
engine()->current->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 {
|
2013-09-18 14:36:02 +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()) {
|
2013-01-16 23:45:11 +00:00
|
|
|
if (!extensible)
|
|
|
|
goto reject;
|
|
|
|
} else {
|
2013-04-12 12:36:41 +00:00
|
|
|
// clause 4
|
2013-08-29 12:31:32 +00:00
|
|
|
if ((pd = 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;
|
|
|
|
} else if (!extensible || !attrs.isWritable()) {
|
2013-01-16 23:45:11 +00:00
|
|
|
goto reject;
|
|
|
|
}
|
2013-04-12 12:36:41 +00:00
|
|
|
} else if (!extensible) {
|
|
|
|
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()) {
|
|
|
|
assert(pd->setter() != 0);
|
2012-10-29 14:37:02 +00:00
|
|
|
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(engine());
|
2013-09-11 12:36:01 +00:00
|
|
|
ScopedCallData callData(scope, 1);
|
2013-09-18 14:36:02 +00:00
|
|
|
callData->args[0] = *value;
|
2013-09-26 20:07:27 +00:00
|
|
|
callData->thisObject = this;
|
2013-09-05 11:22:23 +00:00
|
|
|
pd->setter()->call(callData);
|
2013-01-16 23:45:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-10-29 14:37:02 +00:00
|
|
|
|
2013-01-16 23:45:11 +00:00
|
|
|
{
|
2013-09-18 12:30:53 +00:00
|
|
|
Property *p = insertMember(name, Attr_Data);
|
2013-09-18 14:36:02 +00:00
|
|
|
p->value = *value;
|
2012-11-27 23:12:33 +00:00
|
|
|
return;
|
2012-10-29 14:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reject:
|
2013-06-21 22:09:24 +00:00
|
|
|
if (engine()->current->strictMode) {
|
2013-06-13 05:46:26 +00:00
|
|
|
QString message = QStringLiteral("Cannot assign to read-only property \"");
|
|
|
|
message += name->toQString();
|
|
|
|
message += QLatin1Char('\"');
|
2013-06-21 22:09:24 +00:00
|
|
|
engine()->current->throwTypeError(message);
|
2013-06-13 05:46:26 +00:00
|
|
|
}
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 07:10:42 +00:00
|
|
|
void Object::internalPutIndexed(uint index, const ValueRef value)
|
2013-01-10 14:11:32 +00:00
|
|
|
{
|
2013-10-22 11:26:08 +00:00
|
|
|
if (internalClass->engine->hasException)
|
|
|
|
return;
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
Property *pd = 0;
|
|
|
|
PropertyAttributes attrs;
|
|
|
|
|
|
|
|
uint pidx = propertyIndexFromArrayIndex(index);
|
2013-10-13 20:08:59 +00:00
|
|
|
if (pidx < UINT_MAX && !arrayData[pidx].value.isEmpty()) {
|
|
|
|
pd = arrayData + pidx;
|
|
|
|
attrs = arrayAttributes ? arrayAttributes[pidx] : PropertyAttributes(Attr_Data);
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!pd && isStringObject()) {
|
2013-04-12 12:43:58 +00:00
|
|
|
pd = static_cast<StringObject *>(this)->getIndex(index);
|
2013-04-10 08:46:23 +00:00
|
|
|
if (pd)
|
|
|
|
// 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
|
2013-09-19 07:10:42 +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()) {
|
2013-01-16 23:45:11 +00:00
|
|
|
if (!extensible)
|
|
|
|
goto reject;
|
|
|
|
} else {
|
2013-04-12 12:36:41 +00:00
|
|
|
// clause 4
|
2013-08-29 12:31:32 +00:00
|
|
|
if ((pd = 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;
|
|
|
|
} else if (!extensible || !attrs.isWritable()) {
|
2013-01-16 23:45:11 +00:00
|
|
|
goto reject;
|
|
|
|
}
|
2013-04-12 12:36:41 +00:00
|
|
|
} else if (!extensible) {
|
|
|
|
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()) {
|
|
|
|
assert(pd->setter() != 0);
|
2013-01-10 14:11:32 +00:00
|
|
|
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(engine());
|
2013-09-11 12:36:01 +00:00
|
|
|
ScopedCallData callData(scope, 1);
|
2013-09-19 07:10:42 +00:00
|
|
|
callData->args[0] = *value;
|
2013-09-26 20:07:27 +00:00
|
|
|
callData->thisObject = this;
|
2013-09-05 11:22:23 +00:00
|
|
|
pd->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:
|
2013-06-21 21:42:08 +00:00
|
|
|
if (engine()->current->strictMode)
|
|
|
|
engine()->current->throwTypeError();
|
2013-01-10 14:11:32 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
// Section 8.12.7
|
2013-09-19 07:58:50 +00:00
|
|
|
bool Object::internalDeleteProperty(const StringRef name)
|
2012-10-29 14:37:02 +00:00
|
|
|
{
|
2013-10-22 11:26:08 +00:00
|
|
|
if (internalClass->engine->hasException)
|
|
|
|
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
|
|
|
|
2013-06-21 22:16:40 +00:00
|
|
|
name->makeIdentifier();
|
2013-01-30 13:56:40 +00:00
|
|
|
|
2013-02-10 21:22:53 +00:00
|
|
|
uint memberIdx = internalClass->find(name);
|
|
|
|
if (memberIdx != UINT_MAX) {
|
2013-04-10 08:46:23 +00:00
|
|
|
if (internalClass->propertyData[memberIdx].isConfigurable()) {
|
2013-02-12 10:05:18 +00:00
|
|
|
internalClass->removeMember(this, name->identifier);
|
2013-04-10 08:46:23 +00:00
|
|
|
memmove(memberData + memberIdx, memberData + memberIdx + 1, (internalClass->size - memberIdx)*sizeof(Property));
|
2013-02-10 21:22:53 +00:00
|
|
|
return true;
|
2012-10-29 14:37:02 +00:00
|
|
|
}
|
2013-06-21 18:33:39 +00:00
|
|
|
if (engine()->current->strictMode)
|
|
|
|
engine()->current->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
|
|
|
{
|
2013-10-22 11:26:08 +00:00
|
|
|
if (internalClass->engine->hasException)
|
|
|
|
return false;
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
uint pidx = propertyIndexFromArrayIndex(index);
|
|
|
|
if (pidx == UINT_MAX)
|
|
|
|
return true;
|
2013-10-13 20:08:59 +00:00
|
|
|
if (arrayData[pidx].value.isEmpty())
|
2013-02-05 21:13:27 +00:00
|
|
|
return true;
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
if (!arrayAttributes || arrayAttributes[pidx].isConfigurable()) {
|
2013-10-13 20:08:59 +00:00
|
|
|
arrayData[pidx].value = Primitive::emptyValue();
|
|
|
|
if (arrayAttributes)
|
|
|
|
arrayAttributes[pidx].clear();
|
2013-02-05 21:13:27 +00:00
|
|
|
if (sparseArray) {
|
2013-04-10 08:46:23 +00:00
|
|
|
arrayData[pidx].value.int_32 = arrayFreeList;
|
|
|
|
arrayFreeList = pidx;
|
2013-02-05 21:13:27 +00:00
|
|
|
}
|
2013-01-10 14:11:32 +00:00
|
|
|
return true;
|
2013-02-05 21:13:27 +00:00
|
|
|
}
|
|
|
|
|
2013-06-21 18:33:39 +00:00
|
|
|
if (engine()->current->strictMode)
|
|
|
|
engine()->current->throwTypeError();
|
2013-01-10 14:11:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
// Section 8.12.9
|
2013-09-18 12:30:53 +00:00
|
|
|
bool Object::__defineOwnProperty__(ExecutionContext *ctx, const StringRef 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)
|
2013-04-10 08:46:23 +00:00
|
|
|
return __defineOwnProperty__(ctx, idx, p, attrs);
|
2013-01-10 14:11:32 +00:00
|
|
|
|
2013-06-21 22:16:40 +00:00
|
|
|
name->makeIdentifier();
|
2013-01-30 13:56:40 +00:00
|
|
|
|
2013-09-25 20:42:58 +00:00
|
|
|
Scope scope(ctx);
|
2013-04-10 08:46:23 +00:00
|
|
|
Property *current;
|
|
|
|
PropertyAttributes *cattrs;
|
2013-01-10 22:22:04 +00:00
|
|
|
|
2013-10-01 14:11:55 +00:00
|
|
|
if (isArrayObject() && name->equals(ctx->engine->id_length)) {
|
2013-04-10 08:46:23 +00:00
|
|
|
assert(ArrayObject::LengthPropertyIndex == internalClass->find(ctx->engine->id_length));
|
|
|
|
Property *lp = memberData + ArrayObject::LengthPropertyIndex;
|
|
|
|
cattrs = internalClass->propertyData.data() + ArrayObject::LengthPropertyIndex;
|
|
|
|
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;
|
2013-04-14 20:01:20 +00:00
|
|
|
uint l = p.value.asArrayLength(&ok);
|
2013-09-25 20:42:58 +00:00
|
|
|
if (!ok) {
|
|
|
|
ScopedValue v(scope, p.value);
|
|
|
|
ctx->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-08-15 13:54:15 +00:00
|
|
|
if (attrs.isAccessor())
|
|
|
|
hasAccessorProperty = 1;
|
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
|
2013-03-08 08:38:46 +00:00
|
|
|
{
|
2013-09-18 12:30:53 +00:00
|
|
|
uint member = internalClass->find(name.getPointer());
|
2013-03-08 08:38:46 +00:00
|
|
|
current = (member < UINT_MAX) ? memberData + member : 0;
|
2013-04-10 08:46:23 +00:00
|
|
|
cattrs = internalClass->propertyData.data() + member;
|
2013-03-08 08:38:46 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
if (!current) {
|
|
|
|
// clause 3
|
2012-10-28 20:56:15 +00:00
|
|
|
if (!extensible)
|
|
|
|
goto reject;
|
2012-10-29 14:37:02 +00:00
|
|
|
// clause 4
|
2013-09-18 12:30:53 +00:00
|
|
|
Property *pd = insertMember(name, attrs);
|
2013-04-10 08:46:23 +00:00
|
|
|
*pd = p;
|
|
|
|
pd->fullyPopulated(&attrs);
|
2012-10-29 14:37:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
return __defineOwnProperty__(ctx, current, name, p, attrs);
|
2013-01-14 22:32:57 +00:00
|
|
|
reject:
|
|
|
|
if (ctx->strictMode)
|
2013-02-14 22:04:12 +00:00
|
|
|
ctx->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
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
bool Object::__defineOwnProperty__(ExecutionContext *ctx, uint index, const Property &p, PropertyAttributes attrs)
|
2013-01-10 14:11:32 +00:00
|
|
|
{
|
2013-04-10 08:46:23 +00:00
|
|
|
Property *current = 0;
|
2013-01-14 22:32:57 +00:00
|
|
|
|
|
|
|
// 15.4.5.1, 4b
|
2013-04-10 08:46:23 +00:00
|
|
|
if (isArrayObject() && index >= arrayLength() && !internalClass->propertyData[ArrayObject::LengthPropertyIndex].isWritable())
|
2013-01-14 22:32:57 +00:00
|
|
|
goto reject;
|
|
|
|
|
2013-01-25 12:41:37 +00:00
|
|
|
if (isNonStrictArgumentsObject)
|
2013-04-10 08:46:23 +00:00
|
|
|
return static_cast<ArgumentsObject *>(this)->defineOwnProperty(ctx, index, p, attrs);
|
2013-01-22 21:23:59 +00:00
|
|
|
|
2013-01-10 14:11:32 +00:00
|
|
|
// Clause 1
|
2013-04-10 08:46:23 +00:00
|
|
|
{
|
|
|
|
uint pidx = propertyIndexFromArrayIndex(index);
|
2013-10-13 20:08:59 +00:00
|
|
|
if (pidx < UINT_MAX && !arrayData[pidx].value.isEmpty())
|
2013-04-10 08:46:23 +00:00
|
|
|
current = arrayData + pidx;
|
|
|
|
if (!current && isStringObject())
|
2013-04-12 12:43:58 +00:00
|
|
|
current = static_cast<StringObject *>(this)->getIndex(index);
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
2013-03-08 08:38:46 +00:00
|
|
|
|
2013-01-10 14:11:32 +00:00
|
|
|
if (!current) {
|
|
|
|
// clause 3
|
|
|
|
if (!extensible)
|
|
|
|
goto reject;
|
|
|
|
// clause 4
|
2013-04-10 08:46:23 +00:00
|
|
|
Property *pd = arrayInsert(index, attrs);
|
|
|
|
*pd = p;
|
|
|
|
pd->fullyPopulated(&attrs);
|
2013-01-10 14:11:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-18 12:30:53 +00:00
|
|
|
return __defineOwnProperty__(ctx, current, StringRef::null(), p, attrs);
|
2013-01-14 22:32:57 +00:00
|
|
|
reject:
|
|
|
|
if (ctx->strictMode)
|
2013-02-14 22:04:12 +00:00
|
|
|
ctx->throwTypeError();
|
2013-01-14 22:32:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-18 12:30:53 +00:00
|
|
|
bool Object::__defineOwnProperty__(ExecutionContext *ctx, Property *current, const StringRef 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;
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
PropertyAttributes cattrs = Attr_Data;
|
2013-09-18 12:30:53 +00:00
|
|
|
if (!member.isNull())
|
2013-04-10 08:46:23 +00:00
|
|
|
cattrs = internalClass->propertyData[current - memberData];
|
|
|
|
else if (arrayAttributes)
|
|
|
|
cattrs = arrayAttributes[current - arrayData];
|
|
|
|
|
2013-01-10 14:11:32 +00:00
|
|
|
// clause 6
|
2013-04-10 08:46:23 +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();
|
|
|
|
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);
|
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()) {
|
|
|
|
if (attrs.isWritable() || !current->value.sameValue(p.value))
|
2013-01-10 14:11:32 +00:00
|
|
|
goto reject;
|
|
|
|
}
|
|
|
|
} else { // clause 10
|
2013-04-10 08:46:23 +00:00
|
|
|
assert(cattrs.isAccessor() && attrs.isAccessor());
|
|
|
|
if (!cattrs.isConfigurable()) {
|
|
|
|
if (p.getter() && !(current->getter() == p.getter() || (!current->getter() && (quintptr)p.getter() == 0x1)))
|
2013-01-16 10:00:56 +00:00
|
|
|
goto reject;
|
2013-04-10 08:46:23 +00:00
|
|
|
if (p.setter() && !(current->setter() == p.setter() || (!current->setter() && (quintptr)p.setter() == 0x1)))
|
2013-01-10 14:11:32 +00:00
|
|
|
goto reject;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
accept:
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
current->merge(cattrs, p, attrs);
|
2013-09-18 12:30:53 +00:00
|
|
|
if (!member.isNull()) {
|
|
|
|
internalClass = internalClass->changeMember(member.getPointer(), cattrs);
|
2013-04-10 08:46:23 +00:00
|
|
|
} else {
|
|
|
|
if (cattrs != Attr_Data)
|
|
|
|
ensureArrayAttributes();
|
|
|
|
if (arrayAttributes)
|
|
|
|
arrayAttributes[current - arrayData] = cattrs;
|
|
|
|
}
|
2013-08-15 13:54:15 +00:00
|
|
|
if (attrs.isAccessor())
|
|
|
|
hasAccessorProperty = 1;
|
2013-01-10 14:11:32 +00:00
|
|
|
return true;
|
|
|
|
reject:
|
|
|
|
if (ctx->strictMode)
|
2013-02-14 22:04:12 +00:00
|
|
|
ctx->throwTypeError();
|
2013-01-10 14:11:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-14 22:32:57 +00:00
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
bool Object::__defineOwnProperty__(ExecutionContext *ctx, const QString &name, const Property &p, PropertyAttributes attrs)
|
2012-12-11 22:58:40 +00:00
|
|
|
{
|
2013-09-18 12:30:53 +00:00
|
|
|
Scope scope(ctx);
|
|
|
|
ScopedString s(scope, ctx->engine->newString(name));
|
|
|
|
return __defineOwnProperty__(ctx, 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
|
|
|
|
2013-08-15 13:54:15 +00:00
|
|
|
if (other->protoHasArray() || other->hasAccessorProperty) {
|
2013-08-13 08:43:15 +00:00
|
|
|
uint len = other->arrayLength();
|
|
|
|
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
|
|
|
}
|
|
|
|
} else {
|
|
|
|
arrayReserve(other->arrayDataLen);
|
|
|
|
arrayDataLen = other->arrayDataLen;
|
|
|
|
memcpy(arrayData, other->arrayData, arrayDataLen*sizeof(Property));
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:08:39 +00:00
|
|
|
arrayOffset = 0;
|
2013-08-13 08:43:15 +00:00
|
|
|
|
2013-02-03 21:08:39 +00:00
|
|
|
if (other->sparseArray) {
|
2013-10-13 19:03:44 +00:00
|
|
|
flags &= ~SimpleArray;
|
2013-02-03 10:36:55 +00:00
|
|
|
sparseArray = new SparseArray(*other->sparseArray);
|
2013-02-03 21:08:39 +00:00
|
|
|
arrayFreeList = other->arrayFreeList;
|
|
|
|
}
|
2013-08-13 08:43:15 +00:00
|
|
|
|
|
|
|
setArrayLengthUnchecked(other->arrayLength());
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-26 20:07:27 +00:00
|
|
|
ReturnedValue Object::arrayIndexOf(const ValueRef v, uint fromIndex, uint endIndex, ExecutionContext *ctx, Object *o)
|
2013-02-03 10:36:55 +00:00
|
|
|
{
|
2013-11-01 11:38:32 +00:00
|
|
|
Q_UNUSED(ctx);
|
|
|
|
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(engine());
|
2013-09-09 11:38:10 +00:00
|
|
|
ScopedValue value(scope);
|
|
|
|
|
2013-08-15 13:54:15 +00:00
|
|
|
if (o->protoHasArray() || o->arrayAttributes) {
|
2013-02-03 10:36:55 +00:00
|
|
|
// lets be safe and slow
|
|
|
|
for (uint i = fromIndex; i < endIndex; ++i) {
|
|
|
|
bool exists;
|
2013-09-09 11:38:10 +00:00
|
|
|
value = o->getIndexed(i, &exists);
|
2013-10-22 11:26:08 +00:00
|
|
|
if (scope.hasException())
|
|
|
|
return Encode::undefined();
|
2013-09-26 20:07:27 +00:00
|
|
|
if (exists && __qmljs_strict_equal(value, v))
|
2013-09-12 20:37:41 +00:00
|
|
|
return Encode(i);
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
} else if (sparseArray) {
|
2013-02-03 21:08:39 +00:00
|
|
|
for (SparseArrayNode *n = sparseArray->lowerBound(fromIndex); n != sparseArray->end() && n->key() < endIndex; n = n->nextNode()) {
|
2013-09-09 11:38:10 +00:00
|
|
|
value = o->getValue(arrayData + n->value, arrayAttributes ? arrayAttributes[n->value] : Attr_Data);
|
2013-10-22 11:26:08 +00:00
|
|
|
if (scope.hasException())
|
|
|
|
return Encode::undefined();
|
2013-09-26 20:07:27 +00:00
|
|
|
if (__qmljs_strict_equal(value, v))
|
2013-09-12 20:37:41 +00:00
|
|
|
return Encode(n->key());
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-11-01 11:38:32 +00:00
|
|
|
if (endIndex > arrayDataLen)
|
2013-02-03 21:08:39 +00:00
|
|
|
endIndex = arrayDataLen;
|
2013-04-10 08:46:23 +00:00
|
|
|
Property *pd = arrayData;
|
|
|
|
Property *end = pd + endIndex;
|
2013-02-03 10:36:55 +00:00
|
|
|
pd += fromIndex;
|
|
|
|
while (pd < end) {
|
2013-10-13 20:08:59 +00:00
|
|
|
if (!pd->value.isEmpty()) {
|
2013-09-09 11:38:10 +00:00
|
|
|
value = o->getValue(pd, arrayAttributes ? arrayAttributes[pd - arrayData] : Attr_Data);
|
2013-10-22 11:26:08 +00:00
|
|
|
if (scope.hasException())
|
|
|
|
return Encode::undefined();
|
2013-09-26 20:07:27 +00:00
|
|
|
if (__qmljs_strict_equal(value, v))
|
2013-09-12 20:37:41 +00:00
|
|
|
return Encode((uint)(pd - arrayData));
|
2013-04-12 13:03:16 +00:00
|
|
|
}
|
2013-02-03 10:36:55 +00:00
|
|
|
++pd;
|
|
|
|
}
|
|
|
|
}
|
2013-09-12 20:37:41 +00:00
|
|
|
return Encode(-1);
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Object::arrayConcat(const ArrayObject *other)
|
|
|
|
{
|
2013-02-03 21:08:39 +00:00
|
|
|
int newLen = arrayDataLen + other->arrayLength();
|
2013-02-03 10:36:55 +00:00
|
|
|
if (other->sparseArray)
|
|
|
|
initSparse();
|
2013-04-10 08:46:23 +00:00
|
|
|
// ### copy attributes as well!
|
2013-02-03 10:36:55 +00:00
|
|
|
if (sparseArray) {
|
|
|
|
if (other->sparseArray) {
|
|
|
|
for (const SparseArrayNode *it = other->sparseArray->begin(); it != other->sparseArray->end(); it = it->nextNode())
|
2013-04-10 08:46:23 +00:00
|
|
|
arraySet(arrayDataLen + it->key(), other->arrayData + it->value);
|
2013-02-03 10:36:55 +00:00
|
|
|
} else {
|
2013-02-03 21:08:39 +00:00
|
|
|
int oldSize = arrayDataLen;
|
|
|
|
arrayReserve(oldSize + other->arrayLength());
|
2013-04-10 08:46:23 +00:00
|
|
|
memcpy(arrayData + oldSize, other->arrayData, other->arrayLength()*sizeof(Property));
|
|
|
|
if (arrayAttributes)
|
|
|
|
std::fill(arrayAttributes + oldSize, arrayAttributes + oldSize + other->arrayLength(), PropertyAttributes(Attr_Data));
|
2013-02-03 10:36:55 +00:00
|
|
|
for (uint i = 0; i < other->arrayLength(); ++i) {
|
2013-02-03 21:08:39 +00:00
|
|
|
SparseArrayNode *n = sparseArray->insert(arrayDataLen + i);
|
2013-02-03 10:36:55 +00:00
|
|
|
n->value = oldSize + i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2013-11-01 11:38:32 +00:00
|
|
|
uint oldSize = arrayLength();
|
2013-02-03 21:08:39 +00:00
|
|
|
arrayReserve(oldSize + other->arrayDataLen);
|
|
|
|
if (oldSize > arrayDataLen) {
|
2013-11-01 11:38:32 +00:00
|
|
|
for (uint i = arrayDataLen; i < oldSize; ++i)
|
2013-10-13 20:08:59 +00:00
|
|
|
arrayData[i].value = Primitive::emptyValue();
|
2013-02-03 21:08:39 +00:00
|
|
|
}
|
2013-04-10 08:46:23 +00:00
|
|
|
if (other->arrayAttributes) {
|
2013-11-01 11:38:32 +00:00
|
|
|
for (uint i = 0; i < other->arrayDataLen; ++i) {
|
2013-04-10 08:46:23 +00:00
|
|
|
bool exists;
|
2013-09-26 20:07:27 +00:00
|
|
|
arrayData[oldSize + i].value = const_cast<ArrayObject *>(other)->getIndexed(i, &exists);
|
2013-09-20 13:13:14 +00:00
|
|
|
arrayDataLen = oldSize + i + 1;
|
2013-04-10 08:46:23 +00:00
|
|
|
if (arrayAttributes)
|
|
|
|
arrayAttributes[oldSize + i] = Attr_Data;
|
2013-10-13 20:08:59 +00:00
|
|
|
if (!exists)
|
|
|
|
arrayData[oldSize + i].value = Primitive::emptyValue();
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-09-20 13:13:14 +00:00
|
|
|
arrayDataLen = oldSize + other->arrayDataLen;
|
2013-04-10 08:46:23 +00:00
|
|
|
memcpy(arrayData + oldSize, other->arrayData, other->arrayDataLen*sizeof(Property));
|
|
|
|
if (arrayAttributes)
|
|
|
|
std::fill(arrayAttributes + oldSize, arrayAttributes + oldSize + other->arrayDataLen, PropertyAttributes(Attr_Data));
|
|
|
|
}
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
setArrayLengthUnchecked(newLen);
|
|
|
|
}
|
|
|
|
|
2013-09-19 11:17:55 +00:00
|
|
|
void Object::arraySort(ExecutionContext *context, ObjectRef thisObject, const ValueRef comparefn, uint len)
|
2013-02-03 10:36:55 +00:00
|
|
|
{
|
2013-02-03 21:08:39 +00:00
|
|
|
if (!arrayDataLen)
|
|
|
|
return;
|
|
|
|
|
2013-02-03 10:36:55 +00:00
|
|
|
if (sparseArray) {
|
2013-11-01 11:38:32 +00:00
|
|
|
context->throwUnimplemented(QStringLiteral("Object::sort unimplemented for sparse arrays"));
|
2013-02-03 10:36:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:08:39 +00:00
|
|
|
if (len > arrayDataLen)
|
|
|
|
len = arrayDataLen;
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
// The spec says the sorting goes through a series of get,put and delete operations.
|
|
|
|
// this implies that the attributes don't get sorted around.
|
|
|
|
// behavior of accessor properties is implementation defined. We simply turn them all
|
|
|
|
// into data properties and then sort. This is in line with the sentence above.
|
|
|
|
if (arrayAttributes) {
|
|
|
|
for (uint i = 0; i < len; i++) {
|
2013-10-13 20:08:59 +00:00
|
|
|
if ((arrayAttributes && arrayAttributes[i].isGeneric()) || arrayData[i].value.isEmpty()) {
|
2013-04-10 08:46:23 +00:00
|
|
|
while (--len > i)
|
2013-10-13 20:08:59 +00:00
|
|
|
if (!((arrayAttributes && arrayAttributes[len].isGeneric())|| arrayData[len].value.isEmpty()))
|
2013-04-10 08:46:23 +00:00
|
|
|
break;
|
2013-09-26 20:07:27 +00:00
|
|
|
arrayData[i].value = getValue(arrayData + len, arrayAttributes[len]);
|
2013-10-13 20:08:59 +00:00
|
|
|
arrayData[len].value = Primitive::emptyValue();
|
|
|
|
if (arrayAttributes) {
|
|
|
|
arrayAttributes[i] = Attr_Data;
|
|
|
|
arrayAttributes[len].clear();
|
|
|
|
}
|
2013-04-10 08:46:23 +00:00
|
|
|
} else if (arrayAttributes[i].isAccessor()) {
|
2013-09-26 20:07:27 +00:00
|
|
|
arrayData[i].value = getValue(arrayData + i, arrayAttributes[i]);
|
2013-04-10 08:46:23 +00:00
|
|
|
arrayAttributes[i] = Attr_Data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-21 07:57:58 +00:00
|
|
|
if (!(comparefn->isUndefined() || comparefn->asObject())) {
|
2013-09-05 12:49:55 +00:00
|
|
|
context->throwTypeError();
|
2013-10-21 07:57:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-09-05 12:49:55 +00:00
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
ArrayElementLessThan lessThan(context, thisObject, comparefn);
|
|
|
|
|
|
|
|
Property *begin = arrayData;
|
2013-06-26 10:44:56 +00:00
|
|
|
// We deliberately choose qSort over std::sort here, because with
|
|
|
|
// MSVC in debug builds, std::sort has an ASSERT() that verifies
|
|
|
|
// that the return values of lessThan are perfectly consistent
|
|
|
|
// and aborts otherwise. We do not want JavaScript to easily crash
|
|
|
|
// the entire application and therefore choose qSort, which doesn't
|
|
|
|
// have this property.
|
2013-11-01 11:38:32 +00:00
|
|
|
std::sort(begin, begin + len, lessThan);
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Object::initSparse()
|
|
|
|
{
|
|
|
|
if (!sparseArray) {
|
2013-10-13 19:03:44 +00:00
|
|
|
flags &= ~SimpleArray;
|
2013-02-03 10:36:55 +00:00
|
|
|
sparseArray = new SparseArray;
|
2013-11-01 11:38:32 +00:00
|
|
|
for (uint i = 0; i < arrayDataLen; ++i) {
|
2013-10-13 20:08:59 +00:00
|
|
|
if (!((arrayAttributes && arrayAttributes[i].isGeneric()) || arrayData[i].value.isEmpty())) {
|
2013-02-05 21:14:03 +00:00
|
|
|
SparseArrayNode *n = sparseArray->insert(i);
|
|
|
|
n->value = i + arrayOffset;
|
|
|
|
}
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
|
2013-02-03 21:08:39 +00:00
|
|
|
uint off = arrayOffset;
|
|
|
|
if (!arrayOffset) {
|
|
|
|
arrayFreeList = arrayDataLen;
|
|
|
|
} else {
|
|
|
|
arrayFreeList = 0;
|
|
|
|
arrayData -= off;
|
|
|
|
arrayAlloc += off;
|
|
|
|
int o = off;
|
2013-02-03 10:36:55 +00:00
|
|
|
for (int i = 0; i < o - 1; ++i) {
|
2013-09-25 10:24:36 +00:00
|
|
|
arrayData[i].value = Primitive::fromInt32(i + 1);
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
2013-09-25 10:24:36 +00:00
|
|
|
arrayData[o - 1].value = Primitive::fromInt32(arrayDataLen + off);
|
2013-02-03 21:08:39 +00:00
|
|
|
}
|
2013-11-01 11:38:32 +00:00
|
|
|
for (uint i = arrayDataLen + off; i < arrayAlloc; ++i) {
|
2013-09-25 10:24:36 +00:00
|
|
|
arrayData[i].value = Primitive::fromInt32(i + 1);
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:08:39 +00:00
|
|
|
void Object::arrayReserve(uint n)
|
2013-02-03 10:36:55 +00:00
|
|
|
{
|
2013-02-03 21:08:39 +00:00
|
|
|
if (n < 8)
|
|
|
|
n = 8;
|
|
|
|
if (n >= arrayAlloc) {
|
|
|
|
uint off;
|
|
|
|
if (sparseArray) {
|
|
|
|
assert(arrayFreeList == arrayAlloc);
|
|
|
|
// ### FIXME
|
|
|
|
arrayDataLen = arrayAlloc;
|
|
|
|
off = 0;
|
|
|
|
} else {
|
|
|
|
off = arrayOffset;
|
|
|
|
}
|
|
|
|
arrayAlloc = qMax(n, 2*arrayAlloc);
|
2013-04-10 08:46:23 +00:00
|
|
|
Property *newArrayData = new Property[arrayAlloc];
|
2013-03-01 14:02:46 +00:00
|
|
|
if (arrayData) {
|
2013-04-10 08:46:23 +00:00
|
|
|
memcpy(newArrayData, arrayData, sizeof(Property)*arrayDataLen);
|
2013-03-01 14:02:46 +00:00
|
|
|
delete [] (arrayData - off);
|
|
|
|
}
|
2013-02-03 21:08:39 +00:00
|
|
|
arrayData = newArrayData;
|
|
|
|
if (sparseArray) {
|
|
|
|
for (uint i = arrayFreeList; i < arrayAlloc; ++i) {
|
2013-09-30 13:41:24 +00:00
|
|
|
arrayData[i].value = Primitive::emptyValue();
|
2013-09-25 10:24:36 +00:00
|
|
|
arrayData[i].value = Primitive::fromInt32(i + 1);
|
2013-02-03 21:08:39 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
arrayOffset = 0;
|
|
|
|
}
|
2013-04-10 08:46:23 +00:00
|
|
|
|
|
|
|
if (arrayAttributes) {
|
|
|
|
PropertyAttributes *newAttrs = new PropertyAttributes[arrayAlloc];
|
|
|
|
memcpy(newAttrs, arrayAttributes, sizeof(PropertyAttributes)*arrayDataLen);
|
|
|
|
delete [] (arrayAttributes - off);
|
|
|
|
|
|
|
|
arrayAttributes = newAttrs;
|
|
|
|
if (sparseArray) {
|
|
|
|
for (uint i = arrayFreeList; i < arrayAlloc; ++i)
|
|
|
|
arrayAttributes[i] = Attr_Invalid;
|
|
|
|
}
|
|
|
|
}
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
void Object::ensureArrayAttributes()
|
|
|
|
{
|
|
|
|
if (arrayAttributes)
|
|
|
|
return;
|
|
|
|
|
2013-10-13 19:03:44 +00:00
|
|
|
flags &= ~SimpleArray;
|
2013-04-10 08:46:23 +00:00
|
|
|
arrayAttributes = new PropertyAttributes[arrayAlloc];
|
|
|
|
for (uint i = 0; i < arrayDataLen; ++i)
|
|
|
|
arrayAttributes[i] = Attr_Data;
|
|
|
|
for (uint i = arrayDataLen; i < arrayAlloc; ++i)
|
|
|
|
arrayAttributes[i] = Attr_Invalid;
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:08:39 +00:00
|
|
|
|
2013-02-03 10:36:55 +00:00
|
|
|
bool Object::setArrayLength(uint newLen) {
|
|
|
|
assert(isArrayObject());
|
2013-04-10 08:46:23 +00:00
|
|
|
const Property *lengthProperty = memberData + ArrayObject::LengthPropertyIndex;
|
|
|
|
if (lengthProperty && !internalClass->propertyData[ArrayObject::LengthPropertyIndex].isWritable())
|
2013-02-03 10:36:55 +00:00
|
|
|
return false;
|
|
|
|
uint oldLen = arrayLength();
|
|
|
|
bool ok = true;
|
|
|
|
if (newLen < oldLen) {
|
|
|
|
if (sparseArray) {
|
|
|
|
SparseArrayNode *begin = sparseArray->lowerBound(newLen);
|
2013-02-03 21:08:39 +00:00
|
|
|
if (begin != sparseArray->end()) {
|
|
|
|
SparseArrayNode *it = sparseArray->end()->previousNode();
|
|
|
|
while (1) {
|
2013-04-10 08:46:23 +00:00
|
|
|
Property &pd = arrayData[it->value];
|
|
|
|
if (arrayAttributes) {
|
|
|
|
if (!arrayAttributes[it->value].isConfigurable()) {
|
|
|
|
ok = false;
|
|
|
|
newLen = it->key() + 1;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
arrayAttributes[it->value].clear();
|
|
|
|
}
|
2013-02-03 21:08:39 +00:00
|
|
|
}
|
2013-09-15 13:46:36 +00:00
|
|
|
pd.value.tag = Value::Empty_Type;
|
2013-02-03 21:08:39 +00:00
|
|
|
pd.value.int_32 = arrayFreeList;
|
|
|
|
arrayFreeList = it->value;
|
|
|
|
bool brk = (it == begin);
|
|
|
|
SparseArrayNode *prev = it->previousNode();
|
|
|
|
sparseArray->erase(it);
|
|
|
|
if (brk)
|
|
|
|
break;
|
|
|
|
it = prev;
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2013-04-10 08:46:23 +00:00
|
|
|
Property *it = arrayData + arrayDataLen;
|
|
|
|
const Property *begin = arrayData + newLen;
|
2013-02-03 10:36:55 +00:00
|
|
|
while (--it >= begin) {
|
2013-04-10 08:46:23 +00:00
|
|
|
if (arrayAttributes) {
|
|
|
|
if (!arrayAttributes[it - arrayData].isEmpty() && !arrayAttributes[it - arrayData].isConfigurable()) {
|
|
|
|
ok = false;
|
|
|
|
newLen = it - arrayData + 1;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
arrayAttributes[it - arrayData].clear();
|
|
|
|
}
|
2013-09-30 13:41:24 +00:00
|
|
|
it->value = Primitive::emptyValue();
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-03 21:08:39 +00:00
|
|
|
arrayDataLen = newLen;
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (newLen >= 0x100000)
|
|
|
|
initSparse();
|
|
|
|
}
|
|
|
|
setArrayLengthUnchecked(newLen);
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2013-09-14 09:25:02 +00:00
|
|
|
DEFINE_MANAGED_VTABLE(ArrayObject);
|
|
|
|
|
2013-05-02 20:33:47 +00:00
|
|
|
ArrayObject::ArrayObject(ExecutionEngine *engine, const QStringList &list)
|
2013-08-29 19:23:04 +00:00
|
|
|
: Object(engine->arrayClass)
|
2013-05-02 20:33:47 +00:00
|
|
|
{
|
2013-06-07 12:06:36 +00:00
|
|
|
init(engine);
|
2013-09-19 14:05:25 +00:00
|
|
|
Scope scope(engine);
|
|
|
|
ScopedValue protectThis(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();
|
|
|
|
arrayReserve(len);
|
2013-09-20 13:13:14 +00:00
|
|
|
for (int ii = 0; ii < len; ++ii) {
|
2013-09-25 13:24:50 +00:00
|
|
|
arrayData[ii].value = Encode(engine->newString(list.at(ii)));
|
2013-09-20 13:13:14 +00:00
|
|
|
arrayDataLen = ii + 1;
|
|
|
|
}
|
2013-05-02 20:33:47 +00:00
|
|
|
setArrayLengthUnchecked(len);
|
|
|
|
}
|
|
|
|
|
2013-04-30 21:43:26 +00:00
|
|
|
void ArrayObject::init(ExecutionEngine *engine)
|
2013-01-11 13:33:10 +00:00
|
|
|
{
|
2013-11-01 11:38:32 +00:00
|
|
|
Q_UNUSED(engine);
|
|
|
|
|
2013-01-25 12:13:06 +00:00
|
|
|
type = Type_ArrayObject;
|
2013-09-25 10:24:36 +00:00
|
|
|
memberData[LengthPropertyIndex].value = Primitive::fromInt32(0);
|
2013-01-11 13:33:10 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 20:33:47 +00:00
|
|
|
QStringList ArrayObject::toQStringList() const
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
uint32_t length = arrayLength();
|
2013-09-11 19:48:23 +00:00
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
|
|
|
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;
|
|
|
|
}
|