Ignore:
Timestamp:
Jun 19, 2008, 10:29:29 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Darin.

Prepare JavaScript heap for being per-thread.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/string_object.cpp

    r34607 r34659  
    4141const ClassInfo StringObject::info = { "String", 0, 0, 0 };
    4242
    43 StringObject::StringObject(JSObject *proto)
     43StringObject::StringObject(ExecState* exec, JSObject* proto)
    4444  : JSWrapperObject(proto)
    4545{
    46   setInternalValue(jsString(""));
    47 }
    48 
    49 StringObject::StringObject(JSObject *proto, JSString* string)
     46  setInternalValue(jsString(exec, ""));
     47}
     48
     49StringObject::StringObject(JSObject* proto, JSString* string)
    5050  : JSWrapperObject(proto)
    5151{
     
    5353}
    5454
    55 StringObject::StringObject(JSObject *proto, const UString &string)
     55StringObject::StringObject(ExecState* exec, JSObject* proto, const UString& string)
    5656  : JSWrapperObject(proto)
    5757{
    58   setInternalValue(jsString(string));
     58  setInternalValue(jsString(exec, string));
    5959}
    6060
     
    136136// ECMA 15.5.4
    137137StringPrototype::StringPrototype(ExecState* exec, ObjectPrototype* objProto)
    138   : StringObject(objProto)
     138  : StringObject(exec, objProto)
    139139{
    140140  // The constructor will be added later, after StringConstructor has been built
    141   putDirect(exec->propertyNames().length, jsNumber(0), DontDelete | ReadOnly | DontEnum);
     141  putDirect(exec->propertyNames().length, jsNumber(exec, 0), DontDelete | ReadOnly | DontEnum);
    142142}
    143143
     
    315315                args.append(jsUndefined());
    316316              else
    317                 args.append(jsString(source.substr(matchStart, matchLen)));
     317                args.append(jsString(exec, source.substr(matchStart, matchLen)));
    318318          }
    319319         
    320           args.append(jsNumber(completeMatchStart));
     320          args.append(jsNumber(exec, completeMatchStart));
    321321          args.append(sourceVal);
    322322
     
    352352      return sourceVal;
    353353
    354     return jsString(result);
     354    return jsString(exec, result);
    355355  }
    356356 
     
    366366      ArgList args;
    367367     
    368       args.append(jsString(source.substr(matchPos, matchLen)));
    369       args.append(jsNumber(matchPos));
     368      args.append(jsString(exec, source.substr(matchPos, matchLen)));
     369      args.append(jsNumber(exec, matchPos));
    370370      args.append(sourceVal);
    371371     
     
    373373  }
    374374
    375   return jsString(source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen));
     375  return jsString(exec, source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen));
    376376}
    377377
     
    405405    else
    406406      u = "";
    407     return jsString(u);
     407    return jsString(exec, u);
    408408}
    409409
     
    419419    double dpos = a0->toInteger(exec);
    420420    if (dpos >= 0 && dpos < len)
    421       result = jsNumber(s[static_cast<int>(dpos)]);
     421      result = jsNumber(exec, s[static_cast<int>(dpos)]);
    422422    else
    423       result = jsNaN();
     423      result = jsNaN(exec);
    424424    return result;
    425425}
     
    434434        s += (*it)->toString(exec);
    435435    }
    436     return jsString(s);
     436    return jsString(exec, s);
    437437}
    438438
     
    451451    else if (dpos > len)
    452452        dpos = len;
    453     return jsNumber(s.find(u2, static_cast<int>(dpos)));
     453    return jsNumber(exec, s.find(u2, static_cast<int>(dpos)));
    454454}
    455455
     
    469469    else if (!(dpos <= len)) // true for NaN
    470470        dpos = len;
    471     return jsNumber(s.rfind(u2, static_cast<int>(dpos)));
     471    return jsNumber(exec, s.rfind(u2, static_cast<int>(dpos)));
    472472}
    473473
     
    508508      int lastIndex = 0;
    509509      while (pos >= 0) {
    510         list.append(jsString(u.substr(pos, matchLength)));
     510        list.append(jsString(exec, u.substr(pos, matchLength)));
    511511        lastIndex = pos;
    512512        pos += matchLength == 0 ? 1 : matchLength;
     
    550550    int matchLength;
    551551    regExpObj->performMatch(reg.get(), u, 0, pos, matchLength);
    552     return jsNumber(pos);
     552    return jsNumber(exec, pos);
    553553}
    554554
     
    560560    JSString* sVal = thisObj->inherits(&StringObject::info) ?
    561561      static_cast<StringObject*>(thisObj)->internalValue() :
    562       static_cast<JSString*>(jsString(s));
     562      static_cast<JSString*>(jsString(exec, s));
    563563
    564564    JSValue* a0 = args[0];
     
    587587        if (to > len)
    588588            to = len;
    589         return jsString(s.substr(static_cast<int>(from), static_cast<int>(to - from)));
    590     }
    591 
    592     return jsString("");
     589        return jsString(exec, s.substr(static_cast<int>(from), static_cast<int>(to - from)));
     590    }
     591
     592    return jsString(exec, "");
    593593}
    594594
     
    613613      if (u.isEmpty() && reg->match(u, 0) >= 0) {
    614614        // empty string matched by regexp -> empty array
    615         res->put(exec, exec->propertyNames().length, jsNumber(0));
     615        res->put(exec, exec->propertyNames().length, jsNumber(exec, 0));
    616616        return result;
    617617      }
     
    625625        pos = mpos + (mlen == 0 ? 1 : mlen);
    626626        if (mpos != p0 || mlen) {
    627           res->put(exec,i, jsString(u.substr(p0, mpos-p0)));
     627          res->put(exec,i, jsString(exec, u.substr(p0, mpos-p0)));
    628628          p0 = mpos + mlen;
    629629          i++;
     
    634634            res->put(exec, i++, jsUndefined());
    635635          else
    636             res->put(exec, i++, jsString(u.substr(spos, ovector[si * 2 + 1] - spos)));
     636            res->put(exec, i++, jsString(exec, u.substr(spos, ovector[si * 2 + 1] - spos)));
    637637        }
    638638      }
     
    642642        if (u.isEmpty()) {
    643643          // empty separator matches empty string -> empty array
    644           res->put(exec, exec->propertyNames().length, jsNumber(0));
     644          res->put(exec, exec->propertyNames().length, jsNumber(exec, 0));
    645645          return result;
    646646        } else {
    647647          while (static_cast<uint32_t>(i) != limit && i < u.size()-1)
    648             res->put(exec, i++, jsString(u.substr(p0++, 1)));
     648            res->put(exec, i++, jsString(exec, u.substr(p0++, 1)));
    649649        }
    650650      } else {
    651651        while (static_cast<uint32_t>(i) != limit && (pos = u.find(u2, p0)) >= 0) {
    652           res->put(exec, i, jsString(u.substr(p0, pos-p0)));
     652          res->put(exec, i, jsString(exec, u.substr(p0, pos - p0)));
    653653          p0 = pos + u2.size();
    654654          i++;
     
    658658    // add remaining string, if any
    659659    if (static_cast<uint32_t>(i) != limit)
    660       res->put(exec, i++, jsString(u.substr(p0)));
    661     res->put(exec, exec->propertyNames().length, jsNumber(i));
     660      res->put(exec, i++, jsString(exec, u.substr(p0)));
     661    res->put(exec, exec->propertyNames().length, jsNumber(exec, i));
    662662    return result;
    663663}
     
    675675    double length = a1->isUndefined() ? len : a1->toInteger(exec);
    676676    if (start >= len)
    677       return jsString("");
     677      return jsString(exec, "");
    678678    if (length < 0)
    679       return jsString("");
     679      return jsString(exec, "");
    680680    if (start < 0) {
    681681      start += len;
     
    685685    if (length > len)
    686686      length = len;
    687     return jsString(s.substr(static_cast<int>(start), static_cast<int>(length)));
     687    return jsString(exec, s.substr(static_cast<int>(start), static_cast<int>(length)));
    688688}
    689689
     
    718718      start = temp;
    719719    }
    720     return jsString(s.substr((int)start, (int)end-(int)start));
     720    return jsString(exec, s.substr((int)start, (int)end-(int)start));
    721721}
    722722
     
    728728    JSString* sVal = thisObj->inherits(&StringObject::info)
    729729        ? static_cast<StringObject*>(thisObj)->internalValue()
    730         : static_cast<JSString*>(jsString(s));
     730        : static_cast<JSString*>(jsString(exec, s));
    731731    int ssize = s.size();
    732732    if (!ssize)
     
    743743    if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0)
    744744        return sVal;
    745     return jsString(UString(buffer.releaseBuffer(), length, false));
     745    return jsString(exec, UString(buffer.releaseBuffer(), length, false));
    746746}
    747747
     
    753753    JSString* sVal = thisObj->inherits(&StringObject::info)
    754754        ? static_cast<StringObject*>(thisObj)->internalValue()
    755         : static_cast<JSString*>(jsString(s));
     755        : static_cast<JSString*>(jsString(exec, s));
    756756    int ssize = s.size();
    757757    if (!ssize)
     
    768768    if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0)
    769769        return sVal;
    770     return jsString(UString(buffer.releaseBuffer(), length, false));
     770    return jsString(exec, UString(buffer.releaseBuffer(), length, false));
    771771}
    772772
     
    779779    JSString* sVal = thisObj->inherits(&StringObject::info)
    780780        ? static_cast<StringObject*>(thisObj)->internalValue()
    781         : static_cast<JSString*>(jsString(s));
     781        : static_cast<JSString*>(jsString(exec, s));
    782782    int ssize = s.size();
    783783    if (!ssize)
     
    794794    if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0)
    795795        return sVal;
    796     return jsString(UString(buffer.releaseBuffer(), length, false));
     796    return jsString(exec, UString(buffer.releaseBuffer(), length, false));
    797797}
    798798
     
    804804    JSString* sVal = thisObj->inherits(&StringObject::info)
    805805        ? static_cast<StringObject*>(thisObj)->internalValue()
    806         : static_cast<JSString*>(jsString(s));
     806        : static_cast<JSString*>(jsString(exec, s));
    807807    int ssize = s.size();
    808808    if (!ssize)
     
    819819    if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0)
    820820        return sVal;
    821     return jsString(UString(buffer.releaseBuffer(), length, false));
     821    return jsString(exec, UString(buffer.releaseBuffer(), length, false));
    822822}
    823823
     
    825825{
    826826    if (args.size() < 1)
    827       return jsNumber(0);
    828 
    829     // This optimizes the common case that thisObj is a StringObject
    830     UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
    831     JSValue* a0 = args[0];
    832     return jsNumber(localeCompare(s, a0->toString(exec)));
     827      return jsNumber(exec, 0);
     828
     829    // This optimizes the common case that thisObj is a StringObject
     830    UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
     831    JSValue* a0 = args[0];
     832    return jsNumber(exec, localeCompare(s, a0->toString(exec)));
    833833}
    834834
     
    837837    // This optimizes the common case that thisObj is a StringObject
    838838    UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
    839     return jsString("<big>" + s + "</big>");
     839    return jsString(exec, "<big>" + s + "</big>");
    840840}
    841841
     
    844844    // This optimizes the common case that thisObj is a StringObject
    845845    UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
    846     return jsString("<small>" + s + "</small>");
     846    return jsString(exec, "<small>" + s + "</small>");
    847847}
    848848
     
    851851    // This optimizes the common case that thisObj is a StringObject
    852852    UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
    853     return jsString("<blink>" + s + "</blink>");
     853    return jsString(exec, "<blink>" + s + "</blink>");
    854854}
    855855
     
    858858    // This optimizes the common case that thisObj is a StringObject
    859859    UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
    860     return jsString("<b>" + s + "</b>");
     860    return jsString(exec, "<b>" + s + "</b>");
    861861}
    862862
     
    865865    // This optimizes the common case that thisObj is a StringObject
    866866    UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
    867     return jsString("<tt>" + s + "</tt>");
     867    return jsString(exec, "<tt>" + s + "</tt>");
    868868}
    869869
     
    872872    // This optimizes the common case that thisObj is a StringObject
    873873    UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
    874     return jsString("<i>" + s + "</i>");
     874    return jsString(exec, "<i>" + s + "</i>");
    875875}
    876876
     
    879879    // This optimizes the common case that thisObj is a StringObject
    880880    UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
    881     return jsString("<strike>" + s + "</strike>");
     881    return jsString(exec, "<strike>" + s + "</strike>");
    882882}
    883883
     
    886886    // This optimizes the common case that thisObj is a StringObject
    887887    UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
    888     return jsString("<sub>" + s + "</sub>");
     888    return jsString(exec, "<sub>" + s + "</sub>");
    889889}
    890890
     
    893893    // This optimizes the common case that thisObj is a StringObject
    894894    UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
    895     return jsString("<sup>" + s + "</sup>");
     895    return jsString(exec, "<sup>" + s + "</sup>");
    896896}
    897897
     
    901901    UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
    902902    JSValue* a0 = args[0];
    903     return jsString("<font color=\"" + a0->toString(exec) + "\">" + s + "</font>");
     903    return jsString(exec, "<font color=\"" + a0->toString(exec) + "\">" + s + "</font>");
    904904}
    905905
     
    909909    UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
    910910    JSValue* a0 = args[0];
    911     return jsString("<font size=\"" + a0->toString(exec) + "\">" + s + "</font>");
     911    return jsString(exec, "<font size=\"" + a0->toString(exec) + "\">" + s + "</font>");
    912912}
    913913
     
    917917    UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
    918918    JSValue* a0 = args[0];
    919     return jsString("<a name=\"" + a0->toString(exec) + "\">" + s + "</a>");
     919    return jsString(exec, "<a name=\"" + a0->toString(exec) + "\">" + s + "</a>");
    920920}
    921921
     
    925925    UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
    926926    JSValue* a0 = args[0];
    927     return jsString("<a href=\"" + a0->toString(exec) + "\">" + s + "</a>");
     927    return jsString(exec, "<a href=\"" + a0->toString(exec) + "\">" + s + "</a>");
    928928}
    929929
     
    936936  putDirect(exec->propertyNames().prototype, stringProto, DontEnum|DontDelete|ReadOnly);
    937937
    938   putDirectFunction(new StringConstructorFunction(exec, funcProto, exec->propertyNames().fromCharCode), DontEnum);
     938  putDirectFunction(new (exec) StringConstructorFunction(exec, funcProto, exec->propertyNames().fromCharCode), DontEnum);
    939939
    940940  // no. of arguments for constructor
    941   putDirect(exec->propertyNames().length, jsNumber(1), ReadOnly|DontDelete|DontEnum);
     941  putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly|DontDelete|DontEnum);
    942942}
    943943
     
    949949
    950950// ECMA 15.5.2
    951 JSObject *StringConstructor::construct(ExecState *exec, const ArgList &args)
    952 {
    953   JSObject *proto = exec->lexicalGlobalObject()->stringPrototype();
    954   if (args.size() == 0)
    955     return new StringObject(proto);
    956   return new StringObject(proto, args[0]->toString(exec));
     951JSObject* StringConstructor::construct(ExecState* exec, const ArgList& args)
     952{
     953  JSObject* proto = exec->lexicalGlobalObject()->stringPrototype();
     954  if (!args.size())
     955    return new (exec) StringObject(exec, proto);
     956  return new (exec) StringObject(exec, proto, args[0]->toString(exec));
    957957}
    958958
     
    961961{
    962962  if (args.isEmpty())
    963     return jsString("");
     963    return jsString(exec, "");
    964964  else {
    965965    JSValue *v = args[0];
    966     return jsString(v->toString(exec));
     966    return jsString(exec, v->toString(exec));
    967967  }
    968968}
     
    974974  : InternalFunction(funcProto, name)
    975975{
    976   putDirect(exec->propertyNames().length, jsNumber(1), DontDelete|ReadOnly|DontEnum);
     976  putDirect(exec->propertyNames().length, jsNumber(exec, 1), DontDelete|ReadOnly|DontEnum);
    977977}
    978978
     
    992992    s = "";
    993993
    994   return jsString(s);
     994  return jsString(exec, s);
    995995}
    996996
Note: See TracChangeset for help on using the changeset viewer.