[webkit-dev] bug? // FIXME: <rdar://problem/4949018>

Jack Wootton jackwootton at gmail.com
Thu May 28 09:24:08 PDT 2009


In the file JavaScriptCore/API/JSClassRef.cpp, in the constructor for
OpaqueJSClass. there is a comment

// FIXME: <rdar://problem/4949018>

It occurs later on where the name of any static functions to be added
to the JSClassDefinition are iterated over.  Here is the constructor
copied from the file JSClassRef.cpp in the JavaScriptCore/API
directory.


/********************* Start code *********************/

OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition,
OpaqueJSClass* protoClass)
    : refCount(0)
    // FIXME: <rdar://problem/4949018>
    , className(definition->className)
    , parentClass(definition->parentClass)
    , prototypeClass(0)
    , staticValues(0)
    , staticFunctions(0)
    , initialize(definition->initialize)
    , finalize(definition->finalize)
    , hasProperty(definition->hasProperty)
    , getProperty(definition->getProperty)
    , setProperty(definition->setProperty)
    , deleteProperty(definition->deleteProperty)
    , getPropertyNames(definition->getPropertyNames)
    , callAsFunction(definition->callAsFunction)
    , callAsConstructor(definition->callAsConstructor)
    , hasInstance(definition->hasInstance)
    , convertToType(definition->convertToType)
    , cachedPrototype(0)
{
    if (protoClass)
        prototypeClass = JSClassRetain(protoClass);

    if (const JSStaticValue* staticValue = definition->staticValues) {
        staticValues = new StaticValuesTable();
        while (staticValue->name) {
            // FIXME: <rdar://problem/4949018>
            staticValues->add(Identifier(staticValue->name).ustring().rep(),
                              new
StaticValueEntry(staticValue->getProperty, staticValue->setProperty,
staticValue->attributes));
            ++staticValue;
        }
    }

    if (const JSStaticFunction* staticFunction = definition->staticFunctions) {
        staticFunctions = new StaticFunctionsTable();
        while (staticFunction->name) {
            // FIXME: <rdar://problem/4949018>
            staticFunctions->add(Identifier(staticFunction->name).ustring().rep(),
                                 new
StaticFunctionEntry(staticFunction->callAsFunction,
staticFunction->attributes));
            ++staticFunction;
        }
    }
}

/********************* End code *********************/


Since I am attempting to add static functions, control enters the last
while loop in the function (extracted here for clarity):


/********************* Start code *********************/

 while (staticFunction->name) {
            // FIXME: <rdar://problem/4949018>
            staticFunctions->add(Identifier(staticFunction->name).ustring().rep(),
                                 new
StaticFunctionEntry(staticFunction->callAsFunction,
staticFunction->attributes));
            ++staticFunction;
        }

/********************* End code *********************/

Upon first iteration of the loop control enters the Identifier::add
method as it should do, the function is copied below:


/********************* Start code *********************/

PassRefPtr<UString::Rep> Identifier::add(const char *c)
{
    if (!c)
        return &UString::Rep::null;
    size_t length = strlen(c);
    if (length == 0)
        return &UString::Rep::empty;

    return *identifierTable().add<const char *, CStringTranslator>(c).first;
}

/********************* End code *********************/


The variable 'c' does have a value, it's the first item in the
character array I used to name my function

char funcName[] = { 'f', 'u', 'n', 'c', '\0' };

Therefore the variable 'c' points to the character 'f' and the length
variable is 4.  This all works fine on first iteration of the while
loop in the constructor.  However the loop then iterates a second
time.  I do not know why it's doing this.  Once gain control enters
the Identifier::add method.  'c' does seem to have a value, so it
passes the following check with a problem

/********************* Start code *********************/
 if (!c)
        return &UString::Rep::null;

/********************* End code *********************/

However the next line causes an exception because 'c' has 0 length (or
something along these lines which is causing a problem).  I would
expect this since I only added 1 static function and do not know why
the while loop seems to be continuing after it has successfully added
the only static function.  The following line therefore causes an
exception upon the second time of entering  the Identifier::add
method:

/********************* Start code *********************/

size_t length = strlen(c);

/********************* End code *********************/


Summary
=======

Is the following comment related to the problem I am experiencing?

// FIXME: <rdar://problem/4949018>

Does anyone have any information on the problem I have outlined?


-- 
Regards
Jack


More information about the webkit-dev mailing list