Changeset 4792 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp


Ignore:
Timestamp:
Aug 8, 2003, 8:21:12 AM (22 years ago)
Author:
darin
Message:

Reviewed by John Sullivan.

  • fixed 3365527 -- subscripting JavaScript strings does not work (leads to hang at www.newmagna.com.au)

The JavaScript specification says nothing about this, but other browsers seem to give
read-only access to the characters in a string as if the string was an array of characters.

  • kjs/array_object.cpp: (ArrayInstanceImp::get): Update to use a public toArrayIndex function instead of our own getArrayIndex function, so we can share with string. (ArrayInstanceImp::put): Ditto. (ArrayInstanceImp::hasProperty): Ditto. (ArrayInstanceImp::setLength): Ditto.
  • kjs/ustring.h: Add toArrayIndex.
  • kjs/ustring.cpp: (UString::toArrayIndex): Added. Implements the rule from array.
  • kjs/identifier.h: Add a forwarding function so we can use toArrayIndex.
  • kjs/string_object.cpp: (StringInstanceImp::get): Return a single character string if the property name is an array index. (StringInstanceImp::hasProperty): Return true for property names that are suitable array indices.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/ustring.cpp

    r4639 r4792  
    709709}
    710710
     711// Rule from ECMA 15.2 about what an array index is.
     712// Must exactly match string form of an unsigned integer, and be less than 2^32 - 1.
     713unsigned UString::toArrayIndex(bool *ok) const
     714{
     715  unsigned i = toStrictUInt32(ok);
     716  if (i >= 0xFFFFFFFFU && ok)
     717    *ok = false;
     718  return i;
     719}
     720
    711721int UString::find(const UString &f, int pos) const
    712722{
Note: See TracChangeset for help on using the changeset viewer.