Remove the isString and isArray flags in Managed
These are not needed anymore, as we have the type stored in the object. Change-Id: I86594f4c3b3669ee0576e1ca141a64494e82a176 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
parent
e813c253f3
commit
6370d75d82
|
@ -76,7 +76,7 @@ ArgumentsObject::ArgumentsObject(ExecutionContext *context, int formalParameterC
|
|||
__defineOwnProperty__(context, i, &pd);
|
||||
}
|
||||
defineDefaultProperty(context, QStringLiteral("callee"), Value::fromObject(context->function));
|
||||
isArgumentsObject = true;
|
||||
isNonStrictArgumentsObject = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,12 +97,12 @@ bool ArgumentsObject::defineOwnProperty(ExecutionContext *ctx, uint index, const
|
|||
pd->value = mappedArguments.at(index);
|
||||
}
|
||||
|
||||
isArgumentsObject = false;
|
||||
isNonStrictArgumentsObject = false;
|
||||
bool strict = ctx->strictMode;
|
||||
ctx->strictMode = false;
|
||||
bool result = Object::__defineOwnProperty__(ctx, index, desc);
|
||||
ctx->strictMode = strict;
|
||||
isArgumentsObject = true;
|
||||
isNonStrictArgumentsObject = true;
|
||||
|
||||
if (isMapped && desc->isData()) {
|
||||
if (desc->type != PropertyDescriptor::Generic) {
|
||||
|
|
|
@ -103,7 +103,7 @@ void ArrayPrototype::init(ExecutionContext *ctx, const Value &ctor)
|
|||
|
||||
uint ArrayPrototype::getLength(ExecutionContext *ctx, Object *o)
|
||||
{
|
||||
if (o->isArray)
|
||||
if (o->isArrayObject())
|
||||
return o->array.length();
|
||||
return o->__get__(ctx, ctx->engine->id_length).toUInt32(ctx);
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ Value ArrayPrototype::method_pop(ExecutionContext *ctx)
|
|||
uint len = getLength(ctx, instance);
|
||||
|
||||
if (!len) {
|
||||
if (!instance->isArray)
|
||||
if (!instance->isArrayObject())
|
||||
instance->__put__(ctx, ctx->engine->id_length, Value::fromInt32(0));
|
||||
return Value::undefinedValue();
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ Value ArrayPrototype::method_pop(ExecutionContext *ctx)
|
|||
Value result = instance->__get__(ctx, len - 1);
|
||||
|
||||
instance->__delete__(ctx, len - 1);
|
||||
if (instance->isArray)
|
||||
if (instance->isArrayObject())
|
||||
instance->array.setLengthUnchecked(len - 1);
|
||||
else
|
||||
instance->__put__(ctx, ctx->engine->id_length, Value::fromDouble(len - 1));
|
||||
|
@ -241,7 +241,7 @@ Value ArrayPrototype::method_push(ExecutionContext *ctx)
|
|||
instance->__put__(ctx, idx.toString(ctx), ctx->argument(i));
|
||||
}
|
||||
double newLen = l + ctx->argumentCount;
|
||||
if (!instance->isArray)
|
||||
if (!instance->isArrayObject())
|
||||
instance->__put__(ctx, ctx->engine->id_length, Value::fromDouble(newLen));
|
||||
else
|
||||
ctx->throwRangeError(Value::fromString(ctx, QStringLiteral("Array.prototype.push: Overflow")));
|
||||
|
@ -264,7 +264,7 @@ Value ArrayPrototype::method_push(ExecutionContext *ctx)
|
|||
instance->__put__(ctx, len + i, ctx->argument(i));
|
||||
}
|
||||
uint newLen = len + ctx->argumentCount;
|
||||
if (!instance->isArray)
|
||||
if (!instance->isArrayObject())
|
||||
instance->__put__(ctx, ctx->engine->id_length, Value::fromDouble(newLen));
|
||||
|
||||
if (newLen < INT_MAX)
|
||||
|
@ -302,7 +302,7 @@ Value ArrayPrototype::method_shift(ExecutionContext *ctx)
|
|||
uint len = getLength(ctx, instance);
|
||||
|
||||
if (!len) {
|
||||
if (!instance->isArray)
|
||||
if (!instance->isArrayObject())
|
||||
instance->__put__(ctx, ctx->engine->id_length, Value::fromInt32(0));
|
||||
return Value::undefinedValue();
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ Value ArrayPrototype::method_shift(ExecutionContext *ctx)
|
|||
instance->__delete__(ctx, len - 1);
|
||||
}
|
||||
|
||||
if (!instance->isArray)
|
||||
if (!instance->isArrayObject())
|
||||
instance->__put__(ctx, ctx->engine->id_length, Value::fromDouble(len - 1));
|
||||
return result;
|
||||
}
|
||||
|
@ -474,7 +474,7 @@ Value ArrayPrototype::method_unshift(ExecutionContext *ctx)
|
|||
instance->__put__(ctx, i, ctx->argument(i));
|
||||
}
|
||||
uint newLen = len + ctx->argumentCount;
|
||||
if (!instance->isArray)
|
||||
if (!instance->isArrayObject())
|
||||
instance->__put__(ctx, ctx->engine->id_length, Value::fromDouble(newLen));
|
||||
|
||||
if (newLen < INT_MAX)
|
||||
|
@ -506,7 +506,7 @@ Value ArrayPrototype::method_indexOf(ExecutionContext *ctx)
|
|||
fromIndex = (uint) f;
|
||||
}
|
||||
|
||||
if (instance->isString) {
|
||||
if (instance->isStringObject()) {
|
||||
for (uint k = fromIndex; k < len; ++k) {
|
||||
bool exists;
|
||||
Value v = instance->__get__(ctx, k, &exists);
|
||||
|
|
|
@ -895,7 +895,7 @@ Value JsonObject::method_stringify(ExecutionContext *ctx)
|
|||
Object *o = ctx->argument(1).asObject();
|
||||
if (o) {
|
||||
stringify.replacerFunction = o->asFunctionObject();
|
||||
if (o->isArray) {
|
||||
if (o->isArrayObject()) {
|
||||
for (uint i = 0; i < o->array.length(); ++i) {
|
||||
Value v = o->__get__(ctx, i);
|
||||
if (v.asNumberObject() || v.asStringObject() || v.isNumber())
|
||||
|
|
13
qv4managed.h
13
qv4managed.h
|
@ -76,7 +76,7 @@ private:
|
|||
|
||||
protected:
|
||||
Managed() : markBit(0), inUse(1), extensible(true),
|
||||
isArray(false), isArgumentsObject(false), isString(false), isBuiltinFunction(false), type(Type_Object), unused(0) { }
|
||||
isNonStrictArgumentsObject(false), isBuiltinFunction(false), type(Type_Object), unused(0) { }
|
||||
virtual ~Managed();
|
||||
|
||||
public:
|
||||
|
@ -116,6 +116,9 @@ public:
|
|||
ArgumentsObject *asArgumentsObject() { return type == Type_ArgumentsObject ? reinterpret_cast<ArgumentsObject *>(this) : 0; }
|
||||
ForeachIteratorObject *asForeachIteratorObject() { return type == Type_ForeachIteratorObject ? reinterpret_cast<ForeachIteratorObject *>(this) : 0; }
|
||||
|
||||
bool isArrayObject() const { return type == Type_ArrayObject; }
|
||||
bool isStringObject() const { return type == Type_StringObject; }
|
||||
|
||||
protected:
|
||||
virtual void markObjects() = 0;
|
||||
|
||||
|
@ -125,18 +128,16 @@ protected:
|
|||
quintptr markBit : 1;
|
||||
quintptr inUse : 1;
|
||||
quintptr extensible : 1; // used by Object
|
||||
quintptr isArray : 1; // used by Object & Array
|
||||
quintptr isArgumentsObject : 1;
|
||||
quintptr isString : 1; // used by Object & StringObject
|
||||
quintptr isNonStrictArgumentsObject : 1;
|
||||
quintptr isBuiltinFunction : 1; // used by FunctionObject
|
||||
quintptr needsActivation : 1; // used by FunctionObject
|
||||
quintptr usesArgumentsObject : 1; // used by FunctionObject
|
||||
quintptr strictMode : 1; // used by FunctionObject
|
||||
quintptr type : 4;
|
||||
#if CPU(X86_64)
|
||||
quintptr unused : 50;
|
||||
quintptr unused : 51;
|
||||
#elif CPU(X86)
|
||||
quintptr unused : 18;
|
||||
quintptr unused : 19;
|
||||
#else
|
||||
#error "implement me"
|
||||
#endif
|
||||
|
|
|
@ -209,7 +209,7 @@ PropertyDescriptor *Object::__getOwnProperty__(ExecutionContext *ctx, uint index
|
|||
PropertyDescriptor *p = array.at(index);
|
||||
if(p && p->type != PropertyDescriptor::Generic)
|
||||
return p;
|
||||
if (isString)
|
||||
if (isStringObject())
|
||||
return static_cast<StringObject *>(this)->getIndex(ctx, index);
|
||||
|
||||
return 0;
|
||||
|
@ -241,7 +241,7 @@ PropertyDescriptor *Object::__getPropertyDescriptor__(ExecutionContext *ctx, uin
|
|||
PropertyDescriptor *p = o->array.at(index);
|
||||
if(p && p->type != PropertyDescriptor::Generic)
|
||||
return p;
|
||||
if (o->isString) {
|
||||
if (o->isStringObject()) {
|
||||
p = static_cast<StringObject *>(o)->getIndex(ctx, index);
|
||||
if (p)
|
||||
return p;
|
||||
|
@ -306,7 +306,7 @@ void Object::__put__(ExecutionContext *ctx, String *name, Value value)
|
|||
goto reject;
|
||||
} else if (!pd->isWritable())
|
||||
goto reject;
|
||||
else if (isArray && name->isEqualTo(ctx->engine->id_length)) {
|
||||
else if (isArrayObject() && name->isEqualTo(ctx->engine->id_length)) {
|
||||
bool ok;
|
||||
uint l = value.asArrayLength(ctx, &ok);
|
||||
if (!ok)
|
||||
|
@ -492,7 +492,7 @@ bool Object::__defineOwnProperty__(ExecutionContext *ctx, String *name, const Pr
|
|||
|
||||
PropertyDescriptor *current;
|
||||
|
||||
if (isArray && name->isEqualTo(ctx->engine->id_length)) {
|
||||
if (isArrayObject() && name->isEqualTo(ctx->engine->id_length)) {
|
||||
PropertyDescriptor *lp = array.getLengthProperty();
|
||||
if (desc->isEmpty() || desc->isSubset(lp))
|
||||
return true;
|
||||
|
@ -541,10 +541,10 @@ bool Object::__defineOwnProperty__(ExecutionContext *ctx, uint index, const Prop
|
|||
PropertyDescriptor *current;
|
||||
|
||||
// 15.4.5.1, 4b
|
||||
if (isArray && index >= array.length() && !array.getLengthProperty()->isWritable())
|
||||
if (isArrayObject() && index >= array.length() && !array.getLengthProperty()->isWritable())
|
||||
goto reject;
|
||||
|
||||
if (isArgumentsObject)
|
||||
if (isNonStrictArgumentsObject)
|
||||
return static_cast<ArgumentsObject *>(this)->defineOwnProperty(ctx, index, desc);
|
||||
|
||||
// Clause 1
|
||||
|
@ -647,7 +647,6 @@ Value Object::call(ExecutionContext *context, Value , Value *, int)
|
|||
void ArrayObject::init(ExecutionContext *context)
|
||||
{
|
||||
type = Type_ArrayObject;
|
||||
isArray = true;
|
||||
|
||||
if (!members)
|
||||
members.reset(new PropertyTable());
|
||||
|
|
|
@ -79,7 +79,6 @@ StringObject::StringObject(ExecutionContext *ctx, const Value &value)
|
|||
: value(value)
|
||||
{
|
||||
type = Type_StringObject;
|
||||
isString = true;
|
||||
|
||||
tmpProperty.type = PropertyDescriptor::Data;
|
||||
tmpProperty.enumberable = PropertyDescriptor::Enabled;
|
||||
|
|
Loading…
Reference in New Issue