From ce9e05d57a22860b8b29a79d113702102f34659f Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 1 Jul 2009 11:34:07 +0200 Subject: add placeholder implementations of findChild() and findChildren() --- src/script/bridge/qscriptqobject.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp index b0cfefc..edfedbb 100644 --- a/src/script/bridge/qscriptqobject.cpp +++ b/src/script/bridge/qscriptqobject.cpp @@ -1168,6 +1168,29 @@ void QObjectWrapperObject::getPropertyNames(JSC::ExecState *exec, JSC::PropertyN JSC::JSObject::getPropertyNames(exec, propertyNames); } +static JSC::JSValue JSC_HOST_CALL qobjectProtoFuncFindChild(JSC::ExecState *exec, JSC::JSObject*, + JSC::JSValue thisValue, const JSC::ArgList &args) +{ + if (!thisValue.isObject(&QObjectWrapperObject::info)) + return throwError(exec, JSC::TypeError); + QObject *obj = static_cast(JSC::asObject(thisValue))->value(); + QString name; + if (args.size() != 0) + name = QScript::qtStringFromJSCUString(args.at(0).toString(exec)); + QObject *child = qFindChild(obj, name); + QScriptEngine::QObjectWrapOptions opt = QScriptEngine::PreferExistingWrapperObject; + QScriptEnginePrivate *engine = static_cast(exec->dynamicGlobalObject())->engine; + return engine->newQObject(child, QScriptEngine::QtOwnership, opt); +} + +static JSC::JSValue JSC_HOST_CALL qobjectProtoFuncFindChildren(JSC::ExecState *exec, JSC::JSObject*, + JSC::JSValue thisValue, const JSC::ArgList &args) +{ + if (!thisValue.isObject(&QObjectWrapperObject::info)) + return throwError(exec, JSC::TypeError); + return throwError(exec, JSC::GeneralError, "QObject.prototype.findChildren not implemented"); +} + static JSC::JSValue JSC_HOST_CALL qobjectProtoFuncToString(JSC::ExecState *exec, JSC::JSObject*, JSC::JSValue thisValue, const JSC::ArgList&) { @@ -1186,7 +1209,8 @@ QObjectPrototype::QObjectPrototype(JSC::ExecState* exec, WTF::PassRefPtrpropertyNames().toString, qobjectProtoFuncToString), JSC::DontEnum); - // ### findChild(), findChildren() + putDirectFunction(exec, new (exec) JSC::PrototypeFunction(exec, prototypeFunctionStructure, /*length=*/1, JSC::Identifier(exec, "findChild"), qobjectProtoFuncFindChild), JSC::DontEnum); + putDirectFunction(exec, new (exec) JSC::PrototypeFunction(exec, prototypeFunctionStructure, /*length=*/1, JSC::Identifier(exec, "findChildren"), qobjectProtoFuncFindChildren), JSC::DontEnum); } const JSC::ClassInfo QMetaObjectWrapperObject::info = { "QMetaObject", 0, 0, 0 }; -- cgit v0.12