source: webkit/trunk/JavaScriptCore/runtime/Lookup.cpp@ 53400

Last change on this file since 53400 was 53320, checked in by [email protected], 15 years ago

JavaScriptCore: Make naming & behaviour of UString[Impl] methods more consistent.
https://bugs.webkit.org/show_bug.cgi?id=33702

Reviewed by Sam Weinig.

UString::create() creates a copy of the UChar* passed, but UStringImpl::create() assumes
that it should assume ownership of the provided buffer (with UString::createNonCopying()
and UStringImpl::createCopying() providing the alternate behaviours). Unify on create()
taking a copy of the provided buffer. For non-copying cases, use the name 'adopt', and
make this method take a Vector<UChar>&. For cases where non-copying construction was being
used, other than from a Vector<UChar>, change the code to allocate the storage along with
the UStringImpl using UStringImpl::createUninitialized(). (The adopt() method also more
closely matches that of WebCore::StringImpl).

Also, UString::createUninitialized() and UStringImpl::createUninitialized() have incompatible
behaviours, in that the UString form sets the provided UChar* to a null or non-null value to
indicate success or failure, but UStringImpl uses the returned PassRefPtr<UStringImpl> to
indicate when allocation has failed (potentially leaving the output Char* uninitialized).
This is also incompatible with WebCore::StringImpl's behaviour, in that
StringImpl::createUninitialized() will CRASH() if unable to allocate. Some uses of
createUninitialized() in JSC are unsafe, since they do not test the result for null.
UStringImpl's indication is preferable, since we may want a successful call to set the result
buffer to 0 (specifically, StringImpl returns 0 for the buffer where createUninitialized()
returns the empty string, which seems reasonable to catch bugs early). UString's method
cannot support UStringImpl's behaviour directly, since it returns an object rather than a
pointer.

  • remove UString::createUninitialized(), replace with calls to UStringImpl::createUninitialized()
  • create a UStringImpl::tryCreateUninitialized() form UStringImpl::createUninitialized(), with current behaviour, make createUninitialized() crash on failure to allocate.
  • make cases in JSC that do not check the result call createUninitialized(), and cases that do check call tryCreateUninitialized().

Rename computedHash() to existingHash(), to bring this in line wih WebCore::StringImpl.

  • API/JSClassRef.cpp:

(OpaqueJSClassContextData::OpaqueJSClassContextData):

(JSC::arrayProtoFuncToString):

  • runtime/Identifier.cpp:

(JSC::CStringTranslator::translate):
(JSC::UCharBufferTranslator::translate):

  • runtime/JSString.cpp:

(JSC::JSString::resolveRope):

  • runtime/Lookup.cpp:

(JSC::HashTable::createTable):

  • runtime/Lookup.h:

(JSC::HashTable::entry):

  • runtime/StringBuilder.h:

(JSC::StringBuilder::release):

  • runtime/StringConstructor.cpp:

(JSC::stringFromCharCodeSlowCase):

  • runtime/StringPrototype.cpp:

(JSC::substituteBackreferencesSlow):
(JSC::stringProtoFuncToLowerCase):
(JSC::stringProtoFuncToUpperCase):
(JSC::stringProtoFuncFontsize):
(JSC::stringProtoFuncLink):

  • runtime/Structure.cpp:

(JSC::Structure::despecifyDictionaryFunction):
(JSC::Structure::get):
(JSC::Structure::despecifyFunction):
(JSC::Structure::put):
(JSC::Structure::remove):
(JSC::Structure::insertIntoPropertyMapHashTable):
(JSC::Structure::checkConsistency):

  • runtime/Structure.h:

(JSC::Structure::get):

  • runtime/StructureTransitionTable.h:

(JSC::StructureTransitionTableHash::hash):

  • runtime/UString.cpp:

(JSC::createRep):
(JSC::UString::UString):
(JSC::UString::spliceSubstringsWithSeparators):
(JSC::UString::replaceRange):
(JSC::UString::operator=):

  • runtime/UString.h:

(JSC::UString::adopt):
(JSC::IdentifierRepHash::hash):
(JSC::makeString):

  • runtime/UStringImpl.h:

(JSC::UStringImpl::adopt):
(JSC::UStringImpl::create):
(JSC::UStringImpl::createUninitialized):
(JSC::UStringImpl::tryCreateUninitialized):
(JSC::UStringImpl::existingHash):

WebCore: Rubber stamped by Sam Weinig.

Make naming & behaviour of UString[Impl] methods more consistent.
https://bugs.webkit.org/show_bug.cgi?id=33702

WebCore change reflecting UString method name change computedHash() -> existingHash().

  • platform/text/AtomicString.cpp:

(WebCore::AtomicString::add):
(WebCore::AtomicString::find):

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 */
19
20#include "config.h"
21#include "Lookup.h"
22
23#include "JSFunction.h"
24#include "PrototypeFunction.h"
25
26namespace JSC {
27
28void HashTable::createTable(JSGlobalData* globalData) const
29{
30 ASSERT(!table);
31 int linkIndex = compactHashSizeMask + 1;
32 HashEntry* entries = new HashEntry[compactSize];
33 for (int i = 0; i < compactSize; ++i)
34 entries[i].setKey(0);
35 for (int i = 0; values[i].key; ++i) {
36 UString::Rep* identifier = Identifier::add(globalData, values[i].key).releaseRef();
37 int hashIndex = identifier->existingHash() & compactHashSizeMask;
38 HashEntry* entry = &entries[hashIndex];
39
40 if (entry->key()) {
41 while (entry->next()) {
42 entry = entry->next();
43 }
44 ASSERT(linkIndex < compactSize);
45 entry->setNext(&entries[linkIndex++]);
46 entry = entry->next();
47 }
48
49 entry->initialize(identifier, values[i].attributes, values[i].value1, values[i].value2);
50 }
51 table = entries;
52}
53
54void HashTable::deleteTable() const
55{
56 if (table) {
57 int max = compactSize;
58 for (int i = 0; i != max; ++i) {
59 if (UString::Rep* key = table[i].key())
60 key->deref();
61 }
62 delete [] table;
63 table = 0;
64 }
65}
66
67void setUpStaticFunctionSlot(ExecState* exec, const HashEntry* entry, JSObject* thisObj, const Identifier& propertyName, PropertySlot& slot)
68{
69 ASSERT(entry->attributes() & Function);
70 JSValue* location = thisObj->getDirectLocation(propertyName);
71
72 if (!location) {
73 InternalFunction* function = new (exec) NativeFunctionWrapper(exec, exec->lexicalGlobalObject()->prototypeFunctionStructure(), entry->functionLength(), propertyName, entry->function());
74
75 thisObj->putDirectFunction(propertyName, function, entry->attributes());
76 location = thisObj->getDirectLocation(propertyName);
77 }
78
79 slot.setValueSlot(thisObj, location, thisObj->offsetForLocation(location));
80}
81
82} // namespace JSC
Note: See TracBrowser for help on using the repository browser.