Index: trunk/src/script/api/qscriptengine.cpp
===================================================================
--- trunk/src/script/api/qscriptengine.cpp	(revision 651)
+++ trunk/src/script/api/qscriptengine.cpp	(revision 769)
@@ -42,4 +42,5 @@
 #include <QtCore/qmetaobject.h>
 
+#include "CodeBlock.h"
 #include "Error.h"
 #include "JSArray.h"
@@ -663,5 +664,5 @@
             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;
@@ -697,10 +698,19 @@
         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));
@@ -769,5 +779,5 @@
 
 QScriptEnginePrivate::QScriptEnginePrivate()
-    : registeredScriptValues(0), freeScriptValues(0),
+    : registeredScriptValues(0), freeScriptValues(0), freeScriptValuesCount(0),
       registeredScriptStrings(0), inEval(false)
 {
@@ -1008,9 +1018,13 @@
         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());
     }
 }
@@ -1590,5 +1604,5 @@
 #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);
 
 /*!
@@ -2922,9 +2936,9 @@
     JSC::JSGlobalObject *glob = d->originalGlobalObject();
     if (!jscObject || !jscObject.isObject())
-        jscObject = glob;
+        jscObject = d->globalObject();
 //    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));
 
Index: trunk/src/script/api/qscriptengine_p.h
===================================================================
--- trunk/src/script/api/qscriptengine_p.h	(revision 651)
+++ trunk/src/script/api/qscriptengine_p.h	(revision 769)
@@ -256,4 +256,6 @@
     QScriptValuePrivate *registeredScriptValues;
     QScriptValuePrivate *freeScriptValues;
+    static const int maxFreeScriptValues = 256;
+    int freeScriptValuesCount;
     QScriptStringPrivate *registeredScriptStrings;
     QHash<int, QScriptTypeInfo*> m_typeInfos;
@@ -378,4 +380,5 @@
         QScriptValuePrivate *p = freeScriptValues;
         freeScriptValues = p->next;
+        --freeScriptValuesCount;
         return p;
     }
@@ -385,6 +388,11 @@
 inline void QScriptEnginePrivate::freeScriptValuePrivate(QScriptValuePrivate *p)
 {
-    p->next = freeScriptValues;
-    freeScriptValues = p;
+    if (freeScriptValuesCount < maxFreeScriptValues) {
+        p->next = freeScriptValues;
+        freeScriptValues = p;
+        ++freeScriptValuesCount;
+    } else {
+        qFree(p);
+    }
 }
 
Index: trunk/src/script/api/qscriptvalue.cpp
===================================================================
--- trunk/src/script/api/qscriptvalue.cpp	(revision 651)
+++ trunk/src/script/api/qscriptvalue.cpp	(revision 769)
@@ -793,4 +793,5 @@
         return;
     }
+    JSC::JSObject *thisObject = JSC::asObject(d->jscValue);
     JSC::JSValue other = d->engine->scriptValueToJSCValue(prototype);
 
@@ -799,5 +800,5 @@
     while (nextPrototypeValue && nextPrototypeValue.isObject()) {
         JSC::JSObject *nextPrototype = JSC::asObject(nextPrototypeValue);
-        if (nextPrototype == JSC::asObject(d->jscValue)) {
+        if (nextPrototype == thisObject) {
             qWarning("QScriptValue::setPrototype() failed: cyclic prototype value");
             return;
@@ -805,5 +806,13 @@
         nextPrototypeValue = nextPrototype->prototype();
     }
-    JSC::asObject(d->jscValue)->setPrototype(other);
+
+    thisObject->setPrototype(other);
+
+    // Sync the internal Global Object prototype if appropriate.
+    if (((thisObject == d->engine->originalGlobalObjectProxy)
+         && !d->engine->customGlobalObject())
+        || (thisObject == d->engine->customGlobalObject())) {
+        d->engine->originalGlobalObject()->setPrototype(other);
+    }
 }
 
@@ -1149,8 +1158,13 @@
 
     if (d->type != other.d_ptr->type) {
-        if (d->type == QScriptValuePrivate::JavaScriptCore)
-            return JSC::JSValue::strictEqual(d->jscValue, d->engine->scriptValueToJSCValue(other));
-        else if (other.d_ptr->type == QScriptValuePrivate::JavaScriptCore)
-            return JSC::JSValue::strictEqual(other.d_ptr->engine->scriptValueToJSCValue(*this), other.d_ptr->jscValue);
+        if (d->type == QScriptValuePrivate::JavaScriptCore) {
+            QScriptEnginePrivate *eng_p = d->engine ? d->engine : other.d_ptr->engine;
+            if (eng_p)
+                return JSC::JSValue::strictEqual(d->jscValue, eng_p->scriptValueToJSCValue(other));
+        } else if (other.d_ptr->type == QScriptValuePrivate::JavaScriptCore) {
+            QScriptEnginePrivate *eng_p = other.d_ptr->engine ? other.d_ptr->engine : d->engine;
+            if (eng_p)
+                return JSC::JSValue::strictEqual(eng_p->scriptValueToJSCValue(*this), other.d_ptr->jscValue);
+        }
 
         return false;
@@ -1942,5 +1956,5 @@
     if (!array.isUndefinedOrNull()) {
         if (!array.isObject()) {
-            return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError));
+            return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError, "Arguments must be an array"));
         }
         if (JSC::asObject(array)->classInfo() == &JSC::Arguments::info)
@@ -1953,6 +1967,5 @@
                 applyArgs.append(JSC::asArray(array)->get(exec, i));
         } else {
-            Q_ASSERT_X(false, Q_FUNC_INFO, "implement me");
-//            return JSC::throwError(exec, JSC::TypeError);
+            return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError, "Arguments must be an array"));
         }
     }
Index: trunk/src/script/bridge/qscriptclassobject.cpp
===================================================================
--- trunk/src/script/bridge/qscriptclassobject.cpp	(revision 651)
+++ trunk/src/script/bridge/qscriptclassobject.cpp	(revision 769)
@@ -227,5 +227,5 @@
 
     QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec);
-    //JSC::ExecState *oldFrame = eng_p->currentFrame;
+    JSC::ExecState *oldFrame = eng_p->currentFrame;
     eng_p->pushContext(exec, JSC::JSValue(), args, callee, true);
     QScriptContext *ctx = eng_p->contextForFrame(eng_p->currentFrame);
@@ -235,4 +235,6 @@
     if (!result.isObject())
         result = defaultObject;
+    eng_p->popContext();
+    eng_p->currentFrame = oldFrame;
     return JSC::asObject(eng_p->scriptValueToJSCValue(result));
 }
Index: trunk/src/script/bridge/qscriptqobject_p.h
===================================================================
--- trunk/src/script/bridge/qscriptqobject_p.h	(revision 651)
+++ trunk/src/script/bridge/qscriptqobject_p.h	(revision 769)
@@ -305,5 +305,5 @@
     static WTF::PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)
     {
-        return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType));
+        return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, JSC::ImplementsHasInstance));
     }
 
Index: trunk/src/script/parser/qscriptlexer.cpp
===================================================================
--- trunk/src/script/parser/qscriptlexer.cpp	(revision 651)
+++ trunk/src/script/parser/qscriptlexer.cpp	(revision 769)
@@ -32,5 +32,5 @@
 QT_BEGIN_NAMESPACE
 
-extern double qstrtod(const char *s00, char const **se, bool *ok);
+Q_DECL_IMPORT extern double qstrtod(const char *s00, char const **se, bool *ok);
 
 #define shiftWindowsLineBreak() \
