From 70f8279338ee9f4df39e45403f9357359113ec0d Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 21 May 2013 21:23:01 +0200 Subject: [PATCH] Get rid of v8::String::(Ascii)Value Change-Id: I792a94590efbec852620d101b620b263a90e1d54 Reviewed-by: Simon Hausmann --- src/qml/qml/ftw/qhashedstring_p.h | 11 +--- src/qml/qml/v4/qv4v8.cpp | 10 ---- src/qml/qml/v4/qv4v8_p.h | 42 --------------- src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 71 ++++++++++++-------------- src/quick/items/context2d/qquickcanvasitem.cpp | 2 +- src/quick/items/context2d/qquickcontext2d.cpp | 4 +- 6 files changed, 38 insertions(+), 102 deletions(-) diff --git a/src/qml/qml/ftw/qhashedstring_p.h b/src/qml/qml/ftw/qhashedstring_p.h index cce4970..9393e1f 100644 --- a/src/qml/qml/ftw/qhashedstring_p.h +++ b/src/qml/qml/ftw/qhashedstring_p.h @@ -1182,16 +1182,7 @@ v8::Handle QHashedV8String::string() const QString QHashedV8String::toString() const { - QString result; - result.reserve(m_hash.length); - - v8::String::Value value(m_string); - Q_ASSERT(*value != NULL); - uint16_t* string = *value; - for (int i = 0; i < m_hash.length; ++i) - result.append(string[i]); - - return result; + return m_string->v4Value().toQString(); } QHashedStringRef::QHashedStringRef() diff --git a/src/qml/qml/v4/qv4v8.cpp b/src/qml/qml/v4/qv4v8.cpp index e7ca797..9902528 100644 --- a/src/qml/qml/v4/qv4v8.cpp +++ b/src/qml/qml/v4/qv4v8.cpp @@ -614,16 +614,6 @@ QV4::String *String::asV4String() const return v->stringValue(); } -String::AsciiValue::AsciiValue(Handle obj) -{ - str = obj->ToString()->asQString().toLatin1(); -} - -String::Value::Value(Handle obj) -{ - str = obj->ToString()->asQString(); -} - struct ExternalResourceWrapper : public QV4::Object::ExternalResource { diff --git a/src/qml/qml/v4/qv4v8_p.h b/src/qml/qml/v4/qv4v8_p.h index 11662b9..b73d26e 100644 --- a/src/qml/qml/v4/qv4v8_p.h +++ b/src/qml/qml/v4/qv4v8_p.h @@ -942,48 +942,6 @@ class V8EXPORT String : public Value { */ static Handle NewExternal(ExternalStringResource* resource); - /** - * Converts an object to an ASCII string. - * Useful if you want to print the object. - * If conversion to a string fails (eg. due to an exception in the toString() - * method of the object) then the length() method returns 0 and the * operator - * returns NULL. - */ - class V8EXPORT AsciiValue { - public: - explicit AsciiValue(Handle obj); - ~AsciiValue() {} - char* operator*() { return str.data(); } - const char* operator*() const { return str.constData(); } - int length() const { return str.length(); } - private: - QByteArray str; - - // Disallow copying and assigning. - AsciiValue(const AsciiValue&); - void operator=(const AsciiValue&); - }; - - /** - * Converts an object to a two-byte string. - * If conversion to a string fails (eg. due to an exception in the toString() - * method of the object) then the length() method returns 0 and the * operator - * returns NULL. - */ - class V8EXPORT Value { - public: - explicit Value(Handle obj); - ~Value() {} - uint16_t* operator*() { return (uint16_t *)str.data(); } - const uint16_t* operator*() const { return str.utf16(); } - int length() const { return str.length(); } - private: - QString str; - - // Disallow copying and assigning. - Value(const Value&); - void operator=(const Value&); - }; QString asQString() const; QV4::String *asV4String() const; diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index c69ea9a..a24fb5d 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -74,13 +74,13 @@ enum ConsoleLogTypes { Error }; -static void jsContext(v8::Handle *file, int *line, v8::Handle *function) { +static void jsContext(QString &file, int *line, QString &function) { v8::Handle stackTrace = v8::StackTrace::CurrentStackTrace(1); if (stackTrace->GetFrameCount()) { v8::Handle frame = stackTrace->GetFrame(0); - *file = frame->GetScriptName(); + file = frame->GetScriptName()->v4Value().toQString(); *line = frame->GetLineNumber(); - *function = frame->GetFunctionName(); + function = frame->GetFunctionName()->v4Value().toQString(); } } @@ -127,24 +127,22 @@ QV4::Value console(ConsoleLogTypes logType, const v8::Arguments &args, result.append(jsStack()); } - v8::Handle fileHandle; - v8::Handle functionHandle; + QString file; + QString function; int line; - jsContext(&fileHandle, &line, &functionHandle); + jsContext(file, &line, function); + QMessageLogger logger(file.toUtf8().constData(), line, function.toUtf8().constData()); switch (logType) { case Log: - QMessageLogger(*v8::String::AsciiValue(fileHandle), line, - *v8::String::AsciiValue(functionHandle)).debug("%s", qPrintable(result)); + logger.debug("%s", qPrintable(result)); break; case Warn: - QMessageLogger(*v8::String::AsciiValue(fileHandle), line, - *v8::String::AsciiValue(functionHandle)).warning("%s", qPrintable(result)); + logger.warning("%s", qPrintable(result)); break; case Error: - QMessageLogger(*v8::String::AsciiValue(fileHandle), line, - *v8::String::AsciiValue(functionHandle)).critical("%s", qPrintable(result)); + logger.critical("%s", qPrintable(result)); break; default: break; @@ -185,20 +183,18 @@ QV4::Value consoleProfile(const v8::Arguments &args) - v8::Handle file; - v8::Handle function; + QString file; + QString function; int line; - jsContext(&file, &line, &function); + jsContext(file, &line, function); + QMessageLogger logger(file.toUtf8().constData(), line, function.toUtf8().constData()); if (QQmlProfilerService::startProfiling()) { QV8ProfilerService::instance()->startProfiling(title); - QMessageLogger(*v8::String::AsciiValue(file), line, - *v8::String::AsciiValue(function)).debug("Profiling started."); + logger.debug("Profiling started."); } else { - QMessageLogger(*v8::String::AsciiValue(file), line, - *v8::String::AsciiValue(function)).warning( - "Profiling is already in progress. First, end current profiling session."); + logger.warning("Profiling is already in progress. First, end current profiling session."); } return QV4::Value::undefinedValue(); @@ -212,10 +208,12 @@ QV4::Value consoleProfileEnd(const v8::Arguments &args) Q_UNUSED(args); QString title; - v8::Handle file; - v8::Handle function; + QString file; + QString function; int line; - jsContext(&file, &line, &function); + jsContext(file, &line, function); + + QMessageLogger logger(file.toUtf8().constData(), line, function.toUtf8().constData()); if (QQmlProfilerService::stopProfiling()) { QV8ProfilerService *profiler = QV8ProfilerService::instance(); @@ -223,11 +221,9 @@ QV4::Value consoleProfileEnd(const v8::Arguments &args) QQmlProfilerService::sendProfilingData(); profiler->sendProfilingData(); - QMessageLogger(*v8::String::AsciiValue(file), line, - *v8::String::AsciiValue(function)).debug("Profiling ended."); + logger.debug("Profiling ended."); } else { - QMessageLogger(*v8::String::AsciiValue(file), line, - *v8::String::AsciiValue(function)).warning("Profiling was not started."); + logger.warning("Profiling was not started."); } return QV4::Value::undefinedValue(); @@ -290,13 +286,14 @@ QV4::Value consoleTrace(const v8::Arguments &args) QString stack = jsStack(); - v8::Handle file; - v8::Handle function; + QString file; + QString function; int line; - jsContext(&file, &line, &function); + jsContext(file, &line, function); + + QMessageLogger logger(file.toUtf8().constData(), line, function.toUtf8().constData()); - QMessageLogger(*v8::String::AsciiValue(file), line, *v8::String::AsciiValue(function)).debug( - "%s", qPrintable(stack)); + logger.debug("%s", qPrintable(stack)); return QV4::Value::undefinedValue(); } @@ -322,13 +319,13 @@ QV4::Value consoleAssert(const v8::Arguments &args) QString stack = jsStack(); - v8::Handle file; - v8::Handle function; + QString file; + QString function; int line; - jsContext(&file, &line, &function); + jsContext(file, &line, function); - QMessageLogger(*v8::String::AsciiValue(file), line, *v8::String::AsciiValue(function)).critical( - "%s\n%s", qPrintable(message), qPrintable(stack)); + QMessageLogger logger(file.toUtf8().constData(), line, function.toUtf8().constData()); + logger.critical("%s\n%s", qPrintable(message), qPrintable(stack)); } return QV4::Value::undefinedValue(); diff --git a/src/quick/items/context2d/qquickcanvasitem.cpp b/src/quick/items/context2d/qquickcanvasitem.cpp index b72d043..3d272c6 100644 --- a/src/quick/items/context2d/qquickcanvasitem.cpp +++ b/src/quick/items/context2d/qquickcanvasitem.cpp @@ -740,7 +740,7 @@ void QQuickCanvasItem::getContext(QQmlV4Function *args) return; } - QString contextId = QString::fromUtf16(*v8::String::Value((*args)[0])); + QString contextId = (*args)[0].toQString(); if (d->context != 0) { if (d->context->contextNames().contains(contextId, Qt::CaseInsensitive)) { diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index 61d31f9..80bcbe1 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -127,9 +127,9 @@ static const double Q_PI = 3.14159265358979323846; // pi #define CHECK_RGBA(c) (c == '-' || c == '.' || (c >=0 && c <= 9)) QColor qt_color_from_string(v8::Handle name) { - v8::String::AsciiValue str(name); + QByteArray str = name->v4Value().toQString().toUtf8(); - char *p = *str; + char *p = str.data(); int len = str.length(); //rgb/hsl color string has at least 7 characters if (!p || len > 255 || len <= 7) -- 2.7.4