Changeset 32609 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Apr 27, 2008, 10:59:07 PM (17 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/JSVariableObject.cpp
r32587 r32609 35 35 namespace KJS { 36 36 37 UString::Rep* IdentifierRepHashTraits::nullRepPtr = &UString::Rep::null; // Didn't want to make a whole source file for just this.38 39 37 bool JSVariableObject::deleteProperty(ExecState* exec, const Identifier& propertyName) 40 38 { … … 48 46 { 49 47 SymbolTable::const_iterator end = symbolTable().end(); 50 for (SymbolTable::const_iterator it = symbolTable().begin(); it != end; ++it) 48 for (SymbolTable::const_iterator it = symbolTable().begin(); it != end; ++it) { 51 49 if ((localStorage()[it->second].attributes & DontEnum) == 0) 52 propertyNames.add(Identifier(it->first.get())); 53 50 propertyNames.add(it->first.get()); 51 } 52 54 53 JSObject::getPropertyNames(exec, propertyNames); 55 54 } -
trunk/JavaScriptCore/kjs/JSVariableObject.h
r32587 r32609 91 91 inline bool JSVariableObject::symbolTableGet(const Identifier& propertyName, PropertySlot& slot) 92 92 { 93 size_t index = symbolTable().get(propertyName.ustring().rep()); 94 if (index != missingSymbolMarker()) { 93 size_t index = symbolTable().inlineGet(propertyName.ustring().rep()); 94 if (index == missingSymbolMarker()) 95 return false; 95 96 #ifndef NDEBUG 96 // During initialization, the variable object needs to advertise that it has certain 97 // properties, even if they're not ready for access yet. This check verifies that 98 // no one tries to access such a property. 99 100 // In a release build, we optimize this check away and just return an invalid pointer. 101 // There's no harm in an invalid pointer, since no one dereferences it. 102 if (index >= d->localStorage.size()) { 103 slot.setUngettable(this); 104 return true; 105 } 106 #endif 107 slot.setValueSlot(this, &d->localStorage[index].value); 97 // During initialization, the variable object needs to advertise that it has certain 98 // properties, even if they're not ready for access yet. This check verifies that 99 // no one tries to access such a property. In a release build, we optimize this check 100 // away and just return an invalid pointer. There's no harm in an invalid pointer, 101 // since no one dereferences it. 102 if (index >= d->localStorage.size()) { 103 slot.setUngettable(this); 108 104 return true; 109 105 } 110 return false; 106 #endif 107 slot.setValueSlot(this, &d->localStorage[index].value); 108 return true; 111 109 } 112 110 113 111 inline bool JSVariableObject::symbolTablePut(const Identifier& propertyName, JSValue* value) 114 112 { 115 size_t index = symbolTable(). get(propertyName.ustring().rep());113 size_t index = symbolTable().inlineGet(propertyName.ustring().rep()); 116 114 if (index == missingSymbolMarker()) 117 115 return false; … … 133 131 return true; 134 132 } 135 133 136 134 inline bool JSVariableObject::symbolTableInsert(const Identifier& propertyName, JSValue* value, unsigned attributes) 137 135 { 138 136 if (symbolTable().get(propertyName.ustring().rep()) != missingSymbolMarker()) 139 137 return false; 140 141 ASSERT((attributes & DontDelete) != 0);142 138 size_t localStorageIndex = d->localStorage.size(); 143 139 d->localStorage.append(LocalStorageEntry(value, attributes)); … … 145 141 return true; 146 142 } 143 147 144 } // namespace KJS 148 145 -
trunk/JavaScriptCore/kjs/PropertyNameArray.cpp
r29663 r32609 1 1 // -*- mode: c++; c-basic-offset: 4 -*- 2 2 /* 3 * Copyright (C) 2006 Apple Computer, Inc3 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 4 4 * 5 5 * This library is free software; you can redistribute it and/or … … 25 25 namespace KJS { 26 26 27 void PropertyNameArray::add(const Identifier& ident) 27 static const size_t setThreshold = 20; 28 29 void PropertyNameArray::add(UString::Rep* identifier) 28 30 { 29 if (!m_set.add(ident.ustring().rep()).second) 30 return; 31 32 m_vector.append(ident); 31 ASSERT(identifier->identifierTable); 32 33 size_t size = m_vector.size(); 34 if (size < setThreshold) { 35 for (size_t i = 0; i < size; ++i) { 36 if (identifier == m_vector[i].ustring().rep()) 37 return; 38 } 39 } else { 40 if (m_set.isEmpty()) { 41 for (size_t i = 0; i < size; ++i) 42 m_set.add(m_vector[i].ustring().rep()); 43 } 44 if (!m_set.add(identifier).second) 45 return; 46 } 47 48 m_vector.append(identifier); 33 49 } 34 50 35 void PropertyNameArray::swap(PropertyNameArray& other)36 {37 m_vector.swap(other.m_vector);38 m_set.swap(other.m_set);39 }40 41 42 51 } // namespace KJS 43 -
trunk/JavaScriptCore/kjs/PropertyNameArray.h
r29663 r32609 1 1 // -*- mode: c++; c-basic-offset: 4 -*- 2 2 /* 3 * Copyright (C) 2006 Apple Computer, Inc3 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 4 4 * 5 5 * This library is free software; you can redistribute it and/or … … 24 24 25 25 #include "identifier.h" 26 27 26 #include <wtf/HashSet.h> 28 27 #include <wtf/Vector.h> … … 35 34 typedef Vector<Identifier>::const_iterator const_iterator; 36 35 37 void add(const Identifier&); 36 void add(const Identifier& identifier) { add(identifier.ustring().rep()); } 37 void add(UString::Rep*); 38 void addKnownUnique(UString::Rep* identifier) { m_vector.append(identifier); } 38 39 const_iterator begin() const { return m_vector.begin(); } 39 40 const_iterator end() const { return m_vector.end(); } … … 43 44 const Identifier& operator[](unsigned i) const { return m_vector[i]; } 44 45 45 void swap(PropertyNameArray&);46 46 private: 47 47 typedef HashSet<UString::Rep*, PtrHash<UString::Rep*> > IdentifierSet; 48 49 Vector<Identifier, 20> m_vector; 48 50 IdentifierSet m_set; 49 Vector<Identifier> m_vector;50 51 }; 51 52 52 53 53 } // namespace KJS -
trunk/JavaScriptCore/kjs/SymbolTable.h
r32449 r32609 35 35 namespace KJS { 36 36 37 struct IdentifierRepHash {37 struct IdentifierRepHash : PtrHash<RefPtr<UString::Rep> > { 38 38 static unsigned hash(const RefPtr<UString::Rep>& key) { return key->computedHash(); } 39 static bool equal(const RefPtr<UString::Rep>& a, const RefPtr<UString::Rep>& b) { return a == b; } 40 static const bool safeToCompareToEmptyOrDeleted = true; 41 }; 42 43 struct IdentifierRepHashTraits : HashTraits<RefPtr<UString::Rep> > { 44 static const RefPtr<UString::Rep>& deletedValue() 45 { 46 return *reinterpret_cast<RefPtr<UString::Rep>*>(&nullRepPtr); 47 } 48 49 private: 50 static UString::Rep* nullRepPtr; 39 static unsigned hash(UString::Rep* key) { return key->computedHash(); } 51 40 }; 52 41 … … 54 43 55 44 struct SymbolTableIndexHashTraits : HashTraits<size_t> { 45 static const bool emptyValueIsZero = false; 56 46 static size_t emptyValue() { return missingSymbolMarker(); } 57 47 }; 58 48 59 typedef HashMap<RefPtr<UString::Rep>, size_t, IdentifierRepHash, IdentifierRepHashTraits, SymbolTableIndexHashTraits> SymbolTable;49 typedef HashMap<RefPtr<UString::Rep>, size_t, IdentifierRepHash, HashTraits<RefPtr<UString::Rep> >, SymbolTableIndexHashTraits> SymbolTable; 60 50 61 51 } // namespace KJS -
trunk/JavaScriptCore/kjs/array_instance.cpp
r32220 r32609 208 208 void ArrayInstance::put(ExecState* exec, unsigned i, JSValue* value) 209 209 { 210 if (i > maxArrayIndex) {211 put(exec, Identifier::from(i), value);212 return;213 }214 215 ArrayStorage* storage = m_storage;216 217 210 unsigned length = m_length; 218 211 if (i >= length) { 212 if (i > maxArrayIndex) { 213 put(exec, Identifier::from(i), value); 214 return; 215 } 219 216 length = i + 1; 220 217 m_length = length; 221 218 } 219 220 ArrayStorage* storage = m_storage; 222 221 223 222 if (i < m_vectorLength) { -
trunk/JavaScriptCore/kjs/function.cpp
r31962 r32609 3 3 * Copyright (C) 1999-2002 Harri Porten ([email protected]) 4 4 * Copyright (C) 2001 Peter Kelly ([email protected]) 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 6 6 * Copyright (C) 2007 Cameron Zwarich ([email protected]) 7 7 * Copyright (C) 2007 Maks Orlovich … … 876 876 JSValue* globalFuncKJSPrint(ExecState* exec, JSObject*, const List& args) 877 877 { 878 puts(args[0]->toString(exec).ascii()); 878 CStringBuffer string; 879 args[0]->toString(exec).getCString(string); 880 puts(string.data()); 879 881 return jsUndefined(); 880 882 } -
trunk/JavaScriptCore/kjs/internal.cpp
r29817 r32609 243 243 } 244 244 245 // ------------------------------ global functions ----------------------------- 246 247 #ifndef NDEBUG 248 #include <stdio.h> 249 void printInfo(ExecState *exec, const char *s, JSValue *o, int lineno) 250 { 251 if (!o) 252 fprintf(stderr, "KJS: %s: (null)", s); 253 else { 254 JSValue *v = o; 255 256 UString name; 257 switch (v->type()) { 258 case UnspecifiedType: 259 name = "Unspecified"; 260 break; 261 case UndefinedType: 262 name = "Undefined"; 263 break; 264 case NullType: 265 name = "Null"; 266 break; 267 case BooleanType: 268 name = "Boolean"; 269 break; 270 case StringType: 271 name = "String"; 272 break; 273 case NumberType: 274 name = "Number"; 275 break; 276 case ObjectType: 277 name = static_cast<JSObject *>(v)->className(); 278 if (name.isNull()) 279 name = "(unknown class)"; 280 break; 281 case GetterSetterType: 282 name = "GetterSetter"; 283 break; 284 } 285 UString vString = v->toString(exec); 286 if ( vString.size() > 50 ) 287 vString = vString.substr( 0, 50 ) + "..."; 288 // Can't use two UString::ascii() in the same fprintf call 289 CString tempString( vString.cstring() ); 290 291 fprintf(stderr, "KJS: %s: %s : %s (%p)", 292 s, tempString.c_str(), name.ascii(), (void*)v); 293 294 if (lineno >= 0) 295 fprintf(stderr, ", line %d\n",lineno); 296 else 297 fprintf(stderr, "\n"); 298 } 299 } 300 #endif 301 302 } 245 } -
trunk/JavaScriptCore/kjs/internal.h
r30679 r32609 109 109 }; 110 110 111 #ifndef NDEBUG112 void printInfo(ExecState *exec, const char *s, JSValue *, int lineno = -1);113 #endif114 115 111 } // namespace 116 112 -
trunk/JavaScriptCore/kjs/object.cpp
r31962 r32609 1 1 // -*- c-basic-offset: 2 -*- 2 2 /* 3 * This file is part of the KDE libraries4 3 * Copyright (C) 1999-2001 Harri Porten ([email protected]) 5 4 * Copyright (C) 2001 Peter Kelly ([email protected]) 6 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.5 * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. 7 6 * Copyright (C) 2007 Eric Seidel ([email protected]) 8 7 * … … 572 571 for (int i = 0; i <= hashSizeMask; ++i, ++e) { 573 572 if (e->key && !(e->attributes & DontEnum)) 574 propertyNames.add( Identifier(e->key));573 propertyNames.add(e->key); 575 574 } 576 575 } -
trunk/JavaScriptCore/kjs/property_map.cpp
r32587 r32609 665 665 UString::Rep* key = m_singleEntryKey; 666 666 if (key && !(m_singleEntryAttributes & DontEnum)) 667 propertyNames.add( Identifier(key));667 propertyNames.add(key); 668 668 #endif 669 669 return; … … 684 684 } 685 685 } 686 for (int k = 0; k < i; ++k) 687 propertyNames.add(Identifier(a[k]->key)); 686 if (!propertyNames.size()) { 687 for (int k = 0; k < i; ++k) 688 propertyNames.addKnownUnique(a[k]->key); 689 } else { 690 for (int k = 0; k < i; ++k) 691 propertyNames.add(a[k]->key); 692 } 688 693 return; 689 694 } … … 705 710 // Put the keys of the sorted entries into the list. 706 711 for (Entry** q = sortedEnumerables.data(); q != p; ++q) 707 propertyNames.add( Identifier(q[0]->key));712 propertyNames.add(q[0]->key); 708 713 } 709 714 -
trunk/JavaScriptCore/kjs/ustring.cpp
r32242 r32609 2 2 /* 3 3 * Copyright (C) 1999-2000 Harri Porten ([email protected]) 4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.4 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 5 5 * Copyright (C) 2007 Cameron Zwarich ([email protected]) 6 6 * … … 862 862 } 863 863 864 CString UString::cstring() const 865 { 866 int length = size(); 867 int neededSize = length + 1; 868 char* buf = new char[neededSize]; 869 870 const UChar* p = data(); 871 char* q = buf; 872 const UChar* limit = p + length; 873 while (p != limit) { 874 *q = static_cast<char>(p[0]); 875 ++p; 876 ++q; 877 } 878 *q = '\0'; 879 880 return CString::adopt(buf, length); 864 bool UString::getCString(CStringBuffer& buffer) const 865 { 866 int length = size(); 867 int neededSize = length + 1; 868 buffer.resize(neededSize); 869 char* buf = buffer.data(); 870 871 UChar ored = 0; 872 const UChar* p = data(); 873 char* q = buf; 874 const UChar* limit = p + length; 875 while (p != limit) { 876 UChar c = p[0]; 877 ored |= c; 878 *q = static_cast<char>(c); 879 ++p; 880 ++q; 881 } 882 *q = '\0'; 883 884 return !(ored & 0xFF00); 881 885 } 882 886 … … 958 962 959 963 // FIXME: If tolerateTrailingJunk is true, then we want to tolerate non-8-bit junk 960 // after the number, so is8Bit is too strict a check. 961 if (!is8Bit()) 964 // after the number, so this is too strict a check. 965 CStringBuffer s; 966 if (!getCString(s)) 962 967 return NaN; 963 964 CString s = cstring(); 965 const char* c = s.c_str(); 968 const char* c = s.data(); 966 969 967 970 // skip leading white space -
trunk/JavaScriptCore/kjs/ustring.h
r32319 r32609 2 2 /* 3 3 * Copyright (C) 1999-2000 Harri Porten ([email protected]) 4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.4 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 77 77 }; 78 78 79 typedef Vector<char, 32> CStringBuffer; 80 79 81 /** 80 82 * @short Unicode string class … … 220 222 /** 221 223 * @return The string converted to the 8-bit string type CString(). 222 * This method is not Unicode safe and shouldn't be used unless the string223 * is known to be ASCII.224 */225 CString cstring() const; 226 /** 227 * Convert the Unicode string to plain ASCII chars chopping of any higher224 * Returns false if any character is non-ASCII. 225 */ 226 bool getCString(CStringBuffer&) const; 227 228 /** 229 * Convert the Unicode string to plain ASCII chars chopping off any higher 228 230 * bytes. This method should only be used for *debugging* purposes as it 229 231 * is neither Unicode safe nor free from side effects nor thread-safe.
Note:
See TracChangeset
for help on using the changeset viewer.