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
|
|
|
|
2014-01-20 12:51:00 +00:00
|
|
|
DEFINE_OBJECT_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-02-10 21:22:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-11-21 12:15:46 +00:00
|
|
|
Object::Object(InternalClass *ic)
|
|
|
|
: Managed(ic)
|
2013-04-23 05:31:02 +00:00
|
|
|
, memberDataAlloc(InlinePropertySize), memberData(inlineProperties)
|
|
|
|
{
|
2013-11-21 13:26:08 +00:00
|
|
|
Q_ASSERT(internalClass->vtable && internalClass->vtable != &Managed::static_vtbl);
|
2013-04-23 05:31:02 +00:00
|
|
|
|
|
|
|
if (internalClass->size >= memberDataAlloc) {
|
|
|
|
memberDataAlloc = internalClass->size;
|
|
|
|
memberData = new Property[memberDataAlloc];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-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()) {
|
2014-01-08 14:59:34 +00:00
|
|
|
if (FunctionObject *set = pd->setter()) {
|
|
|
|
Scope scope(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;
|
2014-01-08 14:59:34 +00:00
|
|
|
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-11-21 15:41:32 +00:00
|
|
|
if (engine()->currentContext()->strictMode)
|
|
|
|
engine()->currentContext()->throwTypeError();
|
2013-03-07 11:55:02 +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-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));
|
|
|
|
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-11-03 14:23:05 +00:00
|
|
|
void Object::defineDefaultProperty(const StringRef name, ReturnedValue (*code)(CallContext *), int argumentCount)
|
2013-09-18 13:34:13 +00:00
|
|
|
{
|
|
|
|
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-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);
|
|
|
|
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-11-03 14:23:05 +00:00
|
|
|
void Object::defineAccessorProperty(const StringRef 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);
|
|
|
|
p->setGetter(getter ? v4->newBuiltinFunction(v4->rootContext, name, getter)->getPointer() : 0);
|
|
|
|
p->setSetter(setter ? v4->newBuiltinFunction(v4->rootContext, name, setter)->getPointer() : 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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-01-07 15:10:00 +00:00
|
|
|
insertMember(name, value, Attr_ReadOnly);
|
2012-12-12 23:53:04 +00:00
|
|
|
}
|
|
|
|
|
2013-11-02 15:30:26 +00:00
|
|
|
void Object::markObjects(Managed *that, ExecutionEngine *e)
|
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-11-02 15:30:26 +00:00
|
|
|
o->memberData[i].value.mark(e);
|
2013-10-15 20:27:10 +00:00
|
|
|
} 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];
|
2014-01-09 10:05:08 +00:00
|
|
|
pd.value.mark(e);
|
|
|
|
if (o->internalClass->propertyData[i].isAccessor())
|
|
|
|
pd.set.mark(e);
|
2013-10-15 20:27:10 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-16 08:16:57 +00:00
|
|
|
if (o->arrayData)
|
2014-01-20 15:01:26 +00:00
|
|
|
o->arrayData->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
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2014-01-07 15:10:00 +00:00
|
|
|
void Object::insertMember(const StringRef s, const Property &p, 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);
|
|
|
|
|
2014-01-07 15:10:00 +00:00
|
|
|
memberData[idx] = p;
|
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-12-16 08:16:57 +00:00
|
|
|
Property *p = arrayData->getProperty(index);
|
|
|
|
if (p) {
|
2014-01-07 14:36:28 +00:00
|
|
|
if (attrs)
|
|
|
|
*attrs = arrayData->attributes(index);
|
|
|
|
return p;
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
|
|
|
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)
|
2014-01-08 14:13:30 +00:00
|
|
|
return __getPropertyDescriptor__(idx, attrs);
|
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-12-16 08:16:57 +00:00
|
|
|
Property *p = o->arrayData->getProperty(index);
|
|
|
|
if (p) {
|
2014-01-07 14:36:28 +00:00
|
|
|
if (attrs)
|
|
|
|
*attrs = o->arrayData->attributes(index);
|
|
|
|
return p;
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2014-01-08 11:46:53 +00:00
|
|
|
bool Object::hasProperty(const StringRef 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
|
|
|
|
|
|
|
const Object *o = this;
|
|
|
|
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
|
|
|
{
|
|
|
|
const Object *o = this;
|
|
|
|
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-01-04 21:32:13 +00:00
|
|
|
bool Object::hasOwnProperty(const StringRef name) const
|
|
|
|
{
|
2014-01-08 11:46:53 +00:00
|
|
|
uint idx = name->asArrayIndex();
|
|
|
|
if (idx != UINT_MAX)
|
|
|
|
return hasOwnProperty(idx);
|
|
|
|
|
|
|
|
if (internalClass->find(name) < UINT_MAX)
|
|
|
|
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-01-08 11:46:53 +00:00
|
|
|
if (!arrayData->isEmpty(index))
|
|
|
|
return true;
|
|
|
|
if (isStringObject()) {
|
|
|
|
String *s = static_cast<const StringObject *>(this)->value.asString();
|
|
|
|
if (index < (uint)s->length())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!queryIndexed(index).isEmpty())
|
|
|
|
return true;
|
|
|
|
return false;
|
2014-01-04 21:32:13 +00:00
|
|
|
}
|
|
|
|
|
2014-01-20 12:51:00 +00:00
|
|
|
ReturnedValue Object::construct(Managed *m, CallData *)
|
|
|
|
{
|
|
|
|
return m->engine()->currentContext()->throwTypeError();
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnedValue Object::call(Managed *m, CallData *)
|
|
|
|
{
|
|
|
|
return m->engine()->currentContext()->throwTypeError();
|
|
|
|
}
|
|
|
|
|
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-12-16 08:16:57 +00:00
|
|
|
if (o->arrayData->get(index) != Primitive::emptyValue().asReturnedValue())
|
|
|
|
return o->arrayData->attributes(index);
|
|
|
|
|
2013-08-08 10:52:56 +00:00
|
|
|
if (o->isStringObject()) {
|
2014-01-08 13:57:07 +00:00
|
|
|
String *s = static_cast<const StringObject *>(o)->value.asString();
|
|
|
|
if (index < (uint)s->length())
|
|
|
|
return (Attr_NotWritable|Attr_NotConfigurable);
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
|
|
|
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;
|
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-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-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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-01-08 13:51:33 +00:00
|
|
|
void Object::advanceIterator(Managed *m, ObjectIterator *it, StringRef name, uint *index, Property *pd, 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;
|
|
|
|
|
2013-12-16 08:16:57 +00:00
|
|
|
if (o->arrayData) {
|
|
|
|
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;
|
2014-01-09 10:05:08 +00:00
|
|
|
Property *p = reinterpret_cast<Property *>(o->arrayData->data + pidx);
|
2013-12-16 08:16:57 +00:00
|
|
|
it->arrayNode = it->arrayNode->nextNode();
|
|
|
|
PropertyAttributes a = o->arrayData->attributes(k);
|
|
|
|
if (!(it->flags & ObjectIterator::EnumerableOnly) || a.isEnumerable()) {
|
|
|
|
it->arrayIndex = k + 1;
|
|
|
|
*index = k;
|
2014-01-08 13:51:33 +00:00
|
|
|
*attrs = a;
|
|
|
|
*pd = *p;
|
|
|
|
return;
|
2013-12-16 08:16:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
it->arrayNode = 0;
|
|
|
|
it->arrayIndex = UINT_MAX;
|
|
|
|
}
|
|
|
|
// dense arrays
|
|
|
|
while (it->arrayIndex < o->arrayData->length()) {
|
2014-01-24 21:55:39 +00:00
|
|
|
Value *val = o->arrayData->data + it->arrayIndex;
|
2013-12-16 08:16:57 +00:00
|
|
|
PropertyAttributes a = o->arrayData->attributes(it->arrayIndex);
|
|
|
|
++it->arrayIndex;
|
2014-01-09 10:05:08 +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-01-09 10:05:08 +00:00
|
|
|
pd->value = *val;
|
2014-01-08 13:51:33 +00:00
|
|
|
return;
|
2013-06-10 15:11:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2014-01-08 13:51:33 +00:00
|
|
|
*attrs = a;
|
|
|
|
*pd = *p;
|
|
|
|
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
|
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;
|
2013-12-16 08:16:57 +00:00
|
|
|
PropertyAttributes attrs;
|
2013-01-30 14:43:22 +00:00
|
|
|
Object *o = this;
|
|
|
|
while (o) {
|
2013-12-16 08:16:57 +00:00
|
|
|
Property *p = o->arrayData->getProperty(index);
|
|
|
|
if (p) {
|
2014-01-07 14:36:28 +00:00
|
|
|
pd = p;
|
|
|
|
attrs = o->arrayData->attributes(index);
|
|
|
|
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-11-21 15:41:32 +00:00
|
|
|
engine()->currentContext()->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
|
|
|
|
2014-01-07 15:10:00 +00:00
|
|
|
insertMember(name, value);
|
|
|
|
return;
|
2012-10-29 14:37:02 +00:00
|
|
|
|
|
|
|
reject:
|
2013-11-21 15:41:32 +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('\"');
|
2013-11-21 15:41:32 +00:00
|
|
|
engine()->currentContext()->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
|
|
|
PropertyAttributes attrs;
|
|
|
|
|
2014-01-07 14:36:28 +00:00
|
|
|
Property *pd = arrayData->getProperty(index);
|
|
|
|
if (pd)
|
2013-12-16 08:16:57 +00:00
|
|
|
attrs = arrayData->attributes(index);
|
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-11-21 15:41:32 +00:00
|
|
|
if (engine()->currentContext()->strictMode)
|
|
|
|
engine()->currentContext()->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-11-21 15:41:32 +00:00
|
|
|
if (engine()->currentContext()->strictMode)
|
|
|
|
engine()->currentContext()->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;
|
|
|
|
|
2014-01-22 14:25:50 +00:00
|
|
|
if (!arrayData || arrayData->vtable()->del(this, index))
|
2013-02-05 21:13:27 +00:00
|
|
|
return true;
|
|
|
|
|
2013-11-21 15:41:32 +00:00
|
|
|
if (engine()->currentContext()->strictMode)
|
|
|
|
engine()->currentContext()->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;
|
2014-01-09 10:05:08 +00:00
|
|
|
uint memberIndex;
|
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;
|
2013-11-19 11:46:34 +00:00
|
|
|
cattrs = internalClass->propertyData.constData() + ArrayObject::LengthPropertyIndex;
|
2013-04-10 08:46:23 +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;
|
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
|
2014-01-09 10:05:08 +00:00
|
|
|
memberIndex = internalClass->find(name.getPointer());
|
|
|
|
current = (memberIndex < UINT_MAX) ? memberData + memberIndex : 0;
|
|
|
|
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
|
2012-10-28 20:56:15 +00:00
|
|
|
if (!extensible)
|
|
|
|
goto reject;
|
2012-10-29 14:37:02 +00:00
|
|
|
// clause 4
|
2014-01-07 15:10:00 +00:00
|
|
|
Property pd = p;
|
|
|
|
pd.fullyPopulated(&attrs);
|
|
|
|
insertMember(name, pd, attrs);
|
2012-10-29 14:37:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-09 10:05:08 +00:00
|
|
|
return __defineOwnProperty__(ctx, memberIndex, 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-01-14 22:32:57 +00:00
|
|
|
// 15.4.5.1, 4b
|
2013-12-16 08:16:57 +00:00
|
|
|
if (isArrayObject() && index >= getLength() && !internalClass->propertyData[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))
|
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
|
|
|
|
2014-01-03 10:58:03 +00:00
|
|
|
return defineOwnProperty2(ctx, index, p, attrs);
|
|
|
|
reject:
|
|
|
|
if (ctx->strictMode)
|
|
|
|
ctx->throwTypeError();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Object::defineOwnProperty2(ExecutionContext *ctx, uint index, const Property &p, PropertyAttributes attrs)
|
|
|
|
{
|
|
|
|
Property *current = 0;
|
|
|
|
|
2013-01-10 14:11:32 +00:00
|
|
|
// Clause 1
|
2013-04-10 08:46:23 +00:00
|
|
|
{
|
2014-01-07 14:36:28 +00:00
|
|
|
current = arrayData->getProperty(index);
|
2013-04-10 08:46:23 +00:00
|
|
|
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-12-16 08:16:57 +00:00
|
|
|
Property pp(p);
|
|
|
|
pp.fullyPopulated(&attrs);
|
|
|
|
if (attrs == Attr_Data) {
|
|
|
|
Scope scope(ctx);
|
|
|
|
ScopedValue v(scope, pp.value);
|
|
|
|
arraySet(index, v);
|
|
|
|
} else {
|
|
|
|
arraySet(index, pp, attrs);
|
|
|
|
}
|
2013-01-10 14:11:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-09 10:05:08 +00:00
|
|
|
return __defineOwnProperty__(ctx, index, 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;
|
|
|
|
}
|
|
|
|
|
2014-01-09 10:05:08 +00:00
|
|
|
bool Object::__defineOwnProperty__(ExecutionContext *ctx, uint index, 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;
|
|
|
|
|
2014-01-09 10:05:08 +00:00
|
|
|
Property *current;
|
2013-12-16 08:16:57 +00:00
|
|
|
PropertyAttributes cattrs;
|
2014-01-09 10:05:08 +00:00
|
|
|
if (!member.isNull()) {
|
|
|
|
current = memberData + index;
|
|
|
|
cattrs = internalClass->propertyData[index];
|
|
|
|
} else {
|
|
|
|
current = arrayData->getProperty(index);
|
|
|
|
cattrs = arrayData->attributes(index);
|
|
|
|
}
|
2013-04-10 08:46:23 +00:00
|
|
|
|
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();
|
2014-01-09 10:05:08 +00:00
|
|
|
if (member.isNull()) {
|
|
|
|
// need to convert the array and the slot
|
|
|
|
initSparseArray();
|
2014-01-22 14:25:50 +00:00
|
|
|
setArrayAttributes(index, cattrs);
|
2014-01-09 10:05:08 +00:00
|
|
|
current = arrayData->getProperty(index);
|
|
|
|
}
|
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-01-09 10:05:08 +00:00
|
|
|
if (member.isNull()) {
|
|
|
|
// need to convert the array and the slot
|
2014-01-22 14:25:50 +00:00
|
|
|
setArrayAttributes(index, cattrs);
|
2014-01-09 10:05:08 +00:00
|
|
|
current = arrayData->getProperty(index);
|
|
|
|
}
|
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
|
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-01-09 10:05:08 +00:00
|
|
|
if (!p.value.isEmpty() && current->value.val != p.value.val)
|
2013-01-16 10:00:56 +00:00
|
|
|
goto reject;
|
2014-01-09 10:05:08 +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);
|
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 {
|
2014-01-22 14:25:50 +00:00
|
|
|
setArrayAttributes(index, cattrs);
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
2014-01-09 10:05:08 +00:00
|
|
|
if (cattrs.isAccessor())
|
2013-08-15 13:54:15 +00:00
|
|
|
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-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-01-09 10:05:08 +00:00
|
|
|
} else if (!other->arrayData) {
|
|
|
|
;
|
|
|
|
} else if (other->hasAccessorProperty && other->arrayData->attrs && other->arrayData->isSparse()){
|
|
|
|
// do it the slow way
|
2014-01-13 08:09:14 +00:00
|
|
|
ScopedValue v(scope);
|
2014-01-09 10:05:08 +00:00
|
|
|
for (const SparseArrayNode *it = static_cast<const SparseArrayData *>(other->arrayData)->sparse->begin();
|
2014-01-13 08:09:14 +00:00
|
|
|
it != static_cast<const SparseArrayData *>(other->arrayData)->sparse->end(); it = it->nextNode()) {
|
|
|
|
v = other->getValue(reinterpret_cast<Property *>(other->arrayData->data + it->value), other->arrayData->attrs[it->value]);
|
|
|
|
arraySet(it->key(), v);
|
|
|
|
}
|
2013-08-13 08:43:15 +00:00
|
|
|
} else {
|
2013-12-16 08:16:57 +00:00
|
|
|
Q_ASSERT(!arrayData && other->arrayData);
|
2014-01-24 13:29:40 +00:00
|
|
|
ArrayData::realloc(this, other->arrayData->type, 0, other->arrayData->alloc, other->arrayData->attrs);
|
2013-12-16 08:16:57 +00:00
|
|
|
if (other->arrayType() == ArrayData::Sparse) {
|
|
|
|
SparseArrayData *od = static_cast<SparseArrayData *>(other->arrayData);
|
2014-01-24 13:29:40 +00:00
|
|
|
SparseArrayData *dd = static_cast<SparseArrayData *>(arrayData);
|
2013-12-16 08:16:57 +00:00
|
|
|
dd->sparse = new SparseArray(*od->sparse);
|
|
|
|
dd->freeList = od->freeList;
|
2014-01-24 13:29:40 +00:00
|
|
|
} else {
|
2014-01-13 08:09:14 +00:00
|
|
|
SimpleArrayData *d = static_cast<SimpleArrayData *>(arrayData);
|
|
|
|
d->len = static_cast<SimpleArrayData *>(other->arrayData)->len;
|
|
|
|
d->offset = 0;
|
|
|
|
}
|
2014-01-24 21:55:39 +00:00
|
|
|
memcpy(arrayData->data, other->arrayData->data, 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
|
|
|
{
|
2013-12-16 08:16:57 +00:00
|
|
|
Scope scope(m->engine());
|
2014-01-20 12:51:00 +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());
|
|
|
|
const Property *lengthProperty = memberData + ArrayObject::LengthPropertyIndex;
|
|
|
|
if (lengthProperty && !internalClass->propertyData[ArrayObject::LengthPropertyIndex].isWritable())
|
|
|
|
return false;
|
|
|
|
uint oldLen = getLength();
|
|
|
|
bool ok = true;
|
|
|
|
if (newLen < oldLen) {
|
2014-01-22 14:25:50 +00:00
|
|
|
if (!arrayData) {
|
|
|
|
Q_ASSERT(!newLen);
|
|
|
|
} else {
|
|
|
|
uint l = arrayData->vtable()->truncate(this, newLen);
|
|
|
|
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
|
|
|
{
|
2013-12-16 08:16:57 +00:00
|
|
|
if (arrayType() == ArrayData::Sparse)
|
2013-02-03 21:08:39 +00:00
|
|
|
return;
|
|
|
|
|
2014-01-24 13:29:40 +00:00
|
|
|
ArrayData::realloc(this, ArrayData::Sparse, 0, 0, false);
|
2013-02-03 10:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-20 12:51:00 +00:00
|
|
|
DEFINE_OBJECT_VTABLE(ArrayObject);
|
2013-09-14 09:25:02 +00:00
|
|
|
|
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-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-01-22 14:25:50 +00:00
|
|
|
arrayPut(ii, (v = engine->newString(list.at(ii))));
|
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-09-25 10:24:36 +00:00
|
|
|
memberData[LengthPropertyIndex].value = Primitive::fromInt32(0);
|
2013-01-11 13:33:10 +00:00
|
|
|
}
|
|
|
|
|
2013-12-16 08:16:57 +00:00
|
|
|
ReturnedValue ArrayObject::getLookup(Managed *m, Lookup *l)
|
|
|
|
{
|
|
|
|
if (l->name->equals(m->engine()->id_length)) {
|
|
|
|
// special case, as the property is on the object itself
|
|
|
|
l->getter = Lookup::arrayLengthGetter;
|
|
|
|
ArrayObject *a = static_cast<ArrayObject *>(m);
|
|
|
|
return a->memberData[ArrayObject::LengthPropertyIndex].value.asReturnedValue();
|
|
|
|
}
|
|
|
|
return Object::getLookup(m, l);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint ArrayObject::getLength(const Managed *m)
|
|
|
|
{
|
|
|
|
const ArrayObject *a = static_cast<const ArrayObject *>(m);
|
|
|
|
if (a->memberData[ArrayObject::LengthPropertyIndex].value.isInteger())
|
|
|
|
return a->memberData[ArrayObject::LengthPropertyIndex].value.integerValue();
|
|
|
|
return Primitive::toUInt32(a->memberData[ArrayObject::LengthPropertyIndex].value.doubleValue());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-12-16 08:16:57 +00:00
|
|
|
uint32_t length = getLength();
|
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;
|
|
|
|
}
|