Changeset 2772 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Nov 19, 2002, 6:35:01 PM (23 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/error_object.cpp
r1799 r2772 42 42 // The constructor will be added later in ErrorObjectImp's constructor 43 43 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); 46 46 put(exec, toStringPropertyName, Object(new ErrorProtoFuncImp(exec,funcProto)), DontEnum); 47 47 } … … 66 66 UString s = "Error"; 67 67 68 Value v = thisObj.get(exec, "name");68 Value v = thisObj.get(exec, namePropertyName); 69 69 if (v.type() != UndefinedType) { 70 70 s = v.toString(exec); 71 71 } 72 72 73 v = thisObj.get(exec, "message");73 v = thisObj.get(exec, messagePropertyName); 74 74 if (v.type() != UndefinedType) { 75 75 s += ": "+v.toString(exec); … … 88 88 // ECMA 15.11.3.1 Error.prototype 89 89 put(exec, prototypePropertyName, Object(errorProto), DontEnum|DontDelete|ReadOnly); 90 //put(exec, "name", String(n));90 //put(exec, namePropertyName, String(n)); 91 91 } 92 92 … … 103 103 104 104 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))); 106 106 } 107 107 … … 129 129 Value protect(this); 130 130 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)); 133 133 } 134 134 … … 157 157 Object obj(new ObjectImp(Object(proto))); 158 158 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))); 160 160 return obj; 161 161 } -
trunk/JavaScriptCore/kjs/function.cpp
r2766 r2772 289 289 { 290 290 Value protect(this); 291 put(exec, "callee", Object(func), DontEnum);291 put(exec,calleePropertyName, Object(func), DontEnum); 292 292 put(exec,lengthPropertyName, Number(args.size()), DontEnum); 293 293 if (!args.isEmpty()) { -
trunk/JavaScriptCore/kjs/function_object.cpp
r2766 r2772 259 259 c++, i++; 260 260 if (i == len) { 261 fimp->addParameter( param);261 fimp->addParameter(Identifier(param)); 262 262 params++; 263 263 break; 264 264 } else if (*c == ',') { 265 fimp->addParameter( param);265 fimp->addParameter(Identifier(param)); 266 266 params++; 267 267 c++, i++; … … 281 281 Object objCons = exec->interpreter()->builtinObject(); 282 282 Object prototype = objCons.construct(exec,List::empty()); 283 prototype.put(exec, "constructor",283 prototype.put(exec, constructorPropertyName, 284 284 Object(fimp), DontEnum|DontDelete|ReadOnly); 285 285 fimp->put(exec,prototypePropertyName,prototype,DontEnum|DontDelete|ReadOnly); -
trunk/JavaScriptCore/kjs/identifier.cpp
r2769 r2772 26 26 Identifier Identifier::null; 27 27 28 extern const Identifier argumentsPropertyName("arguments"); 29 extern const Identifier calleePropertyName("callee"); 30 extern const Identifier constructorPropertyName("constructor"); 31 extern const Identifier lengthPropertyName("length"); 32 extern const Identifier messagePropertyName("message"); 33 extern const Identifier namePropertyName("name"); 34 extern const Identifier prototypePropertyName("prototype"); 35 extern const Identifier specialPrototypePropertyName("__proto__"); 36 extern const Identifier toLocaleStringPropertyName("toLocaleString"); 37 extern const Identifier toStringPropertyName("toString"); 38 extern const Identifier valueOfPropertyName("valueOf"); 39 28 40 bool operator==(const Identifier &a, const char *b) 29 41 { … … 31 43 } 32 44 33 void Identifier::aboutToDestroyUStringRep(UString::Rep *)45 UString::Rep *Identifier::add(const char *c) 34 46 { 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 67 UString::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 84 UString::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 92 void Identifier::remove(UString::Rep *) 93 { 94 // Here's where we find the string already in the hash table, and remove it. 35 95 } 36 96 -
trunk/JavaScriptCore/kjs/identifier.h
r2769 r2772 31 31 public: 32 32 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)) { } 35 36 36 37 const UString &ustring() const { return _ustring; } … … 43 44 const char *ascii() const { return _ustring.ascii(); } 44 45 45 static Identifier from(unsigned y) { return UString::from(y); }46 static Identifier from(unsigned y) { return Identifier(UString::from(y)); } 46 47 47 48 bool isNull() const { return _ustring.isNull(); } … … 58 59 friend bool operator==(const Identifier &, const char *); 59 60 60 static void aboutToDestroyUStringRep(UString::Rep *);61 static void remove(UString::Rep *); 61 62 62 63 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 63 68 UString _ustring; 64 69 }; … … 74 79 } 75 80 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 76 93 } 77 94 -
trunk/JavaScriptCore/kjs/lexer.cpp
r2760 r2772 505 505 } 506 506 /* 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); 508 508 token = IDENT; 509 509 break; -
trunk/JavaScriptCore/kjs/nodes.cpp
r2766 r2772 447 447 KJS_CHECKEXCEPTIONVALUE 448 448 449 obj.put(exec, n.toString(exec), v);449 obj.put(exec, Identifier(n.toString(exec)), v); 450 450 451 451 return obj; … … 505 505 return Reference(o, i); 506 506 String s = v2.toString(exec); 507 return Reference(o, s.value());507 return Reference(o, Identifier(s.value())); 508 508 } 509 509 … … 1218 1218 "Shift expression not an object into IN expression." ); 1219 1219 Object o2(static_cast<ObjectImp*>(v2.imp())); 1220 b = o2.hasProperty(exec, v1.toString(exec));1220 b = o2.hasProperty(exec, Identifier(v1.toString(exec))); 1221 1221 } else { 1222 1222 if (v2.type() != ObjectType) -
trunk/JavaScriptCore/kjs/number_object.cpp
r2760 r2772 56 56 57 57 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); 59 59 put(exec,valueOfPropertyName, Object(new NumberProtoFuncImp(exec,funcProto,NumberProtoFuncImp::ValueOf, 0)), DontEnum); 60 60 } -
trunk/JavaScriptCore/kjs/object.cpp
r2760 r2772 41 41 namespace KJS { 42 42 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 50 43 // ------------------------------ Object --------------------------------------- 51 44 -
trunk/JavaScriptCore/kjs/object.h
r2760 r2772 704 704 { imp()->setInternalValue(v); } 705 705 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 713 706 }; // namespace 714 707 -
trunk/JavaScriptCore/kjs/string_object.cpp
r2760 r2772 534 534 put(exec,prototypePropertyName, Object(stringProto), DontEnum|DontDelete|ReadOnly); 535 535 536 static UStringfromCharCode("fromCharCode");536 static Identifier fromCharCode("fromCharCode"); 537 537 put(exec,fromCharCode, Object(new StringObjectFuncImp(exec,funcProto)), DontEnum); 538 538 -
trunk/JavaScriptCore/kjs/testkjs.cpp
r1326 r2772 63 63 Interpreter interp(global); 64 64 // add debug() function 65 global.put(interp.globalExec(), "debug", Object(new TestFunctionImp()));65 global.put(interp.globalExec(), Identifier("debug"), Object(new TestFunctionImp())); 66 66 // 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())); 68 68 69 69 const int BufferSize = 200000; … … 93 93 int lineno = -1; 94 94 if (exVal.type() == ObjectType) { 95 Value lineVal = Object::dynamicCast(exVal).get(exec, "line");95 Value lineVal = Object::dynamicCast(exVal).get(exec,Identifier("line")); 96 96 if (lineVal.type() == NumberType) 97 97 lineno = int(lineVal.toNumber(exec)); -
trunk/JavaScriptCore/kjs/ustring.cpp
r2769 r2772 165 165 r->rc = 1; 166 166 r->_hash = 0; 167 168 167 return r; 169 168 } … … 172 171 { 173 172 if (capacity == capacityForIdentifier) 174 Identifier:: aboutToDestroyUStringRep(this);173 Identifier::remove(this); 175 174 delete [] dat; 176 175 delete this; 177 176 } 178 177 179 void UString::Rep::computeHash() const 180 { 181 int length = len; 178 unsigned UString::Rep::computeHash(const UChar *s, int length) 179 { 182 180 int prefixLength = length < 8 ? length : 8; 183 181 int suffixPosition = length < 16 ? 8 : length - 8; … … 185 183 unsigned h = length; 186 184 for (int i = 0; i < prefixLength; i++) 187 h = 127 * h + dat[i].unicode();185 h = 127 * h + s[i].unicode(); 188 186 for (int i = suffixPosition; i < length; i++) 189 h = 127 * h + dat[i].unicode();187 h = 127 * h + s[i].unicode(); 190 188 if (h == 0) 191 189 h = 0x80000000; 192 _hash = h; 190 return h; 191 } 192 193 unsigned 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; 193 207 } 194 208 … … 247 261 d = c; 248 262 rep = Rep::create(d, length); 249 }250 251 UString::UString(const UString &b)252 {253 attach(b.rep);254 263 } 255 264 -
trunk/JavaScriptCore/kjs/ustring.h
r2769 r2772 217 217 int size() const { return len; } 218 218 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 *); 221 222 222 223 void ref() { ++rc; } … … 263 264 * Copy constructor. Makes a shallow copy only. 264 265 */ 265 UString(const UString & );266 UString(const UString &s) { attach(s.rep); } 266 267 /** 267 268 * Convenience declaration only ! You'll be on your own to write the
Note:
See TracChangeset
for help on using the changeset viewer.