v8::TryCatch tc;
v8::Handle<v8::Value> callbackArgs[] = { instance };
- v8::Handle<v8::Function>::Cast(callback)->Call(engine->global(), 1, callbackArgs);
+ v8::Handle<v8::Function>::Cast(callback)->Call(v8::Value::fromV4Value(engine->global()), 1, callbackArgs);
if (tc.HasCaught()) {
db.rollback();
db.transaction();
v8::TryCatch tc;
v8::Handle<v8::Value> callbackArgs[] = { instance };
- callback->Call(engine->global(), 1, callbackArgs);
+ callback->Call(v8::Value::fromV4Value(engine->global()), 1, callbackArgs);
q->inTransaction = false;
v8::TryCatch tc;
v8::Handle<v8::Function> callback = v8::Handle<v8::Function>::Cast(dbcreationCallback);
v8::Handle<v8::Value> args[] = { instance };
- callback->Call(engine->global(), 1, args);
+ callback->Call(v8::Value::fromV4Value(engine->global()), 1, args);
if (tc.HasCaught()) {
tc.ReThrow();
return;
v8::Local<v8::Value> result;
{
v8::TryCatch try_catch;
- v8::Handle<v8::Object> This = ep->v8engine()->global();
+ v8::Handle<v8::Object> This = v8::Value::fromV4Value(ep->v8engine()->global());
if (scopeObject() && requiresThisObject()) {
v8::Handle<v8::Value> value = ep->v8engine()->newQObject(scopeObject());
if (value->IsObject()) This = v8::Handle<v8::Object>::Cast(value);
return false;
} else if (isVarProperty) {
if (!result.IsEmpty() && result->IsFunction()
- && !result->ToObject()->GetHiddenValue(v8engine->bindingFlagKey()).IsEmpty()) {
+ && !result->ToObject()->GetHiddenValue(v8::Value::fromV4Value(v8engine->bindingFlagKey())).IsEmpty()) {
// we explicitly disallow this case to avoid confusion. Users can still store one
// in an array in a var property if they need to, but the common case is user error.
expression->delayedError()->setErrorDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration."));
writeValueProperty(object, core, QVariant(), context, flags);
} else if (type == qMetaTypeId<QJSValue>()) {
if (!result.IsEmpty() && result->IsFunction()
- && !result->ToObject()->GetHiddenValue(v8engine->bindingFlagKey()).IsEmpty()) {
+ && !result->ToObject()->GetHiddenValue(v8::Value::fromV4Value(v8engine->bindingFlagKey())).IsEmpty()) {
expression->delayedError()->setErrorDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration."));
return false;
}
- writeValueProperty(object, core, QVariant::fromValue(v8engine->scriptValueFromInternal(result)), context, flags);
+ writeValueProperty(object, core, QVariant::fromValue(v8engine->scriptValueFromInternal(result->v4Value())), context, flags);
} else if (isUndefined) {
QString errorStr = QLatin1String("Unable to assign [undefined] to ");
if (!QMetaType::typeName(type))
expression->delayedError()->setErrorDescription(errorStr);
return false;
} else if (result->IsFunction()) {
- if (!result->ToObject()->GetHiddenValue(v8engine->bindingFlagKey()).IsEmpty())
+ if (!result->ToObject()->GetHiddenValue(v8::Value::fromV4Value(v8engine->bindingFlagKey())).IsEmpty())
expression->delayedError()->setErrorDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration."));
else
expression->delayedError()->setErrorDescription(QLatin1String("Unable to assign a function to a property of any type other than var."));
v8::TryCatch try_catch;
- v8::Local<v8::Value> result = function->Call(ep->v8engine()->global(), data->parameterCount, args);
+ v8::Local<v8::Value> result = function->Call(v8::Value::fromV4Value(ep->v8engine()->global()), data->parameterCount, args);
QVariant rv;
if (try_catch.HasCaught()) {
xmlhttprequest->Set(v8::String::New("HEADERS_RECEIVED"), v8::Integer::New(2), attributes);
xmlhttprequest->Set(v8::String::New("LOADING"), v8::Integer::New(3), attributes);
xmlhttprequest->Set(v8::String::New("DONE"), v8::Integer::New(4), attributes);
- engine->global()->Set(v8::String::New("XMLHttpRequest"), xmlhttprequest->GetFunction());
+ v8::Local<v8::Object>::New(v8::Value::fromV4Value(engine->global()))->Set(v8::String::New("XMLHttpRequest"), xmlhttprequest->GetFunction());
QQmlXMLHttpRequestData *data = new QQmlXMLHttpRequestData;
return data;
v8::HandleScope handle_scope;
v8::Context::Scope scope(v8engine->context());
new (output.getjsvalueptr()) QJSValue(v8engine->scriptValueFromInternal(
- v8engine->valueTypeWrapper()->newValueType(tmp, vt)));
+ v8engine->valueTypeWrapper()->newValueType(tmp, vt)->v4Value()));
JSVALUE_REGISTER(instr->unaryop.output);
}
}
MARK_CLEAN_REGISTER(instr->unaryop.output);
}
QV8Engine *v8engine = QQmlEnginePrivate::get(context->engine)->v8engine();
- new (output.getjsvalueptr()) QJSValue(v8engine->scriptValueFromInternal(tmp));
+ new (output.getjsvalueptr()) QJSValue(v8engine->scriptValueFromInternal(tmp->v4Value()));
JSVALUE_REGISTER(instr->unaryop.output);
}
}
Q_D(QJSEngine);
QScriptIsolate api(d, QScriptIsolate::NotNullEngine);
v8::HandleScope handleScope;
- return d->scriptValueFromInternal(d->newQObject(object, QV8Engine::JavaScriptOwnership));
+ return d->scriptValueFromInternal(d->newQObject(object, QV8Engine::JavaScriptOwnership)->v4Value());
}
/*!
QJSValuePrivate(QV4::ExecutionEngine *e, const QV4::Value &v)
: PersistentValuePrivate(e, v)
, string(QString())
- {}
+ {
+ if (value.isDeleted())
+ value = QV4::Value::undefinedValue();
+ }
QJSValuePrivate(QV4::ExecutionEngine *e, QV4::Object *o)
: PersistentValuePrivate(e, QV4::Value::fromObject(o))
, string(QString())
V8THROW_TYPE("binding(): argument (binding expression) must be a function");
v8::Handle<v8::Object> rv = args[0]->ToObject()->Clone();
- rv->SetHiddenValue(V8ENGINE()->bindingFlagKey(), v8::Boolean::New(true));
+ rv->SetHiddenValue(v8::Value::fromV4Value(V8ENGINE()->bindingFlagKey()), v8::Boolean::New(true));
return rv;
}
QHashedV8String propertystring(property);
- if (context->imports && QV8Engine::startsWithUpper(property)) {
+ if (context->imports && QV8Engine::startsWithUpper(property->v4Value().asString())) {
// Search for attached properties, enums and imported scripts
QQmlTypeNameCache::Result r = context->imports->query(propertystring);
QV8GCCallback::registerGcPrologueCallback();
m_strongReferencer = qPersistentNew(v8::Object::New());
- m_bindingFlagKey = qPersistentNew(v8::String::New("qml::binding"));
+ m_bindingFlagKey = QV4::PersistentValue(m_v4Engine, QV4::Value::fromString(m_v4Engine->current, QStringLiteral("qml::binding")));
m_contextWrapper.init(this);
m_qobjectWrapper.init(this);
m_qobjectWrapper.destroy();
m_contextWrapper.destroy();
- qPersistentDispose(m_bindingFlagKey);
-
if (m_ownsV8Context)
qPersistentDispose(m_context);
}
return QVariant(value->BooleanValue());
if (typeHint == QMetaType::QJsonValue)
- return QVariant::fromValue(jsonValueFromJS(value));
+ return QVariant::fromValue(jsonValueFromJS(value->v4Value()));
if (typeHint == qMetaTypeId<QJSValue>())
- return QVariant::fromValue(scriptValueFromInternal(value));
+ return QVariant::fromValue(scriptValueFromInternal(value->v4Value()));
if (value->IsObject()) {
QV8ObjectResource *r = (QV8ObjectResource *)value->ToObject()->GetExternalResource();
}
} else if (typeHint == QMetaType::QJsonObject
&& !value->IsArray() && !value->IsFunction()) {
- return QVariant::fromValue(jsonObjectFromJS(value));
+ return QVariant::fromValue(jsonObjectFromJS(value->v4Value()));
}
}
return qVariantFromValue<QList<QObject*> >(list);
} else if (typeHint == QMetaType::QJsonArray) {
- return QVariant::fromValue(jsonArrayFromJS(value));
+ return QVariant::fromValue(jsonArrayFromJS(value->v4Value()));
}
bool succeeded = false;
case QMetaType::QVariantMap:
return objectFromVariantMap(this, *reinterpret_cast<const QVariantMap *>(ptr));
case QMetaType::QJsonValue:
- return jsonValueToJS(*reinterpret_cast<const QJsonValue *>(ptr));
+ return v8::Value::fromV4Value(jsonValueToJS(*reinterpret_cast<const QJsonValue *>(ptr)));
case QMetaType::QJsonObject:
- return jsonObjectToJS(*reinterpret_cast<const QJsonObject *>(ptr));
+ return v8::Value::fromV4Value(jsonObjectToJS(*reinterpret_cast<const QJsonObject *>(ptr)));
case QMetaType::QJsonArray:
- return jsonArrayToJS(*reinterpret_cast<const QJsonArray *>(ptr));
+ return v8::Value::fromV4Value(jsonArrayToJS(*reinterpret_cast<const QJsonArray *>(ptr)));
default:
break;
initQmlGlobalObject();
}
-v8::Handle<v8::Value> QV8Engine::throwException(v8::Handle<v8::Value> value)
+QV4::Value QV8Engine::global()
{
- __qmljs_throw(m_v4Engine->current, value->v4Value());
- return value;
+ return QV4::Value::fromObject(m_v4Engine->globalObject);
}
// Converts a QVariantList to JS.
return QV4::Value::nullValue();
} else {
// Fall back to wrapping in a QVariant.
- result = newVariant(QVariant(type, data))->v4Value();
+ result = variantWrapper()->newVariant(QVariant(type, data))->v4Value();
}
}
}
case QMetaType::QObjectStar: {
v8::Handle<v8::Value> v = v8::Value::fromV4Value(value);
if (isQObject(v) || value.isNull()) {
- *reinterpret_cast<QObject* *>(data) = qtObjectFromJS(v);
+ *reinterpret_cast<QObject* *>(data) = qtObjectFromJS(v->v4Value());
return true;
} break;
}
*reinterpret_cast<QVariant*>(data) = variantFromJS(value);
return true;
case QMetaType::QJsonValue:
- *reinterpret_cast<QJsonValue *>(data) = jsonValueFromJS(v8::Value::fromV4Value(value));
+ *reinterpret_cast<QJsonValue *>(data) = jsonValueFromJS(value);
return true;
case QMetaType::QJsonObject:
- *reinterpret_cast<QJsonObject *>(data) = jsonObjectFromJS(v8::Value::fromV4Value(value));
+ *reinterpret_cast<QJsonObject *>(data) = jsonObjectFromJS(value);
return true;
case QMetaType::QJsonArray:
- *reinterpret_cast<QJsonArray *>(data) = jsonArrayFromJS(v8::Value::fromV4Value(value));
+ *reinterpret_cast<QJsonArray *>(data) = jsonArrayFromJS(value);
return true;
default:
;
// Try to use magic; for compatibility with qscriptvalue_cast.
QByteArray name = QMetaType::typeName(type);
- if (convertToNativeQObject(v8::Value::fromV4Value(value), name, reinterpret_cast<void* *>(data)))
+ if (convertToNativeQObject(value, name, reinterpret_cast<void* *>(data)))
return true;
if (isVariant(v8::Value::fromV4Value(value)) && name.endsWith('*')) {
int valueType = QMetaType::type(name.left(name.size()-1));
- QVariant &var = variantValue(v8::Value::fromV4Value(value));
+ QVariant &var = variantWrapper()->variantValue(v8::Value::fromV4Value(value));
if (valueType == var.userType()) {
// We have T t, T* is requested, so return &t.
*reinterpret_cast<void* *>(data) = var.data();
while (proto->IsObject()) {
bool canCast = false;
if (isVariant(proto)) {
- canCast = (type == variantValue(proto).userType())
- || (valueType && (valueType == variantValue(proto).userType()));
+ canCast = (type == variantWrapper()->variantValue(proto).userType())
+ || (valueType && (valueType == variantWrapper()->variantValue(proto).userType()));
}
else if (isQObject(proto)) {
QByteArray className = name.left(name.size()-1);
- if (QObject *qobject = qtObjectFromJS(proto))
+ if (QObject *qobject = qtObjectFromJS(proto->v4Value()))
canCast = qobject->qt_metacast(className) != 0;
}
if (canCast) {
if (value.asRegExpObject())
return QJSConverter::toRegExp(v8::Handle<v8::RegExp>::Cast(v8::Value::fromV4Value(value)));
if (isVariant(v8::Value::fromV4Value(value)))
- return variantValue(v8::Value::fromV4Value(value));
+ return variantWrapper()->variantValue(v8::Value::fromV4Value(value));
if (isQObject(v8::Value::fromV4Value(value)))
- return qVariantFromValue(qtObjectFromJS(v8::Value::fromV4Value(value)));
- if (isValueType(v8::Value::fromV4Value(value)))
- return toValueType(v8::Value::fromV4Value(value));
+ return qVariantFromValue(qtObjectFromJS(value));
+ if (isValueType(value))
+ return toValueType(value);
return variantMapFromJS(value.asObject(), visitedObjects);
}
-v8::Handle<v8::Value> QV8Engine::jsonValueToJS(const QJsonValue &value)
+QV4::Value QV8Engine::jsonValueToJS(const QJsonValue &value)
{
- return v8::Value::fromV4Value(m_jsonWrapper.fromJsonValue(value));
+ return m_jsonWrapper.fromJsonValue(value);
}
-QJsonValue QV8Engine::jsonValueFromJS(v8::Handle<v8::Value> value)
+QJsonValue QV8Engine::jsonValueFromJS(const QV4::Value &value)
{
- return m_jsonWrapper.toJsonValue(value.get()->v4Value());
+ return m_jsonWrapper.toJsonValue(value);
}
-v8::Local<v8::Object> QV8Engine::jsonObjectToJS(const QJsonObject &object)
+QV4::Value QV8Engine::jsonObjectToJS(const QJsonObject &object)
{
- return v8::Local<v8::Object>::New(v8::Value::fromV4Value(m_jsonWrapper.fromJsonObject(object)));
+ return m_jsonWrapper.fromJsonObject(object);
}
-QJsonObject QV8Engine::jsonObjectFromJS(v8::Handle<v8::Value> value)
+QJsonObject QV8Engine::jsonObjectFromJS(const QV4::Value &value)
{
- return m_jsonWrapper.toJsonObject(value.get()->v4Value().asObject());
+ return m_jsonWrapper.toJsonObject(value.asObject());
}
-v8::Local<v8::Array> QV8Engine::jsonArrayToJS(const QJsonArray &array)
+QV4::Value QV8Engine::jsonArrayToJS(const QJsonArray &array)
{
- return v8::Local<v8::Array>::New(v8::Value::fromV4Value(m_jsonWrapper.fromJsonArray(array)));
+ return m_jsonWrapper.fromJsonArray(array);
}
-QJsonArray QV8Engine::jsonArrayFromJS(v8::Handle<v8::Value> value)
+QJsonArray QV8Engine::jsonArrayFromJS(const QV4::Value &value)
{
- return m_jsonWrapper.toJsonArray(value.get()->v4Value().asArrayObject());
+ return m_jsonWrapper.toJsonArray(value.asArrayObject());
}
-bool QV8Engine::convertToNativeQObject(v8::Handle<v8::Value> value,
- const QByteArray &targetType,
- void **result)
+bool QV8Engine::convertToNativeQObject(const QV4::Value &value, const QByteArray &targetType, void **result)
{
if (!targetType.endsWith('*'))
return false;
return false;
}
-QObject *QV8Engine::qtObjectFromJS(v8::Handle<v8::Value> value)
+QObject *QV8Engine::qtObjectFromJS(const QV4::Value &value)
{
- if (!value->IsObject())
+ if (!value.isObject())
return 0;
- QV8ObjectResource *r = (QV8ObjectResource *)value->ToObject()->GetExternalResource();
+ QV8ObjectResource *r = (QV8ObjectResource *)v8::Value::fromV4Value(value)->ToObject()->GetExternalResource();
if (!r)
return 0;
QV8ObjectResource::ResourceType type = r->resourceType();
return 0;
}
-
-QVariant &QV8Engine::variantValue(v8::Handle<v8::Value> value)
-{
- return variantWrapper()->variantValue(value);
-}
-
-// Creates a QVariant wrapper object.
-v8::Local<v8::Object> QV8Engine::newVariant(const QVariant &value)
-{
- return variantWrapper()->newVariant(value);
-}
-
-QJSValue QV8Engine::evaluate(v8::Handle<v8::Script> script, v8::TryCatch& tryCatch)
-{
- v8::HandleScope handleScope;
-
- if (script.IsEmpty()) {
- v8::Handle<v8::Value> exception = tryCatch.Exception();
- if (exception.IsEmpty()) {
- // This is possible on syntax errors like { a:12, b:21 } <- missing "(", ")" around expression.
- return QJSValue();
- }
- return new QJSValuePrivate(m_v4Engine, exception.get()->v4Value());
- }
- v8::Handle<v8::Value> result;
- result = script->Run();
- if (result.IsEmpty()) {
- v8::Handle<v8::Value> exception = tryCatch.Exception();
- // TODO: figure out why v8 doesn't always produce an exception value
- //Q_ASSERT(!exception.IsEmpty());
- if (exception.IsEmpty())
- exception = v8::Exception::Error(v8::String::New("missing exception value"));
- return new QJSValuePrivate(m_v4Engine, exception.get()->v4Value());
- }
- return new QJSValuePrivate(m_v4Engine, result.get()->v4Value());
-}
-
-QJSValue QV8Engine::scriptValueFromInternal(v8::Handle<v8::Value> value) const
+QJSValue QV8Engine::scriptValueFromInternal(const QV4::Value &value) const
{
- if (value.IsEmpty())
- return QJSValue();
- return new QJSValuePrivate(m_v4Engine, value.get()->v4Value());
+ return new QJSValuePrivate(m_v4Engine, value);
}
QJSValue QV8Engine::newArray(uint length)
return handle;
}
-QJSValue QV8Engine::evaluate(const QString& program, const QString& fileName, quint16 lineNumber)
-{
- v8::TryCatch tryCatch;
- v8::ScriptOrigin scriptOrigin(QJSConverter::toString(fileName), v8::Integer::New(lineNumber - 1));
- v8::Handle<v8::Script> script;
- script = v8::Script::Compile(QJSConverter::toString(program), &scriptOrigin);
- if (script.IsEmpty()) {
- // TODO: Why don't we get the exception, as with Script::Compile()?
- // Q_ASSERT(tryCatch.HasCaught());
- QV4::Object *error = m_v4Engine->newSyntaxErrorObject(m_v4Engine->current, 0);
- return new QJSValuePrivate(m_v4Engine, QV4::Value::fromObject(error));
- }
- return evaluate(script, tryCatch);
-}
-
QV4::Value QV8Engine::evaluateScript(const QString &script, QV4::Object *scopeObject)
{
QV4::ExecutionContext *ctx = m_v4Engine->current;
void initQmlGlobalObject();
void setEngine(QQmlEngine *engine);
QQmlEngine *engine() { return m_engine; }
- v8::Local<v8::Object> global() { return m_context->Global(); }
+ QV4::Value global();
v8::Handle<v8::Context> context() const { return m_context; }
-// inline void registerValue(QJSValuePrivate *data);
-// inline void unregisterValue(QJSValuePrivate *data);
-// inline void invalidateAllValues();
-
-// inline void registerValueIterator(QJSValueIteratorPrivate *data);
-// inline void unregisterValueIterator(QJSValueIteratorPrivate *data);
-// inline void invalidateAllIterators();
-
QV8ContextWrapper *contextWrapper() { return &m_contextWrapper; }
QV8QObjectWrapper *qobjectWrapper() { return &m_qobjectWrapper; }
QV8TypeWrapper *typeWrapper() { return &m_typeWrapper; }
QV4::Value getOwnPropertyNames(const QV4::Value &o);
void freezeObject(const QV4::Value &value);
- static inline bool startsWithUpper(v8::Handle<v8::String>);
+ static inline bool startsWithUpper(QV4::String *);
QVariant toVariant(v8::Handle<v8::Value>, int typeHint);
v8::Handle<v8::Value> fromVariant(const QVariant &);
v8::Local<v8::String> toString(const QString &string);
// Create a new value type object
- inline v8::Handle<v8::Value> newValueType(QObject *, int coreIndex, QQmlValueType *);
- inline v8::Handle<v8::Value> newValueType(const QVariant &, QQmlValueType *);
- inline bool isValueType(v8::Handle<v8::Value>) const;
- inline QVariant toValueType(v8::Handle<v8::Value> obj);
+ inline QV4::Value newValueType(QObject *, int coreIndex, QQmlValueType *);
+ inline QV4::Value newValueType(const QVariant &, QQmlValueType *);
+ inline bool isValueType(const QV4::Value &value) const;
+ inline QVariant toValueType(const QV4::Value &obj);
// Create a new sequence type object
- inline v8::Handle<v8::Value> newSequence(int sequenceType, QObject *, int coreIndex, bool *succeeded);
-
- // Create a new QVariant object. This doesn't examine the type of the variant, but always returns
- // a QVariant wrapper
- inline v8::Handle<v8::Value> newQVariant(const QVariant &);
+ inline QV4::Value newSequence(int sequenceType, QObject *, int coreIndex, bool *succeeded);
// Return the JS string key for the "function is a binding" flag
- inline v8::Handle<v8::String> bindingFlagKey() const;
+ inline QV4::Value bindingFlagKey() const;
// Return the network access manager for this engine. By default this returns the network
// access manager of the QQmlEngine. It is overridden in the case of a threaded v8
inline void collectGarbage() { gc(); }
void gc();
- v8::Handle<v8::Value> throwException(v8::Handle<v8::Value> value);
-
#ifdef QML_GLOBAL_HANDLE_DEBUGGING
// Used for handle debugging
static void registerHandle(void *);
inline Deletable *extensionData(int) const;
void setExtensionData(int, Deletable *);
- QJSValue evaluate(const QString &program, const QString &fileName = QString(), quint16 lineNumber = 1);
- QJSValue evaluate(v8::Handle<v8::Script> script, v8::TryCatch& tryCatch);
QV4::Value evaluateScript(const QString &script, QV4::Object *scopeObject = 0);
QJSValue newArray(uint length);
- v8::Local<v8::Object> newVariant(const QVariant &variant);
QV4::Value variantListToJS(const QVariantList &lst);
inline QVariantList variantListFromJS(QV4::ArrayObject *array)
inline QVariant variantFromJS(const QV4::Value &value)
{ V8ObjectSet visitedObjects; return variantFromJS(value, visitedObjects); }
- v8::Handle<v8::Value> jsonValueToJS(const QJsonValue &value);
- QJsonValue jsonValueFromJS(v8::Handle<v8::Value> value);
- v8::Local<v8::Object> jsonObjectToJS(const QJsonObject &object);
- QJsonObject jsonObjectFromJS(v8::Handle<v8::Value> value);
- v8::Local<v8::Array> jsonArrayToJS(const QJsonArray &array);
- QJsonArray jsonArrayFromJS(v8::Handle<v8::Value> value);
+ QV4::Value jsonValueToJS(const QJsonValue &value);
+ QJsonValue jsonValueFromJS(const QV4::Value &value);
+ QV4::Value jsonObjectToJS(const QJsonObject &object);
+ QJsonObject jsonObjectFromJS(const QV4::Value &value);
+ QV4::Value jsonArrayToJS(const QJsonArray &array);
+ QJsonArray jsonArrayFromJS(const QV4::Value &value);
QV4::Value metaTypeToJS(int type, const void *data);
bool metaTypeFromJS(const QV4::Value &value, int type, void *data);
- bool convertToNativeQObject(v8::Handle<v8::Value> value,
+ bool convertToNativeQObject(const QV4::Value &value,
const QByteArray &targetType,
void **result);
- QVariant &variantValue(v8::Handle<v8::Value> value);
-
- QJSValue scriptValueFromInternal(v8::Handle<v8::Value>) const;
+ QJSValue scriptValueFromInternal(const QV4::Value &) const;
// used for console.time(), console.timeEnd()
void startTimer(const QString &timerName);
// used for console.count()
int consoleCountHelper(const QString &file, quint16 line, quint16 column);
- QObject *qtObjectFromJS(v8::Handle<v8::Value> value);
+ QObject *qtObjectFromJS(const QV4::Value &value);
static QDateTime qtDateTimeFromJsDate(double jsDate);
bool m_ownsV8Context;
v8::Persistent<v8::Context> m_context;
- v8::Persistent<v8::String> m_bindingFlagKey;
+ QV4::PersistentValue m_bindingFlagKey;
QV8ContextWrapper m_contextWrapper;
QV8QObjectWrapper m_qobjectWrapper;
return result;
}
-v8::Handle<v8::Value> QV8Engine::newValueType(QObject *object, int property, QQmlValueType *type)
+QV4::Value QV8Engine::newValueType(QObject *object, int property, QQmlValueType *type)
{
- return m_valueTypeWrapper.newValueType(object, property, type);
+ return m_valueTypeWrapper.newValueType(object, property, type)->v4Value();
}
-v8::Handle<v8::Value> QV8Engine::newValueType(const QVariant &value, QQmlValueType *type)
+QV4::Value QV8Engine::newValueType(const QVariant &value, QQmlValueType *type)
{
- return m_valueTypeWrapper.newValueType(value, type);
+ return m_valueTypeWrapper.newValueType(value, type)->v4Value();
}
-bool QV8Engine::isValueType(v8::Handle<v8::Value> obj) const
+bool QV8Engine::isValueType(const QV4::Value &value) const
{
- return obj->IsObject()?m_valueTypeWrapper.isValueType(v8::Handle<v8::Object>::Cast(obj)):false;
+ return value.isObject() ? m_valueTypeWrapper.isValueType(v8::Handle<v8::Object>::Cast(v8::Value::fromV4Value(value))) : false;
}
-QVariant QV8Engine::toValueType(v8::Handle<v8::Value> obj)
+QVariant QV8Engine::toValueType(const QV4::Value &obj)
{
- return obj->IsObject()?m_valueTypeWrapper.toVariant(v8::Handle<v8::Object>::Cast(obj)):QVariant();
+ return obj.isObject() ? m_valueTypeWrapper.toVariant(v8::Handle<v8::Object>::Cast(v8::Value::fromV4Value(obj))) : QVariant();
}
-v8::Handle<v8::Value> QV8Engine::newSequence(int sequenceType, QObject *object, int property, bool *succeeded)
+QV4::Value QV8Engine::newSequence(int sequenceType, QObject *object, int property, bool *succeeded)
{
- return m_sequenceWrapper.newSequence(sequenceType, object, property, succeeded);
+ return m_sequenceWrapper.newSequence(sequenceType, object, property, succeeded)->v4Value();
}
-v8::Handle<v8::String> QV8Engine::bindingFlagKey() const
+QV4::Value QV8Engine::bindingFlagKey() const
{
return m_bindingFlagKey;
}
// XXX Can this be made more optimal? It is called prior to resolving each and every
// unqualified name in QV8ContextWrapper.
-bool QV8Engine::startsWithUpper(v8::Handle<v8::String> string)
+bool QV8Engine::startsWithUpper(QV4::String *string)
{
- v8::String::Value value(string);
- Q_ASSERT(*value != NULL);
- uint16_t c = **value;
+ uint16_t c = string->toQString().at(0).unicode();
return (c >= 'A' && c <= 'Z') ||
(c > 127 && QChar::category(c) == QChar::Letter_Uppercase);
}
if (!callback.IsEmpty()) {
v8::Handle<v8::Value> args[] = { status };
v8::TryCatch tc;
- callback->Call(engine->global(), 1, args);
+ callback->Call(v8::Value::fromV4Value(engine->global()), 1, args);
}
}
v8::Local<v8::Function> fn = v8::Local<v8::Function>::Cast(script->Run());
v8::Handle<v8::Value> invokeFn = v8::FunctionTemplate::New(Invoke)->GetFunction();
v8::Handle<v8::Value> args[] = { invokeFn };
- v8::Local<v8::Function> createFn = v8::Local<v8::Function>::Cast(fn->Call(engine->global(), 1, args));
+ v8::Local<v8::Function> createFn = v8::Local<v8::Function>::Cast(fn->Call(v8::Value::fromV4Value(engine->global()), 1, args));
m_methodConstructor = qPersistentNew<v8::Function>(createFn);
}
}
{
- v8::Local<v8::Object> prototype = engine->global()->Get(v8::String::New("Function"))->ToObject()->Get(v8::String::New("prototype"))->ToObject();
+ v8::Local<v8::Object> prototype = v8::Local<v8::Object>::New(v8::Value::fromV4Value(engine->global()))
+ ->Get(v8::String::New("Function"))->ToObject()->Get(v8::String::New("prototype"))->ToObject();
prototype->Set(v8::String::New("connect"), connect, v8::DontEnum);
prototype->Set(v8::String::New("disconnect"), disconnect, v8::DontEnum);
}
if (QQmlValueTypeFactory::isValueType(v.userType())) {
if (QQmlValueType *valueType = QQmlValueTypeFactory::valueType(v.userType()))
- return engine->newValueType(object, property.coreIndex, valueType); // VariantReference value-type.
+ return v8::Value::fromV4Value(engine->newValueType(object, property.coreIndex, valueType)); // VariantReference value-type.
}
return engine->fromVariant(v);
Q_ASSERT(notifier == 0);
if (QQmlValueType *valueType = QQmlValueTypeFactory::valueType(property.propType))
- return engine->newValueType(object, property.coreIndex, valueType);
+ return v8::Value::fromV4Value(engine->newValueType(object, property.coreIndex, valueType));
} else {
Q_ASSERT(notifier == 0);
// see if it's a sequence type
bool succeeded = false;
- v8::Handle<v8::Value> retn = engine->newSequence(property.propType, object, property.coreIndex,
- &succeeded);
+ v8::Handle<v8::Value> retn = v8::Value::fromV4Value(engine->newSequence(property.propType, object, property.coreIndex,
+ &succeeded));
if (succeeded)
return retn;
}
v8::Integer::New(index)
};
Q_ASSERT(argv[0]->IsObject());
- return engine->qobjectWrapper()->m_methodConstructor->Call(engine->global(), 2, argv);
+ return engine->qobjectWrapper()->m_methodConstructor->Call(v8::Value::fromV4Value(engine->global()), 2, argv);
}
static v8::Handle<v8::Value> createWithGlobal(QV8Engine *engine, QObject *object,
v8::Handle<v8::Value> *objectHandle,
v8::Context::GetCallingQmlGlobal()
};
Q_ASSERT(argv[0]->IsObject());
- return engine->qobjectWrapper()->m_methodConstructor->Call(engine->global(), 3, argv);
+ return engine->qobjectWrapper()->m_methodConstructor->Call(v8::Value::fromV4Value(engine->global()), 3, argv);
}
};
{
QQmlBinding *newBinding = 0;
if (value->IsFunction()) {
- if (value->ToObject()->GetHiddenValue(engine->bindingFlagKey()).IsEmpty()) {
+ if (value->ToObject()->GetHiddenValue(v8::Value::fromV4Value(engine->bindingFlagKey())).IsEmpty()) {
if (!property->isVarProperty() && property->propType != qMetaTypeId<QJSValue>()) {
// assigning a JS function to a non var or QJSValue property or is not allowed.
QString error = QLatin1String("Cannot assign JavaScript function to ");
} else if (value->IsUndefined() && property->propType == QMetaType::QJsonValue) {
PROPERTY_STORE(QJsonValue, QJsonValue(QJsonValue::Undefined));
} else if (!newBinding && property->propType == qMetaTypeId<QJSValue>()) {
- PROPERTY_STORE(QJSValue, engine->scriptValueFromInternal(value));
+ PROPERTY_STORE(QJSValue, engine->scriptValueFromInternal(value->v4Value()));
} else if (value->IsUndefined()) {
QString error = QLatin1String("Cannot assign [undefined] to ");
if (!QMetaType::typeName(property->propType))
if (!result.IsEmpty())
return result;
- if (QV8Engine::startsWithUpper(property)) {
+ if (QV8Engine::startsWithUpper(property->v4Value().asString())) {
// Check for attached properties
if (context && context->imports) {
QQmlTypeNameCache::Result r = context->imports->query(propertystring);
// This is one of our special QObject method wrappers
v8::Handle<v8::Value> args[] = { engine->qobjectWrapper()->m_hiddenObject };
- v8::Local<v8::Value> data = function->Call(engine->global(), 1, args);
+ v8::Local<v8::Value> data = function->Call(v8::Value::fromV4Value(engine->global()), 1, args);
if (data->IsArray()) {
v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(data);
v8::TryCatch try_catch;
if (connection.thisObject.IsEmpty()) {
- connection.function->Call(engine->global(), argCount, args.data());
+ connection.function->Call(v8::Value::fromV4Value(engine->global()), argCount, args.data());
} else {
connection.function->Call(connection.thisObject, argCount, args.data());
}
handlePtr = new (&allocData) QQmlV4Handle(QQmlV4Handle::fromV8Handle(value));
type = callType;
} else if (callType == QMetaType::QJsonArray) {
- jsonArrayPtr = new (&allocData) QJsonArray(engine->jsonArrayFromJS(value));
+ jsonArrayPtr = new (&allocData) QJsonArray(engine->jsonArrayFromJS(value->v4Value()));
type = callType;
} else if (callType == QMetaType::QJsonObject) {
- jsonObjectPtr = new (&allocData) QJsonObject(engine->jsonObjectFromJS(value));
+ jsonObjectPtr = new (&allocData) QJsonObject(engine->jsonObjectFromJS(value->v4Value()));
type = callType;
} else if (callType == QMetaType::QJsonValue) {
- jsonValuePtr = new (&allocData) QJsonValue(engine->jsonValueFromJS(value));
+ jsonValuePtr = new (&allocData) QJsonValue(engine->jsonValueFromJS(value->v4Value()));
type = callType;
} else if (callType == QMetaType::Void) {
*qvariantPtr = QVariant();
} else if (type == qMetaTypeId<QQmlV4Handle>()) {
return handlePtr->toV8Handle();
} else if (type == QMetaType::QJsonArray) {
- return engine->jsonArrayToJS(*jsonArrayPtr);
+ return v8::Value::fromV4Value(engine->jsonArrayToJS(*jsonArrayPtr));
} else if (type == QMetaType::QJsonObject) {
- return engine->jsonObjectToJS(*jsonObjectPtr);
+ return v8::Value::fromV4Value(engine->jsonObjectToJS(*jsonObjectPtr));
} else if (type == QMetaType::QJsonValue) {
- return engine->jsonValueToJS(*jsonValuePtr);
+ return v8::Value::fromV4Value(engine->jsonValueToJS(*jsonValuePtr));
} else if (type == -1 || type == qMetaTypeId<QVariant>()) {
QVariant value = *qvariantPtr;
v8::Handle<v8::Value> rv = engine->fromVariant(value);
bool operator()(SequenceElementType e0, SequenceElementType e1) \
{ \
v8::Handle<v8::Value> argv[2] = { eng->fromVariant(e0), eng->fromVariant(e1) }; \
- v8::Handle<v8::Value> compareValue = jsFn->Call(eng->global(), 2, argv); \
+ v8::Handle<v8::Value> compareValue = jsFn->Call(v8::Value::fromV4Value(eng->global()), 2, argv); \
return compareValue->NumberValue() < 0; \
} \
private: \
QObject *qobjectSingleton = siinfo->qobjectApi(e);
if (qobjectSingleton) {
// check for enum value
- if (QV8Engine::startsWithUpper(property)) {
+ if (QV8Engine::startsWithUpper(property->v4Value().asString())) {
if (resource->mode == IncludeEnums) {
QString name = property->v4Value().toQString();
} else {
- if (QV8Engine::startsWithUpper(property)) {
+ if (QV8Engine::startsWithUpper(property->v4Value().asString())) {
bool ok = false;
int value = type->enumValue(propertystring, &ok);
if (ok)
QQmlBinding *newBinding = 0;
if (value->IsFunction()) {
- if (value->ToObject()->GetHiddenValue(r->engine->bindingFlagKey()).IsEmpty()) {
+ if (value->ToObject()->GetHiddenValue(v8::Value::fromV4Value(r->engine->bindingFlagKey())).IsEmpty()) {
// assigning a JS function to a non-var-property is not allowed.
QString error = QLatin1String("Cannot assign JavaScript function to value-type property");
v8::ThrowException(v8::Exception::Error(r->engine->toString(error)));
v8::Handle<v8::Value> args[] = {
V8FUNCTION(QQuickWorkerScriptEnginePrivate::sendMessage, this)
};
- v8::Local<v8::Value> createsendvalue = createsendconstructor->Call(global(), 1, args);
+ v8::Local<v8::Value> createsendvalue = createsendconstructor->Call(v8::Value::fromV4Value(global()), 1, args);
createsend = qPersistentNew<v8::Function>(v8::Handle<v8::Function>::Cast(createsendvalue));
}
v8::Local<v8::Function> QQuickWorkerScriptEnginePrivate::WorkerEngine::sendFunction(int id)
{
v8::Handle<v8::Value> args[] = { v8::Integer::New(id) };
- return v8::Local<v8::Function>::Cast(createsend->Call(global(), 1, args));
+ return v8::Local<v8::Function>::Cast(createsend->Call(v8::Value::fromV4Value(global()), 1, args));
}
// Requires handle and context scope
v8::Handle<v8::Value> arg)
{
v8::Handle<v8::Value> args[] = { object, arg };
- onmessage->Call(global(), 2, args);
+ onmessage->Call(v8::Value::fromV4Value(global()), 2, args);
}
QNetworkAccessManager *QQuickWorkerScriptEnginePrivate::WorkerEngine::networkAccessManager()