diff options
Diffstat (limited to 'src/qml/jsruntime/qv4proxy.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4proxy.cpp | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/qml/jsruntime/qv4proxy.cpp b/src/qml/jsruntime/qv4proxy.cpp index 109ab61059..974788d420 100644 --- a/src/qml/jsruntime/qv4proxy.cpp +++ b/src/qml/jsruntime/qv4proxy.cpp @@ -13,6 +13,7 @@ using namespace QV4; DEFINE_OBJECT_VTABLE(ProxyObject); DEFINE_OBJECT_VTABLE(ProxyFunctionObject); +DEFINE_OBJECT_VTABLE(ProxyConstructorObject); void Heap::ProxyObject::init(const QV4::Object *target, const QV4::Object *handler) { @@ -25,12 +26,9 @@ void Heap::ProxyObject::init(const QV4::Object *target, const QV4::Object *handl void Heap::ProxyFunctionObject::init(const QV4::FunctionObject *target, const QV4::Object *handler) { ExecutionEngine *e = internalClass->engine; - FunctionObject::init(e->rootContext()); + FunctionObject::init(e); this->target.set(e, target->d()); this->handler.set(e, handler->d()); - - if (!target->isConstructor()) - jsConstruct = nullptr; } @@ -643,7 +641,8 @@ OwnPropertyKeyIterator *ProxyObject::virtualOwnPropertyKeys(const Object *m, Val } -ReturnedValue ProxyFunctionObject::virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *newTarget) +ReturnedValue ProxyConstructorObject::virtualCallAsConstructor( + const FunctionObject *f, const Value *argv, int argc, const Value *newTarget) { Scope scope(f); const ProxyObject *o = static_cast<const ProxyObject *>(f); @@ -658,10 +657,8 @@ ReturnedValue ProxyFunctionObject::virtualCallAsConstructor(const FunctionObject if (scope.hasException()) return Encode::undefined(); - if (trap->isNullOrUndefined()) { - Q_ASSERT(target->isConstructor()); + if (trap->isNullOrUndefined()) return target->callAsConstructor(argv, argc, newTarget); - } if (!trap->isFunctionObject()) return scope.engine->throwTypeError(); @@ -708,11 +705,11 @@ ReturnedValue ProxyFunctionObject::virtualCall(const FunctionObject *f, const Va DEFINE_OBJECT_VTABLE(Proxy); -void Heap::Proxy::init(QV4::ExecutionContext *ctx) +void Heap::Proxy::init(QV4::ExecutionEngine *engine) { - Heap::FunctionObject::init(ctx, QStringLiteral("Proxy")); + Heap::FunctionObject::init(engine, QStringLiteral("Proxy")); - Scope scope(ctx); + Scope scope(engine); Scoped<QV4::Proxy> ctor(scope, this); ctor->defineDefaultProperty(QStringLiteral("revocable"), QV4::Proxy::method_revocable, 2); ctor->defineReadonlyConfigurableProperty(scope.engine->id_length(), Value::fromInt32(2)); @@ -734,9 +731,18 @@ ReturnedValue Proxy::virtualCallAsConstructor(const FunctionObject *f, const Val return scope.engine->throwTypeError(); const FunctionObject *targetFunction = target->as<FunctionObject>(); - if (targetFunction) - return scope.engine->memoryManager->allocate<ProxyFunctionObject>(targetFunction, handler)->asReturnedValue(); - return scope.engine->memoryManager->allocate<ProxyObject>(target, handler)->asReturnedValue(); + if (!targetFunction) { + return scope.engine->memoryManager->allocate<ProxyObject>(target, handler) + ->asReturnedValue(); + } + + if (targetFunction->isConstructor()) { + return scope.engine->memoryManager->allocate<ProxyConstructorObject>( + targetFunction, handler)->asReturnedValue(); + } + + return scope.engine->memoryManager->allocate<ProxyFunctionObject>(targetFunction, handler) + ->asReturnedValue(); } ReturnedValue Proxy::virtualCall(const FunctionObject *f, const Value *, const Value *, int) @@ -753,7 +759,10 @@ ReturnedValue Proxy::method_revocable(const FunctionObject *f, const Value *, co Q_ASSERT(proxy); ScopedString revoke(scope, scope.engine->newString(QStringLiteral("revoke"))); - ScopedFunctionObject revoker(scope, scope.engine->memoryManager->allocate<FunctionObject>(scope.engine->rootContext(), nullptr, method_revoke)); + ScopedFunctionObject revoker( + scope, + scope.engine->memoryManager->allocate<DynamicFunctionObject>( + scope.engine, nullptr, method_revoke)); revoker->defineReadonlyConfigurableProperty(scope.engine->id_length(), Value::fromInt32(0)); revoker->defineDefaultProperty(scope.engine->symbol_revokableProxy(), proxy); |