3 JSVM::JSVM(QQmlEngine *parent) : QObject{parent}, parentEngine(parent) {}
5 QJSValue JSVM::runInContext(QString code, QJSValue props) {
6 auto engine = QQmlEngine(this);
8 auto objectKeysFunction = parentEngine->evaluate("Object.keys");
9 auto keys = objectKeysFunction.call({props});
10 const int keyLength = keys.property("length").toInt();
11 for (int i = 0; i < keyLength; ++i) {
12 auto key = keys.property(i).toString();
13 auto value = props.property(key).toString();
14 qDebug() << "Setting property" << key << value;
15 engine.globalObject().setProperty(key, value);
18 auto res = engine.evaluate(code).toString();
19 return parentEngine->toScriptValue(res);