diff options
Diffstat (limited to 'src/qml/jsruntime')
| -rw-r--r-- | src/qml/jsruntime/qv4context.cpp | 71 | ||||
| -rw-r--r-- | src/qml/jsruntime/qv4context_p.h | 5 | ||||
| -rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 18 | ||||
| -rw-r--r-- | src/qml/jsruntime/qv4engine_p.h | 8 | ||||
| -rw-r--r-- | src/qml/jsruntime/qv4errorobject.cpp | 2 | ||||
| -rw-r--r-- | src/qml/jsruntime/qv4lookup.cpp | 4 | ||||
| -rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 2 | ||||
| -rw-r--r-- | src/qml/jsruntime/qv4scopedvalue_p.h | 9 | ||||
| -rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 7 | ||||
| -rw-r--r-- | src/qml/jsruntime/qv4string.cpp | 6 | ||||
| -rw-r--r-- | src/qml/jsruntime/qv4stringobject.cpp | 2 |
11 files changed, 84 insertions, 50 deletions
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index 1a1efc0b4c..56701457e4 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -363,6 +363,7 @@ void ExecutionContext::mark() void ExecutionContext::setProperty(String *name, const Value& value) { + Scope scope(this); for (ExecutionContext *ctx = this; ctx; ctx = ctx->outer) { if (ctx->type == Type_WithContext) { Object *w = static_cast<WithContext *>(ctx)->withObject; @@ -398,8 +399,10 @@ void ExecutionContext::setProperty(String *name, const Value& value) } } } - if (strictMode || name->isEqualTo(engine->id_this)) - throwReferenceError(Value::fromString(name)); + if (strictMode || name->isEqualTo(engine->id_this)) { + Scoped<String> n(scope, name); + throwReferenceError(n); + } engine->globalObject->put(name, value); } @@ -463,7 +466,8 @@ ReturnedValue ExecutionContext::getProperty(String *name) return v.asReturnedValue(); } } - throwReferenceError(Value::fromString(name)); + Scoped<String> n(scope, name); + throwReferenceError(n); return Value::undefinedValue().asReturnedValue(); } @@ -595,75 +599,92 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Object **base) return v.asReturnedValue(); } } - throwReferenceError(Value::fromString(name)); + Scoped<String> n(scope, name); + throwReferenceError(n); return Value::undefinedValue().asReturnedValue(); } -void ExecutionContext::throwError(const Value &value) +void ExecutionContext::throwError(const ValueRef value) { - Scope scope(this); - ScopedValue v(scope, value); - __qmljs_throw(this, v); + __qmljs_throw(this, value); } void ExecutionContext::throwError(const QString &message) { - Value v = Value::fromString(this, message); - throwError(Value::fromObject(engine->newErrorObject(v))); + Scope scope(this); + ScopedValue v(scope, Value::fromString(this, message)); + v = engine->newErrorObject(v); + throwError(v); } void ExecutionContext::throwSyntaxError(const QString &message, const QString &fileName, int line, int column) { - Object *error = engine->newSyntaxErrorObject(message, fileName, line, column); - throwError(Value::fromObject(error)); + Scope scope(this); + Scoped<Object> error(scope, engine->newSyntaxErrorObject(message, fileName, line, column)); + throwError(error); } void ExecutionContext::throwSyntaxError(const QString &message) { - Object *error = engine->newSyntaxErrorObject(message); - throwError(Value::fromObject(error)); + Scope scope(this); + Scoped<Object> error(scope, engine->newSyntaxErrorObject(message)); + throwError(error); } void ExecutionContext::throwTypeError() { - throwError(Value::fromObject(engine->newTypeErrorObject(QStringLiteral("Type error")))); + Scope scope(this); + Scoped<Object> error(scope, engine->newTypeErrorObject(QStringLiteral("Type error"))); + throwError(error); } void ExecutionContext::throwTypeError(const QString &message) { - throwError(Value::fromObject(engine->newTypeErrorObject(message))); + Scope scope(this); + Scoped<Object> error(scope, engine->newTypeErrorObject(message)); + throwError(error); } void ExecutionContext::throwUnimplemented(const QString &message) { - Value v = Value::fromString(this, QStringLiteral("Unimplemented ") + message); - throwError(Value::fromObject(engine->newErrorObject(v))); + Scope scope(this); + ScopedValue v(scope, Value::fromString(this, QStringLiteral("Unimplemented ") + message)); + v = engine->newErrorObject(v); + throwError(v); } -void ExecutionContext::throwReferenceError(Value value) +void ExecutionContext::throwReferenceError(const ValueRef value) { - String *s = value.toString(this); + Scope scope(this); + Scoped<String> s(scope, value->toString(this)); QString msg = s->toQString() + QStringLiteral(" is not defined"); - throwError(Value::fromObject(engine->newReferenceErrorObject(msg))); + Scoped<Object> error(scope, engine->newReferenceErrorObject(msg)); + throwError(error); } void ExecutionContext::throwReferenceError(const QString &message, const QString &fileName, int line, int column) { + Scope scope(this); QString msg = message + QStringLiteral(" is not defined"); - throwError(Value::fromObject(engine->newReferenceErrorObject(msg, fileName, line, column))); + Scoped<Object> error(scope, engine->newReferenceErrorObject(msg, fileName, line, column)); + throwError(error); } void ExecutionContext::throwRangeError(Value value) { - String *s = value.toString(this); + Scope scope(this); + Scoped<String> s(scope, value.toString(this)); QString msg = s->toQString() + QStringLiteral(" out of range"); - throwError(Value::fromObject(engine->newRangeErrorObject(msg))); + Scoped<Object> error(scope, engine->newRangeErrorObject(msg)); + throwError(error); } void ExecutionContext::throwURIError(Value msg) { - throwError(Value::fromObject(engine->newURIErrorObject(msg))); + Scope scope(this); + Scoped<Object> error(scope, engine->newURIErrorObject(msg)); + throwError(error); } void SimpleCallContext::initSimpleCallContext(ExecutionEngine *engine) diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index 8ebffea981..0c3b189401 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -54,6 +54,7 @@ struct ExecutionEngine; struct DeclarativeEnvironment; struct Lookup; struct Function; +struct ValueRef; namespace CompiledData { struct CompilationUnit; @@ -129,13 +130,13 @@ struct Q_QML_EXPORT ExecutionContext void createMutableBinding(String *name, bool deletable); - void Q_NORETURN throwError(const Value &value); + void Q_NORETURN throwError(const QV4::ValueRef value); void Q_NORETURN throwError(const QString &message); void Q_NORETURN throwSyntaxError(const QString &message); void Q_NORETURN throwSyntaxError(const QString &message, const QString &fileName, int line, int column); void Q_NORETURN throwTypeError(); void Q_NORETURN throwTypeError(const QString &message); - void Q_NORETURN throwReferenceError(Value value); + void Q_NORETURN throwReferenceError(const ValueRef value); void Q_NORETURN throwReferenceError(const QString &value, const QString &fileName, int line, int column); void Q_NORETURN throwRangeError(Value value); void Q_NORETURN throwURIError(Value msg); diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 875ab84cf5..0187099f62 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -375,10 +375,10 @@ String *ExecutionEngine::newIdentifier(const QString &text) return identifierTable->insertString(text); } -Object *ExecutionEngine::newStringObject(const Value &value) +Returned<Object> *ExecutionEngine::newStringObject(const Value &value) { StringObject *object = new (memoryManager) StringObject(this, value); - return object; + return object->asReturned<Object>(); } Returned<Object> *ExecutionEngine::newNumberObject(const Value &value) @@ -455,20 +455,22 @@ Returned<RegExpObject> *ExecutionEngine::newRegExpObject(const QRegExp &re) return object->asReturned<RegExpObject>(); } -Object *ExecutionEngine::newErrorObject(const Value &value) +Returned<Object> *ExecutionEngine::newErrorObject(const Value &value) { ErrorObject *object = new (memoryManager) ErrorObject(errorClass, value); - return object; + return object->asReturned<Object>(); } -Object *ExecutionEngine::newSyntaxErrorObject(const QString &message) +Returned<Object> *ExecutionEngine::newSyntaxErrorObject(const QString &message) { - return new (memoryManager) SyntaxErrorObject(this, Value::fromString(this, message)); + Object *error = new (memoryManager) SyntaxErrorObject(this, Value::fromString(this, message)); + return error->asReturned<Object>(); } -Object *ExecutionEngine::newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column) +Returned<Object> *ExecutionEngine::newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column) { - return new (memoryManager) SyntaxErrorObject(this, message, fileName, line, column); + Object *error = new (memoryManager) SyntaxErrorObject(this, message, fileName, line, column); + return error->asReturned<Object>(); } diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index a59a837499..5ef7d08a4a 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -270,7 +270,7 @@ struct Q_QML_EXPORT ExecutionEngine String *newString(const QString &s); String *newIdentifier(const QString &text); - Object *newStringObject(const Value &value); + Returned<Object> *newStringObject(const Value &value); Returned<Object> *newNumberObject(const Value &value); Returned<Object> *newBooleanObject(const Value &value); @@ -285,9 +285,9 @@ struct Q_QML_EXPORT ExecutionEngine Returned<RegExpObject> *newRegExpObject(RegExp* re, bool global); Returned<RegExpObject> *newRegExpObject(const QRegExp &re); - Object *newErrorObject(const Value &value); - Object *newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column); - Object *newSyntaxErrorObject(const QString &message); + Returned<Object> *newErrorObject(const Value &value); + Returned<Object> *newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column); + Returned<Object> *newSyntaxErrorObject(const QString &message); Object *newReferenceErrorObject(const QString &message); Object *newReferenceErrorObject(const QString &message, const QString &fileName, int lineNumber, int columnNumber); Object *newTypeErrorObject(const QString &message); diff --git a/src/qml/jsruntime/qv4errorobject.cpp b/src/qml/jsruntime/qv4errorobject.cpp index 7c75d1162a..987d5083fa 100644 --- a/src/qml/jsruntime/qv4errorobject.cpp +++ b/src/qml/jsruntime/qv4errorobject.cpp @@ -242,7 +242,7 @@ ErrorCtor::ErrorCtor(ExecutionContext *scope, String *name) ReturnedValue ErrorCtor::construct(Managed *m, CallData *callData) { - return Value::fromObject(m->engine()->newErrorObject(callData->argc ? callData->args[0] : Value::undefinedValue())).asReturnedValue(); + return Encode(m->engine()->newErrorObject(callData->argc ? callData->args[0] : Value::undefinedValue())); } ReturnedValue ErrorCtor::call(Managed *that, CallData *callData) diff --git a/src/qml/jsruntime/qv4lookup.cpp b/src/qml/jsruntime/qv4lookup.cpp index a4116b049e..a844a25008 100644 --- a/src/qml/jsruntime/qv4lookup.cpp +++ b/src/qml/jsruntime/qv4lookup.cpp @@ -334,7 +334,9 @@ ReturnedValue Lookup::globalGetterGeneric(Lookup *l, ExecutionContext *ctx) return o->getValue(p, attrs); } } - ctx->throwReferenceError(Value::fromString(l->name)); + Scope scope(ctx); + Scoped<String> n(scope, l->name); + ctx->throwReferenceError(n); } ReturnedValue Lookup::globalGetter0(Lookup *l, ExecutionContext *ctx) diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 7af8b21cc5..d98087b6a4 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -607,7 +607,7 @@ Returned<Object> *__qmljs_convert_to_object(ExecutionContext *ctx, const ValueRe case Value::Boolean_Type: return ctx->engine->newBooleanObject(*value); case Value::String_Type: - return ctx->engine->newStringObject(*value)->asReturned<Object>(); + return ctx->engine->newStringObject(*value); break; case Value::Object_Type: Q_UNREACHABLE(); diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index eed49bfe1f..4bbd3303ee 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -142,7 +142,7 @@ struct ScopedValue ScopedValue(const Scope &scope, Returned<T> *t) { ptr = scope.engine->jsStackTop++; - ptr->val = T::toValue(t->getPointer()); + *ptr = T::toValue(t->getPointer()); #ifndef QT_NO_DEBUG ++scope.size; #endif @@ -159,8 +159,8 @@ struct ScopedValue } template<typename T> - ScopedValue &operator=(const Returned<T> *t) { - ptr->val = T::toValue(t->getPointer()); + ScopedValue &operator=(Returned<T> *t) { + *ptr = T::toValue(t->getPointer()); return *this; } @@ -331,6 +331,9 @@ struct ScopedCallData { struct ValueRef { ValueRef(const ScopedValue &v) : ptr(v.ptr) {} + template <typename T> + ValueRef(const Scoped<T> &v) + : ptr(v.ptr) {} ValueRef(const PersistentValue &v) : ptr(&v.d->value) {} ValueRef(PersistentValuePrivate *p) diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index e3c9505ab7..1834e28be6 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -153,6 +153,7 @@ void Script::parse() parsed = true; ExecutionEngine *v4 = scope->engine; + Scope valueScope(v4); MemoryManager::GCBlocker gcBlocker(v4->memoryManager); @@ -199,9 +200,11 @@ void Script::parse() compilationUnitHolder = Value::fromObject(new (v4->memoryManager) CompilationUnitHolder(v4, compilationUnit)); } - if (!vmFunction) + if (!vmFunction) { // ### FIX file/line number - v4->current->throwError(QV4::Value::fromObject(v4->newSyntaxErrorObject("Syntax error"))); + Scoped<Object> error(valueScope, v4->newSyntaxErrorObject("Syntax error")); + v4->current->throwError(error); + } } ReturnedValue Script::run() diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp index 2b2eda7c8c..d0f3a196b7 100644 --- a/src/qml/jsruntime/qv4string.cpp +++ b/src/qml/jsruntime/qv4string.cpp @@ -173,15 +173,17 @@ ReturnedValue String::getIndexed(Managed *m, uint index, bool *hasProperty) void String::put(Managed *m, String *name, const Value &value) { + Scope scope(m->engine()); String *that = static_cast<String *>(m); - Object *o = that->engine()->newStringObject(Value::fromString(that)); + Scoped<Object> o(scope, that->engine()->newStringObject(Value::fromString(that))); o->put(name, value); } void String::putIndexed(Managed *m, uint index, const Value &value) { + Scope scope(m->engine()); String *that = static_cast<String *>(m); - Object *o = m->engine()->newStringObject(Value::fromString(that)); + Scoped<Object> o(scope, that->engine()->newStringObject(Value::fromString(that))); o->putIndexed(index, value); } diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index dfdb639d1e..2223432ec9 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -167,7 +167,7 @@ ReturnedValue StringCtor::construct(Managed *m, CallData *callData) value = Value::fromString(callData->args[0].toString(m->engine()->current)); else value = Value::fromString(m->engine()->current, QString()); - return Value::fromObject(m->engine()->newStringObject(value)).asReturnedValue(); + return Encode(m->engine()->newStringObject(value)); } ReturnedValue StringCtor::call(Managed *m, CallData *callData) |
