diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-09-11 13:55:01 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-18 13:13:18 +0200 |
commit | 1a2a83f80ba4ecc28eba72af57c81bd43a45946c (patch) | |
tree | c2e4eb4d9bb57873ca340f6bbbf2342b36c91452 /src/qml/jsruntime/qv4stringobject.cpp | |
parent | 826550af450b39f47a3c00ec316acf1e317f12c6 (diff) | |
download | qtdeclarative-1a2a83f80ba4ecc28eba72af57c81bd43a45946c.tar.gz |
Use a ReturnedValue for Managed::call()
Change-Id: Ief2d75e9789dd367c603d90dc0fe5316a0d055e3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4stringobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4stringobject.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index d595533714..b66ee6c180 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -170,14 +170,14 @@ Value StringCtor::construct(Managed *m, CallData *callData) return Value::fromObject(m->engine()->newStringObject(value)); } -Value StringCtor::call(Managed *m, CallData *callData) +ReturnedValue StringCtor::call(Managed *m, CallData *callData) { Value value; if (callData->argc) value = Value::fromString(callData->args[0].toString(m->engine()->current)); else value = Value::fromString(m->engine()->current, QString()); - return value; + return value.asReturnedValue(); } void StringPrototype::init(ExecutionEngine *engine, const Value &ctor) @@ -351,6 +351,7 @@ Value StringPrototype::method_match(SimpleCallContext *context) if (context->thisObject.isUndefined() || context->thisObject.isNull()) context->throwTypeError(); + ValueScope scope(context); String *s = context->thisObject.toString(context); Value regexp = context->argumentCount ? context->arguments[0] : Value::undefinedValue(); @@ -374,7 +375,7 @@ Value StringPrototype::method_match(SimpleCallContext *context) callData->thisObject = Value::fromObject(rx); callData->args[0] = Value::fromString(s); if (!global) - return exec->call(callData); + return Value::fromReturnedValue(exec->call(callData)); String *lastIndex = context->engine->newString(QStringLiteral("lastIndex")); rx->put(lastIndex, Value::fromInt32(0)); @@ -382,11 +383,13 @@ Value StringPrototype::method_match(SimpleCallContext *context) double previousLastIndex = 0; uint n = 0; + ScopedValue result(scope); + ScopedValue matchStr(scope); while (1) { - Value result = exec->call(callData); - if (result.isNull()) + result = exec->call(callData); + if (result->isNull()) break; - assert(result.isObject()); + assert(result->isObject()); double thisIndex = rx->get(lastIndex, 0).toInteger(); if (previousLastIndex == thisIndex) { previousLastIndex = thisIndex + 1; @@ -394,7 +397,7 @@ Value StringPrototype::method_match(SimpleCallContext *context) } else { previousLastIndex = thisIndex; } - Value matchStr = result.objectValue()->getIndexed(0); + matchStr = result->objectValue()->getIndexed(0); a->arraySet(n, matchStr); ++n; } @@ -452,6 +455,7 @@ static void appendReplacementString(QString *result, const QString &input, const Value StringPrototype::method_replace(SimpleCallContext *ctx) { + ValueScope scope(ctx); QString string; if (StringObject *thisString = ctx->thisObject.asStringObject()) string = thisString->value.stringValue()->toQString(); @@ -507,6 +511,7 @@ Value StringPrototype::method_replace(SimpleCallContext *ctx) QString result; Value replaceValue = ctx->argument(1); + ScopedValue replacement(scope); if (FunctionObject* searchCallback = replaceValue.asFunctionObject()) { result.reserve(string.length() + 10*numStringMatches); ScopedCallData callData(ctx->engine, numCaptures + 2); @@ -528,9 +533,9 @@ Value StringPrototype::method_replace(SimpleCallContext *ctx) callData->args[numCaptures] = Value::fromUInt32(matchStart); callData->args[numCaptures + 1] = Value::fromString(ctx, string); - Value replacement = searchCallback->call(callData); + replacement = searchCallback->call(callData); result += string.midRef(lastEnd, matchStart - lastEnd); - result += replacement.toString(ctx)->toQString(); + result += replacement->toString(ctx)->toQString(); lastEnd = matchEnd; } result += string.midRef(lastEnd); |