#include <private/qlocale_p.h>
#include <private/qlocale_data_p.h>
+#include <private/qv4dateobject_p.h>
+
QT_BEGIN_NAMESPACE
class QV8LocaleDataResource : public QV8ObjectResource
if (args.Length() == 0) {
// Use QLocale for standard toLocaleString() function
QLocale locale;
- return QJSConverter::toString(locale.toString(dt));
+ return QV4::Value::fromString(args.GetIsolate()->GetEngine()->newString(locale.toString(dt)));
}
if (!isLocaleObject(args[0]))
if (args.Length() == 0) {
// Use QLocale for standard toLocaleString() function
QLocale locale;
- return QJSConverter::toString(locale.toString(time));
+ return QV4::Value::fromString(args.GetIsolate()->GetEngine()->newString(locale.toString(time)));
}
if (!isLocaleObject(args[0]))
if (args.Length() == 0) {
// Use QLocale for standard toLocaleString() function
QLocale locale;
- return QJSConverter::toString(locale.toString(date));
+ return QV4::Value::fromString(args.GetIsolate()->GetEngine()->newString(locale.toString(date)));
}
if (!isLocaleObject(args[0]))
{
if (args.Length() == 1 && args[0]->IsString()) {
QLocale locale;
- QString dateString = QJSConverter::toString(args[0]->ToString());
+ QString dateString = args[0]->v4Value().toString(args.GetIsolate()->GetEngine()->current)->toQString();
QDateTime dt = locale.toDateTime(dateString);
- return QJSConverter::toDateTime(dt);
+ return QV4::Value::fromObject(QJSConverter::toDateTime(dt));
}
if (args.Length() < 1 || args.Length() > 3 || !isLocaleObject(args[0]))
dt = r->locale.toDateTime(dateString, enumFormat);
}
- return QJSConverter::toDateTime(dt);
+ return QV4::Value::fromObject(QJSConverter::toDateTime(dt));
}
v8::Handle<v8::Value> QQmlDateExtension::fromLocaleTimeString(const v8::Arguments& args)
{
if (args.Length() == 1 && args[0]->IsString()) {
QLocale locale;
- QString timeString = QJSConverter::toString(args[0]->ToString());
+ QString timeString = args[0]->v4Value().toString(args.GetIsolate()->GetEngine()->current)->toQString();
QTime time = locale.toTime(timeString);
QDateTime dt = QDateTime::currentDateTime();
dt.setTime(time);
- return QJSConverter::toDateTime(dt);
+ return QV4::Value::fromObject(QJSConverter::toDateTime(dt));
}
if (args.Length() < 1 || args.Length() > 3 || !isLocaleObject(args[0]))
QDateTime dt = QDateTime::currentDateTime();
dt.setTime(tm);
- return QJSConverter::toDateTime(dt);
+ return QV4::Value::fromObject(QJSConverter::toDateTime(dt));
}
v8::Handle<v8::Value> QQmlDateExtension::fromLocaleDateString(const v8::Arguments& args)
{
if (args.Length() == 1 && args[0]->IsString()) {
QLocale locale;
- QString dateString = QJSConverter::toString(args[0]->ToString());
+ QString dateString = args[0]->v4Value().toString(args.GetIsolate()->GetEngine()->current)->toQString();
QDate date = locale.toDate(dateString);
- return QJSConverter::toDateTime(QDateTime(date));
+ return QV4::Value::fromObject(QJSConverter::toDateTime(QDateTime(date)));
}
if (args.Length() < 1 || args.Length() > 3 || !isLocaleObject(args[0]))
dt = r->locale.toDate(dateString, enumFormat);
}
- return QJSConverter::toDateTime(QDateTime(dt));
+ return QV4::Value::fromObject(QJSConverter::toDateTime(QDateTime(dt)));
}
v8::Handle<v8::Value> QQmlDateExtension::timeZoneUpdated(const v8::Arguments& args)
if (args.Length() == 0) {
// Use QLocale for standard toLocaleString() function
QLocale locale;
- return QJSConverter::toString(locale.toString(number));
+ return QV4::Value::fromString(args.GetIsolate()->GetEngine()->newString(locale.toString(number)));
}
if (!isLocaleObject(args[0]))
if (args.Length() == 0) {
// Use QLocale for standard toLocaleString() function
QLocale locale;
- return QJSConverter::toString(locale.toString(number));
+ return QV4::Value::fromString(args.GetIsolate()->GetEngine()->newString(locale.toString(number)));
}
if (!isLocaleObject(args[0]))
return v8::Number::New(Q_QNAN);
bool ok = false;
- double val = locale.toDouble(QJSConverter::toString(ns), &ok);
+ double val = locale.toDouble(ns->v4Value().asString()->toQString(), &ok);
if (!ok)
V8THROW_ERROR("Locale: Number.fromLocaleString(): Invalid format")
if (!args.This()->IsString() && !args.This()->IsStringObject())
return v8::Undefined();
- QString thisString = QJSConverter::toString(args.This()->ToString());
- QString thatString = QJSConverter::toString(args[0]->ToString());
+ QString thisString = args.This()->v4Value().toString(args.GetIsolate()->GetEngine()->current)->toQString();
+ QString thatString = args[0]->v4Value().toString(args.GetIsolate()->GetEngine()->current)->toQString();
return v8::Integer::New(QString::localeAwareCompare(thisString, thatString));
}
return object;
}
-Object *ExecutionEngine::newDateObject(const Value &value)
+DateObject *ExecutionEngine::newDateObject(const Value &value)
{
- Object *object = new (memoryManager) DateObject(this, value);
+ DateObject *object = new (memoryManager) DateObject(this, value);
object->prototype = datePrototype;
return object;
}
ArrayObject *newArrayObject(ExecutionContext *ctx);
- Object *newDateObject(const Value &value);
+ DateObject *newDateObject(const Value &value);
RegExpObject *newRegExpObject(const QString &pattern, int flags);
RegExpObject *newRegExpObject(RegExp* re, bool global);
#include "qjsconverter_p.h"
#include <stdlib.h>
+#include <private/qv4jsir_p.h>
+#include <private/qv4regexpobject_p.h>
+#include <private/qv4dateobject_p.h>
+
#ifndef QJSCONVERTER_IMPL_P_H
#define QJSCONVERTER_IMPL_P_H
extern char *qdtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve, char **digits_str);
Q_CORE_EXPORT QString qt_regexp_toCanonical(const QString &, QRegExp::PatternSyntax);
-
-quint32 QJSConverter::toArrayIndex(const QString& string)
-{
- // FIXME this function should be exported by JSC C API.
- bool ok;
- quint32 idx = string.toUInt(&ok);
- if (!ok || toString(idx) != string)
- idx = 0xffffffff;
-
- return idx;
-}
-
-QString QJSConverter::toString(v8::Handle<v8::String> jsString)
-{
- if (jsString.IsEmpty())
- return QString();
- QString qstr;
- qstr.resize(jsString->Length());
- jsString->Write(reinterpret_cast<uint16_t*>(qstr.data()));
- return qstr;
-}
-
-v8::Local<v8::String> QJSConverter::toString(const QString& string)
-{
- return v8::String::New(reinterpret_cast<const uint16_t*>(string.data()), string.size());
-}
-
-QString QJSConverter::toString(double value)
-{
- // FIXME this should be easier. The ideal fix is to create
- // a new function in V8 API which could cover the functionality.
-
- if (qIsNaN(value))
- return QString::fromLatin1("NaN");
- if (qIsInf(value))
- return QString::fromLatin1(value < 0 ? "-Infinity" : "Infinity");
- if (!value)
- return QString::fromLatin1("0");
-
- QVarLengthArray<char, 25> buf;
- int decpt;
- int sign;
- char* result = 0;
- char* endresult;
- (void)qdtoa(value, 0, 0, &decpt, &sign, &endresult, &result);
-
- if (!result)
- return QString();
-
- int resultLen = endresult - result;
- if (decpt <= 0 && decpt > -6) {
- buf.resize(-decpt + 2 + sign);
- memset(buf.data(), '0', -decpt + 2 + sign);
- if (sign) // fix the sign.
- buf[0] = '-';
- buf[sign + 1] = '.';
- buf.append(result, resultLen);
- } else {
- if (sign)
- buf.append('-');
- int length = buf.size() - sign + resultLen;
- if (decpt <= 21 && decpt > 0) {
- if (length <= decpt) {
- const char* zeros = "0000000000000000000000000";
- buf.append(result, resultLen);
- buf.append(zeros, decpt - length);
- } else {
- buf.append(result, decpt);
- buf.append('.');
- buf.append(result + decpt, resultLen - decpt);
- }
- } else if (result[0] >= '0' && result[0] <= '9') {
- if (length > 1) {
- buf.append(result, 1);
- buf.append('.');
- buf.append(result + 1, resultLen - 1);
- } else
- buf.append(result, resultLen);
- buf.append('e');
- buf.append(decpt >= 0 ? '+' : '-');
- int e = qAbs(decpt - 1);
- if (e >= 100)
- buf.append('0' + e / 100);
- if (e >= 10)
- buf.append('0' + (e % 100) / 10);
- buf.append('0' + e % 10);
- }
- }
- free(result);
- buf.append(0);
- return QString::fromLatin1(buf.constData());
-}
-
// Converts a JS RegExp to a QRegExp.
// The conversion is not 100% exact since ECMA regexp and QRegExp
// have different semantics/flags, but we try to do our best.
-QRegExp QJSConverter::toRegExp(v8::Handle<v8::RegExp> jsRegExp)
+QRegExp QJSConverter::toRegExp(const QV4::RegExpObject *jsRegExp)
{
- QString pattern = QJSConverter::toString(jsRegExp->GetSource());
- Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive;
- if (jsRegExp->GetFlags() & v8::RegExp::kIgnoreCase)
- caseSensitivity = Qt::CaseInsensitive;
+ QV4::RegExp *re = jsRegExp->value;
+ QString pattern = re->pattern();
+ Qt::CaseSensitivity caseSensitivity = re->ignoreCase() ? Qt::CaseInsensitive : Qt::CaseSensitive;
return QRegExp(pattern, caseSensitivity, QRegExp::RegExp2);
}
// Converts a QRegExp to a JS RegExp.
// The conversion is not 100% exact since ECMA regexp and QRegExp
// have different semantics/flags, but we try to do our best.
-v8::Local<v8::RegExp> QJSConverter::toRegExp(const QRegExp &re)
+QV4::RegExpObject *QJSConverter::toRegExp(const QRegExp &re)
{
// Convert the pattern to a ECMAScript pattern.
QString pattern = qt_regexp_toCanonical(re.pattern(), re.patternSyntax());
pattern = ecmaPattern;
}
- int flags = v8::RegExp::kNone;
+ int flags = 0;
if (re.caseSensitivity() == Qt::CaseInsensitive)
- flags |= v8::RegExp::kIgnoreCase;
+ flags |= QQmlJS::V4IR::RegExp::RegExp_IgnoreCase;
- return v8::RegExp::New(QJSConverter::toString(pattern), static_cast<v8::RegExp::Flags>(flags));
+ QV4::ExecutionEngine *e = v8::Isolate::GetCurrent()->GetEngine();
+ return e->newRegExpObject(pattern, flags);
}
// Converts a QStringList to JS.
// The result is a new Array object with length equal to the length
// of the QStringList, and the elements being the QStringList's
// elements converted to JS Strings.
-v8::Local<v8::Array> QJSConverter::toStringList(const QStringList &lst)
+QV4::Value QJSConverter::toStringList(const QStringList &list)
{
- v8::Local<v8::Array> result = v8::Array::New(lst.size());
- for (int i = 0; i < lst.size(); ++i)
- result->Set(i, toString(lst.at(i)));
- return result;
+ QV4::ExecutionEngine *e = v8::Isolate::GetCurrent()->GetEngine();
+ QV4::ArrayObject *a = e->newArrayObject(e->current);
+ int len = list.count();
+ a->arrayReserve(len);
+ for (int ii = 0; ii < len; ++ii)
+ a->arrayData[ii].value = QV4::Value::fromString(e->newString(list.at(ii)));
+ a->setArrayLengthUnchecked(len);
+ return QV4::Value::fromObject(a);
}
// Converts a JS Array object to a QStringList.
// The result is a QStringList with length equal to the length
// of the JS Array, and elements being the JS Array's elements
// converted to QStrings.
-QStringList QJSConverter::toStringList(v8::Handle<v8::Array> jsArray)
+QStringList QJSConverter::toStringList(const QV4::Value &jsArray)
{
QStringList result;
- uint32_t length = jsArray->Length();
+
+ QV4::ArrayObject *a = jsArray.asArrayObject();
+ if (!a)
+ return result;
+ QV4::ExecutionEngine *e = a->internalClass->engine;
+
+ uint32_t length = a->arrayLength();
for (uint32_t i = 0; i < length; ++i)
- result.append(toString(jsArray->Get(i)->ToString()));
+ result.append(a->getIndexed(e->current, i).toString(e->current)->toQString());
return result;
}
// Converts a JS Date to a QDateTime.
-QDateTime QJSConverter::toDateTime(v8::Handle<v8::Date> jsDate)
+QDateTime QJSConverter::toDateTime(QV4::DateObject *jsDate)
{
- return QDateTime::fromMSecsSinceEpoch(jsDate->NumberValue());
+ return QDateTime::fromMSecsSinceEpoch(jsDate->value.doubleValue());
}
// Converts a QDateTime to a JS Date.
-v8::Local<v8::Value> QJSConverter::toDateTime(const QDateTime &dt)
+QV4::DateObject *QJSConverter::toDateTime(const QDateTime &dt)
{
double date;
if (!dt.isValid())
date = qSNaN();
else
date = dt.toMSecsSinceEpoch();
- return v8::Date::New(date);
+ QV4::ExecutionEngine *e = v8::Isolate::GetCurrent()->GetEngine();
+ return e->newDateObject(QV4::Value::fromDouble(date));
}
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
+namespace QV4 {
+struct RegExpObject;
+struct DateObject;
+struct Value;
+}
+
/*
\internal
\class QJSConverter
*/
class QJSConverter {
public:
- static quint32 toArrayIndex(const QString& string);
-
- static QString toString(v8::Handle<v8::String> jsString);
- static v8::Local<v8::String> toString(const QString& string);
- static QString toString(double value);
-
- enum {
- PropertyAttributeMask = v8::ReadOnly | v8::DontDelete | v8::DontEnum,
- };
-
// Converts a JS RegExp to a QRegExp.
// The conversion is not 100% exact since ECMA regexp and QRegExp
// have different semantics/flags, but we try to do our best.
- static QRegExp toRegExp(v8::Handle<v8::RegExp> jsRegExp);
+ static QRegExp toRegExp(const QV4::RegExpObject *jsRegExp);
// Converts a QRegExp to a JS RegExp.
// The conversion is not 100% exact since ECMA regexp and QRegExp
// have different semantics/flags, but we try to do our best.
- static v8::Local<v8::RegExp> toRegExp(const QRegExp &re);
+ static QV4::RegExpObject *toRegExp(const QRegExp &re);
// Converts a QStringList to JS.
// The result is a new Array object with length equal to the length
// of the QStringList, and the elements being the QStringList's
// elements converted to JS Strings.
- static v8::Local<v8::Array> toStringList(const QStringList &lst);
+ static QV4::Value toStringList(const QStringList &list);
// Converts a JS Array object to a QStringList.
// The result is a QStringList with length equal to the length
// of the JS Array, and elements being the JS Array's elements
// converted to QStrings.
- static QStringList toStringList(v8::Handle<v8::Array> jsArray);
+ static QStringList toStringList(const QV4::Value &jsArray);
// Converts a JS Date to a QDateTime.
- static QDateTime toDateTime(v8::Handle<v8::Date> jsDate);
+ static QDateTime toDateTime(QV4::DateObject *jsDate);
// Converts a QDateTime to a JS Date.
- static v8::Local<v8::Value> toDateTime(const QDateTime &dt);
+ static QV4::DateObject *toDateTime(const QDateTime &dt);
};
QT_END_NAMESPACE
int columnNumber = frame->GetColumn();
QString stackFrame =
- QString::fromLatin1("%1 (%2:%3:%4)").arg(QJSConverter::toString(function),
- QJSConverter::toString(script),
+ QString::fromLatin1("%1 (%2:%3:%4)").arg(function->v4Value().asString()->toQString(),
+ script->v4Value().asString()->toQString(),
QString::number(lineNumber),
QString::number(columnNumber));
stackFrames.append(stackFrame);
#include <private/qv4mm_p.h>
#include <private/qv4objectproto_p.h>
#include <private/qv4globalobject_p.h>
+#include <private/qv4regexpobject_p.h>
Q_DECLARE_METATYPE(QList<int>)
return QV4::Value::fromObject(m_v4Engine->newDateObject(QV4::Value::fromDouble(
qtDateTimeToJsDate(QDateTime(QDate(1970,1,1), *reinterpret_cast<const QTime *>(ptr))))));
case QMetaType::QRegExp:
- return QJSConverter::toRegExp(*reinterpret_cast<const QRegExp *>(ptr))->v4Value();
+ return QV4::Value::fromObject(QJSConverter::toRegExp(*reinterpret_cast<const QRegExp *>(ptr)));
case QMetaType::QObjectStar:
return newQObject(*reinterpret_cast<QObject* const *>(ptr));
case QMetaType::QStringList:
const QString &fileName,
quint16 lineNumber)
{
- v8::Local<v8::String> v8source = QJSConverter::toString(source);
- v8::Local<v8::String> v8fileName = QJSConverter::toString(fileName);
+ v8::Handle<v8::String> v8source = QV4::Value::fromString(m_v4Engine->newString(source));
+ v8::Handle<v8::String> v8fileName = QV4::Value::fromString(m_v4Engine->newString(fileName));
v8::ScriptOrigin origin(v8fileName, v8::Integer::New(lineNumber - 1));
if (sourceLength == -1)
sourceLength = int(strlen(source));
- v8::Local<v8::String> v8source = v8::String::New(source, sourceLength);
- v8::Local<v8::String> v8fileName = QJSConverter::toString(fileName);
+ v8::Handle<v8::String> v8source = QV4::Value::fromString(m_v4Engine->newString(QString::fromUtf8(source, sourceLength)));
+ v8::Handle<v8::String> v8fileName = QV4::Value::fromString(m_v4Engine->newString(fileName));
v8::ScriptOrigin origin(v8fileName, v8::Integer::New(lineNumber - 1));
if (value->IsRegExp()) {
v8::Context::Scope scope(context());
- return QJSConverter::toRegExp(v8::Handle<v8::RegExp>::Cast(value));
+ return QJSConverter::toRegExp(value->v4Value().asRegExpObject());
}
if (value->IsArray()) {
v8::Context::Scope scope(context());
case QMetaType::QChar:
return QV4::Value::fromUInt32((*reinterpret_cast<const QChar*>(data)).unicode());
case QMetaType::QStringList:
- result = QJSConverter::toStringList(*reinterpret_cast<const QStringList *>(data))->v4Value();
+ result = QJSConverter::toStringList(*reinterpret_cast<const QStringList *>(data));
break;
case QMetaType::QVariantList:
result = variantListToJS(*reinterpret_cast<const QVariantList *>(data));
result = variantMapToJS(*reinterpret_cast<const QVariantMap *>(data));
break;
case QMetaType::QDateTime:
- result = QJSConverter::toDateTime(*reinterpret_cast<const QDateTime *>(data))->v4Value();
+ result = QV4::Value::fromObject(QJSConverter::toDateTime(*reinterpret_cast<const QDateTime *>(data)));
break;
case QMetaType::QDate:
- result = QJSConverter::toDateTime(QDateTime(*reinterpret_cast<const QDate *>(data)))->v4Value();
+ result = QV4::Value::fromObject(QJSConverter::toDateTime(QDateTime(*reinterpret_cast<const QDate *>(data))));
break;
case QMetaType::QRegExp:
- result = QJSConverter::toRegExp(*reinterpret_cast<const QRegExp *>(data))->v4Value();
+ result = QV4::Value::fromObject(QJSConverter::toRegExp(*reinterpret_cast<const QRegExp *>(data)));
break;
case QMetaType::QObjectStar:
result = newQObject(*reinterpret_cast<QObject* const *>(data));
} break;
case QMetaType::QRegExp:
if (QV4::RegExpObject *r = value.asRegExpObject()) {
- *reinterpret_cast<QRegExp *>(data) = QJSConverter::toRegExp(v8::Handle<v8::RegExp>::Cast(v8::Value::fromV4Value(value)));
+ *reinterpret_cast<QRegExp *>(data) = QJSConverter::toRegExp(r);
return true;
} break;
case QMetaType::QObjectStar: {
}
case QMetaType::QStringList:
if (QV4::ArrayObject *a = value.asArrayObject()) {
- *reinterpret_cast<QStringList *>(data) = QJSConverter::toStringList(v8::Handle<v8::Array>::Cast(v8::Value::fromV4Value(value)));
+ *reinterpret_cast<QStringList *>(data) = QJSConverter::toStringList(value);
return true;
} break;
case QMetaType::QVariantList:
if (QV4::ArrayObject *a = value.asArrayObject())
return variantListFromJS(a, visitedObjects);
if (QV4::DateObject *d = value.asDateObject())
- return QJSConverter::toDateTime(v8::Handle<v8::Date>::Cast(v8::Value::fromV4Value(value)));
- if (value.asRegExpObject())
- return QJSConverter::toRegExp(v8::Handle<v8::RegExp>::Cast(v8::Value::fromV4Value(value)));
+ return QJSConverter::toDateTime(d);
+ if (QV4::RegExpObject *re = value.asRegExpObject())
+ return QJSConverter::toRegExp(re);
if (isVariant(v8::Value::fromV4Value(value)))
return variantWrapper()->variantValue(v8::Value::fromV4Value(value));
if (isQObject(value))
}
}
-v8::Local<v8::String> QV8Engine::toString(const QString &string)
+QV4::Value QV8Engine::toString(const QString &string)
{
- return QJSConverter::toString(string);
+ return QV4::Value::fromString(m_v4Engine->newString(string));
}
inline QObject *toQObject(const QV4::Value &value);
// Return a JS string for the given QString \a string
- v8::Local<v8::String> toString(const QString &string);
+ QV4::Value toString(const QString &string);
// Create a new value type object
inline QV4::Value newValueType(QObject *, int coreIndex, QQmlValueType *);