Changeset 2772 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Nov 19, 2002, 6:35:01 PM (23 years ago)
Author:
darin
Message:
  • a few more globals for often-used property names
  • conversion to Identifier from UString must now be explicit
  • kjs/error_object.cpp:
  • kjs/function.cpp:
  • kjs/function_object.cpp:
  • kjs/identifier.cpp:
  • kjs/identifier.h:
  • kjs/lexer.cpp:
  • kjs/nodes.cpp:
  • kjs/number_object.cpp:
  • kjs/object.cpp:
  • kjs/object.h:
  • kjs/string_object.cpp:
  • kjs/testkjs.cpp:
  • kjs/ustring.cpp:
  • kjs/ustring.h:
Location:
trunk/JavaScriptCore/kjs
Files:
14 edited

Legend:

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

    r1799 r2772  
    4242  // The constructor will be added later in ErrorObjectImp's constructor
    4343
    44   put(exec, "name",     String("Error"), DontEnum);
    45   put(exec, "message",  String("Unknown error"), DontEnum);
     44  put(exec, namePropertyName,     String("Error"), DontEnum);
     45  put(exec, messagePropertyName,  String("Unknown error"), DontEnum);
    4646  put(exec, toStringPropertyName, Object(new ErrorProtoFuncImp(exec,funcProto)), DontEnum);
    4747}
     
    6666  UString s = "Error";
    6767
    68   Value v = thisObj.get(exec,"name");
     68  Value v = thisObj.get(exec, namePropertyName);
    6969  if (v.type() != UndefinedType) {
    7070    s = v.toString(exec);
    7171  }
    7272
    73   v = thisObj.get(exec,"message");
     73  v = thisObj.get(exec, messagePropertyName);
    7474  if (v.type() != UndefinedType) {
    7575    s += ": "+v.toString(exec);
     
    8888  // ECMA 15.11.3.1 Error.prototype
    8989  put(exec, prototypePropertyName, Object(errorProto), DontEnum|DontDelete|ReadOnly);
    90   //put(exec, "name", String(n));
     90  //put(exec, namePropertyName, String(n));
    9191}
    9292
     
    103103
    104104  if (!args.isEmpty() && args[0].type() != UndefinedType) {
    105     obj.put(exec,"message", String(args[0].toString(exec)));
     105    obj.put(exec, messagePropertyName, String(args[0].toString(exec)));
    106106  }
    107107
     
    129129  Value protect(this);
    130130  errType = et;
    131   put(exec,"name",String(name));
    132   put(exec,"message",String(message));
     131  put(exec, namePropertyName, String(name));
     132  put(exec, messagePropertyName, String(message));
    133133}
    134134
     
    157157  Object obj(new ObjectImp(Object(proto)));
    158158  if (args[0].type() != UndefinedType)
    159     obj.put(exec, "message", String(args[0].toString(exec)));
     159    obj.put(exec, messagePropertyName, String(args[0].toString(exec)));
    160160  return obj;
    161161}
  • trunk/JavaScriptCore/kjs/function.cpp

    r2766 r2772  
    289289{
    290290  Value protect(this);
    291   put(exec,"callee", Object(func), DontEnum);
     291  put(exec,calleePropertyName, Object(func), DontEnum);
    292292  put(exec,lengthPropertyName, Number(args.size()), DontEnum);
    293293  if (!args.isEmpty()) {
  • trunk/JavaScriptCore/kjs/function_object.cpp

    r2766 r2772  
    259259              c++, i++;
    260260          if (i == len) {
    261               fimp->addParameter(param);
     261              fimp->addParameter(Identifier(param));
    262262              params++;
    263263              break;
    264264          } else if (*c == ',') {
    265               fimp->addParameter(param);
     265              fimp->addParameter(Identifier(param));
    266266              params++;
    267267              c++, i++;
     
    281281  Object objCons = exec->interpreter()->builtinObject();
    282282  Object prototype = objCons.construct(exec,List::empty());
    283   prototype.put(exec, "constructor",
     283  prototype.put(exec, constructorPropertyName,
    284284                Object(fimp), DontEnum|DontDelete|ReadOnly);
    285285  fimp->put(exec,prototypePropertyName,prototype,DontEnum|DontDelete|ReadOnly);
  • trunk/JavaScriptCore/kjs/identifier.cpp

    r2769 r2772  
    2626Identifier Identifier::null;
    2727
     28extern const Identifier argumentsPropertyName("arguments");
     29extern const Identifier calleePropertyName("callee");
     30extern const Identifier constructorPropertyName("constructor");
     31extern const Identifier lengthPropertyName("length");
     32extern const Identifier messagePropertyName("message");
     33extern const Identifier namePropertyName("name");
     34extern const Identifier prototypePropertyName("prototype");
     35extern const Identifier specialPrototypePropertyName("__proto__");
     36extern const Identifier toLocaleStringPropertyName("toLocaleString");
     37extern const Identifier toStringPropertyName("toString");
     38extern const Identifier valueOfPropertyName("valueOf");
     39
    2840bool operator==(const Identifier &a, const char *b)
    2941{
     
    3143}
    3244
    33 void Identifier::aboutToDestroyUStringRep(UString::Rep *)
     45UString::Rep *Identifier::add(const char *c)
    3446{
     47  if (!c)
     48    return &UString::Rep::null;
     49  int length = strlen(c);
     50  if (length == 0)
     51    return &UString::Rep::empty;
     52
     53  // Here's where we compute a hash and find it or put it in the hash table.
     54  UChar *d = new UChar[length];
     55  for (int i = 0; i < length; i++)
     56    d[i] = c[i];
     57
     58  UString::Rep *r = new UString::Rep;
     59  r->dat = d;
     60  r->len = length;
     61  r->capacity = length;
     62  r->rc = 0;
     63  r->_hash = 0;
     64  return r;
     65}
     66
     67UString::Rep *Identifier::add(const UChar *s, int length)
     68{
     69  // Here's where we compute a hash and find it or put it in the hash table.
     70
     71  UChar *d = new UChar[length];
     72  for (int i = 0; i < length; i++)
     73    d[i] = s[i];
     74
     75  UString::Rep *r = new UString::Rep;
     76  r->dat = d;
     77  r->len = length;
     78  r->capacity = length;
     79  r->rc = 0;
     80  r->_hash = 0;
     81  return r;
     82}
     83
     84UString::Rep *Identifier::add(const UString &s)
     85{
     86  // Here's where we compute a hash and find it or put it in the hash table.
     87  // Don't forget to check for the case of a string that's already in the table by looking at capacity.
     88 
     89  return s.rep;
     90}
     91
     92void Identifier::remove(UString::Rep *)
     93{
     94  // Here's where we find the string already in the hash table, and remove it.
    3595}
    3696
  • trunk/JavaScriptCore/kjs/identifier.h

    r2769 r2772  
    3131    public:
    3232        Identifier() { }
    33         Identifier(const char *s) : _ustring(s) { }
    34         Identifier(const UString &s) : _ustring(s) { }
     33        Identifier(const char *s) : _ustring(add(s)) { }
     34        Identifier(const UChar *s, int length) : _ustring(add(s, length)) { }
     35        explicit Identifier(const UString &s) : _ustring(add(s)) { }
    3536       
    3637        const UString &ustring() const { return _ustring; }
     
    4344        const char *ascii() const { return _ustring.ascii(); }
    4445       
    45         static Identifier from(unsigned y) { return UString::from(y); }
     46        static Identifier from(unsigned y) { return Identifier(UString::from(y)); }
    4647       
    4748        bool isNull() const { return _ustring.isNull(); }
     
    5859        friend bool operator==(const Identifier &, const char *);
    5960   
    60         static void aboutToDestroyUStringRep(UString::Rep *);
     61        static void remove(UString::Rep *);
    6162
    6263    private:
     64        static UString::Rep *add(const char *);
     65        static UString::Rep *add(const UChar *, int length);
     66        static UString::Rep *add(const UString &);
     67       
    6368        UString _ustring;
    6469    };
     
    7479    }
    7580
     81    extern const Identifier argumentsPropertyName;
     82    extern const Identifier calleePropertyName;
     83    extern const Identifier constructorPropertyName;
     84    extern const Identifier lengthPropertyName;
     85    extern const Identifier messagePropertyName;
     86    extern const Identifier namePropertyName;
     87    extern const Identifier prototypePropertyName;
     88    extern const Identifier specialPrototypePropertyName;
     89    extern const Identifier toLocaleStringPropertyName;
     90    extern const Identifier toStringPropertyName;
     91    extern const Identifier valueOfPropertyName;
     92
    7693}
    7794
  • trunk/JavaScriptCore/kjs/lexer.cpp

    r2760 r2772  
    505505      }
    506506      /* TODO: close leak on parse error. same holds true for String */
    507       kjsyylval.ustr = new UString(buffer16, pos16);
     507      kjsyylval.ident = new KJS::Identifier(buffer16, pos16);
    508508      token = IDENT;
    509509      break;
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r2766 r2772  
    447447  KJS_CHECKEXCEPTIONVALUE
    448448
    449   obj.put(exec,n.toString(exec), v);
     449  obj.put(exec, Identifier(n.toString(exec)), v);
    450450
    451451  return obj;
     
    505505    return Reference(o, i);
    506506  String s = v2.toString(exec);
    507   return Reference(o, s.value());
     507  return Reference(o, Identifier(s.value()));
    508508}
    509509
     
    12181218                             "Shift expression not an object into IN expression." );
    12191219      Object o2(static_cast<ObjectImp*>(v2.imp()));
    1220       b = o2.hasProperty(exec,v1.toString(exec));
     1220      b = o2.hasProperty(exec, Identifier(v1.toString(exec)));
    12211221  } else {
    12221222    if (v2.type() != ObjectType)
  • trunk/JavaScriptCore/kjs/number_object.cpp

    r2760 r2772  
    5656
    5757  put(exec,toStringPropertyName,       Object(new NumberProtoFuncImp(exec,funcProto,NumberProtoFuncImp::ToString,       1)), DontEnum);
    58   put(exec,"toLocaleString", Object(new NumberProtoFuncImp(exec,funcProto,NumberProtoFuncImp::ToLocaleString, 0)), DontEnum);
     58  put(exec,toLocaleStringPropertyName, Object(new NumberProtoFuncImp(exec,funcProto,NumberProtoFuncImp::ToLocaleString, 0)), DontEnum);
    5959  put(exec,valueOfPropertyName,        Object(new NumberProtoFuncImp(exec,funcProto,NumberProtoFuncImp::ValueOf,        0)), DontEnum);
    6060}
  • trunk/JavaScriptCore/kjs/object.cpp

    r2760 r2772  
    4141namespace KJS {
    4242
    43 extern const Identifier argumentsPropertyName("arguments");
    44 extern const Identifier lengthPropertyName("length");
    45 extern const Identifier prototypePropertyName("prototype");
    46 extern const Identifier specialPrototypePropertyName("__proto__");
    47 extern const Identifier toStringPropertyName("toString");
    48 extern const Identifier valueOfPropertyName("valueOf");
    49 
    5043// ------------------------------ Object ---------------------------------------
    5144
  • trunk/JavaScriptCore/kjs/object.h

    r2760 r2772  
    704704    { imp()->setInternalValue(v); }
    705705
    706   extern const Identifier argumentsPropertyName;
    707   extern const Identifier lengthPropertyName;
    708   extern const Identifier prototypePropertyName;
    709   extern const Identifier specialPrototypePropertyName;
    710   extern const Identifier toStringPropertyName;
    711   extern const Identifier valueOfPropertyName;
    712 
    713706}; // namespace
    714707
  • trunk/JavaScriptCore/kjs/string_object.cpp

    r2760 r2772  
    534534  put(exec,prototypePropertyName, Object(stringProto), DontEnum|DontDelete|ReadOnly);
    535535
    536   static UString fromCharCode("fromCharCode");
     536  static Identifier fromCharCode("fromCharCode");
    537537  put(exec,fromCharCode, Object(new StringObjectFuncImp(exec,funcProto)), DontEnum);
    538538
  • trunk/JavaScriptCore/kjs/testkjs.cpp

    r1326 r2772  
    6363    Interpreter interp(global);
    6464    // add debug() function
    65     global.put(interp.globalExec(),"debug", Object(new TestFunctionImp()));
     65    global.put(interp.globalExec(), Identifier("debug"), Object(new TestFunctionImp()));
    6666    // add "print" for compatibility with the mozilla js shell
    67     global.put(interp.globalExec(),"print", Object(new TestFunctionImp()));
     67    global.put(interp.globalExec(), Identifier("print"), Object(new TestFunctionImp()));
    6868
    6969    const int BufferSize = 200000;
     
    9393        int lineno = -1;
    9494        if (exVal.type() == ObjectType) {
    95           Value lineVal = Object::dynamicCast(exVal).get(exec,"line");
     95          Value lineVal = Object::dynamicCast(exVal).get(exec,Identifier("line"));
    9696          if (lineVal.type() == NumberType)
    9797            lineno = int(lineVal.toNumber(exec));
  • trunk/JavaScriptCore/kjs/ustring.cpp

    r2769 r2772  
    165165  r->rc = 1;
    166166  r->_hash = 0;
    167 
    168167  return r;
    169168}
     
    172171{
    173172  if (capacity == capacityForIdentifier)
    174     Identifier::aboutToDestroyUStringRep(this);
     173    Identifier::remove(this);
    175174  delete [] dat;
    176175  delete this;
    177176}
    178177
    179 void UString::Rep::computeHash() const
    180 {
    181     int length = len;
     178unsigned UString::Rep::computeHash(const UChar *s, int length)
     179{
    182180    int prefixLength = length < 8 ? length : 8;
    183181    int suffixPosition = length < 16 ? 8 : length - 8;
     
    185183    unsigned h = length;
    186184    for (int i = 0; i < prefixLength; i++)
    187         h = 127 * h + dat[i].unicode();
     185        h = 127 * h + s[i].unicode();
    188186    for (int i = suffixPosition; i < length; i++)
    189         h = 127 * h + dat[i].unicode();
     187        h = 127 * h + s[i].unicode();
    190188    if (h == 0)
    191189        h = 0x80000000;
    192     _hash = h;
     190    return h;
     191}
     192
     193unsigned UString::Rep::computeHash(const char *s)
     194{
     195    int length = strlen(s);
     196    int prefixLength = length < 8 ? length : 8;
     197    int suffixPosition = length < 16 ? 8 : length - 8;
     198
     199    unsigned h = length;
     200    for (int i = 0; i < prefixLength; i++)
     201        h = 127 * h + (unsigned char)s[i];
     202    for (int i = suffixPosition; i < length; i++)
     203        h = 127 * h + (unsigned char)s[i];
     204    if (h == 0)
     205        h = 0x80000000;
     206    return h;
    193207}
    194208
     
    247261    d = c;
    248262  rep = Rep::create(d, length);
    249 }
    250 
    251 UString::UString(const UString &b)
    252 {
    253   attach(b.rep);
    254263}
    255264
  • trunk/JavaScriptCore/kjs/ustring.h

    r2769 r2772  
    217217      int size() const { return len; }
    218218     
    219       int hash() const { if (_hash == 0) computeHash(); return _hash; }
    220       void computeHash() const;
     219      int hash() const { if (_hash == 0) _hash = computeHash(dat, len); return _hash; }
     220      static unsigned computeHash(const UChar *, int length);
     221      static unsigned computeHash(const char *);
    221222
    222223      void ref() { ++rc; }
     
    263264     * Copy constructor. Makes a shallow copy only.
    264265     */
    265     UString(const UString &);
     266    UString(const UString &s) { attach(s.rep); }
    266267    /**
    267268     * Convenience declaration only ! You'll be on your own to write the
Note: See TracChangeset for help on using the changeset viewer.