Reviewed by Darin.

        Prepare JavaScript heap for being per-thread.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@34659 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/kjs/string_object.cpp b/JavaScriptCore/kjs/string_object.cpp
index cf293aa..d2c4853 100644
--- a/JavaScriptCore/kjs/string_object.cpp
+++ b/JavaScriptCore/kjs/string_object.cpp
@@ -40,22 +40,22 @@
 
 const ClassInfo StringObject::info = { "String", 0, 0, 0 };
 
-StringObject::StringObject(JSObject *proto)
+StringObject::StringObject(ExecState* exec, JSObject* proto)
   : JSWrapperObject(proto)
 {
-  setInternalValue(jsString(""));
+  setInternalValue(jsString(exec, ""));
 }
 
-StringObject::StringObject(JSObject *proto, JSString* string)
+StringObject::StringObject(JSObject* proto, JSString* string)
   : JSWrapperObject(proto)
 {
   setInternalValue(string);
 }
 
-StringObject::StringObject(JSObject *proto, const UString &string)
+StringObject::StringObject(ExecState* exec, JSObject* proto, const UString& string)
   : JSWrapperObject(proto)
 {
-  setInternalValue(jsString(string));
+  setInternalValue(jsString(exec, string));
 }
 
 bool StringObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
@@ -135,10 +135,10 @@
 */
 // ECMA 15.5.4
 StringPrototype::StringPrototype(ExecState* exec, ObjectPrototype* objProto)
-  : StringObject(objProto)
+  : StringObject(exec, objProto)
 {
   // The constructor will be added later, after StringConstructor has been built
-  putDirect(exec->propertyNames().length, jsNumber(0), DontDelete | ReadOnly | DontEnum);
+  putDirect(exec->propertyNames().length, jsNumber(exec, 0), DontDelete | ReadOnly | DontEnum);
 }
 
 bool StringPrototype::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot)
@@ -314,10 +314,10 @@
               if (matchStart < 0)
                 args.append(jsUndefined());
               else
-                args.append(jsString(source.substr(matchStart, matchLen)));
+                args.append(jsString(exec, source.substr(matchStart, matchLen)));
           }
           
-          args.append(jsNumber(completeMatchStart));
+          args.append(jsNumber(exec, completeMatchStart));
           args.append(sourceVal);
 
           substitutedReplacement = replacementFunction->callAsFunction(exec, exec->globalThisValue(), args)->toString(exec);
@@ -351,7 +351,7 @@
     if (result == source)
       return sourceVal;
 
-    return jsString(result);
+    return jsString(exec, result);
   }
   
   // First arg is a string
@@ -365,14 +365,14 @@
   if (replacementFunction) {
       ArgList args;
       
-      args.append(jsString(source.substr(matchPos, matchLen)));
-      args.append(jsNumber(matchPos));
+      args.append(jsString(exec, source.substr(matchPos, matchLen)));
+      args.append(jsNumber(exec, matchPos));
       args.append(sourceVal);
       
       replacementString = replacementFunction->callAsFunction(exec, exec->globalThisValue(), args)->toString(exec);
   }
 
-  return jsString(source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen));
+  return jsString(exec, source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen));
 }
 
 JSValue* stringProtoFuncToString(ExecState* exec, JSObject* thisObj, const ArgList&)
@@ -404,7 +404,7 @@
       u = s.substr(static_cast<int>(dpos), 1);
     else
       u = "";
-    return jsString(u);
+    return jsString(exec, u);
 }
 
 JSValue* stringProtoFuncCharCodeAt(ExecState* exec, JSObject* thisObj, const ArgList& args)
@@ -418,9 +418,9 @@
     JSValue* a0 = args[0];
     double dpos = a0->toInteger(exec);
     if (dpos >= 0 && dpos < len)
-      result = jsNumber(s[static_cast<int>(dpos)]);
+      result = jsNumber(exec, s[static_cast<int>(dpos)]);
     else
-      result = jsNaN();
+      result = jsNaN(exec);
     return result;
 }
 
@@ -433,7 +433,7 @@
     for (ArgList::const_iterator it = args.begin(); it != end; ++it) {
         s += (*it)->toString(exec);
     }
-    return jsString(s);
+    return jsString(exec, s);
 }
 
 JSValue* stringProtoFuncIndexOf(ExecState* exec, JSObject* thisObj, const ArgList& args)
@@ -450,7 +450,7 @@
         dpos = 0;
     else if (dpos > len)
         dpos = len;
-    return jsNumber(s.find(u2, static_cast<int>(dpos)));
+    return jsNumber(exec, s.find(u2, static_cast<int>(dpos)));
 }
 
 JSValue* stringProtoFuncLastIndexOf(ExecState* exec, JSObject* thisObj, const ArgList& args)
@@ -468,7 +468,7 @@
         dpos = 0;
     else if (!(dpos <= len)) // true for NaN
         dpos = len;
-    return jsNumber(s.rfind(u2, static_cast<int>(dpos)));
+    return jsNumber(exec, s.rfind(u2, static_cast<int>(dpos)));
 }
 
 JSValue* stringProtoFuncMatch(ExecState* exec, JSObject* thisObj, const ArgList& args)
@@ -507,7 +507,7 @@
       ArgList list;
       int lastIndex = 0;
       while (pos >= 0) {
-        list.append(jsString(u.substr(pos, matchLength)));
+        list.append(jsString(exec, u.substr(pos, matchLength)));
         lastIndex = pos;
         pos += matchLength == 0 ? 1 : matchLength;
         regExpObj->performMatch(reg.get(), u, pos, pos, matchLength);
@@ -549,7 +549,7 @@
     int pos;
     int matchLength;
     regExpObj->performMatch(reg.get(), u, 0, pos, matchLength);
-    return jsNumber(pos);
+    return jsNumber(exec, pos);
 }
 
 JSValue* stringProtoFuncReplace(ExecState* exec, JSObject* thisObj, const ArgList& args)
@@ -559,7 +559,7 @@
 
     JSString* sVal = thisObj->inherits(&StringObject::info) ?
       static_cast<StringObject*>(thisObj)->internalValue() :
-      static_cast<JSString*>(jsString(s));
+      static_cast<JSString*>(jsString(exec, s));
 
     JSValue* a0 = args[0];
     JSValue* a1 = args[1];
@@ -586,10 +586,10 @@
             from = 0;
         if (to > len)
             to = len;
-        return jsString(s.substr(static_cast<int>(from), static_cast<int>(to - from)));
+        return jsString(exec, s.substr(static_cast<int>(from), static_cast<int>(to - from)));
     }
 
-    return jsString("");
+    return jsString(exec, "");
 }
 
 JSValue* stringProtoFuncSplit(ExecState* exec, JSObject* thisObj, const ArgList& args)
@@ -612,7 +612,7 @@
       RegExp *reg = static_cast<RegExpObject *>(a0)->regExp();
       if (u.isEmpty() && reg->match(u, 0) >= 0) {
         // empty string matched by regexp -> empty array
-        res->put(exec, exec->propertyNames().length, jsNumber(0));
+        res->put(exec, exec->propertyNames().length, jsNumber(exec, 0));
         return result;
       }
       pos = 0;
@@ -624,7 +624,7 @@
         int mlen = ovector[1] - ovector[0];
         pos = mpos + (mlen == 0 ? 1 : mlen);
         if (mpos != p0 || mlen) {
-          res->put(exec,i, jsString(u.substr(p0, mpos-p0)));
+          res->put(exec,i, jsString(exec, u.substr(p0, mpos-p0)));
           p0 = mpos + mlen;
           i++;
         }
@@ -633,7 +633,7 @@
           if (spos < 0)
             res->put(exec, i++, jsUndefined());
           else
-            res->put(exec, i++, jsString(u.substr(spos, ovector[si * 2 + 1] - spos)));
+            res->put(exec, i++, jsString(exec, u.substr(spos, ovector[si * 2 + 1] - spos)));
         }
       }
     } else {
@@ -641,15 +641,15 @@
       if (u2.isEmpty()) {
         if (u.isEmpty()) {
           // empty separator matches empty string -> empty array
-          res->put(exec, exec->propertyNames().length, jsNumber(0));
+          res->put(exec, exec->propertyNames().length, jsNumber(exec, 0));
           return result;
         } else {
           while (static_cast<uint32_t>(i) != limit && i < u.size()-1)
-            res->put(exec, i++, jsString(u.substr(p0++, 1)));
+            res->put(exec, i++, jsString(exec, u.substr(p0++, 1)));
         }
       } else {
         while (static_cast<uint32_t>(i) != limit && (pos = u.find(u2, p0)) >= 0) {
-          res->put(exec, i, jsString(u.substr(p0, pos-p0)));
+          res->put(exec, i, jsString(exec, u.substr(p0, pos - p0)));
           p0 = pos + u2.size();
           i++;
         }
@@ -657,8 +657,8 @@
     }
     // add remaining string, if any
     if (static_cast<uint32_t>(i) != limit)
-      res->put(exec, i++, jsString(u.substr(p0)));
-    res->put(exec, exec->propertyNames().length, jsNumber(i));
+      res->put(exec, i++, jsString(exec, u.substr(p0)));
+    res->put(exec, exec->propertyNames().length, jsNumber(exec, i));
     return result;
 }
 
@@ -674,9 +674,9 @@
     double start = a0->toInteger(exec);
     double length = a1->isUndefined() ? len : a1->toInteger(exec);
     if (start >= len)
-      return jsString("");
+      return jsString(exec, "");
     if (length < 0)
-      return jsString("");
+      return jsString(exec, "");
     if (start < 0) {
       start += len;
       if (start < 0)
@@ -684,7 +684,7 @@
     }
     if (length > len)
       length = len;
-    return jsString(s.substr(static_cast<int>(start), static_cast<int>(length)));
+    return jsString(exec, s.substr(static_cast<int>(start), static_cast<int>(length)));
 }
 
 JSValue* stringProtoFuncSubstring(ExecState* exec, JSObject* thisObj, const ArgList& args)
@@ -717,7 +717,7 @@
       end = start;
       start = temp;
     }
-    return jsString(s.substr((int)start, (int)end-(int)start));
+    return jsString(exec, s.substr((int)start, (int)end-(int)start));
 }
 
 JSValue* stringProtoFuncToLowerCase(ExecState* exec, JSObject* thisObj, const ArgList&)
@@ -727,7 +727,7 @@
     
     JSString* sVal = thisObj->inherits(&StringObject::info)
         ? static_cast<StringObject*>(thisObj)->internalValue()
-        : static_cast<JSString*>(jsString(s));
+        : static_cast<JSString*>(jsString(exec, s));
     int ssize = s.size();
     if (!ssize)
         return sVal;
@@ -742,7 +742,7 @@
     }
     if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0)
         return sVal;
-    return jsString(UString(buffer.releaseBuffer(), length, false));
+    return jsString(exec, UString(buffer.releaseBuffer(), length, false));
 }
 
 JSValue* stringProtoFuncToUpperCase(ExecState* exec, JSObject* thisObj, const ArgList&)
@@ -752,7 +752,7 @@
 
     JSString* sVal = thisObj->inherits(&StringObject::info)
         ? static_cast<StringObject*>(thisObj)->internalValue()
-        : static_cast<JSString*>(jsString(s));
+        : static_cast<JSString*>(jsString(exec, s));
     int ssize = s.size();
     if (!ssize)
         return sVal;
@@ -767,7 +767,7 @@
     }
     if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0)
         return sVal;
-    return jsString(UString(buffer.releaseBuffer(), length, false));
+    return jsString(exec, UString(buffer.releaseBuffer(), length, false));
 }
 
 JSValue* stringProtoFuncToLocaleLowerCase(ExecState* exec, JSObject* thisObj, const ArgList&)
@@ -778,7 +778,7 @@
     // FIXME: See http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt for locale-sensitive mappings that aren't implemented.
     JSString* sVal = thisObj->inherits(&StringObject::info)
         ? static_cast<StringObject*>(thisObj)->internalValue()
-        : static_cast<JSString*>(jsString(s));
+        : static_cast<JSString*>(jsString(exec, s));
     int ssize = s.size();
     if (!ssize)
         return sVal;
@@ -793,7 +793,7 @@
     }
     if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0)
         return sVal;
-    return jsString(UString(buffer.releaseBuffer(), length, false));
+    return jsString(exec, UString(buffer.releaseBuffer(), length, false));
 }
 
 JSValue* stringProtoFuncToLocaleUpperCase(ExecState* exec, JSObject* thisObj, const ArgList&)
@@ -803,7 +803,7 @@
 
     JSString* sVal = thisObj->inherits(&StringObject::info)
         ? static_cast<StringObject*>(thisObj)->internalValue()
-        : static_cast<JSString*>(jsString(s));
+        : static_cast<JSString*>(jsString(exec, s));
     int ssize = s.size();
     if (!ssize)
         return sVal;
@@ -818,81 +818,81 @@
     }
     if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0)
         return sVal;
-    return jsString(UString(buffer.releaseBuffer(), length, false));
+    return jsString(exec, UString(buffer.releaseBuffer(), length, false));
 }
 
 JSValue* stringProtoFuncLocaleCompare(ExecState* exec, JSObject* thisObj, const ArgList& args)
 {
     if (args.size() < 1)
-      return jsNumber(0);
+      return jsNumber(exec, 0);
 
     // This optimizes the common case that thisObj is a StringObject
     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
     JSValue* a0 = args[0];
-    return jsNumber(localeCompare(s, a0->toString(exec)));
+    return jsNumber(exec, localeCompare(s, a0->toString(exec)));
 }
 
 JSValue* stringProtoFuncBig(ExecState* exec, JSObject* thisObj, const ArgList&)
 {
     // This optimizes the common case that thisObj is a StringObject
     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
-    return jsString("<big>" + s + "</big>");
+    return jsString(exec, "<big>" + s + "</big>");
 }
 
 JSValue* stringProtoFuncSmall(ExecState* exec, JSObject* thisObj, const ArgList&)
 {
     // This optimizes the common case that thisObj is a StringObject
     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
-    return jsString("<small>" + s + "</small>");
+    return jsString(exec, "<small>" + s + "</small>");
 }
 
 JSValue* stringProtoFuncBlink(ExecState* exec, JSObject* thisObj, const ArgList&)
 {
     // This optimizes the common case that thisObj is a StringObject
     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
-    return jsString("<blink>" + s + "</blink>");
+    return jsString(exec, "<blink>" + s + "</blink>");
 }
 
 JSValue* stringProtoFuncBold(ExecState* exec, JSObject* thisObj, const ArgList&)
 {
     // This optimizes the common case that thisObj is a StringObject
     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
-    return jsString("<b>" + s + "</b>");
+    return jsString(exec, "<b>" + s + "</b>");
 }
 
 JSValue* stringProtoFuncFixed(ExecState* exec, JSObject* thisObj, const ArgList&)
 {
     // This optimizes the common case that thisObj is a StringObject
     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
-    return jsString("<tt>" + s + "</tt>");
+    return jsString(exec, "<tt>" + s + "</tt>");
 }
 
 JSValue* stringProtoFuncItalics(ExecState* exec, JSObject* thisObj, const ArgList&)
 {
     // This optimizes the common case that thisObj is a StringObject
     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
-    return jsString("<i>" + s + "</i>");
+    return jsString(exec, "<i>" + s + "</i>");
 }
 
 JSValue* stringProtoFuncStrike(ExecState* exec, JSObject* thisObj, const ArgList&)
 {
     // This optimizes the common case that thisObj is a StringObject
     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
-    return jsString("<strike>" + s + "</strike>");
+    return jsString(exec, "<strike>" + s + "</strike>");
 }
 
 JSValue* stringProtoFuncSub(ExecState* exec, JSObject* thisObj, const ArgList&)
 {
     // This optimizes the common case that thisObj is a StringObject
     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
-    return jsString("<sub>" + s + "</sub>");
+    return jsString(exec, "<sub>" + s + "</sub>");
 }
 
 JSValue* stringProtoFuncSup(ExecState* exec, JSObject* thisObj, const ArgList&)
 {
     // This optimizes the common case that thisObj is a StringObject
     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
-    return jsString("<sup>" + s + "</sup>");
+    return jsString(exec, "<sup>" + s + "</sup>");
 }
 
 JSValue* stringProtoFuncFontcolor(ExecState* exec, JSObject* thisObj, const ArgList& args)
@@ -900,7 +900,7 @@
     // This optimizes the common case that thisObj is a StringObject
     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
     JSValue* a0 = args[0];
-    return jsString("<font color=\"" + a0->toString(exec) + "\">" + s + "</font>");
+    return jsString(exec, "<font color=\"" + a0->toString(exec) + "\">" + s + "</font>");
 }
 
 JSValue* stringProtoFuncFontsize(ExecState* exec, JSObject* thisObj, const ArgList& args)
@@ -908,7 +908,7 @@
     // This optimizes the common case that thisObj is a StringObject
     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
     JSValue* a0 = args[0];
-    return jsString("<font size=\"" + a0->toString(exec) + "\">" + s + "</font>");
+    return jsString(exec, "<font size=\"" + a0->toString(exec) + "\">" + s + "</font>");
 }
 
 JSValue* stringProtoFuncAnchor(ExecState* exec, JSObject* thisObj, const ArgList& args)
@@ -916,7 +916,7 @@
     // This optimizes the common case that thisObj is a StringObject
     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
     JSValue* a0 = args[0];
-    return jsString("<a name=\"" + a0->toString(exec) + "\">" + s + "</a>");
+    return jsString(exec, "<a name=\"" + a0->toString(exec) + "\">" + s + "</a>");
 }
 
 JSValue* stringProtoFuncLink(ExecState* exec, JSObject* thisObj, const ArgList& args)
@@ -924,7 +924,7 @@
     // This optimizes the common case that thisObj is a StringObject
     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
     JSValue* a0 = args[0];
-    return jsString("<a href=\"" + a0->toString(exec) + "\">" + s + "</a>");
+    return jsString(exec, "<a href=\"" + a0->toString(exec) + "\">" + s + "</a>");
 }
 
 // ------------------------------ StringConstructor ------------------------------
@@ -935,10 +935,10 @@
   // ECMA 15.5.3.1 String.prototype
   putDirect(exec->propertyNames().prototype, stringProto, DontEnum|DontDelete|ReadOnly);
 
-  putDirectFunction(new StringConstructorFunction(exec, funcProto, exec->propertyNames().fromCharCode), DontEnum);
+  putDirectFunction(new (exec) StringConstructorFunction(exec, funcProto, exec->propertyNames().fromCharCode), DontEnum);
 
   // no. of arguments for constructor
-  putDirect(exec->propertyNames().length, jsNumber(1), ReadOnly|DontDelete|DontEnum);
+  putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly|DontDelete|DontEnum);
 }
 
 
@@ -948,22 +948,22 @@
 }
 
 // ECMA 15.5.2
-JSObject *StringConstructor::construct(ExecState *exec, const ArgList &args)
+JSObject* StringConstructor::construct(ExecState* exec, const ArgList& args)
 {
-  JSObject *proto = exec->lexicalGlobalObject()->stringPrototype();
-  if (args.size() == 0)
-    return new StringObject(proto);
-  return new StringObject(proto, args[0]->toString(exec));
+  JSObject* proto = exec->lexicalGlobalObject()->stringPrototype();
+  if (!args.size())
+    return new (exec) StringObject(exec, proto);
+  return new (exec) StringObject(exec, proto, args[0]->toString(exec));
 }
 
 // ECMA 15.5.1
 JSValue *StringConstructor::callAsFunction(ExecState *exec, JSObject* /*thisObj*/, const ArgList &args)
 {
   if (args.isEmpty())
-    return jsString("");
+    return jsString(exec, "");
   else {
     JSValue *v = args[0];
-    return jsString(v->toString(exec));
+    return jsString(exec, v->toString(exec));
   }
 }
 
@@ -973,7 +973,7 @@
 StringConstructorFunction::StringConstructorFunction(ExecState* exec, FunctionPrototype* funcProto, const Identifier& name)
   : InternalFunction(funcProto, name)
 {
-  putDirect(exec->propertyNames().length, jsNumber(1), DontDelete|ReadOnly|DontEnum);
+  putDirect(exec->propertyNames().length, jsNumber(exec, 1), DontDelete|ReadOnly|DontEnum);
 }
 
 JSValue *StringConstructorFunction::callAsFunction(ExecState *exec, JSObject* /*thisObj*/, const ArgList &args)
@@ -991,7 +991,7 @@
   } else
     s = "";
 
-  return jsString(s);
+  return jsString(exec, s);
 }
 
 } // namespace KJS