diff options
author | Erik Verbruggen <[email protected]> | 2016-06-22 10:12:13 +0200 |
---|---|---|
committer | Erik Verbruggen <[email protected]> | 2016-06-22 11:07:05 +0000 |
commit | 702c4247d74ffb7e4fb1aaca96d70f4591203ba2 (patch) | |
tree | 6c0a41332cf4a8ab0051600efdd27b0746574795 /src/qml/jsruntime/qv4jsonobject.cpp | |
parent | fd0e3c6d569a7410fff33974ce9f908dc2de0e22 (diff) |
V4: Pass scope around as parameters inside the runtime.
The implementation of many (or all) runtime functions consist of first
creating a QV4::Scope, which saves and restores the JS stack pointer.
It also prevents tail-calls because of that restoring behavior. In many
cases it suffices to do that at the entry-point of the runtime.
The return value of a JS function call is now also stored in the scope.
Previously, all return values were stored in a ScopedValue, got loaded
on return, and immediately stored in another ScopedValue in the caller.
This resulted in a lot of stores, where now there is only one store
needed, and no extra ScopedValue for every function.
Change-Id: I13d80fc0ce72c5702ef1536d41d12f710c5914fa
Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4jsonobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4jsonobject.cpp | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp index 0ae7c33dea..7661dd1903 100644 --- a/src/qml/jsruntime/qv4jsonobject.cpp +++ b/src/qml/jsruntime/qv4jsonobject.cpp @@ -685,53 +685,53 @@ static QString quote(const QString &str) QString Stringify::Str(const QString &key, const Value &v) { Scope scope(v4); + scope.result = v; - ScopedValue value(scope, v); - ScopedObject o(scope, value); + ScopedObject o(scope, scope.result); if (o) { ScopedString s(scope, v4->newString(QStringLiteral("toJSON"))); ScopedFunctionObject toJSON(scope, o->get(s)); if (!!toJSON) { ScopedCallData callData(scope, 1); - callData->thisObject = value; + callData->thisObject = scope.result; callData->args[0] = v4->newString(key); - value = toJSON->call(callData); + toJSON->call(scope, callData); } } if (replacerFunction) { ScopedObject holder(scope, v4->newObject()); - holder->put(scope.engine, QString(), value); + holder->put(scope.engine, QString(), scope.result); ScopedCallData callData(scope, 2); callData->args[0] = v4->newString(key); - callData->args[1] = value; + callData->args[1] = scope.result; callData->thisObject = holder; - value = replacerFunction->call(callData); + replacerFunction->call(scope, callData); } - o = value->asReturnedValue(); + o = scope.result.asReturnedValue(); if (o) { if (NumberObject *n = o->as<NumberObject>()) - value = Encode(n->value()); + scope.result = Encode(n->value()); else if (StringObject *so = o->as<StringObject>()) - value = so->d()->string; + scope.result = so->d()->string; else if (BooleanObject *b = o->as<BooleanObject>()) - value = Encode(b->value()); + scope.result = Encode(b->value()); } - if (value->isNull()) + if (scope.result.isNull()) return QStringLiteral("null"); - if (value->isBoolean()) - return value->booleanValue() ? QStringLiteral("true") : QStringLiteral("false"); - if (value->isString()) - return quote(value->stringValue()->toQString()); - - if (value->isNumber()) { - double d = value->toNumber(); - return std::isfinite(d) ? value->toQString() : QStringLiteral("null"); + if (scope.result.isBoolean()) + return scope.result.booleanValue() ? QStringLiteral("true") : QStringLiteral("false"); + if (scope.result.isString()) + return quote(scope.result.stringValue()->toQString()); + + if (scope.result.isNumber()) { + double d = scope.result.toNumber(); + return std::isfinite(d) ? scope.result.toQString() : QStringLiteral("null"); } - o = value->asReturnedValue(); + o = scope.result.asReturnedValue(); if (o) { if (!o->as<FunctionObject>()) { if (o->as<ArrayObject>()) { |