The property should be writable and also set to 0 if no match is found.
Change-Id: I4288ad239980260c7610c5de0061cc42ac38bb7a
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
arrayPrototype = new (memoryManager) ArrayPrototype(rootContext);
datePrototype = new (memoryManager) DatePrototype();
functionPrototype = new (memoryManager) FunctionPrototype(rootContext);
- regExpPrototype = new (memoryManager) RegExpPrototype();
+ regExpPrototype = new (memoryManager) RegExpPrototype(this);
errorPrototype = new (memoryManager) ErrorPrototype();
evalErrorPrototype = new (memoryManager) EvalErrorPrototype(rootContext);
rangeErrorPrototype = new (memoryManager) RangeErrorPrototype(rootContext);
RegExpObject *ExecutionEngine::newRegExpObject(PassRefPtr<RegExp> re, bool global)
{
- RegExpObject *object = new (memoryManager) RegExpObject(re, global);
+ RegExpObject *object = new (memoryManager) RegExpObject(this, re, global);
object->prototype = regExpPrototype;
return object;
}
}
+RegExpObject::RegExpObject(ExecutionEngine *engine, PassRefPtr<RegExp> value, bool global)
+ : value(value)
+ , global(global)
+{
+ if (!members)
+ members.reset(new PropertyTable());
+ lastIndexProperty = members->insert(engine->identifier("lastIndex"));
+ lastIndexProperty->type = PropertyDescriptor::Data;
+ lastIndexProperty->writable = PropertyDescriptor::Enabled;
+ lastIndexProperty->enumberable = PropertyDescriptor::Disabled;
+ lastIndexProperty->configurable = PropertyDescriptor::Disabled;
+ lastIndexProperty->value = Value::fromInt32(0);
+}
+
Value RegExpObject::__get__(ExecutionContext *ctx, String *name, bool *hasProperty)
{
QString n = name->toQString();
v = Value::fromBoolean(value->ignoreCase());
else if (n == QLatin1String("multiline"))
v = Value::fromBoolean(value->multiLine());
- else if (n == QLatin1String("lastIndex"))
- v = lastIndex;
if (v.type() != Value::Undefined_Type) {
if (hasProperty)
*hasProperty = true;
struct RegExpObject: Object {
RefPtr<RegExp> value;
- Value lastIndex;
+ PropertyDescriptor *lastIndexProperty;
bool global;
- RegExpObject(PassRefPtr<RegExp> value, bool global): value(value), lastIndex(Value::fromInt32(0)), global(global) {}
+ RegExpObject(ExecutionEngine *engine, PassRefPtr<RegExp> value, bool global);
virtual QString className() { return QStringLiteral("RegExp"); }
virtual RegExpObject *asRegExpObject() { return this; }
virtual Value __get__(ExecutionContext *ctx, String *name, bool *hasProperty);
arg = __qmljs_to_string(arg, ctx);
QString s = arg.stringValue()->toQString();
- int offset = r->global ? r->lastIndex.toInt32(ctx) : 0;
- if (offset < 0 || offset > s.length())
+ int offset = r->global ? r->lastIndexProperty->value.toInt32(ctx) : 0;
+ if (offset < 0 || offset > s.length()) {
+ r->lastIndexProperty->value = Value::fromInt32(0);
return Value::nullValue();
+ }
uint* matchOffsets = (uint*)alloca(r->value->captureCount() * 2 * sizeof(uint));
int result = r->value->match(s, offset, matchOffsets);
- if (result == -1)
+ if (result == -1) {
+ r->lastIndexProperty->value = Value::fromInt32(0);
return Value::nullValue();
+ }
// fill in result data
ArrayObject *array = ctx->engine->newArrayObject(ctx)->asArrayObject();
array->__put__(ctx, QLatin1String("input"), arg);
if (r->global)
- r->lastIndex = Value::fromInt32(matchOffsets[1]);
+ r->lastIndexProperty->value = Value::fromInt32(matchOffsets[1]);
return Value::fromObject(array);
}
struct RegExpPrototype: RegExpObject
{
- RegExpPrototype(): RegExpObject(RegExp::create(0, QString()), false) {}
+ RegExpPrototype(ExecutionEngine* engine): RegExpObject(engine, RegExp::create(0, QString()), false) {}
void init(ExecutionContext *ctx, const Value &ctor);
static Value method_exec(ExecutionContext *ctx);
S15.10.2.12_A5_T1 failing
S15.10.2.8_A3_T18 failing
S15.10.6.2_A1_T2 failing
-S15.10.6.2_A4_T1 failing
-S15.10.6.2_A4_T10 failing
-S15.10.6.2_A4_T11 failing
-S15.10.6.2_A4_T12 failing
-S15.10.6.2_A4_T2 failing
-S15.10.6.2_A4_T3 failing
-S15.10.6.2_A4_T4 failing
-S15.10.6.2_A4_T5 failing
-S15.10.6.2_A4_T6 failing
-S15.10.6.2_A4_T7 failing
-S15.10.6.2_A4_T8 failing
-S15.10.6.2_A4_T9 failing
-S15.10.6.2_A5_T1 failing
-S15.10.6.2_A5_T2 failing
-S15.10.6.2_A5_T3 failing
S15.10.7_A2_T1 failing
15.10.7.1-2 failing
S15.10.7.1_A10 failing
S15.10.7.4_A10 failing
S15.10.7.4_A8 failing
S15.10.7.4_A9 failing
-15.10.7.5-2 failing
-S15.10.7.5_A8 failing
-S15.10.7.5_A9 failing
S15.11.4.2_A1 failing
S15.11.4.2_A2 failing
S15.11.4.3_A1 failing