--- a/src/script/api/qscriptengine.cpp Wed Apr 21 12:15:23 2010 +0300
+++ b/src/script/api/qscriptengine.cpp Wed Apr 21 20:15:53 2010 +0300
@@ -41,6 +41,7 @@
#include <QtCore/qstringlist.h>
#include <QtCore/qmetaobject.h>
+#include "CodeBlock.h"
#include "Error.h"
#include "JSArray.h"
#include "JSLock.h"
@@ -662,7 +663,7 @@
else if (encStr == QLatin1String("UnicodeUTF8"))
encoding = QCoreApplication::UnicodeUTF8;
else
- return JSC::throwError(exec, JSC::GeneralError, QString::fromLatin1("qsTranslate(): invalid encoding '%s'").arg(encStr));
+ return JSC::throwError(exec, JSC::GeneralError, QString::fromLatin1("qsTranslate(): invalid encoding '%0'").arg(encStr));
}
int n = -1;
if (args.size() > 4)
@@ -696,12 +697,21 @@
if ((args.size() > 1) && !args.at(1).isString())
return JSC::throwError(exec, JSC::GeneralError, "qsTr(): second argument (comment) must be a string");
if ((args.size() > 2) && !args.at(2).isNumber())
- return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): third argument (n) must be a number");
+ return JSC::throwError(exec, JSC::GeneralError, "qsTr(): third argument (n) must be a number");
#ifndef QT_NO_QOBJECT
QString context;
- QScriptContext *ctx = QScriptEnginePrivate::contextForFrame(exec);
- if (ctx && ctx->parentContext())
- context = QFileInfo(QScriptContextInfo(ctx->parentContext()).fileName()).baseName();
+ // The first non-empty source URL in the call stack determines the translation context.
+ {
+ JSC::ExecState *frame = exec->removeHostCallFrameFlag();
+ while (frame) {
+ if (frame->codeBlock() && frame->codeBlock()->source()
+ && !frame->codeBlock()->source()->url().isEmpty()) {
+ context = QFileInfo(frame->codeBlock()->source()->url()).baseName();
+ break;
+ }
+ frame = frame->callerFrame()->removeHostCallFrameFlag();
+ }
+ }
#endif
QString text(args.at(0).toString(exec));
#ifndef QT_NO_QOBJECT
@@ -1007,11 +1017,15 @@
if (object == globalObject())
return;
QScript::GlobalObject *glob = static_cast<QScript::GlobalObject*>(originalGlobalObject());
- if (object == originalGlobalObjectProxy)
+ if (object == originalGlobalObjectProxy) {
glob->customGlobalObject = 0;
- else {
+ // Sync the internal prototype, since JSObject::prototype() is not virtual.
+ glob->setPrototype(originalGlobalObjectProxy->prototype());
+ } else {
Q_ASSERT(object != originalGlobalObject());
glob->customGlobalObject = object;
+ // Sync the internal prototype, since JSObject::prototype() is not virtual.
+ glob->setPrototype(object->prototype());
}
}
@@ -1589,7 +1603,7 @@
#ifndef QT_NO_REGEXP
-extern QString qt_regexp_toCanonical(const QString &, QRegExp::PatternSyntax);
+Q_DECL_IMPORT extern QString qt_regexp_toCanonical(const QString &, QRegExp::PatternSyntax);
/*!
Creates a QtScript object of class RegExp with the given
@@ -2925,7 +2939,7 @@
// unsigned attribs = JSC::DontEnum;
JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 5, JSC::Identifier(exec, "qsTranslate"), QScript::functionQsTranslate));
JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 2, JSC::Identifier(exec, "QT_TRANSLATE_NOOP"), QScript::functionQsTranslateNoOp));
- JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 3, JSC::Identifier(exec, "qsTr"), QScript::functionQsTr));
+ JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::PrototypeFunction(exec, glob->prototypeFunctionStructure(), 3, JSC::Identifier(exec, "qsTr"), QScript::functionQsTr));
JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "QT_TR_NOOP"), QScript::functionQsTrNoOp));
glob->stringPrototype()->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "arg"), QScript::stringProtoFuncArg));