diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-09-01 11:48:15 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-09-02 07:12:17 +0000 |
commit | 74c8fe86755af485f8d0a47799d6d50f00070f05 (patch) | |
tree | 9e3d8c51d46d9f0fa2555cc77d184d6b3ee1be7d /src/qml/jsruntime/qv4stringobject.cpp | |
parent | a91383545c6f487cff61f401d11f1e85939222e9 (diff) |
Always set the correct FunctionObject when calling JS functions
Renamed ScopedCallData to JSCall, enforced passing a JS
FunctionObject to it, and added call() and callAsConstructor()
methods to it.
Change-Id: I30db65c9765c2896b5909fe2105c0934c6dad861
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4stringobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4stringobject.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index 4964769b88..66ad5e79d2 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -411,9 +411,9 @@ ReturnedValue StringPrototype::method_match(const BuiltinFunction *b, CallData * ScopedValue regexp(scope, callData->argument(0)); Scoped<RegExpObject> rx(scope, regexp); if (!rx) { - ScopedCallData callData(scope, 1); - callData->args[0] = regexp; - rx = scope.engine->regExpCtor()->construct(callData); + JSCall jsCall(scope, scope.engine->regExpCtor(), 1); + jsCall->args[0] = regexp; + rx = jsCall.callAsConstructor(); } if (!rx) @@ -426,11 +426,11 @@ ReturnedValue StringPrototype::method_match(const BuiltinFunction *b, CallData * ScopedString execString(scope, scope.engine->newString(QStringLiteral("exec"))); ScopedFunctionObject exec(scope, scope.engine->regExpPrototype()->get(execString)); - ScopedCallData cData(scope, 1); - cData->thisObject = rx; - cData->args[0] = s; + JSCall jsCall(scope, exec, 1); + jsCall->thisObject = rx; + jsCall->args[0] = s; if (!global) - return exec->call(cData); + return jsCall.call(); ScopedString lastIndex(scope, scope.engine->newString(QStringLiteral("lastIndex"))); rx->put(lastIndex, ScopedValue(scope, Primitive::fromInt32(0))); @@ -442,7 +442,7 @@ ReturnedValue StringPrototype::method_match(const BuiltinFunction *b, CallData * ScopedValue index(scope); ScopedValue result(scope); while (1) { - result = exec->call(cData); + result = jsCall.call(); if (result->isNull()) break; assert(result->isObject()); @@ -590,8 +590,8 @@ ReturnedValue StringPrototype::method_replace(const BuiltinFunction *b, CallData ScopedFunctionObject searchCallback(scope, replaceValue); if (!!searchCallback) { result.reserve(string.length() + 10*numStringMatches); - ScopedCallData callData(scope, numCaptures + 2); - callData->thisObject = Primitive::undefinedValue(); + JSCall jsCall(scope, searchCallback, numCaptures + 2); + jsCall->thisObject = Primitive::undefinedValue(); int lastEnd = 0; ScopedValue entry(scope); for (int i = 0; i < numStringMatches; ++i) { @@ -602,15 +602,15 @@ ReturnedValue StringPrototype::method_replace(const BuiltinFunction *b, CallData entry = Primitive::undefinedValue(); if (start != JSC::Yarr::offsetNoMatch && end != JSC::Yarr::offsetNoMatch) entry = scope.engine->newString(string.mid(start, end - start)); - callData->args[k] = entry; + jsCall->args[k] = entry; } uint matchStart = matchOffsets[i * numCaptures * 2]; Q_ASSERT(matchStart >= static_cast<uint>(lastEnd)); uint matchEnd = matchOffsets[i * numCaptures * 2 + 1]; - callData->args[numCaptures] = Primitive::fromUInt32(matchStart); - callData->args[numCaptures + 1] = scope.engine->newString(string); + jsCall->args[numCaptures] = Primitive::fromUInt32(matchStart); + jsCall->args[numCaptures + 1] = scope.engine->newString(string); - replacement = searchCallback->call(callData); + replacement = jsCall.call(); result += string.midRef(lastEnd, matchStart - lastEnd); result += replacement->toQString(); lastEnd = matchEnd; @@ -652,9 +652,9 @@ ReturnedValue StringPrototype::method_search(const BuiltinFunction *b, CallData RegExpObject *regExp = regExpObj->as<RegExpObject>(); if (!regExp) { - ScopedCallData callData(scope, 1); - callData->args[0] = regExpObj; - regExpObj = scope.engine->regExpCtor()->construct(callData); + JSCall jsCall(scope, scope.engine->regExpCtor(), 1); + jsCall->args[0] = regExpObj; + regExpObj = jsCall.callAsConstructor(); if (scope.engine->hasException) return QV4::Encode::undefined(); |