aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-11-01 09:19:55 +0100
committerLars Knoll <lars.knoll@qt.io>2017-11-13 08:56:36 +0000
commitcf8e87abaabd2f9aaf643d9563b526a662d3941d (patch)
tree204dbc7a47e8be1db4c4b0519efcfa274d090373
parent5c268e5b3a0af4e516e87cadc5904eeefafe4aa2 (diff)
Convert methods of RegExp to new calling convention
Change-Id: Ie364357b5e1ecf09eb264181e11b0247b07fad6c Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
-rw-r--r--src/qml/jsruntime/qv4object.cpp23
-rw-r--r--src/qml/jsruntime/qv4object_p.h4
-rw-r--r--src/qml/jsruntime/qv4regexpobject.cpp39
-rw-r--r--src/qml/jsruntime/qv4regexpobject_p.h20
-rw-r--r--src/qml/jsruntime/qv4stringobject.cpp4
5 files changed, 57 insertions, 33 deletions
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp
index bfc4eb9ce1..8a178506aa 100644
--- a/src/qml/jsruntime/qv4object.cpp
+++ b/src/qml/jsruntime/qv4object.cpp
@@ -212,6 +212,29 @@ void Object::defineAccessorProperty(String *name, ReturnedValue (*getter)(const
insertMember(name, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
}
+void Object::defineAccessorProperty(const QString &name, ReturnedValue (*getter)(const FunctionObject *, const Value *, const Value *, int),
+ ReturnedValue (*setter)(const FunctionObject *, const Value *, const Value *, int))
+{
+ ExecutionEngine *e = engine();
+ Scope scope(e);
+ ScopedString s(scope, e->newIdentifier(name));
+ defineAccessorProperty(s, getter, setter);
+}
+
+void Object::defineAccessorProperty(String *name, ReturnedValue (*getter)(const FunctionObject *, const Value *, const Value *, int),
+ ReturnedValue (*setter)(const FunctionObject *, const Value *, const Value *, int))
+{
+ ExecutionEngine *v4 = engine();
+ QV4::Scope scope(v4);
+ ScopedProperty p(scope);
+ ExecutionContext *global = v4->rootContext();
+ p->setGetter(ScopedFunctionObject(scope, (getter ? BuiltinFunction::create(global, name, getter) : 0)));
+ p->setSetter(ScopedFunctionObject(scope, (setter ? BuiltinFunction::create(global, name, setter) : 0)));
+ insertMember(name, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
+}
+
+
+
void Object::defineReadonlyProperty(const QString &name, const Value &value)
{
QV4::ExecutionEngine *e = engine();
diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h
index d2e7f3ff8c..9a1cb2c696 100644
--- a/src/qml/jsruntime/qv4object_p.h
+++ b/src/qml/jsruntime/qv4object_p.h
@@ -298,6 +298,10 @@ struct Q_QML_EXPORT Object: Managed {
ReturnedValue (*setter)(const BuiltinFunction *, CallData *));
void defineAccessorProperty(String *name, ReturnedValue (*getter)(const BuiltinFunction *, CallData *),
ReturnedValue (*setter)(const BuiltinFunction *, CallData *));
+ void defineAccessorProperty(const QString &name, ReturnedValue (*getter)(const FunctionObject *, const Value *, const Value *, int),
+ ReturnedValue (*setter)(const FunctionObject *, const Value *, const Value *, int));
+ void defineAccessorProperty(String *name, ReturnedValue (*getter)(const FunctionObject *, const Value *, const Value *, int),
+ ReturnedValue (*setter)(const FunctionObject *, const Value *, const Value *, int));
/* Fixed: Writable: false, Enumerable: false, Configurable: false */
void defineReadonlyProperty(const QString &name, const Value &value);
void defineReadonlyProperty(String *name, const Value &value);
diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp
index 3ff5349e74..f95719b25f 100644
--- a/src/qml/jsruntime/qv4regexpobject.cpp
+++ b/src/qml/jsruntime/qv4regexpobject.cpp
@@ -311,13 +311,13 @@ void RegExpPrototype::init(ExecutionEngine *engine, Object *constructor)
}
/* used by String.match */
-ReturnedValue RegExpPrototype::execFirstMatch(const BuiltinFunction *b, CallData *callData)
+ReturnedValue RegExpPrototype::execFirstMatch(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
{
Scope scope(b);
- Scoped<RegExpObject> r(scope, callData->thisObject.as<RegExpObject>());
+ Scoped<RegExpObject> r(scope, thisObject->as<RegExpObject>());
Q_ASSERT(r && r->global());
- ScopedString str(scope, callData->args[0]);
+ ScopedString str(scope, argc ? argv[0] : Primitive::undefinedValue());
Q_ASSERT(str);
QString s = str->toQString();
@@ -356,14 +356,14 @@ ReturnedValue RegExpPrototype::execFirstMatch(const BuiltinFunction *b, CallData
return retVal;
}
-ReturnedValue RegExpPrototype::method_exec(const BuiltinFunction *b, CallData *callData)
+ReturnedValue RegExpPrototype::method_exec(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
{
Scope scope(b);
- Scoped<RegExpObject> r(scope, callData->thisObject.as<RegExpObject>());
+ Scoped<RegExpObject> r(scope, thisObject->as<RegExpObject>());
if (!r)
return scope.engine->throwTypeError();
- ScopedValue arg(scope, callData->argument(0));
+ ScopedValue arg(scope, argc ? argv[0]: Primitive::undefinedValue());
ScopedString str(scope, arg->toString(scope.engine));
if (scope.hasException())
RETURN_UNDEFINED();
@@ -413,40 +413,37 @@ ReturnedValue RegExpPrototype::method_exec(const BuiltinFunction *b, CallData *c
return array.asReturnedValue();
}
-ReturnedValue RegExpPrototype::method_test(const BuiltinFunction *b, CallData *callData)
+ReturnedValue RegExpPrototype::method_test(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
{
- Value res = Value::fromReturnedValue(method_exec(b, callData));
+ Value res = Value::fromReturnedValue(method_exec(b, thisObject, argv, argc));
return Encode(!res.isNull());
}
-ReturnedValue RegExpPrototype::method_toString(const BuiltinFunction *b, CallData *callData)
+ReturnedValue RegExpPrototype::method_toString(const FunctionObject *b, const Value *thisObject, const Value *, int)
{
ExecutionEngine *v4 = b->engine();
- RegExpObject *r = callData->thisObject.as<RegExpObject>();
+ const RegExpObject *r = thisObject->as<RegExpObject>();
if (!r)
return v4->throwTypeError();
return Encode(v4->newString(r->toString()));
}
-ReturnedValue RegExpPrototype::method_compile(const BuiltinFunction *b, CallData *callData)
+ReturnedValue RegExpPrototype::method_compile(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
{
Scope scope(b);
- Scoped<RegExpObject> r(scope, callData->thisObject.as<RegExpObject>());
+ Scoped<RegExpObject> r(scope, thisObject->as<RegExpObject>());
if (!r)
return scope.engine->throwTypeError();
- JSCallData jsCallData(scope, callData->argc());
- memcpy(jsCallData->args, callData->args, callData->argc()*sizeof(Value));
-
- Scoped<RegExpObject> re(scope, scope.engine->regExpCtor()->callAsConstructor(jsCallData));
+ Scoped<RegExpObject> re(scope, scope.engine->regExpCtor()->callAsConstructor(argv, argc));
r->d()->value.set(scope.engine, re->value());
return Encode::undefined();
}
template <int index>
-ReturnedValue RegExpPrototype::method_get_lastMatch_n(const BuiltinFunction *b, CallData *)
+ReturnedValue RegExpPrototype::method_get_lastMatch_n(const FunctionObject *b, const Value *, const Value *, int)
{
Scope scope(b);
ScopedArrayObject lastMatch(scope, static_cast<RegExpCtor*>(scope.engine->regExpCtor())->lastMatch());
@@ -456,7 +453,7 @@ ReturnedValue RegExpPrototype::method_get_lastMatch_n(const BuiltinFunction *b,
return res->asReturnedValue();
}
-ReturnedValue RegExpPrototype::method_get_lastParen(const BuiltinFunction *b, CallData *)
+ReturnedValue RegExpPrototype::method_get_lastParen(const FunctionObject *b, const Value *, const Value *, int)
{
Scope scope(b);
ScopedArrayObject lastMatch(scope, static_cast<RegExpCtor*>(scope.engine->regExpCtor())->lastMatch());
@@ -466,12 +463,12 @@ ReturnedValue RegExpPrototype::method_get_lastParen(const BuiltinFunction *b, Ca
return res->asReturnedValue();
}
-ReturnedValue RegExpPrototype::method_get_input(const BuiltinFunction *b, CallData *)
+ReturnedValue RegExpPrototype::method_get_input(const FunctionObject *b, const Value *, const Value *, int)
{
return static_cast<RegExpCtor*>(b->engine()->regExpCtor())->lastInput()->asReturnedValue();
}
-ReturnedValue RegExpPrototype::method_get_leftContext(const BuiltinFunction *b, CallData *)
+ReturnedValue RegExpPrototype::method_get_leftContext(const FunctionObject *b, const Value *, const Value *, int)
{
Scope scope(b);
Scoped<RegExpCtor> regExpCtor(scope, scope.engine->regExpCtor());
@@ -479,7 +476,7 @@ ReturnedValue RegExpPrototype::method_get_leftContext(const BuiltinFunction *b,
return Encode(scope.engine->newString(lastInput.left(regExpCtor->lastMatchStart())));
}
-ReturnedValue RegExpPrototype::method_get_rightContext(const BuiltinFunction *b, CallData *)
+ReturnedValue RegExpPrototype::method_get_rightContext(const FunctionObject *b, const Value *, const Value *, int)
{
Scope scope(b);
Scoped<RegExpCtor> regExpCtor(scope, scope.engine->regExpCtor());
diff --git a/src/qml/jsruntime/qv4regexpobject_p.h b/src/qml/jsruntime/qv4regexpobject_p.h
index 1f92516928..37e8994c23 100644
--- a/src/qml/jsruntime/qv4regexpobject_p.h
+++ b/src/qml/jsruntime/qv4regexpobject_p.h
@@ -158,19 +158,19 @@ struct RegExpPrototype: RegExpObject
{
void init(ExecutionEngine *engine, Object *ctor);
- static ReturnedValue method_exec(const BuiltinFunction *, CallData *callData);
- static ReturnedValue method_test(const BuiltinFunction *, CallData *callData);
- static ReturnedValue method_toString(const BuiltinFunction *, CallData *callData);
- static ReturnedValue method_compile(const BuiltinFunction *, CallData *callData);
+ static ReturnedValue method_exec(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
+ static ReturnedValue method_test(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
+ static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
+ static ReturnedValue method_compile(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
template <int index>
- static ReturnedValue method_get_lastMatch_n(const BuiltinFunction *, CallData *callData);
- static ReturnedValue method_get_lastParen(const BuiltinFunction *, CallData *callData);
- static ReturnedValue method_get_input(const BuiltinFunction *, CallData *callData);
- static ReturnedValue method_get_leftContext(const BuiltinFunction *, CallData *callData);
- static ReturnedValue method_get_rightContext(const BuiltinFunction *, CallData *callData);
+ static ReturnedValue method_get_lastMatch_n(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
+ static ReturnedValue method_get_lastParen(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
+ static ReturnedValue method_get_input(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
+ static ReturnedValue method_get_leftContext(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
+ static ReturnedValue method_get_rightContext(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
- static ReturnedValue execFirstMatch(const BuiltinFunction *b, CallData *callData);
+ static ReturnedValue execFirstMatch(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
};
}
diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp
index 571a638355..f32acc6eed 100644
--- a/src/qml/jsruntime/qv4stringobject.cpp
+++ b/src/qml/jsruntime/qv4stringobject.cpp
@@ -428,7 +428,7 @@ ReturnedValue StringPrototype::method_match(const BuiltinFunction *b, CallData *
qSwap(callData->thisObject, callData->args[0]);
if (!global)
- return RegExpPrototype::method_exec(b, callData);
+ return RegExpPrototype::method_exec(b, &callData->thisObject, callData->args, callData->argc());
// rx is now in thisObject
RegExpObject *rx = static_cast<RegExpObject *>(&callData->thisObject);
@@ -438,7 +438,7 @@ ReturnedValue StringPrototype::method_match(const BuiltinFunction *b, CallData *
int previousLastIndex = 0;
uint n = 0;
while (1) {
- Value result = Primitive::fromReturnedValue(RegExpPrototype::execFirstMatch(b, callData));
+ Value result = Primitive::fromReturnedValue(RegExpPrototype::execFirstMatch(b, &callData->thisObject, callData->args, callData->argc()));
if (result.isNull())
break;
int index = rx->lastIndex();