Fixed length fields for various functions, behavioiur of string functions
to match tests. Added missing virtuals to BoundFunction. Fixed eval access to parameters and locals. git-svn-id: svn://10.0.0.236/trunk@105516 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -124,7 +124,7 @@ static JSValue String_split(Context *cx, const JSValue& thisValue, JSValue *argv
|
||||
{
|
||||
ContextStackReplacement csr(cx);
|
||||
|
||||
ASSERT(thisValue.isObject());
|
||||
ASSERT(thisValue.isObject() || thisValue.isFunction() || thisValue.isType());
|
||||
JSValue S = thisValue.toString(cx);
|
||||
|
||||
JSArrayInstance *A = (JSArrayInstance *)Array_Type->newInstance(cx);
|
||||
@@ -147,11 +147,13 @@ static JSValue String_split(Context *cx, const JSValue& thisValue, JSValue *argv
|
||||
if (lim == 0)
|
||||
return JSValue(A);
|
||||
|
||||
/* XXX standard requires this, but Monkey doesn't do it and the tests break
|
||||
|
||||
if (separatorV.isUndefined()) {
|
||||
A->setProperty(cx, widenCString("0"), NULL, S);
|
||||
return JSValue(A);
|
||||
}
|
||||
|
||||
*/
|
||||
if (s == 0) {
|
||||
MatchResult z;
|
||||
splitMatch(S.string, 0, R, z);
|
||||
@@ -194,7 +196,7 @@ step11:
|
||||
|
||||
static JSValue String_charAt(Context *cx, const JSValue& thisValue, JSValue *argv, uint32 argc)
|
||||
{
|
||||
ASSERT(thisValue.isObject());
|
||||
ASSERT(thisValue.isObject() || thisValue.isFunction() || thisValue.isType());
|
||||
const String *str = thisValue.toString(cx).string;
|
||||
|
||||
uint32 pos = 0;
|
||||
@@ -210,7 +212,7 @@ static JSValue String_charAt(Context *cx, const JSValue& thisValue, JSValue *arg
|
||||
|
||||
static JSValue String_charCodeAt(Context *cx, const JSValue& thisValue, JSValue *argv, uint32 argc)
|
||||
{
|
||||
ASSERT(thisValue.isObject());
|
||||
ASSERT(thisValue.isObject() || thisValue.isFunction() || thisValue.isType());
|
||||
const String *str = thisValue.toString(cx).string;
|
||||
|
||||
uint32 pos = 0;
|
||||
@@ -225,7 +227,7 @@ static JSValue String_charCodeAt(Context *cx, const JSValue& thisValue, JSValue
|
||||
|
||||
static JSValue String_concat(Context *cx, const JSValue& thisValue, JSValue *argv, uint32 argc)
|
||||
{
|
||||
ASSERT(thisValue.isObject());
|
||||
ASSERT(thisValue.isObject() || thisValue.isFunction() || thisValue.isType());
|
||||
const String *str = thisValue.toString(cx).string;
|
||||
String *result = new String(*str);
|
||||
|
||||
@@ -238,7 +240,7 @@ static JSValue String_concat(Context *cx, const JSValue& thisValue, JSValue *arg
|
||||
|
||||
static JSValue String_indexOf(Context *cx, const JSValue& thisValue, JSValue *argv, uint32 argc)
|
||||
{
|
||||
ASSERT(thisValue.isObject());
|
||||
ASSERT(thisValue.isObject() || thisValue.isFunction() || thisValue.isType());
|
||||
if (argc == 0)
|
||||
return JSValue(-1.0);
|
||||
|
||||
@@ -251,10 +253,10 @@ static JSValue String_indexOf(Context *cx, const JSValue& thisValue, JSValue *ar
|
||||
if (arg1 < 0)
|
||||
pos = 0;
|
||||
else
|
||||
if (toUInt32(arg1) >= str->size())
|
||||
if (arg1 >= str->size())
|
||||
pos = str->size();
|
||||
else
|
||||
pos = toUInt32(arg1);
|
||||
pos = arg1;
|
||||
}
|
||||
pos = str->find(*searchStr, pos);
|
||||
if (pos == String::npos)
|
||||
@@ -264,27 +266,26 @@ static JSValue String_indexOf(Context *cx, const JSValue& thisValue, JSValue *ar
|
||||
|
||||
static JSValue String_lastIndexOf(Context *cx, const JSValue& thisValue, JSValue *argv, uint32 argc)
|
||||
{
|
||||
ASSERT(thisValue.isObject());
|
||||
ASSERT(thisValue.isObject() || thisValue.isFunction() || thisValue.isType());
|
||||
if (argc == 0)
|
||||
return JSValue(-1.0);
|
||||
|
||||
const String *str = thisValue.toString(cx).string;
|
||||
const String *searchStr = argv[0].toString(cx).string;
|
||||
uint32 pos = 0;
|
||||
uint32 pos = str->size();
|
||||
|
||||
if (argc > 1) {
|
||||
float64 fpos = argv[1].toNumber(cx).f64;
|
||||
if (fpos != fpos)
|
||||
if (JSDOUBLE_IS_NaN(fpos))
|
||||
pos = str->size();
|
||||
else {
|
||||
int32 arg1 = (int32)(fpos);
|
||||
if (arg1 < 0)
|
||||
if (fpos < 0)
|
||||
pos = 0;
|
||||
else
|
||||
if (toUInt32(arg1) >= str->size())
|
||||
if (fpos >= str->size())
|
||||
pos = str->size();
|
||||
else
|
||||
pos = toUInt32(arg1);
|
||||
pos = (int32)(fpos);
|
||||
}
|
||||
}
|
||||
pos = str->rfind(*searchStr, pos);
|
||||
@@ -300,7 +301,7 @@ static JSValue String_localeCompare(Context * /*cx*/, const JSValue& /*thisValue
|
||||
|
||||
static JSValue String_toLowerCase(Context *cx, const JSValue& thisValue, JSValue * /*argv*/, uint32 /*argc*/)
|
||||
{
|
||||
ASSERT(thisValue.isObject());
|
||||
ASSERT(thisValue.isObject() || thisValue.isFunction() || thisValue.isType());
|
||||
JSValue S = thisValue.toString(cx);
|
||||
|
||||
String *result = new String(*S.string);
|
||||
@@ -312,7 +313,7 @@ static JSValue String_toLowerCase(Context *cx, const JSValue& thisValue, JSValue
|
||||
|
||||
static JSValue String_toUpperCase(Context *cx, const JSValue& thisValue, JSValue * /*argv*/, uint32 /*argc*/)
|
||||
{
|
||||
ASSERT(thisValue.isObject());
|
||||
ASSERT(thisValue.isObject() || thisValue.isFunction() || thisValue.isType());
|
||||
JSValue S = thisValue.toString(cx);
|
||||
|
||||
String *result = new String(*S.string);
|
||||
@@ -324,7 +325,7 @@ static JSValue String_toUpperCase(Context *cx, const JSValue& thisValue, JSValue
|
||||
|
||||
static JSValue String_slice(Context *cx, const JSValue& thisValue, JSValue *argv, uint32 argc)
|
||||
{
|
||||
ASSERT(thisValue.isObject());
|
||||
ASSERT(thisValue.isObject() || thisValue.isFunction() || thisValue.isType());
|
||||
const String *sourceString = thisValue.toString(cx).string;
|
||||
|
||||
uint32 sourceLength = sourceString->size();
|
||||
@@ -375,34 +376,42 @@ static JSValue String_slice(Context *cx, const JSValue& thisValue, JSValue *argv
|
||||
|
||||
static JSValue String_substring(Context *cx, const JSValue& thisValue, JSValue *argv, uint32 argc)
|
||||
{
|
||||
ASSERT(thisValue.isObject());
|
||||
ASSERT(thisValue.isObject() || thisValue.isFunction() || thisValue.isType());
|
||||
const String *sourceString = thisValue.toString(cx).string;
|
||||
|
||||
uint32 sourceLength = sourceString->size();
|
||||
uint32 start, end;
|
||||
|
||||
if (argc > 0) {
|
||||
int32 arg0 = (int32)(argv[0].toInt32(cx).f64);
|
||||
if (arg0 < 0)
|
||||
float64 farg0 = argv[0].toNumber(cx).f64;
|
||||
if (JSDOUBLE_IS_NaN(farg0) || (farg0 < 0))
|
||||
start = 0;
|
||||
else
|
||||
if (toUInt32(arg0) < sourceLength)
|
||||
start = toUInt32(arg0);
|
||||
else
|
||||
else {
|
||||
if (!JSDOUBLE_IS_FINITE(farg0))
|
||||
start = sourceLength;
|
||||
else {
|
||||
start = JSValue::float64ToUInt32(farg0);
|
||||
if (start > sourceLength)
|
||||
start = sourceLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
start = 0;
|
||||
|
||||
if (argc > 1) {
|
||||
int32 arg1 = (int32)(argv[1].toInt32(cx).f64);
|
||||
if (arg1 < 0)
|
||||
float64 farg1 = argv[1].toNumber(cx).f64;
|
||||
if (JSDOUBLE_IS_NaN(farg1) || (farg1 < 0))
|
||||
end = 0;
|
||||
else
|
||||
if (toUInt32(arg1) < sourceLength)
|
||||
end = toUInt32(arg1);
|
||||
else
|
||||
else {
|
||||
if (!JSDOUBLE_IS_FINITE(farg1))
|
||||
end = sourceLength;
|
||||
else {
|
||||
end = JSValue::float64ToUInt32(farg1);
|
||||
if (end > sourceLength)
|
||||
end = sourceLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
end = sourceLength;
|
||||
@@ -427,10 +436,10 @@ Context::PrototypeFunctions *getStringProtos()
|
||||
{ "charCodeAt", Number_Type, 1, String_charCodeAt },
|
||||
{ "concat", String_Type, 1, String_concat },
|
||||
{ "indexOf", Number_Type, 1, String_indexOf },
|
||||
{ "lastIndexOf", Number_Type, 1, String_lastIndexOf },
|
||||
{ "lastIndexOf", Number_Type, 2, String_lastIndexOf }, // XXX ECMA spec says 1, but tests want 2 XXX
|
||||
{ "localeCompare", Number_Type, 1, String_localeCompare },
|
||||
{ "slice", String_Type, 2, String_slice },
|
||||
{ "split", Array_Type, 2, String_split },
|
||||
{ "split", Array_Type, 1, String_split }, // XXX ECMA spec says 2, but tests want 1 XXX
|
||||
{ "substring", String_Type, 2, String_substring },
|
||||
{ "toSource", String_Type, 0, String_toString },
|
||||
{ "toLocaleUpperCase", String_Type, 0, String_toUpperCase }, // (sic)
|
||||
|
||||
Reference in New Issue
Block a user