aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-08-08 15:03:57 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-15 14:24:34 +0000
commitcecd8be881034153fc6b92e96f152a4a0c189ae4 (patch)
treecf554f3cb78ab6a0d02947870345d3660ddc36e0
parent2e3d2565aab881d4b86911a59769e777de8a9c9f (diff)
Implement RegExp.prototype[Symbol.search]
Change-Id: Ie966628d020eb010eb5ecc3279fed2b002975728 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--src/qml/jsruntime/qv4regexpobject.cpp35
-rw-r--r--src/qml/jsruntime/qv4regexpobject_p.h1
-rw-r--r--tests/auto/qml/ecmascripttests/TestExpectations18
3 files changed, 36 insertions, 18 deletions
diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp
index 8d457352d7..63b0d1524f 100644
--- a/src/qml/jsruntime/qv4regexpobject.cpp
+++ b/src/qml/jsruntime/qv4regexpobject.cpp
@@ -342,6 +342,7 @@ void RegExpPrototype::init(ExecutionEngine *engine, Object *constructor)
defineDefaultProperty(QStringLiteral("exec"), method_exec, 1);
defineDefaultProperty(engine->symbol_match(), method_match, 1);
defineAccessorProperty(scope.engine->id_multiline(), method_get_multiline, nullptr);
+ defineDefaultProperty(engine->symbol_search(), method_search, 1);
defineAccessorProperty(QStringLiteral("source"), method_get_source, nullptr);
defineAccessorProperty(scope.engine->id_sticky(), method_get_sticky, nullptr);
defineDefaultProperty(QStringLiteral("test"), method_test, 1);
@@ -557,6 +558,40 @@ ReturnedValue RegExpPrototype::method_get_multiline(const FunctionObject *f, con
return Encode(b);
}
+ReturnedValue RegExpPrototype::method_search(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
+{
+ Scope scope(f);
+ ScopedObject rx(scope, thisObject);
+ if (!rx)
+ return scope.engine->throwTypeError();
+
+ ScopedString s(scope, (argc ? argv[0] : Primitive::undefinedValue()).toString(scope.engine));
+ if (scope.hasException())
+ return Encode::undefined();
+
+ ScopedValue previousLastIndex(scope, rx->get(scope.engine->id_lastIndex()));
+ if (previousLastIndex->toNumber() != 0) {
+ if (!rx->put(scope.engine->id_lastIndex(), Primitive::fromInt32(0)))
+ return scope.engine->throwTypeError();
+ }
+
+ ScopedValue result(scope, exec(scope.engine, rx, s));
+ if (scope.hasException())
+ return Encode::undefined();
+
+ ScopedValue currentLastIndex(scope, rx->get(scope.engine->id_lastIndex()));
+ if (!currentLastIndex->sameValue(previousLastIndex)) {
+ if (!rx->put(scope.engine->id_lastIndex(), previousLastIndex))
+ return scope.engine->throwTypeError();
+ }
+
+ if (result->isNull())
+ return Encode(-1);
+ ScopedObject o(scope, result);
+ Q_ASSERT(o);
+ return o->get(scope.engine->id_index());
+}
+
ReturnedValue RegExpPrototype::method_get_source(const FunctionObject *f, const Value *thisObject, const Value *, int)
{
Scope scope(f);
diff --git a/src/qml/jsruntime/qv4regexpobject_p.h b/src/qml/jsruntime/qv4regexpobject_p.h
index 71936e2450..1aebbf3e58 100644
--- a/src/qml/jsruntime/qv4regexpobject_p.h
+++ b/src/qml/jsruntime/qv4regexpobject_p.h
@@ -166,6 +166,7 @@ struct RegExpPrototype: RegExpObject
static ReturnedValue method_get_ignoreCase(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_match(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_get_multiline(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
+ static ReturnedValue method_search(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_get_source(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_get_sticky(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_test(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
diff --git a/tests/auto/qml/ecmascripttests/TestExpectations b/tests/auto/qml/ecmascripttests/TestExpectations
index 5c2ad1f799..13552bd78b 100644
--- a/tests/auto/qml/ecmascripttests/TestExpectations
+++ b/tests/auto/qml/ecmascripttests/TestExpectations
@@ -771,24 +771,6 @@ built-ins/RegExp/prototype/Symbol.replace/y-fail-lastindex.js fails
built-ins/RegExp/prototype/Symbol.replace/y-fail-return.js fails
built-ins/RegExp/prototype/Symbol.replace/y-init-lastindex.js fails
built-ins/RegExp/prototype/Symbol.replace/y-set-lastindex.js fails
-built-ins/RegExp/prototype/Symbol.search/coerce-string-err.js fails
-built-ins/RegExp/prototype/Symbol.search/coerce-string.js fails
-built-ins/RegExp/prototype/Symbol.search/cstm-exec-return-index.js fails
-built-ins/RegExp/prototype/Symbol.search/failure-return-val.js fails
-built-ins/RegExp/prototype/Symbol.search/get-lastindex-err.js fails
-built-ins/RegExp/prototype/Symbol.search/lastindex-no-restore.js fails
-built-ins/RegExp/prototype/Symbol.search/length.js fails
-built-ins/RegExp/prototype/Symbol.search/match-err.js fails
-built-ins/RegExp/prototype/Symbol.search/name.js fails
-built-ins/RegExp/prototype/Symbol.search/prop-desc.js fails
-built-ins/RegExp/prototype/Symbol.search/set-lastindex-init-err.js fails
-built-ins/RegExp/prototype/Symbol.search/set-lastindex-init.js fails
-built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore-err.js fails
-built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore.js fails
-built-ins/RegExp/prototype/Symbol.search/success-get-index-err.js fails
-built-ins/RegExp/prototype/Symbol.search/success-return-val.js fails
-built-ins/RegExp/prototype/Symbol.search/u-lastindex-advance.js fails
-built-ins/RegExp/prototype/Symbol.search/y-fail-return.js fails
built-ins/RegExp/prototype/Symbol.split/coerce-flags-err.js fails
built-ins/RegExp/prototype/Symbol.split/coerce-flags.js fails
built-ins/RegExp/prototype/Symbol.split/coerce-limit-err.js fails