Ignore:
Timestamp:
Feb 9, 2010, 3:55:39 AM (15 years ago)
Author:
[email protected]
Message:

Three small string fixes:
(1) StringBuilder::release should CRASH if the buffer allocation failed.
(2) Remove weird, dead code from JSString::tryGetValue, replace with an ASSERT.
(3) Move UString::createFromUTF8 out to the API, as tryCreateStringFromUTF8.

This is only used from the API, and (now) unlike other UString::create
methods may return UString::null() to indicate failure cases. Better
handle these in the API.

Reviewed by Oliver Hunt.

  • API/JSClassRef.cpp:

(tryCreateStringFromUTF8):
(OpaqueJSClass::OpaqueJSClass):
(OpaqueJSClassContextData::OpaqueJSClassContextData):

  • runtime/JSString.h:

(JSC::Fiber::tryGetValue):

  • runtime/StringBuilder.h:

(JSC::StringBuilder::release):

  • runtime/UString.cpp:

(JSC::UString::UString):
(JSC::UString::from):
(JSC::UString::find):

  • runtime/UString.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSClassRef.cpp

    r54428 r54545  
    3434#include <runtime/ObjectPrototype.h>
    3535#include <runtime/Identifier.h>
     36#include <wtf/unicode/UTF8.h>
    3637
    3738using namespace std;
    3839using namespace JSC;
     40using namespace WTF::Unicode;
    3941
    4042const JSClassDefinition kJSClassDefinitionEmpty = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
     43
     44UString tryCreateStringFromUTF8(const char* string)
     45{
     46    if (!string)
     47        return UString::null();
     48
     49    size_t length = strlen(string);
     50    Vector<UChar, 1024> buffer(length);
     51    UChar* p = buffer.data();
     52    if (conversionOK != convertUTF8ToUTF16(&string, string + length, &p, p + length))
     53        return UString::null();
     54
     55    return UString(buffer.data(), p - buffer.data());
     56}
    4157
    4258OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* protoClass)
     
    5470    , hasInstance(definition->hasInstance)
    5571    , convertToType(definition->convertToType)
    56     , m_className(UString::createFromUTF8(definition->className).rep()->ref())
     72    , m_className(tryCreateStringFromUTF8(definition->className))
    5773    , m_staticValues(0)
    5874    , m_staticFunctions(0)
     
    6379        m_staticValues = new OpaqueJSClassStaticValuesTable();
    6480        while (staticValue->name) {
    65             // Use a local variable here to sidestep an RVCT compiler bug.
    66             StaticValueEntry* entry = new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes);
    67             m_staticValues->add(UString::createFromUTF8(staticValue->name).rep()->ref(), entry);
     81            UString valueName = tryCreateStringFromUTF8(staticValue->name);
     82            if (!valueName.isNull()) {
     83                // Use a local variable here to sidestep an RVCT compiler bug.
     84                StaticValueEntry* entry = new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes);
     85                m_staticValues->add(valueName.rep()->ref(), entry);
     86            }
    6887            ++staticValue;
    6988        }
     
    7392        m_staticFunctions = new OpaqueJSClassStaticFunctionsTable();
    7493        while (staticFunction->name) {
    75             // Use a local variable here to sidestep an RVCT compiler bug.
    76             StaticFunctionEntry* entry = new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes);
    77             m_staticFunctions->add(UString::createFromUTF8(staticFunction->name).rep()->ref(), entry);
     94            UString functionName = tryCreateStringFromUTF8(staticFunction->name);
     95            if (!functionName.isNull()) {
     96                // Use a local variable here to sidestep an RVCT compiler bug.
     97                StaticFunctionEntry* entry = new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes);
     98                m_staticFunctions->add(functionName.rep()->ref(), entry);
     99            }
    78100            ++staticFunction;
    79101        }
     
    147169            StaticValueEntry* entry = new StaticValueEntry(it->second->getProperty, it->second->setProperty, it->second->attributes);
    148170            staticValues->add(UString::Rep::create(it->first->data(), it->first->size()), entry);
    149 
    150         }
    151            
     171        }
    152172    } else
    153173        staticValues = 0;
    154        
    155174
    156175    if (jsClass->m_staticFunctions) {
Note: See TracChangeset for help on using the changeset viewer.