JavaScriptCore:
2008-07-06 Sam Weinig <sam@webkit.org>
Reviewed by Cameron Zwarich.
Second step in broad cleanup effort.
[ File list elided ]
WebCore:
2008-07-06 Sam Weinig <sam@webkit.org>
Reviewed by Cameron Zwarich.
Add #include for kjs/protect.h.
* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::loadRequestAsynchronously):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@35027 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 10d383a..1f165c4 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,11 @@
+2008-07-06 Sam Weinig <sam@webkit.org>
+
+ Reviewed by Cameron Zwarich.
+
+ Second step in broad cleanup effort.
+
+ [ File list elided ]
+
2008-07-05 Sam Weinig <sam@webkit.org>
Reviewed by Cameron Zwarich.
diff --git a/JavaScriptCore/JavaScriptCore.exp b/JavaScriptCore/JavaScriptCore.exp
index d79ab85..6b2441e 100644
--- a/JavaScriptCore/JavaScriptCore.exp
+++ b/JavaScriptCore/JavaScriptCore.exp
@@ -170,8 +170,8 @@
__ZN3KJS6JSCell3putEPNS_9ExecStateEjPNS_7JSValueE
__ZN3KJS6JSCell9getObjectEv
__ZN3KJS6JSCellnwEmPNS_9ExecStateE
-__ZN3KJS6JSLock12DropAllLocksC1Eb
__ZN3KJS6JSLock12DropAllLocksC1EPNS_9ExecStateE
+__ZN3KJS6JSLock12DropAllLocksC1Eb
__ZN3KJS6JSLock12DropAllLocksD1Ev
__ZN3KJS6JSLock14registerThreadEv
__ZN3KJS6JSLock4lockEb
@@ -210,7 +210,7 @@
__ZN3KJS8JSObject14deletePropertyEPNS_9ExecStateERKNS_10IdentifierE
__ZN3KJS8JSObject14deletePropertyEPNS_9ExecStateEj
__ZN3KJS8JSObject16getPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayE
-__ZN3KJS8JSObject17putDirectFunctionEPNS_16InternalFunctionEi
+__ZN3KJS8JSObject17putDirectFunctionEPNS_16InternalFunctionEj
__ZN3KJS8JSObject17putWithAttributesEPNS_9ExecStateERKNS_10IdentifierEPNS_7JSValueEj
__ZN3KJS8JSObject17putWithAttributesEPNS_9ExecStateEjPNS_7JSValueEj
__ZN3KJS8JSObject18getOwnPropertySlotEPNS_9ExecStateEjRNS_12PropertySlotE
diff --git a/JavaScriptCore/kjs/JSActivation.cpp b/JavaScriptCore/kjs/JSActivation.cpp
index 66a275d..6ff0cb3 100644
--- a/JavaScriptCore/kjs/JSActivation.cpp
+++ b/JavaScriptCore/kjs/JSActivation.cpp
@@ -76,7 +76,7 @@
// We don't call through to JSObject because there's no way to give an
// activation object getter properties or a prototype.
- ASSERT(!_prop.hasGetterSetterProperties());
+ ASSERT(!m_propertyMap.hasGetterSetterProperties());
ASSERT(prototype() == jsNull());
return false;
}
@@ -89,8 +89,8 @@
// We don't call through to JSObject because __proto__ and getter/setter
// properties are non-standard extensions that other implementations do not
// expose in the activation object.
- ASSERT(!_prop.hasGetterSetterProperties());
- _prop.put(propertyName, value, 0, true);
+ ASSERT(!m_propertyMap.hasGetterSetterProperties());
+ m_propertyMap.put(propertyName, value, 0, true);
}
// FIXME: Make this function honor ReadOnly (const) and DontEnum
@@ -102,8 +102,8 @@
// We don't call through to JSObject because __proto__ and getter/setter
// properties are non-standard extensions that other implementations do not
// expose in the activation object.
- ASSERT(!_prop.hasGetterSetterProperties());
- _prop.put(propertyName, value, attributes, true);
+ ASSERT(!m_propertyMap.hasGetterSetterProperties());
+ m_propertyMap.put(propertyName, value, attributes, true);
}
bool JSActivation::deleteProperty(ExecState* exec, const Identifier& propertyName)
diff --git a/JavaScriptCore/kjs/JSGlobalData.h b/JavaScriptCore/kjs/JSGlobalData.h
index 14a63d7..7e1a466 100644
--- a/JavaScriptCore/kjs/JSGlobalData.h
+++ b/JavaScriptCore/kjs/JSGlobalData.h
@@ -90,7 +90,7 @@
static JSGlobalData*& sharedInstanceInternal();
struct DataInstance {
- DataInstance() : m_data(0) {}
+ DataInstance() : m_data(0) { }
~DataInstance() { delete m_data; }
operator JSGlobalData*&() { return m_data; }
diff --git a/JavaScriptCore/kjs/JSGlobalObject.cpp b/JavaScriptCore/kjs/JSGlobalObject.cpp
index c69cc5b..37c0a7c 100644
--- a/JavaScriptCore/kjs/JSGlobalObject.cpp
+++ b/JavaScriptCore/kjs/JSGlobalObject.cpp
@@ -176,7 +176,7 @@
// which would be wasteful -- or uninitialized pointers -- which would be
// dangerous. (The allocations below may cause a GC.)
- _prop.clear();
+ m_propertyMap.clear();
symbolTable().clear();
setRegisterArray(0, 0);
diff --git a/JavaScriptCore/kjs/JSGlobalObject.h b/JavaScriptCore/kjs/JSGlobalObject.h
index 81a9f5d..6a2d5df 100644
--- a/JavaScriptCore/kjs/JSGlobalObject.h
+++ b/JavaScriptCore/kjs/JSGlobalObject.h
@@ -1,4 +1,3 @@
-// -*- c-basic-offset: 4 -*-
/*
* Copyright (C) 2007 Eric Seidel <eric@webkit.org>
* Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
@@ -20,8 +19,8 @@
*
*/
-#ifndef KJS_GlobalObject_h
-#define KJS_GlobalObject_h
+#ifndef JSGlobalObject_h
+#define JSGlobalObject_h
#include "JSGlobalData.h"
#include "JSVariableObject.h"
@@ -296,4 +295,4 @@
} // namespace KJS
-#endif // KJS_GlobalObject_h
+#endif // JSGlobalObject_h
diff --git a/JavaScriptCore/kjs/JSGlobalObjectFunctions.cpp b/JavaScriptCore/kjs/JSGlobalObjectFunctions.cpp
index 2916fd6..6a38e8b 100644
--- a/JavaScriptCore/kjs/JSGlobalObjectFunctions.cpp
+++ b/JavaScriptCore/kjs/JSGlobalObjectFunctions.cpp
@@ -48,89 +48,92 @@
namespace KJS {
-static JSValue* encode(ExecState* exec, const ArgList& args, const char* do_not_escape)
+static JSValue* encode(ExecState* exec, const ArgList& args, const char* doNotEscape)
{
- UString r = "", s, str = args[0]->toString(exec);
- CString cstr = str.UTF8String(true);
- if (!cstr.c_str())
- return throwError(exec, URIError, "String contained an illegal UTF-16 sequence.");
- const char* p = cstr.c_str();
- for (size_t k = 0; k < cstr.size(); k++, p++) {
- char c = *p;
- if (c && strchr(do_not_escape, c)) {
- r.append(c);
- } else {
- char tmp[4];
- sprintf(tmp, "%%%02X", (unsigned char)c);
- r += tmp;
+ UString str = args[0]->toString(exec);
+ CString cstr = str.UTF8String(true);
+ if (!cstr.c_str())
+ return throwError(exec, URIError, "String contained an illegal UTF-16 sequence.");
+
+ UString result = "";
+ const char* p = cstr.c_str();
+ for (size_t k = 0; k < cstr.size(); k++, p++) {
+ char c = *p;
+ if (c && strchr(doNotEscape, c))
+ result.append(c);
+ else {
+ char tmp[4];
+ sprintf(tmp, "%%%02X", static_cast<unsigned char>(c));
+ result += tmp;
+ }
}
- }
- return jsString(exec, r);
+ return jsString(exec, result);
}
-static JSValue* decode(ExecState* exec, const ArgList& args, const char* do_not_unescape, bool strict)
+static JSValue* decode(ExecState* exec, const ArgList& args, const char* doNotUnescape, bool strict)
{
- UString s = "", str = args[0]->toString(exec);
- int k = 0, len = str.size();
- const UChar* d = str.data();
- UChar u = 0;
- while (k < len) {
- const UChar* p = d + k;
- UChar c = *p;
- if (c == '%') {
- int charLen = 0;
- if (k <= len - 3 && isASCIIHexDigit(p[1]) && isASCIIHexDigit(p[2])) {
- const char b0 = Lexer::convertHex(p[1], p[2]);
- const int sequenceLen = UTF8SequenceLength(b0);
- if (sequenceLen != 0 && k <= len - sequenceLen * 3) {
- charLen = sequenceLen * 3;
- char sequence[5];
- sequence[0] = b0;
- for (int i = 1; i < sequenceLen; ++i) {
- const UChar* q = p + i * 3;
- if (q[0] == '%' && isASCIIHexDigit(q[1]) && isASCIIHexDigit(q[2]))
- sequence[i] = Lexer::convertHex(q[1], q[2]);
- else {
- charLen = 0;
- break;
+ UString result = "";
+ UString str = args[0]->toString(exec);
+ int k = 0;
+ int len = str.size();
+ const UChar* d = str.data();
+ UChar u = 0;
+ while (k < len) {
+ const UChar* p = d + k;
+ UChar c = *p;
+ if (c == '%') {
+ int charLen = 0;
+ if (k <= len - 3 && isASCIIHexDigit(p[1]) && isASCIIHexDigit(p[2])) {
+ const char b0 = Lexer::convertHex(p[1], p[2]);
+ const int sequenceLen = UTF8SequenceLength(b0);
+ if (sequenceLen != 0 && k <= len - sequenceLen * 3) {
+ charLen = sequenceLen * 3;
+ char sequence[5];
+ sequence[0] = b0;
+ for (int i = 1; i < sequenceLen; ++i) {
+ const UChar* q = p + i * 3;
+ if (q[0] == '%' && isASCIIHexDigit(q[1]) && isASCIIHexDigit(q[2]))
+ sequence[i] = Lexer::convertHex(q[1], q[2]);
+ else {
+ charLen = 0;
+ break;
+ }
+ }
+ if (charLen != 0) {
+ sequence[sequenceLen] = 0;
+ const int character = decodeUTF8Sequence(sequence);
+ if (character < 0 || character >= 0x110000)
+ charLen = 0;
+ else if (character >= 0x10000) {
+ // Convert to surrogate pair.
+ result.append(static_cast<UChar>(0xD800 | ((character - 0x10000) >> 10)));
+ u = static_cast<UChar>(0xDC00 | ((character - 0x10000) & 0x3FF));
+ } else
+ u = static_cast<UChar>(character);
+ }
+ }
}
- }
- if (charLen != 0) {
- sequence[sequenceLen] = 0;
- const int character = decodeUTF8Sequence(sequence);
- if (character < 0 || character >= 0x110000) {
- charLen = 0;
- } else if (character >= 0x10000) {
- // Convert to surrogate pair.
- s.append(static_cast<UChar>(0xD800 | ((character - 0x10000) >> 10)));
- u = static_cast<UChar>(0xDC00 | ((character - 0x10000) & 0x3FF));
- } else {
- u = static_cast<UChar>(character);
+ if (charLen == 0) {
+ if (strict)
+ return throwError(exec, URIError);
+ // The only case where we don't use "strict" mode is the "unescape" function.
+ // For that, it's good to support the wonky "%u" syntax for compatibility with WinIE.
+ if (k <= len - 6 && p[1] == 'u'
+ && isASCIIHexDigit(p[2]) && isASCIIHexDigit(p[3])
+ && isASCIIHexDigit(p[4]) && isASCIIHexDigit(p[5])) {
+ charLen = 6;
+ u = Lexer::convertUnicode(p[2], p[3], p[4], p[5]);
+ }
}
- }
+ if (charLen && (u == 0 || u >= 128 || !strchr(doNotUnescape, u))) {
+ c = u;
+ k += charLen - 1;
+ }
}
- }
- if (charLen == 0) {
- if (strict)
- return throwError(exec, URIError);
- // The only case where we don't use "strict" mode is the "unescape" function.
- // For that, it's good to support the wonky "%u" syntax for compatibility with WinIE.
- if (k <= len - 6 && p[1] == 'u'
- && isASCIIHexDigit(p[2]) && isASCIIHexDigit(p[3])
- && isASCIIHexDigit(p[4]) && isASCIIHexDigit(p[5])) {
- charLen = 6;
- u = Lexer::convertUnicode(p[2], p[3], p[4], p[5]);
- }
- }
- if (charLen && (u == 0 || u >= 128 || !strchr(do_not_unescape, u))) {
- c = u;
- k += charLen - 1;
- }
+ k++;
+ result.append(c);
}
- k++;
- s.append(c);
- }
- return jsString(exec, s);
+ return jsString(exec, result);
}
static bool isStrWhiteSpace(unsigned short c)
@@ -155,13 +158,12 @@
{
int digit = -1;
- if (c >= '0' && c <= '9') {
+ if (c >= '0' && c <= '9')
digit = c - '0';
- } else if (c >= 'A' && c <= 'Z') {
+ else if (c >= 'A' && c <= 'Z')
digit = c - 'A' + 10;
- } else if (c >= 'a' && c <= 'z') {
+ else if (c >= 'a' && c <= 'z')
digit = c - 'a' + 10;
- }
if (digit >= radix)
return -1;
@@ -195,15 +197,14 @@
int length = s.size();
int p = 0;
- while (p < length && isStrWhiteSpace(s[p])) {
+ while (p < length && isStrWhiteSpace(s[p]))
++p;
- }
double sign = 1;
if (p < length) {
- if (s[p] == '+') {
+ if (s[p] == '+')
++p;
- } else if (s[p] == '-') {
+ else if (s[p] == '-') {
sign = -1;
++p;
}
@@ -254,17 +255,16 @@
// Need to skip any whitespace and then one + or - sign.
int length = s.size();
int p = 0;
- while (p < length && isStrWhiteSpace(s[p])) {
+ while (p < length && isStrWhiteSpace(s[p]))
++p;
- }
- if (p < length && (s[p] == '+' || s[p] == '-')) {
- ++p;
- }
- if (length - p >= 2 && s[p] == '0' && (s[p + 1] == 'x' || s[p + 1] == 'X')) {
- return 0;
- }
- return s.toDouble( true /*tolerant*/, false /* NaN for empty string */ );
+ if (p < length && (s[p] == '+' || s[p] == '-'))
+ ++p;
+
+ if (length - p >= 2 && s[p] == '0' && (s[p + 1] == 'x' || s[p + 1] == 'X'))
+ return 0;
+
+ return s.toDouble(true /*tolerant*/, false /* NaN for empty string */);
}
JSValue* globalFuncEval(ExecState* exec, JSObject* function, JSValue* thisValue, const ArgList& args)
@@ -277,15 +277,15 @@
JSValue* x = args[0];
if (!x->isString())
return x;
-
+
UString s = x->toString(exec);
-
+
int sourceId;
int errLine;
UString errMsg;
RefPtr<EvalNode> evalNode = exec->parser()->parse<EvalNode>(exec, UString(), 1, UStringSourceProvider::create(s), &sourceId, &errLine, &errMsg);
-
+
if (!evalNode)
return throwError(exec, SyntaxError, errMsg, errLine, sourceId, NULL);
@@ -356,7 +356,9 @@
"0123456789"
"*+-./@_";
- UString r = "", s, str = args[0]->toString(exec);
+ UString result = "";
+ UString s;
+ UString str = args[0]->toString(exec);
const UChar* c = str.data();
for (int k = 0; k < str.size(); k++, c++) {
int u = c[0];
@@ -364,23 +366,25 @@
char tmp[7];
sprintf(tmp, "%%u%04X", u);
s = UString(tmp);
- } else if (u != 0 && strchr(do_not_escape, (char)u))
+ } else if (u != 0 && strchr(do_not_escape, static_cast<char>(u)))
s = UString(c, 1);
else {
char tmp[4];
sprintf(tmp, "%%%02X", u);
s = UString(tmp);
}
- r += s;
+ result += s;
}
- return jsString(exec, r);
+ return jsString(exec, result);
}
JSValue* globalFuncUnescape(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
{
- UString s = "", str = args[0]->toString(exec);
- int k = 0, len = str.size();
+ UString result = "";
+ UString str = args[0]->toString(exec);
+ int k = 0;
+ int len = str.size();
while (k < len) {
const UChar* c = str.data() + k;
UChar u;
@@ -396,10 +400,10 @@
k += 2;
}
k++;
- s.append(*c);
+ result.append(*c);
}
- return jsString(exec, s);
+ return jsString(exec, result);
}
#ifndef NDEBUG
diff --git a/JavaScriptCore/kjs/JSImmediate.h b/JavaScriptCore/kjs/JSImmediate.h
index 9447dad..cda2aeb 100644
--- a/JavaScriptCore/kjs/JSImmediate.h
+++ b/JavaScriptCore/kjs/JSImmediate.h
@@ -33,347 +33,347 @@
namespace KJS {
-class ExecState;
-class JSObject;
-class JSValue;
-class UString;
+ class ExecState;
+ class JSObject;
+ class JSValue;
+ class UString;
-/*
- * A JSValue* is either a pointer to a cell (a heap-allocated object) or an immediate (a type-tagged
- * signed int masquerading as a pointer). The low two bits in a JSValue* are available
- * for type tagging because allocator alignment guarantees they will be 00 in cell pointers.
- *
- * For example, on a 32 bit system:
- *
- * JSCell*: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 00
- * [ high 30 bits: pointer address ] [ low 2 bits -- always 0 ]
- *
- * JSImmediate: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX TT
- * [ high 30 bits: signed int ] [ low 2 bits -- type tag ]
- *
- * The bit "payload" (the high 30 bits) is a 30 bit signed int for immediate numbers, a flag to distinguish true/false
- * and undefined/null.
- *
- * Notice that the JSType value of NullType is 4, which requires 3 bits to encode. Since we only have 2 bits
- * available for type tagging, we tag the null immediate with UndefinedType, and JSImmediate::type() has
- * to sort them out.
- */
+ /*
+ * A JSValue* is either a pointer to a cell (a heap-allocated object) or an immediate (a type-tagged
+ * signed int masquerading as a pointer). The low two bits in a JSValue* are available
+ * for type tagging because allocator alignment guarantees they will be 00 in cell pointers.
+ *
+ * For example, on a 32 bit system:
+ *
+ * JSCell*: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 00
+ * [ high 30 bits: pointer address ] [ low 2 bits -- always 0 ]
+ *
+ * JSImmediate: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX TT
+ * [ high 30 bits: signed int ] [ low 2 bits -- type tag ]
+ *
+ * The bit "payload" (the high 30 bits) is a 30 bit signed int for immediate numbers, a flag to distinguish true/false
+ * and undefined/null.
+ *
+ * Notice that the JSType value of NullType is 4, which requires 3 bits to encode. Since we only have 2 bits
+ * available for type tagging, we tag the null immediate with UndefinedType, and JSImmediate::type() has
+ * to sort them out.
+ */
-class JSImmediate {
-public:
- static ALWAYS_INLINE bool isImmediate(const JSValue* v)
+ class JSImmediate {
+ public:
+ static ALWAYS_INLINE bool isImmediate(const JSValue* v)
+ {
+ return getTag(v) != 0;
+ }
+
+ static ALWAYS_INLINE bool isNumber(const JSValue* v)
+ {
+ return (getTag(v) == NumberType);
+ }
+
+ static ALWAYS_INLINE bool isPositiveNumber(const JSValue* v)
+ {
+ // A single mask to check for the sign bit and the number tag all at once.
+ return (reinterpret_cast<uintptr_t>(v) & (0x80000000 | NumberType)) == NumberType;
+ }
+
+ static ALWAYS_INLINE bool isBoolean(const JSValue* v)
+ {
+ return (getTag(v) == BooleanType);
+ }
+
+ // Since we have room for only 3 unique tags, null and undefined have to share.
+ static ALWAYS_INLINE bool isUndefinedOrNull(const JSValue* v)
+ {
+ return (getTag(v) == UndefinedType);
+ }
+
+ static bool isNegative(const JSValue* v)
+ {
+ ASSERT(isNumber(v));
+ return reinterpret_cast<uintptr_t>(v) & 0x80000000;
+ }
+
+ static JSValue* from(char);
+ static JSValue* from(signed char);
+ static JSValue* from(unsigned char);
+ static JSValue* from(short);
+ static JSValue* from(unsigned short);
+ static JSValue* from(int);
+ static JSValue* from(unsigned);
+ static JSValue* from(long);
+ static JSValue* from(unsigned long);
+ static JSValue* from(long long);
+ static JSValue* from(unsigned long long);
+ static JSValue* from(double);
+
+ static ALWAYS_INLINE bool areBothImmediateNumbers(const JSValue* v1, const JSValue* v2)
+ {
+ return (reinterpret_cast<uintptr_t>(v1) & reinterpret_cast<uintptr_t>(v2) & TagMask) == NumberType;
+ }
+
+ static ALWAYS_INLINE JSValue* andImmediateNumbers(const JSValue* v1, const JSValue* v2)
+ {
+ ASSERT(areBothImmediateNumbers(v1, v2));
+ return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v1) & reinterpret_cast<uintptr_t>(v2));
+ }
+
+ static ALWAYS_INLINE JSValue* xorImmediateNumbers(const JSValue* v1, const JSValue* v2)
+ {
+ ASSERT(areBothImmediateNumbers(v1, v2));
+ return tag(reinterpret_cast<uintptr_t>(v1) ^ reinterpret_cast<uintptr_t>(v2), NumberType);
+ }
+
+ static ALWAYS_INLINE JSValue* orImmediateNumbers(const JSValue* v1, const JSValue* v2)
+ {
+ ASSERT(areBothImmediateNumbers(v1, v2));
+ return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v1) | reinterpret_cast<uintptr_t>(v2));
+ }
+
+ static ALWAYS_INLINE JSValue* rightShiftImmediateNumbers(const JSValue* val, const JSValue* shift)
+ {
+ ASSERT(areBothImmediateNumbers(val, shift));
+ return reinterpret_cast<JSValue*>((reinterpret_cast<intptr_t>(val) >> ((reinterpret_cast<uintptr_t>(shift) >> 2) & 0x1f)) | NumberType);
+ }
+
+ static ALWAYS_INLINE bool canDoFastAdditiveOperations(const JSValue* v)
+ {
+ // Number is non-negative and an operation involving two of these can't overflow.
+ // Checking for allowed negative numbers takes more time than it's worth on SunSpider.
+ return (reinterpret_cast<uintptr_t>(v) & (NumberType + (3 << 30))) == NumberType;
+ }
+
+ static ALWAYS_INLINE JSValue* addImmediateNumbers(const JSValue* v1, const JSValue* v2)
+ {
+ ASSERT(canDoFastAdditiveOperations(v1));
+ ASSERT(canDoFastAdditiveOperations(v2));
+ return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v1) + (reinterpret_cast<uintptr_t>(v2) & ~NumberType));
+ }
+
+ static ALWAYS_INLINE JSValue* subImmediateNumbers(const JSValue* v1, const JSValue* v2)
+ {
+ ASSERT(canDoFastAdditiveOperations(v1));
+ ASSERT(canDoFastAdditiveOperations(v2));
+ return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v1) - (reinterpret_cast<uintptr_t>(v2) & ~NumberType));
+ }
+
+ static ALWAYS_INLINE JSValue* incImmediateNumber(const JSValue* v)
+ {
+ ASSERT(canDoFastAdditiveOperations(v));
+ return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v) + TagMask + 1);
+ }
+
+ static ALWAYS_INLINE JSValue* decImmediateNumber(const JSValue* v)
+ {
+ ASSERT(canDoFastAdditiveOperations(v));
+ return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v) - (TagMask + 1));
+ }
+
+ static double toDouble(const JSValue*);
+ static bool toBoolean(const JSValue*);
+ static JSObject* toObject(const JSValue*, ExecState*);
+ static UString toString(const JSValue*);
+ static uint32_t toTruncatedUInt32(const JSValue*);
+ static JSType type(const JSValue*);
+
+ static bool getUInt32(const JSValue*, uint32_t&);
+ static bool getTruncatedInt32(const JSValue*, int32_t&);
+ static bool getTruncatedUInt32(const JSValue*, uint32_t&);
+
+ static int32_t getTruncatedInt32(const JSValue*);
+
+ static JSValue* trueImmediate();
+ static JSValue* falseImmediate();
+ static JSValue* undefinedImmediate();
+ static JSValue* nullImmediate();
+
+ static JSValue* impossibleValue();
+
+ static JSObject* prototype(const JSValue*, ExecState*);
+
+ private:
+ static const uintptr_t TagMask = 3; // type tags are 2 bits long
+
+ // Immediate values are restricted to a 30 bit signed value.
+ static const int minImmediateInt = -(1 << 29);
+ static const int maxImmediateInt = (1 << 29) - 1;
+ static const unsigned maxImmediateUInt = maxImmediateInt;
+
+ static ALWAYS_INLINE JSValue* tag(uintptr_t bits, uintptr_t tag)
+ {
+ return reinterpret_cast<JSValue*>(bits | tag);
+ }
+
+ static ALWAYS_INLINE uintptr_t unTag(const JSValue* v)
+ {
+ return reinterpret_cast<uintptr_t>(v) & ~TagMask;
+ }
+
+ static ALWAYS_INLINE uintptr_t getTag(const JSValue* v)
+ {
+ return reinterpret_cast<uintptr_t>(v) & TagMask;
+ }
+ };
+
+ ALWAYS_INLINE JSValue* JSImmediate::trueImmediate() { return tag(1 << 2, BooleanType); }
+ ALWAYS_INLINE JSValue* JSImmediate::falseImmediate() { return tag(0, BooleanType); }
+ ALWAYS_INLINE JSValue* JSImmediate::undefinedImmediate() { return tag(1 << 2, UndefinedType); }
+ ALWAYS_INLINE JSValue* JSImmediate::nullImmediate() { return tag(0, UndefinedType); }
+
+ // This value is impossible because 0x4 is not a valid pointer but a tag of 0 would indicate non-immediate
+ ALWAYS_INLINE JSValue* JSImmediate::impossibleValue() { return tag(1 << 2, 0); }
+
+ ALWAYS_INLINE bool JSImmediate::toBoolean(const JSValue* v)
{
- return getTag(v) != 0;
- }
-
- static ALWAYS_INLINE bool isNumber(const JSValue* v)
- {
- return (getTag(v) == NumberType);
- }
-
- static ALWAYS_INLINE bool isPositiveNumber(const JSValue* v)
- {
- // A single mask to check for the sign bit and the number tag all at once.
- return (reinterpret_cast<uintptr_t>(v) & (0x80000000 | NumberType)) == NumberType;
- }
-
- static ALWAYS_INLINE bool isBoolean(const JSValue* v)
- {
- return (getTag(v) == BooleanType);
- }
-
- // Since we have room for only 3 unique tags, null and undefined have to share.
- static ALWAYS_INLINE bool isUndefinedOrNull(const JSValue* v)
- {
- return (getTag(v) == UndefinedType);
+ ASSERT(isImmediate(v));
+ uintptr_t bits = unTag(v);
+ return (bits != 0) & (JSImmediate::getTag(v) != UndefinedType);
}
- static bool isNegative(const JSValue* v)
+ ALWAYS_INLINE uint32_t JSImmediate::toTruncatedUInt32(const JSValue* v)
+ {
+ ASSERT(isImmediate(v));
+ return static_cast<uint32_t>(reinterpret_cast<intptr_t>(v) >> 2);
+ }
+
+ ALWAYS_INLINE JSValue* JSImmediate::from(char i)
+ {
+ return tag(i << 2, NumberType);
+ }
+
+ ALWAYS_INLINE JSValue* JSImmediate::from(signed char i)
+ {
+ return tag(i << 2, NumberType);
+ }
+
+ ALWAYS_INLINE JSValue* JSImmediate::from(unsigned char i)
+ {
+ return tag(i << 2, NumberType);
+ }
+
+ ALWAYS_INLINE JSValue* JSImmediate::from(short i)
+ {
+ return tag(i << 2, NumberType);
+ }
+
+ ALWAYS_INLINE JSValue* JSImmediate::from(unsigned short i)
+ {
+ return tag(i << 2, NumberType);
+ }
+
+ ALWAYS_INLINE JSValue* JSImmediate::from(int i)
+ {
+ if ((i < minImmediateInt) | (i > maxImmediateInt))
+ return 0;
+ return tag(i << 2, NumberType);
+ }
+
+ ALWAYS_INLINE JSValue* JSImmediate::from(unsigned i)
+ {
+ if (i > maxImmediateUInt)
+ return 0;
+ return tag(i << 2, NumberType);
+ }
+
+ ALWAYS_INLINE JSValue* JSImmediate::from(long i)
+ {
+ if ((i < minImmediateInt) | (i > maxImmediateInt))
+ return 0;
+ return tag(i << 2, NumberType);
+ }
+
+ ALWAYS_INLINE JSValue* JSImmediate::from(unsigned long i)
+ {
+ if (i > maxImmediateUInt)
+ return 0;
+ return tag(i << 2, NumberType);
+ }
+
+ ALWAYS_INLINE JSValue* JSImmediate::from(long long i)
+ {
+ if ((i < minImmediateInt) | (i > maxImmediateInt))
+ return 0;
+ return tag(static_cast<uintptr_t>(i) << 2, NumberType);
+ }
+
+ ALWAYS_INLINE JSValue* JSImmediate::from(unsigned long long i)
+ {
+ if (i > maxImmediateUInt)
+ return 0;
+ return tag(static_cast<uintptr_t>(i) << 2, NumberType);
+ }
+
+ ALWAYS_INLINE JSValue* JSImmediate::from(double d)
+ {
+ const int intVal = static_cast<int>(d);
+
+ if ((intVal < minImmediateInt) | (intVal > maxImmediateInt))
+ return 0;
+
+ // Check for data loss from conversion to int.
+ if ((intVal != d) || (!intVal && signbit(d)))
+ return 0;
+
+ return tag(intVal << 2, NumberType);
+ }
+
+ ALWAYS_INLINE int32_t JSImmediate::getTruncatedInt32(const JSValue* v)
{
ASSERT(isNumber(v));
- return reinterpret_cast<uintptr_t>(v) & 0x80000000;
+ return static_cast<int32_t>(unTag(v)) >> 2;
}
- static JSValue* from(char);
- static JSValue* from(signed char);
- static JSValue* from(unsigned char);
- static JSValue* from(short);
- static JSValue* from(unsigned short);
- static JSValue* from(int);
- static JSValue* from(unsigned);
- static JSValue* from(long);
- static JSValue* from(unsigned long);
- static JSValue* from(long long);
- static JSValue* from(unsigned long long);
- static JSValue* from(double);
-
- static ALWAYS_INLINE bool areBothImmediateNumbers(const JSValue* v1, const JSValue* v2)
+ ALWAYS_INLINE double JSImmediate::toDouble(const JSValue* v)
{
- return (reinterpret_cast<uintptr_t>(v1) & reinterpret_cast<uintptr_t>(v2) & TagMask) == NumberType;
+ ASSERT(isImmediate(v));
+ const int32_t i = static_cast<int32_t>(unTag(v)) >> 2;
+ if (JSImmediate::getTag(v) == UndefinedType && i)
+ return std::numeric_limits<double>::quiet_NaN();
+ return i;
}
- static ALWAYS_INLINE JSValue* andImmediateNumbers(const JSValue* v1, const JSValue* v2)
+ ALWAYS_INLINE bool JSImmediate::getUInt32(const JSValue* v, uint32_t& i)
{
- ASSERT(areBothImmediateNumbers(v1, v2));
- return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v1) & reinterpret_cast<uintptr_t>(v2));
+ i = static_cast<uintptr_t>(unTag(v)) >> 2;
+ return isPositiveNumber(v);
}
- static ALWAYS_INLINE JSValue* xorImmediateNumbers(const JSValue* v1, const JSValue* v2)
+ ALWAYS_INLINE bool JSImmediate::getTruncatedInt32(const JSValue* v, int32_t& i)
{
- ASSERT(areBothImmediateNumbers(v1, v2));
- return tag(reinterpret_cast<uintptr_t>(v1) ^ reinterpret_cast<uintptr_t>(v2), NumberType);
+ i = static_cast<int32_t>(unTag(v)) >> 2;
+ return isNumber(v);
}
- static ALWAYS_INLINE JSValue* orImmediateNumbers(const JSValue* v1, const JSValue* v2)
+ ALWAYS_INLINE bool JSImmediate::getTruncatedUInt32(const JSValue* v, uint32_t& i)
{
- ASSERT(areBothImmediateNumbers(v1, v2));
- return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v1) | reinterpret_cast<uintptr_t>(v2));
+ return getUInt32(v, i);
}
- static ALWAYS_INLINE JSValue* rightShiftImmediateNumbers(const JSValue* val, const JSValue* shift)
+ ALWAYS_INLINE JSType JSImmediate::type(const JSValue* v)
{
- ASSERT(areBothImmediateNumbers(val, shift));
- return reinterpret_cast<JSValue*>((reinterpret_cast<intptr_t>(val) >> ((reinterpret_cast<uintptr_t>(shift) >> 2) & 0x1f)) | NumberType);
+ ASSERT(isImmediate(v));
+
+ uintptr_t tag = getTag(v);
+ if (tag == UndefinedType)
+ return v == undefinedImmediate() ? UndefinedType : NullType;
+ return static_cast<JSType>(tag);
}
- static ALWAYS_INLINE bool canDoFastAdditiveOperations(const JSValue* v)
+ ALWAYS_INLINE JSValue* jsUndefined()
{
- // Number is non-negative and an operation involving two of these can't overflow.
- // Checking for allowed negative numbers takes more time than it's worth on SunSpider.
- return (reinterpret_cast<uintptr_t>(v) & (NumberType + (3 << 30))) == NumberType;
+ return JSImmediate::undefinedImmediate();
}
- static ALWAYS_INLINE JSValue* addImmediateNumbers(const JSValue* v1, const JSValue* v2)
+ inline JSValue* jsNull()
{
- ASSERT(canDoFastAdditiveOperations(v1));
- ASSERT(canDoFastAdditiveOperations(v2));
- return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v1) + (reinterpret_cast<uintptr_t>(v2) & ~NumberType));
+ return JSImmediate::nullImmediate();
}
- static ALWAYS_INLINE JSValue* subImmediateNumbers(const JSValue* v1, const JSValue* v2)
+ inline JSValue* jsBoolean(bool b)
{
- ASSERT(canDoFastAdditiveOperations(v1));
- ASSERT(canDoFastAdditiveOperations(v2));
- return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v1) - (reinterpret_cast<uintptr_t>(v2) & ~NumberType));
+ return b ? JSImmediate::trueImmediate() : JSImmediate::falseImmediate();
}
- static ALWAYS_INLINE JSValue* incImmediateNumber(const JSValue* v)
- {
- ASSERT(canDoFastAdditiveOperations(v));
- return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v) + TagMask + 1);
- }
-
- static ALWAYS_INLINE JSValue* decImmediateNumber(const JSValue* v)
- {
- ASSERT(canDoFastAdditiveOperations(v));
- return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v) - (TagMask + 1));
- }
-
- static double toDouble(const JSValue*);
- static bool toBoolean(const JSValue*);
- static JSObject* toObject(const JSValue*, ExecState*);
- static UString toString(const JSValue*);
- static uint32_t toTruncatedUInt32(const JSValue*);
- static JSType type(const JSValue*);
-
- static bool getUInt32(const JSValue*, uint32_t&);
- static bool getTruncatedInt32(const JSValue*, int32_t&);
- static bool getTruncatedUInt32(const JSValue*, uint32_t&);
-
- static int32_t getTruncatedInt32(const JSValue*);
-
- static JSValue* trueImmediate();
- static JSValue* falseImmediate();
- static JSValue* undefinedImmediate();
- static JSValue* nullImmediate();
-
- static JSValue* impossibleValue();
-
- static JSObject* prototype(const JSValue*, ExecState*);
-
-private:
- static const uintptr_t TagMask = 3; // type tags are 2 bits long
-
- // Immediate values are restricted to a 30 bit signed value.
- static const int minImmediateInt = -(1 << 29);
- static const int maxImmediateInt = (1 << 29) - 1;
- static const unsigned maxImmediateUInt = maxImmediateInt;
-
- static ALWAYS_INLINE JSValue* tag(uintptr_t bits, uintptr_t tag)
- {
- return reinterpret_cast<JSValue*>(bits | tag);
- }
-
- static ALWAYS_INLINE uintptr_t unTag(const JSValue* v)
- {
- return reinterpret_cast<uintptr_t>(v) & ~TagMask;
- }
-
- static ALWAYS_INLINE uintptr_t getTag(const JSValue* v)
- {
- return reinterpret_cast<uintptr_t>(v) & TagMask;
- }
-};
-
-ALWAYS_INLINE JSValue* JSImmediate::trueImmediate() { return tag(1 << 2, BooleanType); }
-ALWAYS_INLINE JSValue* JSImmediate::falseImmediate() { return tag(0, BooleanType); }
-ALWAYS_INLINE JSValue* JSImmediate::undefinedImmediate() { return tag(1 << 2, UndefinedType); }
-ALWAYS_INLINE JSValue* JSImmediate::nullImmediate() { return tag(0, UndefinedType); }
-
-// This value is impossible because 0x4 is not a valid pointer but a tag of 0 would indicate non-immediate
-ALWAYS_INLINE JSValue* JSImmediate::impossibleValue() { return tag(1 << 2, 0); }
-
-ALWAYS_INLINE bool JSImmediate::toBoolean(const JSValue* v)
-{
- ASSERT(isImmediate(v));
- uintptr_t bits = unTag(v);
- return (bits != 0) & (JSImmediate::getTag(v) != UndefinedType);
-}
-
-ALWAYS_INLINE uint32_t JSImmediate::toTruncatedUInt32(const JSValue* v)
-{
- ASSERT(isImmediate(v));
- return static_cast<uint32_t>(reinterpret_cast<intptr_t>(v) >> 2);
-}
-
-ALWAYS_INLINE JSValue* JSImmediate::from(char i)
-{
- return tag(i << 2, NumberType);
-}
-
-ALWAYS_INLINE JSValue* JSImmediate::from(signed char i)
-{
- return tag(i << 2, NumberType);
-}
-
-ALWAYS_INLINE JSValue* JSImmediate::from(unsigned char i)
-{
- return tag(i << 2, NumberType);
-}
-
-ALWAYS_INLINE JSValue* JSImmediate::from(short i)
-{
- return tag(i << 2, NumberType);
-}
-
-ALWAYS_INLINE JSValue* JSImmediate::from(unsigned short i)
-{
- return tag(i << 2, NumberType);
-}
-
-ALWAYS_INLINE JSValue* JSImmediate::from(int i)
-{
- if ((i < minImmediateInt) | (i > maxImmediateInt))
- return 0;
- return tag(i << 2, NumberType);
-}
-
-ALWAYS_INLINE JSValue* JSImmediate::from(unsigned i)
-{
- if (i > maxImmediateUInt)
- return 0;
- return tag(i << 2, NumberType);
-}
-
-ALWAYS_INLINE JSValue* JSImmediate::from(long i)
-{
- if ((i < minImmediateInt) | (i > maxImmediateInt))
- return 0;
- return tag(i << 2, NumberType);
-}
-
-ALWAYS_INLINE JSValue* JSImmediate::from(unsigned long i)
-{
- if (i > maxImmediateUInt)
- return 0;
- return tag(i << 2, NumberType);
-}
-
-ALWAYS_INLINE JSValue* JSImmediate::from(long long i)
-{
- if ((i < minImmediateInt) | (i > maxImmediateInt))
- return 0;
- return tag(static_cast<uintptr_t>(i) << 2, NumberType);
-}
-
-ALWAYS_INLINE JSValue* JSImmediate::from(unsigned long long i)
-{
- if (i > maxImmediateUInt)
- return 0;
- return tag(static_cast<uintptr_t>(i) << 2, NumberType);
-}
-
-ALWAYS_INLINE JSValue* JSImmediate::from(double d)
-{
- const int intVal = static_cast<int>(d);
-
- if ((intVal < minImmediateInt) | (intVal > maxImmediateInt))
- return 0;
-
- // Check for data loss from conversion to int.
- if ((intVal != d) || (!intVal && signbit(d)))
- return 0;
-
- return tag(intVal << 2, NumberType);
-}
-
-ALWAYS_INLINE int32_t JSImmediate::getTruncatedInt32(const JSValue* v)
-{
- ASSERT(isNumber(v));
- return static_cast<int32_t>(unTag(v)) >> 2;
-}
-
-ALWAYS_INLINE double JSImmediate::toDouble(const JSValue* v)
-{
- ASSERT(isImmediate(v));
- const int32_t i = static_cast<int32_t>(unTag(v)) >> 2;
- if (JSImmediate::getTag(v) == UndefinedType && i)
- return std::numeric_limits<double>::quiet_NaN();
- return i;
-}
-
-ALWAYS_INLINE bool JSImmediate::getUInt32(const JSValue* v, uint32_t& i)
-{
- i = static_cast<uintptr_t>(unTag(v)) >> 2;
- return isPositiveNumber(v);
-}
-
-ALWAYS_INLINE bool JSImmediate::getTruncatedInt32(const JSValue* v, int32_t& i)
-{
- i = static_cast<int32_t>(unTag(v)) >> 2;
- return isNumber(v);
-}
-
-ALWAYS_INLINE bool JSImmediate::getTruncatedUInt32(const JSValue* v, uint32_t& i)
-{
- return getUInt32(v, i);
-}
-
-ALWAYS_INLINE JSType JSImmediate::type(const JSValue* v)
-{
- ASSERT(isImmediate(v));
-
- uintptr_t tag = getTag(v);
- if (tag == UndefinedType)
- return v == undefinedImmediate() ? UndefinedType : NullType;
- return static_cast<JSType>(tag);
-}
-
-ALWAYS_INLINE JSValue* jsUndefined()
-{
- return JSImmediate::undefinedImmediate();
-}
-
-inline JSValue* jsNull()
-{
- return JSImmediate::nullImmediate();
-}
-
-inline JSValue* jsBoolean(bool b)
-{
- return b ? JSImmediate::trueImmediate() : JSImmediate::falseImmediate();
-}
-
} // namespace KJS
#endif
diff --git a/JavaScriptCore/kjs/JSLock.cpp b/JavaScriptCore/kjs/JSLock.cpp
index 78b160c..e27a720 100644
--- a/JavaScriptCore/kjs/JSLock.cpp
+++ b/JavaScriptCore/kjs/JSLock.cpp
@@ -1,7 +1,5 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
- * This file is part of the KDE libraries
- * Copyright (C) 2005 Apple Computer, Inc.
+ * Copyright (C) 2005, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -210,4 +208,4 @@
#endif // USE(MULTIPLE_THREADS)
-}
+} // namespace KJS
diff --git a/JavaScriptCore/kjs/JSLock.h b/JavaScriptCore/kjs/JSLock.h
index 532abf0..c152363 100644
--- a/JavaScriptCore/kjs/JSLock.h
+++ b/JavaScriptCore/kjs/JSLock.h
@@ -1,7 +1,5 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
- * This file is part of the KDE libraries
- * Copyright (C) 2005 Apple Computer, Inc.
+ * Copyright (C) 2005, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -54,7 +52,7 @@
class JSLock : Noncopyable {
public:
- JSLock(ExecState* exec);
+ JSLock(ExecState*);
JSLock(bool lockingForReal)
: m_lockingForReal(lockingForReal)
diff --git a/JavaScriptCore/kjs/JSNotAnObject.h b/JavaScriptCore/kjs/JSNotAnObject.h
index 3abd83f..8d82dff 100644
--- a/JavaScriptCore/kjs/JSNotAnObject.h
+++ b/JavaScriptCore/kjs/JSNotAnObject.h
@@ -44,7 +44,7 @@
}
private:
- // JSValue methods
+ // JSValue methods
virtual JSValue* toPrimitive(ExecState*, JSType preferredType = UnspecifiedType) const;
virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*&);
virtual bool toBoolean(ExecState*) const;
diff --git a/JavaScriptCore/kjs/JSNumberCell.cpp b/JavaScriptCore/kjs/JSNumberCell.cpp
index cf06c68..144be1c 100644
--- a/JavaScriptCore/kjs/JSNumberCell.cpp
+++ b/JavaScriptCore/kjs/JSNumberCell.cpp
@@ -41,33 +41,33 @@
bool JSNumberCell::getPrimitiveNumber(ExecState*, double& number, JSValue*& value)
{
- number = val;
+ number = m_value;
value = this;
return true;
}
-bool JSNumberCell::toBoolean(ExecState *) const
+bool JSNumberCell::toBoolean(ExecState*) const
{
- return val < 0.0 || val > 0.0; // false for NaN
+ return m_value < 0.0 || m_value > 0.0; // false for NaN
}
-double JSNumberCell::toNumber(ExecState *) const
+double JSNumberCell::toNumber(ExecState*) const
{
- return val;
+ return m_value;
}
UString JSNumberCell::toString(ExecState*) const
{
- if (val == 0.0) // +0.0 or -0.0
+ if (m_value == 0.0) // +0.0 or -0.0
return "0";
- return UString::from(val);
+ return UString::from(m_value);
}
UString JSNumberCell::toThisString(ExecState*) const
{
- if (val == 0.0) // +0.0 or -0.0
+ if (m_value == 0.0) // +0.0 or -0.0
return "0";
- return UString::from(val);
+ return UString::from(m_value);
}
JSObject* JSNumberCell::toObject(ExecState* exec) const
@@ -82,23 +82,23 @@
bool JSNumberCell::getUInt32(uint32_t& uint32) const
{
- uint32 = static_cast<uint32_t>(val);
- return uint32 == val;
+ uint32 = static_cast<uint32_t>(m_value);
+ return uint32 == m_value;
}
bool JSNumberCell::getTruncatedInt32(int32_t& int32) const
{
- if (!(val >= -2147483648.0 && val < 2147483648.0))
+ if (!(m_value >= -2147483648.0 && m_value < 2147483648.0))
return false;
- int32 = static_cast<int32_t>(val);
+ int32 = static_cast<int32_t>(m_value);
return true;
}
bool JSNumberCell::getTruncatedUInt32(uint32_t& uint32) const
{
- if (!(val >= 0.0 && val < 4294967296.0))
+ if (!(m_value >= 0.0 && m_value < 4294967296.0))
return false;
- uint32 = static_cast<uint32_t>(val);
+ uint32 = static_cast<uint32_t>(m_value);
return true;
}
diff --git a/JavaScriptCore/kjs/JSNumberCell.h b/JavaScriptCore/kjs/JSNumberCell.h
index 677c1e4..a66bd31 100644
--- a/JavaScriptCore/kjs/JSNumberCell.h
+++ b/JavaScriptCore/kjs/JSNumberCell.h
@@ -34,127 +34,125 @@
namespace KJS {
-class ExecState;
-class Identifier;
-class JSCell;
-class JSObject;
-class JSString;
-class PropertySlot;
+ class ExecState;
+ class Identifier;
+ class JSCell;
+ class JSObject;
+ class JSString;
+ class PropertySlot;
-struct ClassInfo;
-struct Instruction;
+ struct ClassInfo;
+ struct Instruction;
-class JSNumberCell : public JSCell {
- friend JSValue* jsNumberCell(ExecState*, double);
-public:
- double value() const { return val; }
+ class JSNumberCell : public JSCell {
+ friend JSValue* jsNumberCell(ExecState*, double);
+ public:
+ double value() const { return m_value; }
- virtual JSType type() const;
+ virtual JSType type() const;
- virtual JSValue* toPrimitive(ExecState*, JSType preferred = UnspecifiedType) const;
- virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
- virtual bool toBoolean(ExecState*) const;
- virtual double toNumber(ExecState*) const;
- virtual UString toString(ExecState*) const;
- virtual JSObject* toObject(ExecState*) const;
+ virtual JSValue* toPrimitive(ExecState*, JSType preferred = UnspecifiedType) const;
+ virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
+ virtual bool toBoolean(ExecState*) const;
+ virtual double toNumber(ExecState*) const;
+ virtual UString toString(ExecState*) const;
+ virtual JSObject* toObject(ExecState*) const;
- virtual UString toThisString(ExecState*) const;
- virtual JSObject* toThisObject(ExecState*) const;
- virtual JSValue* getJSNumber();
+ virtual UString toThisString(ExecState*) const;
+ virtual JSObject* toThisObject(ExecState*) const;
+ virtual JSValue* getJSNumber();
- void* operator new(size_t size, ExecState* exec)
+ void* operator new(size_t size, ExecState* exec)
+ {
+ #ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
+ return exec->heap()->inlineAllocateNumber(size);
+ #else
+ return exec->heap()->allocateNumber(size);
+ #endif
+ }
+
+ private:
+ JSNumberCell(double value)
+ : m_value(value)
+ {
+ }
+
+ virtual bool getUInt32(uint32_t&) const;
+ virtual bool getTruncatedInt32(int32_t&) const;
+ virtual bool getTruncatedUInt32(uint32_t&) const;
+
+ double m_value;
+ };
+
+ extern const double NaN;
+ extern const double Inf;
+
+ // Beware marking this function ALWAYS_INLINE: It takes a PIC branch, so
+ // inlining it may not always be a win.
+ inline JSValue* jsNumberCell(ExecState* exec, double d)
{
-#ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
- return exec->heap()->inlineAllocateNumber(size);
-#else
- return exec->heap()->allocateNumber(size);
-#endif
+ return new (exec) JSNumberCell(d);
}
-private:
- JSNumberCell(double v)
- : val(v)
+ inline JSValue* jsNaN(ExecState* exec)
{
+ return jsNumberCell(exec, NaN);
}
- virtual bool getUInt32(uint32_t&) const;
- virtual bool getTruncatedInt32(int32_t&) const;
- virtual bool getTruncatedUInt32(uint32_t&) const;
+ ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, double d)
+ {
+ JSValue* v = JSImmediate::from(d);
+ return v ? v : jsNumberCell(exec, d);
+ }
- double val;
-};
+ ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, int i)
+ {
+ JSValue* v = JSImmediate::from(i);
+ return v ? v : jsNumberCell(exec, i);
+ }
-extern const double NaN;
-extern const double Inf;
+ ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, unsigned i)
+ {
+ JSValue* v = JSImmediate::from(i);
+ return v ? v : jsNumberCell(exec, i);
+ }
-// Beware marking this function ALWAYS_INLINE: It takes a PIC branch, so
-// inlining it may not always be a win.
-inline JSValue* jsNumberCell(ExecState* exec, double d)
-{
- return new (exec) JSNumberCell(d);
-}
+ ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, long i)
+ {
+ JSValue* v = JSImmediate::from(i);
+ return v ? v : jsNumberCell(exec, i);
+ }
-inline JSValue* jsNaN(ExecState* exec)
-{
- return jsNumberCell(exec, NaN);
-}
+ ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, unsigned long i)
+ {
+ JSValue* v = JSImmediate::from(i);
+ return v ? v : jsNumberCell(exec, i);
+ }
-ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, double d)
-{
- JSValue* v = JSImmediate::from(d);
- return v ? v : jsNumberCell(exec, d);
-}
+ ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, long long i)
+ {
+ JSValue* v = JSImmediate::from(i);
+ return v ? v : jsNumberCell(exec, static_cast<double>(i));
+ }
-ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, int i)
-{
- JSValue* v = JSImmediate::from(i);
- return v ? v : jsNumberCell(exec, i);
-}
+ ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, unsigned long long i)
+ {
+ JSValue* v = JSImmediate::from(i);
+ return v ? v : jsNumberCell(exec, static_cast<double>(i));
+ }
-ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, unsigned i)
-{
- JSValue* v = JSImmediate::from(i);
- return v ? v : jsNumberCell(exec, i);
-}
+ // --- JSValue inlines ----------------------------
-ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, long i)
-{
- JSValue* v = JSImmediate::from(i);
- return v ? v : jsNumberCell(exec, i);
-}
+ inline double JSValue::uncheckedGetNumber() const
+ {
+ ASSERT(JSImmediate::isImmediate(this) || asCell()->isNumber());
+ return JSImmediate::isImmediate(this) ? JSImmediate::toDouble(this) : static_cast<const JSNumberCell*>(this)->value();
+ }
-ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, unsigned long i)
-{
- JSValue* v = JSImmediate::from(i);
- return v ? v : jsNumberCell(exec, i);
-}
-
-ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, long long i)
-{
- JSValue* v = JSImmediate::from(i);
- return v ? v : jsNumberCell(exec, static_cast<double>(i));
-}
-
-ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, unsigned long long i)
-{
- JSValue* v = JSImmediate::from(i);
- return v ? v : jsNumberCell(exec, static_cast<double>(i));
-}
-
-// --- JSValue inlines ----------------------------
-
-inline double JSValue::uncheckedGetNumber() const
-{
- ASSERT(JSImmediate::isImmediate(this) || asCell()->isNumber());
- return JSImmediate::isImmediate(this) ? JSImmediate::toDouble(this) : static_cast<const JSNumberCell*>(this)->value();
-}
-
-ALWAYS_INLINE JSValue* JSValue::toJSNumber(ExecState* exec) const
-{
- return JSImmediate::isNumber(this) ? const_cast<JSValue*>(this) : jsNumber(exec, this->toNumber(exec));
-}
-
-// -------
+ ALWAYS_INLINE JSValue* JSValue::toJSNumber(ExecState* exec) const
+ {
+ return JSImmediate::isNumber(this) ? const_cast<JSValue*>(this) : jsNumber(exec, this->toNumber(exec));
+ }
} // namespace KJS
diff --git a/JavaScriptCore/kjs/JSObject.cpp b/JavaScriptCore/kjs/JSObject.cpp
index 904113c..a49922b 100644
--- a/JavaScriptCore/kjs/JSObject.cpp
+++ b/JavaScriptCore/kjs/JSObject.cpp
@@ -44,118 +44,117 @@
void JSObject::mark()
{
- JSCell::mark();
+ JSCell::mark();
#if JAVASCRIPT_MARK_TRACING
- static int markStackDepth = 0;
- markStackDepth++;
- for (int i = 0; i < markStackDepth; i++)
- putchar('-');
-
- printf("%s (%p)\n", className().UTF8String().c_str(), this);
+ static int markStackDepth = 0;
+ markStackDepth++;
+ for (int i = 0; i < markStackDepth; i++)
+ putchar('-');
+ printf("%s (%p)\n", className().UTF8String().c_str(), this);
#endif
-
- JSValue *proto = _proto;
- if (!proto->marked())
- proto->mark();
- _prop.mark();
-
+ JSValue* prototype = m_prototype;
+ if (!prototype->marked())
+ prototype->mark();
+
+ m_propertyMap.mark();
+
#if JAVASCRIPT_MARK_TRACING
- markStackDepth--;
+ markStackDepth--;
#endif
}
JSType JSObject::type() const
{
- return ObjectType;
+ return ObjectType;
}
UString JSObject::className() const
{
- const ClassInfo *ci = classInfo();
- if ( ci )
- return ci->className;
- return "Object";
+ const ClassInfo* info = classInfo();
+ if (info)
+ return info->className;
+ return "Object";
}
-bool JSObject::getOwnPropertySlot(ExecState *exec, unsigned propertyName, PropertySlot& slot)
+bool JSObject::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
{
- return getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);
+ return getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);
}
-static void throwSetterError(ExecState *exec)
+static void throwSetterError(ExecState* exec)
{
- throwError(exec, TypeError, "setting a property that has only a getter");
+ throwError(exec, TypeError, "setting a property that has only a getter");
}
// ECMA 8.6.2.2
void JSObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value)
{
- ASSERT(value);
- ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
+ ASSERT(value);
+ ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
- if (propertyName == exec->propertyNames().underscoreProto) {
- JSObject* proto = value->getObject();
+ if (propertyName == exec->propertyNames().underscoreProto) {
+ JSObject* proto = value->getObject();
- // Setting __proto__ to a non-object, non-null value is silently ignored to match Mozilla.
- if (!proto && value != jsNull())
- return;
-
- while (proto) {
- if (proto == this) {
- throwError(exec, GeneralError, "cyclic __proto__ value");
+ // Setting __proto__ to a non-object, non-null value is silently ignored to match Mozilla.
+ if (!proto && value != jsNull())
+ return;
+
+ while (proto) {
+ if (proto == this) {
+ throwError(exec, GeneralError, "cyclic __proto__ value");
+ return;
+ }
+ proto = proto->prototype() ? proto->prototype()->getObject() : 0;
+ }
+
+ setPrototype(value);
return;
- }
- proto = proto->prototype() ? proto->prototype()->getObject() : 0;
}
-
- setPrototype(value);
- return;
- }
-
- // Check if there are any setters or getters in the prototype chain
- JSValue* prototype;
- for (JSObject* obj = this; !obj->_prop.hasGetterSetterProperties(); obj = static_cast<JSObject*>(prototype)) {
- prototype = obj->_proto;
- if (prototype == jsNull()) {
- _prop.put(propertyName, value, 0, true);
- return;
+
+ // Check if there are any setters or getters in the prototype chain
+ JSValue* prototype;
+ for (JSObject* obj = this; !obj->m_propertyMap.hasGetterSetterProperties(); obj = static_cast<JSObject*>(prototype)) {
+ prototype = obj->m_prototype;
+ if (prototype == jsNull()) {
+ m_propertyMap.put(propertyName, value, 0, true);
+ return;
+ }
}
- }
+
+ unsigned attributes;
+ if (m_propertyMap.get(propertyName, attributes) && attributes & ReadOnly)
+ return;
- unsigned attributes;
- if (_prop.get(propertyName, attributes) && attributes & ReadOnly)
- return;
+ for (JSObject* obj = this; ; obj = static_cast<JSObject*>(prototype)) {
+ if (JSValue* gs = obj->m_propertyMap.get(propertyName, attributes)) {
+ if (attributes & IsGetterSetter) {
+ JSObject* setterFunc = static_cast<GetterSetter*>(gs)->setter();
+ if (!setterFunc) {
+ throwSetterError(exec);
+ return;
+ }
+
+ CallData callData;
+ CallType callType = setterFunc->getCallData(callData);
+ ArgList args;
+ args.append(value);
+ call(exec, setterFunc, callType, callData, this, args);
+ return;
+ }
- for (JSObject* obj = this; ; obj = static_cast<JSObject*>(prototype)) {
- if (JSValue* gs = obj->_prop.get(propertyName, attributes)) {
- if (attributes & IsGetterSetter) {
- JSObject* setterFunc = static_cast<GetterSetter*>(gs)->setter();
- if (!setterFunc) {
- throwSetterError(exec);
- return;
+ // If there's an existing property on the object or one of its
+ // prototypes it should be replaced, so break here.
+ break;
}
- CallData callData;
- CallType callType = setterFunc->getCallData(callData);
- ArgList args;
- args.append(value);
- call(exec, setterFunc, callType, callData, this, args);
- return;
- }
-
- // If there's an existing property on the object or one of its
- // prototypes it should be replaced, so break here.
- break;
+ prototype = obj->m_prototype;
+ if (prototype == jsNull())
+ break;
}
-
- prototype = obj->_proto;
- if (prototype == jsNull())
- break;
- }
-
- _prop.put(propertyName, value, 0, true);
+
+ m_propertyMap.put(propertyName, value, 0, true);
}
void JSObject::put(ExecState* exec, unsigned propertyName, JSValue* value)
@@ -173,38 +172,39 @@
putWithAttributes(exec, Identifier::from(exec, propertyName), value, attributes);
}
-bool JSObject::hasProperty(ExecState *exec, const Identifier &propertyName) const
+bool JSObject::hasProperty(ExecState* exec, const Identifier& propertyName) const
{
- PropertySlot slot;
- return const_cast<JSObject *>(this)->getPropertySlot(exec, propertyName, slot);
+ PropertySlot slot;
+ return const_cast<JSObject*>(this)->getPropertySlot(exec, propertyName, slot);
}
-bool JSObject::hasProperty(ExecState *exec, unsigned propertyName) const
+bool JSObject::hasProperty(ExecState* exec, unsigned propertyName) const
{
- PropertySlot slot;
- return const_cast<JSObject *>(this)->getPropertySlot(exec, propertyName, slot);
+ PropertySlot slot;
+ return const_cast<JSObject*>(this)->getPropertySlot(exec, propertyName, slot);
}
// ECMA 8.6.2.5
-bool JSObject::deleteProperty(ExecState* exec, const Identifier &propertyName)
+bool JSObject::deleteProperty(ExecState* exec, const Identifier& propertyName)
{
- unsigned attributes;
- JSValue *v = _prop.get(propertyName, attributes);
- if (v) {
- if ((attributes & DontDelete))
- return false;
- _prop.remove(propertyName);
- if (attributes & IsGetterSetter)
- _prop.setHasGetterSetterProperties(_prop.containsGettersOrSetters());
- return true;
- }
+ unsigned attributes;
+ JSValue* v = m_propertyMap.get(propertyName, attributes);
+ if (v) {
+ if ((attributes & DontDelete))
+ return false;
+ m_propertyMap.remove(propertyName);
+ if (attributes & IsGetterSetter)
+ m_propertyMap.setHasGetterSetterProperties(m_propertyMap.containsGettersOrSetters());
+ return true;
+ }
+
+ // Look in the static hashtable of properties
+ const HashEntry* entry = findPropertyHashEntry(exec, propertyName);
+ if (entry && entry->attributes & DontDelete)
+ return false; // this builtin property can't be deleted
- // Look in the static hashtable of properties
- const HashEntry* entry = findPropertyHashEntry(exec, propertyName);
- if (entry && entry->attributes & DontDelete)
- return false; // this builtin property can't be deleted
- // FIXME: Should the code here actually do some deletion?
- return true;
+ // FIXME: Should the code here actually do some deletion?
+ return true;
}
bool JSObject::hasOwnProperty(ExecState* exec, const Identifier& propertyName) const
@@ -213,9 +213,9 @@
return const_cast<JSObject*>(this)->getOwnPropertySlot(exec, propertyName, slot);
}
-bool JSObject::deleteProperty(ExecState *exec, unsigned propertyName)
+bool JSObject::deleteProperty(ExecState* exec, unsigned propertyName)
{
- return deleteProperty(exec, Identifier::from(exec, propertyName));
+ return deleteProperty(exec, Identifier::from(exec, propertyName));
}
static ALWAYS_INLINE JSValue* callDefaultValueFunction(ExecState* exec, const JSObject* object, const Identifier& propertyName)
@@ -251,7 +251,7 @@
JSValue* JSObject::defaultValue(ExecState* exec, JSType hint) const
{
// Must call toString first for Date objects.
- if ((hint == StringType) || (hint != NumberType && _proto == exec->lexicalGlobalObject()->datePrototype())) {
+ if ((hint == StringType) || (hint != NumberType && m_prototype == exec->lexicalGlobalObject()->datePrototype())) {
if (JSValue* value = callDefaultValueFunction(exec, this, exec->propertyNames().toString))
return value;
if (JSValue* value = callDefaultValueFunction(exec, this, exec->propertyNames().valueOf))
@@ -272,88 +272,86 @@
{
for (const ClassInfo* info = classInfo(); info; info = info->parentClass) {
if (const HashTable* propHashTable = info->propHashTable(exec)) {
- if (const HashEntry* e = propHashTable->entry(exec, propertyName))
- return e;
+ if (const HashEntry* entry = propHashTable->entry(exec, propertyName))
+ return entry;
}
}
return 0;
}
-void JSObject::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunc)
+void JSObject::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunction)
{
- JSValue *o = getDirect(propertyName);
- GetterSetter *gs;
-
- if (o && o->type() == GetterSetterType) {
- gs = static_cast<GetterSetter *>(o);
- } else {
- gs = new (exec) GetterSetter;
- putDirect(propertyName, gs, IsGetterSetter);
+ JSValue* object = getDirect(propertyName);
+ GetterSetter* getterSetter;
+ if (object && object->type() == GetterSetterType)
+ getterSetter = static_cast<GetterSetter*>(object);
+ else {
+ getterSetter = new (exec) GetterSetter;
+ putDirect(propertyName, getterSetter, IsGetterSetter);
}
-
- _prop.setHasGetterSetterProperties(true);
- gs->setGetter(getterFunc);
+
+ m_propertyMap.setHasGetterSetterProperties(true);
+ getterSetter->setGetter(getterFunction);
}
-void JSObject::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunc)
+void JSObject::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunction)
{
- JSValue *o = getDirect(propertyName);
- GetterSetter *gs;
-
- if (o && o->type() == GetterSetterType) {
- gs = static_cast<GetterSetter *>(o);
- } else {
- gs = new (exec) GetterSetter;
- putDirect(propertyName, gs, IsGetterSetter);
+ JSValue* object = getDirect(propertyName);
+ GetterSetter* getterSetter;
+ if (object && object->type() == GetterSetterType)
+ getterSetter = static_cast<GetterSetter*>(object);
+ else {
+ getterSetter = new (exec) GetterSetter;
+ putDirect(propertyName, getterSetter, IsGetterSetter);
}
- _prop.setHasGetterSetterProperties(true);
- gs->setSetter(setterFunc);
+ m_propertyMap.setHasGetterSetterProperties(true);
+ getterSetter->setSetter(setterFunction);
}
JSValue* JSObject::lookupGetter(ExecState*, const Identifier& propertyName)
{
- JSObject* obj = this;
+ JSObject* object = this;
while (true) {
- JSValue* v = obj->getDirect(propertyName);
- if (v) {
- if (v->type() != GetterSetterType)
+ JSValue* value = object->getDirect(propertyName);
+ if (value) {
+ if (value->type() != GetterSetterType)
return jsUndefined();
- JSObject* funcObj = static_cast<GetterSetter*>(v)->getter();
- if (!funcObj)
+ JSObject* functionObject = static_cast<GetterSetter*>(value)->getter();
+ if (!functionObject)
return jsUndefined();
- return funcObj;
+ return functionObject;
}
- if (!obj->prototype() || !obj->prototype()->isObject())
+ if (!object->prototype() || !object->prototype()->isObject())
return jsUndefined();
- obj = static_cast<JSObject*>(obj->prototype());
+ object = static_cast<JSObject*>(object->prototype());
}
}
JSValue* JSObject::lookupSetter(ExecState*, const Identifier& propertyName)
{
- JSObject* obj = this;
+ JSObject* object = this;
while (true) {
- JSValue* v = obj->getDirect(propertyName);
- if (v) {
- if (v->type() != GetterSetterType)
+ JSValue* value = object->getDirect(propertyName);
+ if (value) {
+ if (value->type() != GetterSetterType)
return jsUndefined();
- JSObject* funcObj = static_cast<GetterSetter*>(v)->setter();
- if (!funcObj)
+ JSObject* functionObject = static_cast<GetterSetter*>(value)->setter();
+ if (!functionObject)
return jsUndefined();
- return funcObj;
+ return functionObject;
}
- if (!obj->prototype() || !obj->prototype()->isObject())
+ if (!object->prototype() || !object->prototype()->isObject())
return jsUndefined();
- obj = static_cast<JSObject*>(obj->prototype());
+ object = static_cast<JSObject*>(object->prototype());
}
}
bool JSObject::implementsHasInstance() const
{
- return false;
+ return false;
}
bool JSObject::hasInstance(ExecState* exec, JSValue* value)
@@ -363,13 +361,13 @@
throwError(exec, TypeError, "instanceof called on an object with an invalid prototype property.");
return false;
}
-
+
if (!value->isObject())
return false;
-
- JSObject* o = static_cast<JSObject*>(value);
- while ((o = o->prototype()->getObject())) {
- if (o == proto)
+
+ JSObject* object = static_cast<JSObject*>(value);
+ while ((object = object->prototype()->getObject())) {
+ if (object == proto)
return true;
}
return false;
@@ -377,32 +375,30 @@
bool JSObject::propertyIsEnumerable(ExecState* exec, const Identifier& propertyName) const
{
- unsigned attributes;
-
- if (!getPropertyAttributes(exec, propertyName, attributes))
- return false;
- else
+ unsigned attributes;
+ if (!getPropertyAttributes(exec, propertyName, attributes))
+ return false;
return !(attributes & DontEnum);
}
bool JSObject::getPropertyAttributes(ExecState* exec, const Identifier& propertyName, unsigned& attributes) const
{
- if (_prop.get(propertyName, attributes))
- return true;
+ if (m_propertyMap.get(propertyName, attributes))
+ return true;
- // Look in the static hashtable of properties
- const HashEntry* e = findPropertyHashEntry(exec, propertyName);
- if (e) {
- attributes = e->attributes;
- return true;
- }
+ // Look in the static hashtable of properties
+ const HashEntry* entry = findPropertyHashEntry(exec, propertyName);
+ if (entry) {
+ attributes = entry->attributes;
+ return true;
+ }
- return false;
+ return false;
}
void JSObject::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
{
- _prop.getEnumerablePropertyNames(propertyNames);
+ m_propertyMap.getEnumerablePropertyNames(propertyNames);
// Add properties from the static hashtables of properties
for (const ClassInfo* info = classInfo(); info; info = info->parentClass) {
@@ -412,28 +408,28 @@
table->initializeIfNeeded(exec);
ASSERT(table->table);
int hashSizeMask = table->hashSizeMask;
- const HashEntry* e = table->table;
- for (int i = 0; i <= hashSizeMask; ++i, ++e) {
- if (e->key && !(e->attributes & DontEnum))
- propertyNames.add(e->key);
+ const HashEntry* entry = table->table;
+ for (int i = 0; i <= hashSizeMask; ++i, ++entry) {
+ if (entry->key && !(entry->attributes & DontEnum))
+ propertyNames.add(entry->key);
}
}
- if (_proto->isObject())
- static_cast<JSObject*>(_proto)->getPropertyNames(exec, propertyNames);
+ if (m_prototype->isObject())
+ static_cast<JSObject*>(m_prototype)->getPropertyNames(exec, propertyNames);
}
bool JSObject::toBoolean(ExecState*) const
{
- return true;
+ return true;
}
-double JSObject::toNumber(ExecState *exec) const
+double JSObject::toNumber(ExecState* exec) const
{
- JSValue *prim = toPrimitive(exec,NumberType);
- if (exec->hadException()) // should be picked up soon in nodes.cpp
- return 0.0;
- return prim->toNumber(exec);
+ JSValue* primitive = toPrimitive(exec, NumberType);
+ if (exec->hadException()) // should be picked up soon in nodes.cpp
+ return 0.0;
+ return primitive->toNumber(exec);
}
UString JSObject::toString(ExecState* exec) const
@@ -444,9 +440,9 @@
return primitive->toString(exec);
}
-JSObject *JSObject::toObject(ExecState*) const
+JSObject* JSObject::toObject(ExecState*) const
{
- return const_cast<JSObject*>(this);
+ return const_cast<JSObject*>(this);
}
JSObject* JSObject::toThisObject(ExecState*) const
@@ -459,20 +455,20 @@
return 0;
}
-void JSObject::removeDirect(const Identifier &propertyName)
+void JSObject::removeDirect(const Identifier& propertyName)
{
- _prop.remove(propertyName);
+ m_propertyMap.remove(propertyName);
}
-void JSObject::putDirectFunction(InternalFunction* func, int attr)
+void JSObject::putDirectFunction(InternalFunction* function, unsigned attr)
{
- putDirect(func->functionName(), func, attr);
+ putDirect(function->functionName(), function, attr);
}
void JSObject::fillGetterPropertySlot(PropertySlot& slot, JSValue** location)
{
- if (JSObject* getterFunc = static_cast<GetterSetter*>(*location)->getter())
- slot.setGetterSlot(getterFunc);
+ if (JSObject* getterFunction = static_cast<GetterSetter*>(*location)->getter())
+ slot.setGetterSlot(getterFunction);
else
slot.setUndefined();
}
diff --git a/JavaScriptCore/kjs/JSObject.h b/JavaScriptCore/kjs/JSObject.h
index 46d98d3..151410f 100644
--- a/JavaScriptCore/kjs/JSObject.h
+++ b/JavaScriptCore/kjs/JSObject.h
@@ -35,327 +35,326 @@
namespace KJS {
- class InternalFunction;
- class PropertyNameArray;
- struct HashEntry;
- struct HashTable;
+ class InternalFunction;
+ class PropertyNameArray;
+ struct HashEntry;
+ struct HashTable;
- // ECMA 262-3 8.6.1
- // Property attributes
- enum Attribute { None = 0,
- ReadOnly = 1 << 1, // property can be only read, not written
- DontEnum = 1 << 2, // property doesn't appear in (for .. in ..)
- DontDelete = 1 << 3, // property can't be deleted
- Function = 1 << 4, // property is a function - only used by static hashtables
- IsGetterSetter = 1 << 5 }; // property is a getter or setter
+ // ECMA 262-3 8.6.1
+ // Property attributes
+ enum Attribute {
+ None = 0,
+ ReadOnly = 1 << 1, // property can be only read, not written
+ DontEnum = 1 << 2, // property doesn't appear in (for .. in ..)
+ DontDelete = 1 << 3, // property can't be deleted
+ Function = 1 << 4, // property is a function - only used by static hashtables
+ IsGetterSetter = 1 << 5 // property is a getter or setter
+ };
- class JSObject : public JSCell {
- public:
- /**
- * Creates a new JSObject with the specified prototype
- *
- * @param proto The prototype
- */
- JSObject(JSValue* proto);
+ class JSObject : public JSCell {
+ public:
+ /**
+ * Creates a new JSObject with the specified prototype
+ *
+ * @param prototype The prototype
+ */
+ JSObject(JSValue* prototype);
- /**
- * Creates a new JSObject with a prototype of jsNull()
- * (that is, the ECMAScript "null" value, not a null object pointer).
- */
- JSObject();
-
- virtual void mark();
- virtual JSType type() const;
+ /**
+ * Creates a new JSObject with a prototype of jsNull()
+ * (that is, the ECMAScript "null" value, not a null object pointer).
+ */
+ JSObject();
- /**
- * A pointer to a ClassInfo struct for this class. This provides a basic
- * facility for run-time type information, and can be used to check an
- * object's class an inheritance (see inherits()). This should
- * always return a statically declared pointer, or 0 to indicate that
- * there is no class information.
- *
- * This is primarily useful if you have application-defined classes that you
- * wish to check against for casting purposes.
- *
- * For example, to specify the class info for classes FooImp and BarImp,
- * where FooImp inherits from BarImp, you would add the following in your
- * class declarations:
- *
- * \code
- * class BarImp : public JSObject {
- * virtual const ClassInfo *classInfo() const { return &info; }
- * static const ClassInfo info;
- * // ...
- * };
- *
- * class FooImp : public JSObject {
- * virtual const ClassInfo *classInfo() const { return &info; }
- * static const ClassInfo info;
- * // ...
- * };
- * \endcode
- *
- * And in your source file:
- *
- * \code
- * const ClassInfo BarImp::info = { "Bar", 0, 0, 0 }; // no parent class
- * const ClassInfo FooImp::info = { "Foo", &BarImp::info, 0, 0 };
- * \endcode
- *
- * @see inherits()
- */
+ virtual void mark();
+ virtual JSType type() const;
- /**
- * Checks whether this object inherits from the class with the specified
- * classInfo() pointer. This requires that both this class and the other
- * class return a non-NULL pointer for their classInfo() methods (otherwise
- * it will return false).
- *
- * For example, for two JSObject pointers obj1 and obj2, you can check
- * if obj1's class inherits from obj2's class using the following:
- *
- * if (obj1->inherits(obj2->classInfo())) {
- * // ...
- * }
- *
- * If you have a handle to a statically declared ClassInfo, such as in the
- * classInfo() example, you can check for inheritance without needing
- * an instance of the other class:
- *
- * if (obj1->inherits(FooImp::info)) {
- * // ...
- * }
- *
- * @param cinfo The ClassInfo pointer for the class you want to check
- * inheritance against.
- * @return true if this object's class inherits from class with the
- * ClassInfo pointer specified in cinfo
- */
- bool inherits(const ClassInfo* classInfo) const { return isObject(classInfo); } // FIXME: Merge with isObject.
+ /**
+ * A pointer to a ClassInfo struct for this class. This provides a basic
+ * facility for run-time type information, and can be used to check an
+ * object's class an inheritance (see inherits()). This should
+ * always return a statically declared pointer, or 0 to indicate that
+ * there is no class information.
+ *
+ * This is primarily useful if you have application-defined classes that you
+ * wish to check against for casting purposes.
+ *
+ * For example, to specify the class info for classes FooImp and BarImp,
+ * where FooImp inherits from BarImp, you would add the following in your
+ * class declarations:
+ *
+ * \code
+ * class BarImp : public JSObject {
+ * virtual const ClassInfo *classInfo() const { return &info; }
+ * static const ClassInfo info;
+ * // ...
+ * };
+ *
+ * class FooImp : public JSObject {
+ * virtual const ClassInfo *classInfo() const { return &info; }
+ * static const ClassInfo info;
+ * // ...
+ * };
+ * \endcode
+ *
+ * And in your source file:
+ *
+ * \code
+ * const ClassInfo BarImp::info = { "Bar", 0, 0, 0 }; // no parent class
+ * const ClassInfo FooImp::info = { "Foo", &BarImp::info, 0, 0 };
+ * \endcode
+ *
+ * @see inherits()
+ */
- // internal properties (ECMA 262-3 8.6.2)
+ /**
+ * Checks whether this object inherits from the class with the specified
+ * classInfo() pointer. This requires that both this class and the other
+ * class return a non-NULL pointer for their classInfo() methods (otherwise
+ * it will return false).
+ *
+ * For example, for two JSObject pointers obj1 and obj2, you can check
+ * if obj1's class inherits from obj2's class using the following:
+ *
+ * if (obj1->inherits(obj2->classInfo())) {
+ * // ...
+ * }
+ *
+ * If you have a handle to a statically declared ClassInfo, such as in the
+ * classInfo() example, you can check for inheritance without needing
+ * an instance of the other class:
+ *
+ * if (obj1->inherits(FooImp::info)) {
+ * // ...
+ * }
+ *
+ * @param cinfo The ClassInfo pointer for the class you want to check
+ * inheritance against.
+ * @return true if this object's class inherits from class with the
+ * ClassInfo pointer specified in cinfo
+ */
+ bool inherits(const ClassInfo* classInfo) const { return isObject(classInfo); } // FIXME: Merge with isObject.
- /**
- * Returns the prototype of this object. Note that this is not the same as
- * the "prototype" property.
- *
- * See ECMA 8.6.2
- *
- * @return The object's prototype
- */
- JSValue *prototype() const;
- void setPrototype(JSValue *proto);
+ // internal properties (ECMA 262-3 8.6.2)
- /**
- * Returns the class name of the object
- *
- * See ECMA 8.6.2
- *
- * @return The object's class name
- */
- /**
- * Implementation of the [[Class]] internal property (implemented by all
- * Objects)
- *
- * The default implementation uses classInfo().
- * You should either implement classInfo(), or
- * if you simply need a classname, you can reimplement className()
- * instead.
- */
- virtual UString className() const;
+ /**
+ * Returns the prototype of this object. Note that this is not the same as
+ * the "prototype" property.
+ *
+ * See ECMA 8.6.2
+ *
+ * @return The object's prototype
+ */
+ JSValue* prototype() const;
+ void setPrototype(JSValue* prototype);
- /**
- * Retrieves the specified property from the object. If neither the object
- * or any other object in its prototype chain have the property, this
- * function will return Undefined.
- *
- * See ECMA 8.6.2.1
- *
- * @param exec The current execution state
- * @param propertyName The name of the property to retrieve
- *
- * @return The specified property, or Undefined
- */
- JSValue* get(ExecState* exec, const Identifier& propertyName) const;
- JSValue* get(ExecState* exec, unsigned propertyName) const;
+ /**
+ * Returns the class name of the object
+ *
+ * See ECMA 8.6.2
+ *
+ * @return The object's class name
+ */
+ /**
+ * Implementation of the [[Class]] internal property (implemented by all
+ * Objects)
+ *
+ * The default implementation uses classInfo().
+ * You should either implement classInfo(), or
+ * if you simply need a classname, you can reimplement className()
+ * instead.
+ */
+ virtual UString className() const;
- bool getPropertySlot(ExecState*, const Identifier&, PropertySlot&);
- bool getPropertySlot(ExecState*, unsigned, PropertySlot&);
+ /**
+ * Retrieves the specified property from the object. If neither the object
+ * or any other object in its prototype chain have the property, this
+ * function will return Undefined.
+ *
+ * See ECMA 8.6.2.1
+ *
+ * @param exec The current execution state
+ * @param propertyName The name of the property to retrieve
+ *
+ * @return The specified property, or Undefined
+ */
+ JSValue* get(ExecState*, const Identifier& propertyName) const;
+ JSValue* get(ExecState*, unsigned propertyName) const;
- virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
- virtual bool getOwnPropertySlot(ExecState*, unsigned index, PropertySlot&);
+ bool getPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
+ bool getPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
- /**
- * Sets the specified property.
- *
- * See ECMA 8.6.2.2
- *
- * @param exec The current execution state
- * @param propertyName The name of the property to set
- * @param propertyValue The value to set
- */
- virtual void put(ExecState*, const Identifier& propertyName, JSValue* value);
- virtual void put(ExecState*, unsigned propertyName, JSValue* value);
+ virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
+ virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
- virtual void putWithAttributes(ExecState*, const Identifier& propertyName, JSValue* value, unsigned attributes);
- virtual void putWithAttributes(ExecState*, unsigned propertyName, JSValue* value, unsigned attributes);
+ /**
+ * Sets the specified property.
+ *
+ * See ECMA 8.6.2.2
+ *
+ * @param exec The current execution state
+ * @param propertyName The name of the property to set
+ * @param propertyValue The value to set
+ */
+ virtual void put(ExecState*, const Identifier& propertyName, JSValue* value);
+ virtual void put(ExecState*, unsigned propertyName, JSValue* value);
- /**
- * Checks if a property is enumerable, that is if it doesn't have the DontEnum
- * flag set
- *
- * See ECMA 15.2.4
- * @param exec The current execution state
- * @param propertyName The name of the property
- * @return true if the property is enumerable, otherwise false
- */
- bool propertyIsEnumerable(ExecState *exec, const Identifier &propertyName) const;
+ virtual void putWithAttributes(ExecState*, const Identifier& propertyName, JSValue* value, unsigned attributes);
+ virtual void putWithAttributes(ExecState*, unsigned propertyName, JSValue* value, unsigned attributes);
- /**
- * Checks to see whether the object (or any object in its prototype chain)
- * has a property with the specified name.
- *
- * See ECMA 8.6.2.4
- *
- * @param exec The current execution state
- * @param propertyName The name of the property to check for
- * @return true if the object has the property, otherwise false
- */
- bool hasProperty(ExecState*, const Identifier&) const;
- bool hasProperty(ExecState*, unsigned) const;
- bool hasOwnProperty(ExecState*, const Identifier&) const;
+ /**
+ * Checks if a property is enumerable, that is if it doesn't have the DontEnum
+ * flag set
+ *
+ * See ECMA 15.2.4
+ * @param exec The current execution state
+ * @param propertyName The name of the property
+ * @return true if the property is enumerable, otherwise false
+ */
+ bool propertyIsEnumerable(ExecState*, const Identifier& propertyName) const;
- /**
- * Removes the specified property from the object.
- *
- * See ECMA 8.6.2.5
- *
- * @param exec The current execution state
- * @param propertyName The name of the property to delete
- * @return true if the property was successfully deleted or did not
- * exist on the object. false if deleting the specified property is not
- * allowed.
- */
- virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
- virtual bool deleteProperty(ExecState *exec, unsigned propertyName);
+ /**
+ * Checks to see whether the object (or any object in its prototype chain)
+ * has a property with the specified name.
+ *
+ * See ECMA 8.6.2.4
+ *
+ * @param exec The current execution state
+ * @param propertyName The name of the property to check for
+ * @return true if the object has the property, otherwise false
+ */
+ bool hasProperty(ExecState*, const Identifier& propertyName) const;
+ bool hasProperty(ExecState*, unsigned propertyName) const;
+ bool hasOwnProperty(ExecState*, const Identifier& propertyName) const;
- /**
- * Converts the object into a primitive value. The value return may differ
- * depending on the supplied hint
- *
- * See ECMA 8.6.2.6
- *
- * @param exec The current execution state
- * @param hint The desired primitive type to convert to
- * @return A primitive value converted from the objetc. Note that the
- * type of primitive value returned may not be the same as the requested
- * hint.
- */
- /**
- * Implementation of the [[DefaultValue]] internal property (implemented by
- * all Objects)
- */
- virtual JSValue* defaultValue(ExecState*, JSType hint) const;
+ /**
+ * Removes the specified property from the object.
+ *
+ * See ECMA 8.6.2.5
+ *
+ * @param exec The current execution state
+ * @param propertyName The name of the property to delete
+ * @return true if the property was successfully deleted or did not
+ * exist on the object. false if deleting the specified property is not
+ * allowed.
+ */
+ virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
+ virtual bool deleteProperty(ExecState*, unsigned propertyName);
- /**
- * Whether or not the object implements the hasInstance() method. If this
- * returns false you should not call the hasInstance() method on this
- * object (typically, an assertion will fail to indicate this).
- *
- * @return true if this object implements the hasInstance() method,
- * otherwise false
- */
- virtual bool implementsHasInstance() const;
+ /**
+ * Converts the object into a primitive value. The value return may differ
+ * depending on the supplied hint
+ *
+ * See ECMA 8.6.2.6
+ *
+ * @param exec The current execution state
+ * @param hint The desired primitive type to convert to
+ * @return A primitive value converted from the objetc. Note that the
+ * type of primitive value returned may not be the same as the requested
+ * hint.
+ */
+ /**
+ * Implementation of the [[DefaultValue]] internal property (implemented by
+ * all Objects)
+ */
+ virtual JSValue* defaultValue(ExecState*, JSType hint) const;
- /**
- * Checks whether value delegates behavior to this object. Used by the
- * instanceof operator.
- *
- * @param exec The current execution state
- * @param value The value to check
- * @return true if value delegates behavior to this object, otherwise
- * false
- */
- virtual bool hasInstance(ExecState *exec, JSValue *value);
+ /**
+ * Whether or not the object implements the hasInstance() method. If this
+ * returns false you should not call the hasInstance() method on this
+ * object (typically, an assertion will fail to indicate this).
+ *
+ * @return true if this object implements the hasInstance() method,
+ * otherwise false
+ */
+ virtual bool implementsHasInstance() const;
- virtual void getPropertyNames(ExecState*, PropertyNameArray&);
+ /**
+ * Checks whether value delegates behavior to this object. Used by the
+ * instanceof operator.
+ *
+ * @param exec The current execution state
+ * @param value The value to check
+ * @return true if value delegates behavior to this object, otherwise
+ * false
+ */
+ virtual bool hasInstance(ExecState*, JSValue*);
- virtual JSValue* toPrimitive(ExecState*, JSType preferredType = UnspecifiedType) const;
- virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
- virtual bool toBoolean(ExecState *exec) const;
- virtual double toNumber(ExecState *exec) const;
- virtual UString toString(ExecState *exec) const;
- virtual JSObject *toObject(ExecState *exec) const;
+ virtual void getPropertyNames(ExecState*, PropertyNameArray&);
- virtual JSObject* toThisObject(ExecState*) const;
- virtual JSGlobalObject* toGlobalObject(ExecState*) const;
+ virtual JSValue* toPrimitive(ExecState*, JSType preferredType = UnspecifiedType) const;
+ virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
+ virtual bool toBoolean(ExecState*) const;
+ virtual double toNumber(ExecState*) const;
+ virtual UString toString(ExecState*) const;
+ virtual JSObject* toObject(ExecState*) const;
- virtual bool getPropertyAttributes(ExecState*, const Identifier& propertyName, unsigned& attributes) const;
-
- // WebCore uses this to make document.all and style.filter undetectable
- virtual bool masqueradeAsUndefined() const { return false; }
-
- // This get function only looks at the property map.
- // This is used e.g. by lookupOrCreateFunction (to cache a function, we don't want
- // to look up in the prototype, it might already exist there)
- JSValue *getDirect(const Identifier& propertyName) const
- { return _prop.get(propertyName); }
- JSValue **getDirectLocation(const Identifier& propertyName)
- { return _prop.getLocation(propertyName); }
- JSValue **getDirectLocation(const Identifier& propertyName, bool& isWriteable)
- { return _prop.getLocation(propertyName, isWriteable); }
- void putDirect(const Identifier &propertyName, JSValue *value, int attr = 0);
- void putDirect(ExecState*, const Identifier& propertyName, int value, int attr = 0);
- void removeDirect(const Identifier &propertyName);
-
- // convenience to add a function property under the function's own built-in name
- void putDirectFunction(InternalFunction*, int attr = 0);
+ virtual JSObject* toThisObject(ExecState*) const;
+ virtual JSGlobalObject* toGlobalObject(ExecState*) const;
- void fillGetterPropertySlot(PropertySlot& slot, JSValue **location);
+ virtual bool getPropertyAttributes(ExecState*, const Identifier& propertyName, unsigned& attributes) const;
- virtual void defineGetter(ExecState*, const Identifier& propertyName, JSObject* getterFunction);
- virtual void defineSetter(ExecState*, const Identifier& propertyName, JSObject* setterFunction);
- virtual JSValue* lookupGetter(ExecState*, const Identifier& propertyName);
- virtual JSValue* lookupSetter(ExecState*, const Identifier& propertyName);
+ // WebCore uses this to make document.all and style.filter undetectable
+ virtual bool masqueradeAsUndefined() const { return false; }
- virtual bool isActivationObject() const { return false; }
- virtual bool isGlobalObject() const { return false; }
- virtual bool isVariableObject() const { return false; }
+ // This get function only looks at the property map.
+ // This is used e.g. by lookupOrCreateFunction (to cache a function, we don't want
+ // to look up in the prototype, it might already exist there)
+ JSValue* getDirect(const Identifier& propertyName) const { return m_propertyMap.get(propertyName); }
+ JSValue** getDirectLocation(const Identifier& propertyName) { return m_propertyMap.getLocation(propertyName); }
+ JSValue** getDirectLocation(const Identifier& propertyName, bool& isWriteable) { return m_propertyMap.getLocation(propertyName, isWriteable); }
+ void putDirect(const Identifier& propertyName, JSValue* value, unsigned attr = 0);
+ void putDirect(ExecState*, const Identifier& propertyName, int value, unsigned attr = 0);
+ void removeDirect(const Identifier& propertyName);
- virtual bool isWatchdogException() const { return false; }
+ // convenience to add a function property under the function's own built-in name
+ void putDirectFunction(InternalFunction*, unsigned attr = 0);
- protected:
- PropertyMap _prop;
- bool getOwnPropertySlotForWrite(ExecState*, const Identifier&, PropertySlot&, bool& slotIsWriteable);
+ void fillGetterPropertySlot(PropertySlot&, JSValue** location);
- private:
- const HashEntry* findPropertyHashEntry(ExecState*, const Identifier& propertyName) const;
- JSValue *_proto;
- };
+ virtual void defineGetter(ExecState*, const Identifier& propertyName, JSObject* getterFunction);
+ virtual void defineSetter(ExecState*, const Identifier& propertyName, JSObject* setterFunction);
+ virtual JSValue* lookupGetter(ExecState*, const Identifier& propertyName);
+ virtual JSValue* lookupSetter(ExecState*, const Identifier& propertyName);
+
+ virtual bool isActivationObject() const { return false; }
+ virtual bool isGlobalObject() const { return false; }
+ virtual bool isVariableObject() const { return false; }
+
+ virtual bool isWatchdogException() const { return false; }
+
+ protected:
+ PropertyMap m_propertyMap;
+ bool getOwnPropertySlotForWrite(ExecState*, const Identifier&, PropertySlot&, bool& slotIsWriteable);
+
+ private:
+ const HashEntry* findPropertyHashEntry(ExecState*, const Identifier& propertyName) const;
+ JSValue* m_prototype;
+ };
JSObject* constructEmptyObject(ExecState*);
-inline JSObject::JSObject(JSValue* proto)
- : _proto(proto)
+inline JSObject::JSObject(JSValue* prototype)
+ : m_prototype(prototype)
{
- ASSERT(proto);
- ASSERT(proto == jsNull() || Heap::heap(this) == Heap::heap(proto));
+ ASSERT(prototype);
+ ASSERT(prototype == jsNull() || Heap::heap(this) == Heap::heap(prototype));
}
inline JSObject::JSObject()
- : _proto(jsNull())
+ : m_prototype(jsNull())
{
}
-inline JSValue *JSObject::prototype() const
+inline JSValue* JSObject::prototype() const
{
- return _proto;
+ return m_prototype;
}
-inline void JSObject::setPrototype(JSValue *proto)
+inline void JSObject::setPrototype(JSValue* prototype)
{
- ASSERT(proto);
- _proto = proto;
+ ASSERT(prototype);
+ m_prototype = prototype;
}
inline bool JSCell::isObject(const ClassInfo* info) const
@@ -373,58 +372,57 @@
return !JSImmediate::isImmediate(this) && asCell()->isObject(classInfo);
}
-inline JSValue *JSObject::get(ExecState *exec, const Identifier &propertyName) const
+inline JSValue* JSObject::get(ExecState* exec, const Identifier& propertyName) const
{
- PropertySlot slot(const_cast<JSObject *>(this));
-
- if (const_cast<JSObject *>(this)->getPropertySlot(exec, propertyName, slot))
- return slot.getValue(exec, propertyName);
+ PropertySlot slot(const_cast<JSObject*>(this));
+ if (const_cast<JSObject*>(this)->getPropertySlot(exec, propertyName, slot))
+ return slot.getValue(exec, propertyName);
- return jsUndefined();
+ return jsUndefined();
}
-inline JSValue *JSObject::get(ExecState *exec, unsigned propertyName) const
+inline JSValue* JSObject::get(ExecState* exec, unsigned propertyName) const
{
- PropertySlot slot(const_cast<JSObject *>(this));
- if (const_cast<JSObject *>(this)->getPropertySlot(exec, propertyName, slot))
- return slot.getValue(exec, propertyName);
-
- return jsUndefined();
+ PropertySlot slot(const_cast<JSObject*>(this));
+ if (const_cast<JSObject*>(this)->getPropertySlot(exec, propertyName, slot))
+ return slot.getValue(exec, propertyName);
+
+ return jsUndefined();
}
// It may seem crazy to inline a function this large but it makes a big difference
// since this is function very hot in variable lookup
-inline bool JSObject::getPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
+inline bool JSObject::getPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
- JSObject *object = this;
+ JSObject* object = this;
while (true) {
if (object->getOwnPropertySlot(exec, propertyName, slot))
return true;
- JSValue *proto = object->_proto;
- if (!proto->isObject())
+ JSValue* prototype = object->m_prototype;
+ if (!prototype->isObject())
return false;
- object = static_cast<JSObject *>(proto);
+ object = static_cast<JSObject*>(prototype);
}
}
-inline bool JSObject::getPropertySlot(ExecState *exec, unsigned propertyName, PropertySlot& slot)
+inline bool JSObject::getPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
{
- JSObject *imp = this;
-
- while (true) {
- if (imp->getOwnPropertySlot(exec, propertyName, slot))
- return true;
-
- JSValue *proto = imp->_proto;
- if (!proto->isObject())
- break;
-
- imp = static_cast<JSObject *>(proto);
- }
-
- return false;
+ JSObject* object = this;
+
+ while (true) {
+ if (object->getOwnPropertySlot(exec, propertyName, slot))
+ return true;
+
+ JSValue* prototype = object->m_prototype;
+ if (!prototype->isObject())
+ break;
+
+ object = static_cast<JSObject*>(prototype);
+ }
+
+ return false;
}
// It may seem crazy to inline a function this large, especially a virtual function,
@@ -432,8 +430,8 @@
// base class call to this.
ALWAYS_INLINE bool JSObject::getOwnPropertySlotForWrite(ExecState* exec, const Identifier& propertyName, PropertySlot& slot, bool& slotIsWriteable)
{
- if (JSValue **location = getDirectLocation(propertyName, slotIsWriteable)) {
- if (_prop.hasGetterSetterProperties() && location[0]->type() == GetterSetterType) {
+ if (JSValue** location = getDirectLocation(propertyName, slotIsWriteable)) {
+ if (m_propertyMap.hasGetterSetterProperties() && location[0]->type() == GetterSetterType) {
slotIsWriteable = false;
fillGetterPropertySlot(slot, location);
} else
@@ -443,7 +441,7 @@
// non-standard Netscape extension
if (propertyName == exec->propertyNames().underscoreProto) {
- slot.setValueSlot(&_proto);
+ slot.setValueSlot(&m_prototype);
slotIsWriteable = false;
return true;
}
@@ -456,8 +454,8 @@
// base class call to this.
ALWAYS_INLINE bool JSObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
- if (JSValue **location = getDirectLocation(propertyName)) {
- if (_prop.hasGetterSetterProperties() && location[0]->type() == GetterSetterType)
+ if (JSValue** location = getDirectLocation(propertyName)) {
+ if (m_propertyMap.hasGetterSetterProperties() && location[0]->type() == GetterSetterType)
fillGetterPropertySlot(slot, location);
else
slot.setValueSlot(location);
@@ -466,21 +464,21 @@
// non-standard Netscape extension
if (propertyName == exec->propertyNames().underscoreProto) {
- slot.setValueSlot(&_proto);
+ slot.setValueSlot(&m_prototype);
return true;
}
return false;
}
-inline void JSObject::putDirect(const Identifier &propertyName, JSValue *value, int attr)
+inline void JSObject::putDirect(const Identifier& propertyName, JSValue* value, unsigned attr)
{
- _prop.put(propertyName, value, attr);
+ m_propertyMap.put(propertyName, value, attr);
}
-inline void JSObject::putDirect(ExecState* exec, const Identifier &propertyName, int value, int attr)
+inline void JSObject::putDirect(ExecState* exec, const Identifier& propertyName, int value, unsigned attr)
{
- _prop.put(propertyName, jsNumber(exec, value), attr);
+ m_propertyMap.put(propertyName, jsNumber(exec, value), attr);
}
inline JSValue* JSObject::toPrimitive(ExecState* exec, JSType preferredType) const
@@ -503,10 +501,10 @@
if (cell->getOwnPropertySlot(exec, propertyName, slot))
return slot.getValue(exec, propertyName);
ASSERT(cell->isObject());
- JSValue* proto = static_cast<JSObject*>(cell)->prototype();
- if (!proto->isObject())
+ JSValue* prototype = static_cast<JSObject*>(cell)->prototype();
+ if (!prototype->isObject())
return jsUndefined();
- cell = static_cast<JSCell*>(proto);
+ cell = static_cast<JSCell*>(prototype);
}
}
@@ -525,10 +523,10 @@
if (cell->getOwnPropertySlot(exec, propertyName, slot))
return slot.getValue(exec, propertyName);
ASSERT(cell->isObject());
- JSValue* proto = static_cast<JSObject*>(cell)->prototype();
- if (!proto->isObject())
+ JSValue* prototype = static_cast<JSObject*>(cell)->prototype();
+ if (!prototype->isObject())
return jsUndefined();
- cell = static_cast<JSCell*>(proto);
+ cell = static_cast<JSCell*>(prototype);
}
}
diff --git a/JavaScriptCore/kjs/JSString.cpp b/JavaScriptCore/kjs/JSString.cpp
index f9a1cb2..f52aa97 100644
--- a/JavaScriptCore/kjs/JSString.cpp
+++ b/JavaScriptCore/kjs/JSString.cpp
@@ -32,7 +32,7 @@
JSValue* JSString::toPrimitive(ExecState*, JSType) const
{
- return const_cast<JSString*>(this);
+ return const_cast<JSString*>(this);
}
bool JSString::getPrimitiveNumber(ExecState*, double& number, JSValue*& value)
diff --git a/JavaScriptCore/kjs/JSString.h b/JavaScriptCore/kjs/JSString.h
index 72a9502..abee421 100644
--- a/JavaScriptCore/kjs/JSString.h
+++ b/JavaScriptCore/kjs/JSString.h
@@ -32,91 +32,99 @@
namespace KJS {
- class JSString : public JSCell {
- public:
- JSString(const UString& value) : m_value(value) { Heap::heap(this)->reportExtraMemoryCost(value.cost()); }
- enum HasOtherOwnerType { HasOtherOwner };
- JSString(const UString& value, HasOtherOwnerType) : m_value(value) { }
+ class JSString : public JSCell {
+ public:
+ JSString(const UString& value)
+ : m_value(value)
+ {
+ Heap::heap(this)->reportExtraMemoryCost(value.cost());
+ }
- const UString& value() const { return m_value; }
+ enum HasOtherOwnerType { HasOtherOwner };
+ JSString(const UString& value, HasOtherOwnerType)
+ : m_value(value)
+ {
+ }
- bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
- bool getStringPropertySlot(unsigned propertyName, PropertySlot&);
+ const UString& value() const { return m_value; }
- bool canGetIndex(unsigned i) { return i < static_cast<unsigned>(m_value.size()); }
- JSValue* getIndex(ExecState* exec, unsigned i)
+ bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
+ bool getStringPropertySlot(unsigned propertyName, PropertySlot&);
+
+ bool canGetIndex(unsigned i) { return i < static_cast<unsigned>(m_value.size()); }
+ JSValue* getIndex(ExecState* exec, unsigned i)
+ {
+ ASSERT(canGetIndex(i));
+ return new (exec) JSString(m_value.substr(i, 1));
+ }
+
+ private:
+ virtual JSType type() const { return StringType; }
+
+ virtual JSValue* toPrimitive(ExecState*, JSType preferred = UnspecifiedType) const;
+ virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
+ virtual bool toBoolean(ExecState*) const;
+ virtual double toNumber(ExecState*) const;
+ virtual JSObject* toObject(ExecState*) const;
+ virtual UString toString(ExecState*) const;
+
+ virtual JSObject* toThisObject(ExecState*) const;
+ virtual UString toThisString(ExecState*) const;
+ virtual JSString* toThisJSString(ExecState*);
+
+ // Actually getPropertySlot, not getOwnPropertySlot (see JSCell).
+ virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
+ virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
+
+ static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&);
+ static JSValue* indexGetter(ExecState*, const Identifier&, const PropertySlot&);
+ static JSValue* indexNumericPropertyGetter(ExecState*, unsigned, const PropertySlot&);
+
+ UString m_value;
+ };
+
+ JSString* jsString(ExecState*, const UString&); // returns empty string if passed null string
+ JSString* jsString(ExecState*, const char* = ""); // returns empty string if passed 0
+
+ // Should be used for strings that are owned by an object that will
+ // likely outlive the JSValue this makes, such as the parse tree or a
+ // DOM object that contains a UString
+ JSString* jsOwnedString(ExecState*, const UString&);
+
+ ALWAYS_INLINE bool JSString::getStringPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
- ASSERT(canGetIndex(i));
- return new (exec) JSString(m_value.substr(i, 1));
+ if (propertyName == exec->propertyNames().length) {
+ slot.setCustom(this, lengthGetter);
+ return true;
+ }
+
+ bool isStrictUInt32;
+ unsigned i = propertyName.toStrictUInt32(&isStrictUInt32);
+ if (isStrictUInt32 && i < static_cast<unsigned>(m_value.size())) {
+ slot.setCustomIndex(this, i, indexGetter);
+ return true;
+ }
+
+ return false;
+ }
+
+ ALWAYS_INLINE bool JSString::getStringPropertySlot(unsigned propertyName, PropertySlot& slot)
+ {
+ if (propertyName < static_cast<unsigned>(m_value.size())) {
+ slot.setCustomNumeric(this, indexNumericPropertyGetter);
+ return true;
+ }
+
+ return false;
}
- private:
- virtual JSType type() const { return StringType; }
+ // --- JSValue inlines ----------------------------
- virtual JSValue* toPrimitive(ExecState*, JSType preferred = UnspecifiedType) const;
- virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
- virtual bool toBoolean(ExecState*) const;
- virtual double toNumber(ExecState*) const;
- virtual JSObject* toObject(ExecState*) const;
- virtual UString toString(ExecState*) const;
-
- virtual JSObject* toThisObject(ExecState*) const;
- virtual UString toThisString(ExecState*) const;
- virtual JSString* toThisJSString(ExecState*);
-
- // Actually getPropertySlot, not getOwnPropertySlot (see JSCell).
- virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
- virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
-
- static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&);
- static JSValue* indexGetter(ExecState*, const Identifier&, const PropertySlot&);
- static JSValue* indexNumericPropertyGetter(ExecState*, unsigned, const PropertySlot&);
-
- UString m_value;
- };
-
- JSString* jsString(ExecState*, const UString&); // returns empty string if passed null string
- JSString* jsString(ExecState*, const char* = ""); // returns empty string if passed 0
-
- // Should be used for strings that are owned by an object that will
- // likely outlive the JSValue this makes, such as the parse tree or a
- // DOM object that contains a UString
- JSString* jsOwnedString(ExecState*, const UString&);
-
-ALWAYS_INLINE bool JSString::getStringPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
-{
- if (propertyName == exec->propertyNames().length) {
- slot.setCustom(this, lengthGetter);
- return true;
+ inline JSString* JSValue::toThisJSString(ExecState* exec)
+ {
+ return JSImmediate::isImmediate(this) ? jsString(exec, JSImmediate::toString(this)) : asCell()->toThisJSString(exec);
}
- bool isStrictUInt32;
- unsigned i = propertyName.toStrictUInt32(&isStrictUInt32);
- if (isStrictUInt32 && i < static_cast<unsigned>(m_value.size())) {
- slot.setCustomIndex(this, i, indexGetter);
- return true;
- }
-
- return false;
-}
-
-ALWAYS_INLINE bool JSString::getStringPropertySlot(unsigned propertyName, PropertySlot& slot)
-{
- if (propertyName < static_cast<unsigned>(m_value.size())) {
- slot.setCustomNumeric(this, indexNumericPropertyGetter);
- return true;
- }
-
- return false;
-}
-
-// --- JSValue inlines ----------------------------
-
-inline JSString* JSValue::toThisJSString(ExecState* exec)
-{
- return JSImmediate::isImmediate(this) ? jsString(exec, JSImmediate::toString(this)) : asCell()->toThisJSString(exec);
-}
-
} // namespace KJS
#endif // JSString_h
diff --git a/JavaScriptCore/kjs/JSType.h b/JavaScriptCore/kjs/JSType.h
index 1c9418c..e665e5d 100644
--- a/JavaScriptCore/kjs/JSType.h
+++ b/JavaScriptCore/kjs/JSType.h
@@ -23,20 +23,20 @@
#define KJS_JSTYPE_H
namespace KJS {
-
-/**
- * Primitive types
- */
-enum JSType {
- UnspecifiedType = 0,
- UndefinedType = 1,
- BooleanType = 2,
- NumberType = 3,
- NullType = 4,
- StringType = 5,
- ObjectType = 6,
- GetterSetterType = 7
-};
+
+ /**
+ * Primitive types
+ */
+ enum JSType {
+ UnspecifiedType = 0,
+ UndefinedType = 1,
+ BooleanType = 2,
+ NumberType = 3,
+ NullType = 4,
+ StringType = 5,
+ ObjectType = 6,
+ GetterSetterType = 7
+ };
} // namespace KJS
diff --git a/JavaScriptCore/kjs/JSValue.cpp b/JavaScriptCore/kjs/JSValue.cpp
index 1a861f7..d95e994 100644
--- a/JavaScriptCore/kjs/JSValue.cpp
+++ b/JavaScriptCore/kjs/JSValue.cpp
@@ -28,7 +28,6 @@
namespace KJS {
-static const double D16 = 65536.0; // FIXME: This seems to be unused.
static const double D32 = 4294967296.0;
// ECMA 9.4
diff --git a/JavaScriptCore/kjs/JSValue.h b/JavaScriptCore/kjs/JSValue.h
index ae4d1d2..17365c7 100644
--- a/JavaScriptCore/kjs/JSValue.h
+++ b/JavaScriptCore/kjs/JSValue.h
@@ -32,220 +32,220 @@
namespace KJS {
-class ExecState;
-class Identifier;
-class JSCell;
-class JSObject;
-class JSString;
-class PropertySlot;
-struct ClassInfo;
-struct Instruction;
+ class ExecState;
+ class Identifier;
+ class JSCell;
+ class JSObject;
+ class JSString;
+ class PropertySlot;
+ struct ClassInfo;
+ struct Instruction;
-/**
- * JSValue is the base type for all primitives (Undefined, Null, Boolean,
- * String, Number) and objects in ECMAScript.
- *
- * Note: you should never inherit from JSValue as it is for primitive types
- * only (all of which are provided internally by KJS). Instead, inherit from
- * JSObject.
- */
-class JSValue : Noncopyable {
- friend class JSCell; // so it can derive from this class
- friend class Heap; // so it can call asCell()
- friend class Machine; // so it can call asCell()
-private:
- JSValue();
- virtual ~JSValue();
+ /**
+ * JSValue is the base type for all primitives (Undefined, Null, Boolean,
+ * String, Number) and objects in ECMAScript.
+ *
+ * Note: you should never inherit from JSValue as it is for primitive types
+ * only (all of which are provided internally by KJS). Instead, inherit from
+ * JSObject.
+ */
+ class JSValue : Noncopyable {
+ friend class JSCell; // so it can derive from this class
+ friend class Heap; // so it can call asCell()
+ friend class Machine; // so it can call asCell()
+ private:
+ JSValue();
+ virtual ~JSValue();
-public:
- // Querying the type.
- JSType type() const;
- bool isUndefined() const;
- bool isNull() const;
- bool isUndefinedOrNull() const;
- bool isBoolean() const;
- bool isNumber() const;
- bool isString() const;
- bool isObject() const;
- bool isObject(const ClassInfo*) const; // FIXME: Merge with inherits.
+ public:
+ // Querying the type.
+ JSType type() const;
+ bool isUndefined() const;
+ bool isNull() const;
+ bool isUndefinedOrNull() const;
+ bool isBoolean() const;
+ bool isNumber() const;
+ bool isString() const;
+ bool isObject() const;
+ bool isObject(const ClassInfo*) const; // FIXME: Merge with inherits.
- // Extracting the value.
- bool getBoolean(bool&) const;
- bool getBoolean() const; // false if not a boolean
- bool getNumber(double&) const;
- double getNumber() const; // NaN if not a number
- double uncheckedGetNumber() const;
- bool getString(UString&) const;
- UString getString() const; // null string if not a string
- JSObject* getObject(); // NULL if not an object
- const JSObject* getObject() const; // NULL if not an object
+ // Extracting the value.
+ bool getBoolean(bool&) const;
+ bool getBoolean() const; // false if not a boolean
+ bool getNumber(double&) const;
+ double getNumber() const; // NaN if not a number
+ double uncheckedGetNumber() const;
+ bool getString(UString&) const;
+ UString getString() const; // null string if not a string
+ JSObject* getObject(); // NULL if not an object
+ const JSObject* getObject() const; // NULL if not an object
- CallType getCallData(CallData&);
- ConstructType getConstructData(ConstructData&);
+ CallType getCallData(CallData&);
+ ConstructType getConstructData(ConstructData&);
- // Extracting integer values.
- bool getUInt32(uint32_t&) const;
- bool getTruncatedInt32(int32_t&) const;
- bool getTruncatedUInt32(uint32_t&) const;
-
- // Basic conversions.
- JSValue* toPrimitive(ExecState*, JSType preferredType = UnspecifiedType) const;
- bool getPrimitiveNumber(ExecState*, double& number, JSValue*&);
+ // Extracting integer values.
+ bool getUInt32(uint32_t&) const;
+ bool getTruncatedInt32(int32_t&) const;
+ bool getTruncatedUInt32(uint32_t&) const;
+
+ // Basic conversions.
+ JSValue* toPrimitive(ExecState*, JSType preferredType = UnspecifiedType) const;
+ bool getPrimitiveNumber(ExecState*, double& number, JSValue*&);
- bool toBoolean(ExecState*) const;
+ bool toBoolean(ExecState*) const;
- // toNumber conversion is expected to be side effect free if an exception has
- // been set in the ExecState already.
- double toNumber(ExecState*) const;
- JSValue* toJSNumber(ExecState*) const; // Fast path for when you expect that the value is an immediate number.
- UString toString(ExecState*) const;
- JSObject* toObject(ExecState*) const;
+ // toNumber conversion is expected to be side effect free if an exception has
+ // been set in the ExecState already.
+ double toNumber(ExecState*) const;
+ JSValue* toJSNumber(ExecState*) const; // Fast path for when you expect that the value is an immediate number.
+ UString toString(ExecState*) const;
+ JSObject* toObject(ExecState*) const;
- // Integer conversions.
- double toInteger(ExecState*) const;
- double toIntegerPreserveNaN(ExecState*) const;
- int32_t toInt32(ExecState*) const;
- int32_t toInt32(ExecState*, bool& ok) const;
- uint32_t toUInt32(ExecState*) const;
- uint32_t toUInt32(ExecState*, bool& ok) const;
+ // Integer conversions.
+ double toInteger(ExecState*) const;
+ double toIntegerPreserveNaN(ExecState*) const;
+ int32_t toInt32(ExecState*) const;
+ int32_t toInt32(ExecState*, bool& ok) const;
+ uint32_t toUInt32(ExecState*) const;
+ uint32_t toUInt32(ExecState*, bool& ok) const;
- // These are identical logic to above, and faster than jsNumber(number)->toInt32(exec)
- static int32_t toInt32(double);
- static int32_t toUInt32(double);
+ // These are identical logic to above, and faster than jsNumber(number)->toInt32(exec)
+ static int32_t toInt32(double);
+ static int32_t toUInt32(double);
- // Floating point conversions.
- float toFloat(ExecState*) const;
+ // Floating point conversions.
+ float toFloat(ExecState*) const;
- // Garbage collection.
- void mark();
- bool marked() const;
+ // Garbage collection.
+ void mark();
+ bool marked() const;
- static int32_t toInt32SlowCase(double, bool& ok);
- static uint32_t toUInt32SlowCase(double, bool& ok);
+ static int32_t toInt32SlowCase(double, bool& ok);
+ static uint32_t toUInt32SlowCase(double, bool& ok);
- // Object operations, with the toObject operation included.
- JSValue* get(ExecState*, const Identifier& propertyName) const;
- JSValue* get(ExecState*, unsigned propertyName) const;
- void put(ExecState*, const Identifier& propertyName, JSValue*);
- void put(ExecState*, unsigned propertyName, JSValue*);
- bool deleteProperty(ExecState*, const Identifier& propertyName);
- bool deleteProperty(ExecState*, unsigned propertyName);
+ // Object operations, with the toObject operation included.
+ JSValue* get(ExecState*, const Identifier& propertyName) const;
+ JSValue* get(ExecState*, unsigned propertyName) const;
+ void put(ExecState*, const Identifier& propertyName, JSValue*);
+ void put(ExecState*, unsigned propertyName, JSValue*);
+ bool deleteProperty(ExecState*, const Identifier& propertyName);
+ bool deleteProperty(ExecState*, unsigned propertyName);
- JSObject* toThisObject(ExecState*) const;
- UString toThisString(ExecState*) const;
- JSString* toThisJSString(ExecState*);
+ JSObject* toThisObject(ExecState*) const;
+ UString toThisString(ExecState*) const;
+ JSString* toThisJSString(ExecState*);
- JSValue* getJSNumber(); // 0 if this is not a JSNumber or number object
+ JSValue* getJSNumber(); // 0 if this is not a JSNumber or number object
-private:
- bool getPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
- bool getPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
- int32_t toInt32SlowCase(ExecState*, bool& ok) const;
- uint32_t toUInt32SlowCase(ExecState*, bool& ok) const;
+ private:
+ bool getPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
+ bool getPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
+ int32_t toInt32SlowCase(ExecState*, bool& ok) const;
+ uint32_t toUInt32SlowCase(ExecState*, bool& ok) const;
- // Implementation details.
- JSCell* asCell();
- const JSCell* asCell() const;
-};
+ // Implementation details.
+ JSCell* asCell();
+ const JSCell* asCell() const;
+ };
-inline JSValue::JSValue()
-{
-}
-
-inline JSValue::~JSValue()
-{
-}
-
-inline bool JSValue::isUndefined() const
-{
- return this == jsUndefined();
-}
-
-inline bool JSValue::isNull() const
-{
- return this == jsNull();
-}
-
-inline bool JSValue::isUndefinedOrNull() const
-{
- return JSImmediate::isUndefinedOrNull(this);
-}
-
-inline bool JSValue::isBoolean() const
-{
- return JSImmediate::isBoolean(this);
-}
-
-inline bool JSValue::getBoolean(bool& v) const
-{
- if (JSImmediate::isBoolean(this)) {
- v = JSImmediate::toBoolean(this);
- return true;
+ inline JSValue::JSValue()
+ {
}
-
- return false;
-}
-inline bool JSValue::getBoolean() const
-{
- return JSImmediate::isBoolean(this) ? JSImmediate::toBoolean(this) : false;
-}
-
-ALWAYS_INLINE int32_t JSValue::toInt32(ExecState* exec) const
-{
- int32_t i;
- if (getTruncatedInt32(i))
- return i;
- bool ok;
- return toInt32SlowCase(exec, ok);
-}
-
-inline uint32_t JSValue::toUInt32(ExecState* exec) const
-{
- uint32_t i;
- if (getTruncatedUInt32(i))
- return i;
- bool ok;
- return toUInt32SlowCase(exec, ok);
-}
-
-inline int32_t JSValue::toInt32(double val)
-{
- if (!(val >= -2147483648.0 && val < 2147483648.0)) {
- bool ignored;
- return toInt32SlowCase(val, ignored);
+ inline JSValue::~JSValue()
+ {
}
- return static_cast<int32_t>(val);
-}
-inline int32_t JSValue::toUInt32(double val)
-{
- if (!(val >= 0.0 && val < 4294967296.0)) {
- bool ignored;
- return toUInt32SlowCase(val, ignored);
+ inline bool JSValue::isUndefined() const
+ {
+ return this == jsUndefined();
}
- return static_cast<uint32_t>(val);
-}
-inline int32_t JSValue::toInt32(ExecState* exec, bool& ok) const
-{
- int32_t i;
- if (getTruncatedInt32(i)) {
- ok = true;
- return i;
+ inline bool JSValue::isNull() const
+ {
+ return this == jsNull();
}
- return toInt32SlowCase(exec, ok);
-}
-inline uint32_t JSValue::toUInt32(ExecState* exec, bool& ok) const
-{
- uint32_t i;
- if (getTruncatedUInt32(i)) {
- ok = true;
- return i;
+ inline bool JSValue::isUndefinedOrNull() const
+ {
+ return JSImmediate::isUndefinedOrNull(this);
}
- return toUInt32SlowCase(exec, ok);
-}
+
+ inline bool JSValue::isBoolean() const
+ {
+ return JSImmediate::isBoolean(this);
+ }
+
+ inline bool JSValue::getBoolean(bool& v) const
+ {
+ if (JSImmediate::isBoolean(this)) {
+ v = JSImmediate::toBoolean(this);
+ return true;
+ }
+
+ return false;
+ }
+
+ inline bool JSValue::getBoolean() const
+ {
+ return JSImmediate::isBoolean(this) ? JSImmediate::toBoolean(this) : false;
+ }
+
+ ALWAYS_INLINE int32_t JSValue::toInt32(ExecState* exec) const
+ {
+ int32_t i;
+ if (getTruncatedInt32(i))
+ return i;
+ bool ok;
+ return toInt32SlowCase(exec, ok);
+ }
+
+ inline uint32_t JSValue::toUInt32(ExecState* exec) const
+ {
+ uint32_t i;
+ if (getTruncatedUInt32(i))
+ return i;
+ bool ok;
+ return toUInt32SlowCase(exec, ok);
+ }
+
+ inline int32_t JSValue::toInt32(double val)
+ {
+ if (!(val >= -2147483648.0 && val < 2147483648.0)) {
+ bool ignored;
+ return toInt32SlowCase(val, ignored);
+ }
+ return static_cast<int32_t>(val);
+ }
+
+ inline int32_t JSValue::toUInt32(double val)
+ {
+ if (!(val >= 0.0 && val < 4294967296.0)) {
+ bool ignored;
+ return toUInt32SlowCase(val, ignored);
+ }
+ return static_cast<uint32_t>(val);
+ }
+
+ inline int32_t JSValue::toInt32(ExecState* exec, bool& ok) const
+ {
+ int32_t i;
+ if (getTruncatedInt32(i)) {
+ ok = true;
+ return i;
+ }
+ return toInt32SlowCase(exec, ok);
+ }
+
+ inline uint32_t JSValue::toUInt32(ExecState* exec, bool& ok) const
+ {
+ uint32_t i;
+ if (getTruncatedUInt32(i)) {
+ ok = true;
+ return i;
+ }
+ return toUInt32SlowCase(exec, ok);
+ }
} // namespace KJS
diff --git a/JavaScriptCore/kjs/JSVariableObject.h b/JavaScriptCore/kjs/JSVariableObject.h
index 4925fac..45eaf60 100644
--- a/JavaScriptCore/kjs/JSVariableObject.h
+++ b/JavaScriptCore/kjs/JSVariableObject.h
@@ -85,8 +85,8 @@
{
}
- JSVariableObject(JSValue* proto, JSVariableObjectData* data)
- : JSObject(proto)
+ JSVariableObject(JSValue* prototype, JSVariableObjectData* data)
+ : JSObject(prototype)
, d(data) // Subclass owns this pointer.
{
}
diff --git a/JavaScriptCore/kjs/JSWrapperObject.h b/JavaScriptCore/kjs/JSWrapperObject.h
index c0f7354..3af9dc1 100644
--- a/JavaScriptCore/kjs/JSWrapperObject.h
+++ b/JavaScriptCore/kjs/JSWrapperObject.h
@@ -1,7 +1,6 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Maks Orlovich
- * Copyright (C) 2006 Apple Computer, Inc.
+ * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -28,8 +27,8 @@
namespace KJS {
/**
- This class is used as a base for classes such as String,
- Number, Boolean and Date which which are wrappers for primitive
+ This class is used as a base for classes such as String,
+ Number, Boolean and Date which which are wrappers for primitive
types. These classes stores the internal value, which is the
actual value represented by the wrapper objects.
*/
@@ -37,24 +36,8 @@
public:
JSWrapperObject(JSValue* proto);
- /**
- * Returns the internal value of the object. This is used for objects such
- * as String and Boolean which are wrappers for native types. The interal
- * value is the actual value represented by the wrapper objects.
- *
- * @see ECMA 8.6.2
- * @return The internal value of the object
- */
JSValue* internalValue() const;
-
- /**
- * Sets the internal value of the object
- *
- * @see internalValue()
- *
- * @param v The new internal value
- */
- void setInternalValue(JSValue* v);
+ void setInternalValue(JSValue*);
virtual void mark();
@@ -73,10 +56,10 @@
return m_internalValue;
}
- inline void JSWrapperObject::setInternalValue(JSValue* v)
+ inline void JSWrapperObject::setInternalValue(JSValue* value)
{
- ASSERT(v);
- m_internalValue = v;
+ ASSERT(value);
+ m_internalValue = value;
}
} // namespace KJS
diff --git a/JavaScriptCore/kjs/LabelStack.cpp b/JavaScriptCore/kjs/LabelStack.cpp
index 3bb2e4b..b955391 100644
--- a/JavaScriptCore/kjs/LabelStack.cpp
+++ b/JavaScriptCore/kjs/LabelStack.cpp
@@ -25,28 +25,29 @@
namespace KJS {
-bool LabelStack::push(const Identifier &id)
+bool LabelStack::push(const Identifier& id)
{
- if (contains(id))
- return false;
+ if (contains(id))
+ return false;
- StackElem *newtos = new StackElem;
- newtos->id = id;
- newtos->prev = tos;
- tos = newtos;
- return true;
+ StackElem* newTopOfStack = new StackElem;
+ newTopOfStack->id = id;
+ newTopOfStack->prev = m_topOfStack;
+ m_topOfStack = newTopOfStack;
+ return true;
}
bool LabelStack::contains(const Identifier &id) const
{
- if (id.isEmpty())
- return true;
+ if (id.isEmpty())
+ return true;
- for (StackElem *curr = tos; curr; curr = curr->prev)
- if (curr->id == id)
- return true;
+ for (StackElem* curr = m_topOfStack; curr; curr = curr->prev) {
+ if (curr->id == id)
+ return true;
+ }
- return false;
+ return false;
}
} // namespace KJS
diff --git a/JavaScriptCore/kjs/LabelStack.h b/JavaScriptCore/kjs/LabelStack.h
index 375edf1..52766b4 100644
--- a/JavaScriptCore/kjs/LabelStack.h
+++ b/JavaScriptCore/kjs/LabelStack.h
@@ -1,8 +1,7 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
- * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -21,64 +20,52 @@
*
*/
-#ifndef KJS_LABEL_STACK_H
-#define KJS_LABEL_STACK_H
+#ifndef LabelStack_h
+#define LabelStack_h
#include "identifier.h"
#include <wtf/Noncopyable.h>
namespace KJS {
- /**
- * @short The "label set" in Ecma-262 spec
- */
- class LabelStack : Noncopyable {
- public:
- LabelStack()
- : tos(0)
- {
- }
- ~LabelStack();
- /**
- * If id is not empty and is not in the stack already, puts it on top of
- * the stack and returns true, otherwise returns false
- */
- bool push(const Identifier &id);
- /**
- * Is the id in the stack?
- */
- bool contains(const Identifier &id) const;
- /**
- * Removes from the stack the last pushed id (what else?)
- */
- void pop();
+ class LabelStack : Noncopyable {
+ public:
+ LabelStack()
+ : m_topOfStack(0)
+ {
+ }
+ ~LabelStack();
- private:
- struct StackElem {
- Identifier id;
- StackElem *prev;
+ bool push(const Identifier &id);
+ bool contains(const Identifier &id) const;
+ void pop();
+
+ private:
+ struct StackElem {
+ Identifier id;
+ StackElem* prev;
+ };
+
+ StackElem* m_topOfStack;
};
- StackElem *tos;
- };
-
-inline LabelStack::~LabelStack()
-{
- StackElem *prev;
- for (StackElem *e = tos; e; e = prev) {
- prev = e->prev;
- delete e;
+ inline LabelStack::~LabelStack()
+ {
+ StackElem* prev;
+ for (StackElem* e = m_topOfStack; e; e = prev) {
+ prev = e->prev;
+ delete e;
+ }
}
-}
-inline void LabelStack::pop()
-{
- if (StackElem *e = tos) {
- tos = e->prev;
- delete e;
+ inline void LabelStack::pop()
+ {
+ if (StackElem* e = m_topOfStack) {
+ m_topOfStack = e->prev;
+ delete e;
+ }
}
-}
-}
+} // namespace KJS
-#endif // KJS_LABEL_STACK_H
+#endif // LabelStack_h
diff --git a/JavaScriptCore/kjs/MathObject.cpp b/JavaScriptCore/kjs/MathObject.cpp
index 17d1c5d..a973977 100644
--- a/JavaScriptCore/kjs/MathObject.cpp
+++ b/JavaScriptCore/kjs/MathObject.cpp
@@ -104,22 +104,22 @@
JSValue* MathObject::getValueProperty(ExecState* exec, int token) const
{
switch (token) {
- case Euler:
- return jsNumber(exec, exp(1.0));
- case Ln2:
- return jsNumber(exec, log(2.0));
- case Ln10:
- return jsNumber(exec, log(10.0));
- case Log2E:
- return jsNumber(exec, 1.0 / log(2.0));
- case Log10E:
- return jsNumber(exec, 1.0 / log(10.0));
- case Pi:
- return jsNumber(exec, piDouble);
- case Sqrt1_2:
- return jsNumber(exec, sqrt(0.5));
- case Sqrt2:
- return jsNumber(exec, sqrt(2.0));
+ case Euler:
+ return jsNumber(exec, exp(1.0));
+ case Ln2:
+ return jsNumber(exec, log(2.0));
+ case Ln10:
+ return jsNumber(exec, log(10.0));
+ case Log2E:
+ return jsNumber(exec, 1.0 / log(2.0));
+ case Log10E:
+ return jsNumber(exec, 1.0 / log(10.0));
+ case Pi:
+ return jsNumber(exec, piDouble);
+ case Sqrt1_2:
+ return jsNumber(exec, sqrt(0.5));
+ case Sqrt2:
+ return jsNumber(exec, sqrt(2.0));
}
ASSERT_NOT_REACHED();
diff --git a/JavaScriptCore/kjs/NativeErrorConstructor.cpp b/JavaScriptCore/kjs/NativeErrorConstructor.cpp
index 03d6cb2..b00ca9b 100644
--- a/JavaScriptCore/kjs/NativeErrorConstructor.cpp
+++ b/JavaScriptCore/kjs/NativeErrorConstructor.cpp
@@ -30,17 +30,17 @@
const ClassInfo NativeErrorConstructor::info = { "Function", &InternalFunction::info, 0, 0 };
-NativeErrorConstructor::NativeErrorConstructor(ExecState* exec, FunctionPrototype* funcProto, NativeErrorPrototype* prot)
- : InternalFunction(funcProto, Identifier(exec, prot->getDirect(exec->propertyNames().name)->getString()))
- , proto(prot)
+NativeErrorConstructor::NativeErrorConstructor(ExecState* exec, FunctionPrototype* functionPrototype, NativeErrorPrototype* nativeErrorPrototype)
+ : InternalFunction(functionPrototype, Identifier(exec, nativeErrorPrototype->getDirect(exec->propertyNames().name)->getString()))
+ , m_proto(nativeErrorPrototype)
{
- putDirect(exec->propertyNames().length, jsNumber(exec, 1), DontDelete|ReadOnly|DontEnum); // ECMA 15.11.7.5
- putDirect(exec->propertyNames().prototype, proto, DontDelete|ReadOnly|DontEnum);
+ putDirect(exec->propertyNames().length, jsNumber(exec, 1), DontDelete | ReadOnly | DontEnum); // ECMA 15.11.7.5
+ putDirect(exec->propertyNames().prototype, m_proto, DontDelete | ReadOnly | DontEnum);
}
ErrorInstance* NativeErrorConstructor::construct(ExecState* exec, const ArgList& args)
{
- ErrorInstance* object = new (exec) ErrorInstance(proto);
+ ErrorInstance* object = new (exec) ErrorInstance(m_proto);
if (!args[0]->isUndefined())
object->putDirect(exec->propertyNames().message, jsString(exec, args[0]->toString(exec)));
return object;
@@ -71,8 +71,8 @@
void NativeErrorConstructor::mark()
{
JSObject::mark();
- if (proto && !proto->marked())
- proto->mark();
+ if (m_proto && !m_proto->marked())
+ m_proto->mark();
}
} // namespace KJS
diff --git a/JavaScriptCore/kjs/NativeErrorConstructor.h b/JavaScriptCore/kjs/NativeErrorConstructor.h
index c1bd6bf..9fa2e7d 100644
--- a/JavaScriptCore/kjs/NativeErrorConstructor.h
+++ b/JavaScriptCore/kjs/NativeErrorConstructor.h
@@ -32,16 +32,20 @@
class NativeErrorConstructor : public InternalFunction {
public:
NativeErrorConstructor(ExecState*, FunctionPrototype*, NativeErrorPrototype*);
+
virtual void mark();
+
static const ClassInfo info;
+
ErrorInstance* construct(ExecState*, const ArgList&);
private:
- virtual const ClassInfo* classInfo() const { return &info; }
virtual ConstructType getConstructData(ConstructData&);
virtual CallType getCallData(CallData&);
- NativeErrorPrototype* proto;
+ virtual const ClassInfo* classInfo() const { return &info; }
+
+ NativeErrorPrototype* m_proto;
};
} // namespace KJS
diff --git a/JavaScriptCore/kjs/NativeErrorPrototype.cpp b/JavaScriptCore/kjs/NativeErrorPrototype.cpp
index 386e25b..0c5936e 100644
--- a/JavaScriptCore/kjs/NativeErrorPrototype.cpp
+++ b/JavaScriptCore/kjs/NativeErrorPrototype.cpp
@@ -27,8 +27,8 @@
namespace KJS {
-NativeErrorPrototype::NativeErrorPrototype(ExecState* exec, ErrorPrototype* errorProto, const UString& name, const UString& message)
- : JSObject(errorProto)
+NativeErrorPrototype::NativeErrorPrototype(ExecState* exec, ErrorPrototype* errorPrototype, const UString& name, const UString& message)
+ : JSObject(errorPrototype)
{
putDirect(exec->propertyNames().name, jsString(exec, name), 0);
putDirect(exec->propertyNames().message, jsString(exec, message), 0);
diff --git a/JavaScriptCore/kjs/NumberConstructor.cpp b/JavaScriptCore/kjs/NumberConstructor.cpp
index ed1d736..24e6315 100644
--- a/JavaScriptCore/kjs/NumberConstructor.cpp
+++ b/JavaScriptCore/kjs/NumberConstructor.cpp
@@ -28,7 +28,6 @@
namespace KJS {
-
const ClassInfo NumberConstructor::info = { "Function", &InternalFunction::info, 0, ExecState::numberTable };
/* Source for NumberObject.lut.h
@@ -40,11 +39,11 @@
MIN_VALUE NumberConstructor::MinValue DontEnum|DontDelete|ReadOnly
@end
*/
-NumberConstructor::NumberConstructor(ExecState* exec, FunctionPrototype* funcProto, NumberPrototype* numberProto)
- : InternalFunction(funcProto, Identifier(exec, numberProto->info.className))
+NumberConstructor::NumberConstructor(ExecState* exec, FunctionPrototype* functionPrototype, NumberPrototype* numberPrototype)
+ : InternalFunction(functionPrototype, Identifier(exec, numberPrototype->info.className))
{
// Number.Prototype
- putDirect(exec->propertyNames().prototype, numberProto, DontEnum|DontDelete|ReadOnly);
+ putDirect(exec->propertyNames().prototype, numberPrototype, DontEnum | DontDelete | ReadOnly);
// no. of arguments for constructor
putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete);
diff --git a/JavaScriptCore/kjs/NumberConstructor.h b/JavaScriptCore/kjs/NumberConstructor.h
index a649e08..89113c7 100644
--- a/JavaScriptCore/kjs/NumberConstructor.h
+++ b/JavaScriptCore/kjs/NumberConstructor.h
@@ -29,11 +29,6 @@
class FunctionPrototype;
class NumberPrototype;
- /**
- * @internal
- *
- * The initial value of the the global variable's "Number" property
- */
class NumberConstructor : public InternalFunction {
public:
NumberConstructor(ExecState*, FunctionPrototype*, NumberPrototype*);
@@ -48,6 +43,7 @@
private:
virtual ConstructType getConstructData(ConstructData&);
virtual CallType getCallData(CallData&);
+
virtual const ClassInfo* classInfo() const { return &info; }
};
diff --git a/JavaScriptCore/kjs/NumberObject.cpp b/JavaScriptCore/kjs/NumberObject.cpp
index 30758a2..b47aceb 100644
--- a/JavaScriptCore/kjs/NumberObject.cpp
+++ b/JavaScriptCore/kjs/NumberObject.cpp
@@ -29,8 +29,8 @@
const ClassInfo NumberObject::info = { "Number", 0, 0, 0 };
-NumberObject::NumberObject(JSObject* proto)
- : JSWrapperObject(proto)
+NumberObject::NumberObject(JSObject* prototype)
+ : JSWrapperObject(prototype)
{
}
diff --git a/JavaScriptCore/kjs/NumberObject.h b/JavaScriptCore/kjs/NumberObject.h
index bc00ae0..284bd59 100644
--- a/JavaScriptCore/kjs/NumberObject.h
+++ b/JavaScriptCore/kjs/NumberObject.h
@@ -31,10 +31,12 @@
class NumberObject : public JSWrapperObject {
public:
NumberObject(JSObject* prototype);
+
static const ClassInfo info;
private:
virtual const ClassInfo* classInfo() const { return &info; }
+
virtual JSValue* getJSNumber();
};
diff --git a/JavaScriptCore/kjs/NumberPrototype.cpp b/JavaScriptCore/kjs/NumberPrototype.cpp
index 79dbc9e..7c15eb3 100644
--- a/JavaScriptCore/kjs/NumberPrototype.cpp
+++ b/JavaScriptCore/kjs/NumberPrototype.cpp
@@ -63,7 +63,7 @@
// ECMA 15.7.4.2 - 15.7.4.7
-static UString integer_part_noexp(double d)
+static UString integerPartNoExp(double d)
{
int decimalPoint;
int sign;
@@ -94,7 +94,7 @@
return str;
}
-static UString char_sequence(char c, int count)
+static UString charSequence(char c, int count)
{
Vector<char, 2048> buf(count + 1, c);
buf[count] = '\0';
@@ -133,7 +133,6 @@
return static_cast<double>(result);
}
-
JSValue* numberProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)
{
JSValue* v = thisValue->getJSNumber();
@@ -228,7 +227,7 @@
double df = fractionDigits->toInteger(exec);
if (!(df >= 0 && df <= 20))
return throwError(exec, RangeError, "toFixed() digits argument must be between 0 and 20");
- int f = (int)df;
+ int f = static_cast<int>(df);
double x = v->uncheckedGetNumber();
if (isnan(x))
@@ -249,7 +248,7 @@
if (fabs(n / tenToTheF - x) >= fabs((n + 1) / tenToTheF - x))
n++;
- UString m = integer_part_noexp(n);
+ UString m = integerPartNoExp(n);
int k = m.size();
if (k <= f) {
@@ -318,7 +317,7 @@
double df = fractionalDigitsValue->toInteger(exec);
if (!(df >= 0 && df <= 20))
return throwError(exec, RangeError, "toExponential() argument must between 0 and 20");
- int fractionalDigits = (int)df;
+ int fractionalDigits = static_cast<int>(df);
bool includeAllDigits = fractionalDigitsValue->isUndefined();
int decimalAdjust = 0;
@@ -392,7 +391,7 @@
if (!(doublePrecision >= 1 && doublePrecision <= 21)) // true for NaN
return throwError(exec, RangeError, "toPrecision() argument must be between 1 and 21");
- int precision = (int)doublePrecision;
+ int precision = static_cast<int>(doublePrecision);
int e = 0;
UString m;
@@ -416,7 +415,7 @@
ASSERT(intPow10(precision - 1) <= n);
ASSERT(n < intPow10(precision));
- m = integer_part_noexp(n);
+ m = integerPartNoExp(n);
if (e < -6 || e >= precision) {
if (m.size() > 1)
m = m.substr(0, 1) + "." + m.substr(1);
@@ -425,7 +424,7 @@
return jsString(exec, s + m + "e-" + UString::from(-e));
}
} else {
- m = char_sequence('0', precision);
+ m = charSequence('0', precision);
e = 0;
}
@@ -436,7 +435,7 @@
return jsString(exec, s + m.substr(0, e + 1) + "." + m.substr(e + 1));
return jsString(exec, s + m);
}
- return jsString(exec, s + "0." + char_sequence('0', -(e + 1)) + m);
+ return jsString(exec, s + "0." + charSequence('0', -(e + 1)) + m);
}
} // namespace KJS
diff --git a/JavaScriptCore/kjs/NumberPrototype.h b/JavaScriptCore/kjs/NumberPrototype.h
index 5483d03..9557d41 100644
--- a/JavaScriptCore/kjs/NumberPrototype.h
+++ b/JavaScriptCore/kjs/NumberPrototype.h
@@ -29,12 +29,6 @@
class FunctionPrototype;
class ObjectPrototype;
- /**
- * @internal
- *
- * The initial value of Number.prototype (and thus all objects created
- * with the Number constructor
- */
class NumberPrototype : public NumberObject {
public:
NumberPrototype(ExecState*, ObjectPrototype*, FunctionPrototype*);
diff --git a/JavaScriptCore/kjs/ObjectConstructor.cpp b/JavaScriptCore/kjs/ObjectConstructor.cpp
index dd77dbe..00340d5 100644
--- a/JavaScriptCore/kjs/ObjectConstructor.cpp
+++ b/JavaScriptCore/kjs/ObjectConstructor.cpp
@@ -27,14 +27,14 @@
namespace KJS {
-ObjectConstructor::ObjectConstructor(ExecState* exec, ObjectPrototype* objProto, FunctionPrototype* funcProto)
- : InternalFunction(funcProto, Identifier(exec, "Object"))
+ObjectConstructor::ObjectConstructor(ExecState* exec, ObjectPrototype* objectPrototype, FunctionPrototype* functionPrototype)
+ : InternalFunction(functionPrototype, Identifier(exec, "Object"))
{
- // ECMA 15.2.3.1
- putDirect(exec->propertyNames().prototype, objProto, DontEnum|DontDelete|ReadOnly);
+ // ECMA 15.2.3.1
+ putDirect(exec->propertyNames().prototype, objectPrototype, DontEnum | DontDelete | ReadOnly);
- // no. of arguments for constructor
- putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete);
+ // no. of arguments for constructor
+ putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete);
}
// ECMA 15.2.2
diff --git a/JavaScriptCore/kjs/ObjectConstructor.h b/JavaScriptCore/kjs/ObjectConstructor.h
index 39299f6..5969501 100644
--- a/JavaScriptCore/kjs/ObjectConstructor.h
+++ b/JavaScriptCore/kjs/ObjectConstructor.h
@@ -28,14 +28,10 @@
class FunctionPrototype;
class ObjectPrototype;
- /**
- * @internal
- *
- * The initial value of the the global variable's "Object" property
- */
class ObjectConstructor : public InternalFunction {
public:
ObjectConstructor(ExecState*, ObjectPrototype*, FunctionPrototype*);
+
private:
virtual ConstructType getConstructData(ConstructData&);
virtual CallType getCallData(CallData&);
diff --git a/JavaScriptCore/kjs/PropertyMap.cpp b/JavaScriptCore/kjs/PropertyMap.cpp
index 0fa25d9..d55ab8f 100644
--- a/JavaScriptCore/kjs/PropertyMap.cpp
+++ b/JavaScriptCore/kjs/PropertyMap.cpp
@@ -63,7 +63,9 @@
static int numRehashes;
static int numRemoves;
-struct PropertyMapStatisticsExitLogger { ~PropertyMapStatisticsExitLogger(); };
+struct PropertyMapStatisticsExitLogger {
+ ~PropertyMapStatisticsExitLogger();
+};
static PropertyMapStatisticsExitLogger logger;
@@ -85,7 +87,10 @@
unsigned index;
PropertyMapEntry(UString::Rep* k, JSValue* v, int a)
- : key(k), value(v), attributes(a), index(0)
+ : key(k)
+ , value(v)
+ , attributes(a)
+ , index(0)
{
}
};
@@ -142,7 +147,7 @@
#endif
return;
}
-
+
unsigned entryCount = m_u.table->keyCount + m_u.table->deletedSentinelCount;
for (unsigned i = 1; i <= entryCount; i++) {
if (UString::Rep* key = m_u.table->entries()[i].key)
@@ -174,12 +179,12 @@
m_u.table->deletedSentinelCount = 0;
}
-JSValue* PropertyMap::get(const Identifier& name, unsigned& attributes) const
+JSValue* PropertyMap::get(const Identifier& propertyName, unsigned& attributes) const
{
- ASSERT(!name.isNull());
-
- UString::Rep* rep = name._ustring.rep();
-
+ ASSERT(!propertyName.isNull());
+
+ UString::Rep* rep = propertyName._ustring.rep();
+
if (!m_usingTable) {
#if USE_SINGLE_ENTRY
if (rep == m_singleEntryKey) {
@@ -189,7 +194,7 @@
#endif
return 0;
}
-
+
unsigned i = rep->computedHash();
#if DUMP_PROPERTYMAP_STATS
@@ -229,12 +234,12 @@
}
}
-JSValue* PropertyMap::get(const Identifier& name) const
+JSValue* PropertyMap::get(const Identifier& propertyName) const
{
- ASSERT(!name.isNull());
-
- UString::Rep* rep = name._ustring.rep();
-
+ ASSERT(!propertyName.isNull());
+
+ UString::Rep* rep = propertyName._ustring.rep();
+
if (!m_usingTable) {
#if USE_SINGLE_ENTRY
if (rep == m_singleEntryKey)
@@ -242,7 +247,7 @@
#endif
return 0;
}
-
+
unsigned i = rep->computedHash();
#if DUMP_PROPERTYMAP_STATS
@@ -278,12 +283,12 @@
}
}
-JSValue** PropertyMap::getLocation(const Identifier& name)
+JSValue** PropertyMap::getLocation(const Identifier& propertyName)
{
- ASSERT(!name.isNull());
-
- UString::Rep* rep = name._ustring.rep();
-
+ ASSERT(!propertyName.isNull());
+
+ UString::Rep* rep = propertyName._ustring.rep();
+
if (!m_usingTable) {
#if USE_SINGLE_ENTRY
if (rep == m_singleEntryKey)
@@ -291,7 +296,7 @@
#endif
return 0;
}
-
+
unsigned i = rep->computedHash();
#if DUMP_PROPERTYMAP_STATS
@@ -327,12 +332,12 @@
}
}
-JSValue** PropertyMap::getLocation(const Identifier& name, bool& isWriteable)
+JSValue** PropertyMap::getLocation(const Identifier& propertyName, bool& isWriteable)
{
- ASSERT(!name.isNull());
-
- UString::Rep* rep = name._ustring.rep();
-
+ ASSERT(!propertyName.isNull());
+
+ UString::Rep* rep = propertyName._ustring.rep();
+
if (!m_usingTable) {
#if USE_SINGLE_ENTRY
if (rep == m_singleEntryKey) {
@@ -342,7 +347,7 @@
#endif
return 0;
}
-
+
unsigned i = rep->computedHash();
#if DUMP_PROPERTYMAP_STATS
@@ -382,15 +387,15 @@
}
}
-void PropertyMap::put(const Identifier& name, JSValue* value, unsigned attributes, bool checkReadOnly)
+void PropertyMap::put(const Identifier& propertyName, JSValue* value, unsigned attributes, bool checkReadOnly)
{
- ASSERT(!name.isNull());
+ ASSERT(!propertyName.isNull());
ASSERT(value);
-
+
checkConsistency();
- UString::Rep* rep = name._ustring.rep();
-
+ UString::Rep* rep = propertyName._ustring.rep();
+
#if USE_SINGLE_ENTRY
if (!m_usingTable) {
if (!m_singleEntryKey) {
@@ -428,7 +433,7 @@
break;
if (m_u.table->entries()[entryIndex - 1].key == rep) {
- if (checkReadOnly && (m_u.table->entries()[entryIndex - 1].attributes & ReadOnly))
+ if (checkReadOnly && (m_u.table->entries()[entryIndex - 1].attributes & ReadOnly))
return;
// Put a new value in an existing hash table entry.
m_u.table->entries()[entryIndex - 1].value = value;
@@ -466,11 +471,9 @@
// the end that we were planning on using, so search backwards for the empty
// slot that we can use. We know it will be there because we did at least one
// deletion in the past that left an entry empty.
- while (m_u.table->entries()[--entryIndex - 1].key)
- ;
+ while (m_u.table->entries()[--entryIndex - 1].key) { }
}
-
// Create a new hash table entry.
m_u.table->entryIndicies[i & m_u.table->sizeMask] = entryIndex;
@@ -573,7 +576,7 @@
checkConsistency();
Table* oldTable = m_u.table;
-
+
m_u.table = static_cast<Table*>(fastZeroedMalloc(Table::allocationSize(newTableSize)));
m_u.table->size = newTableSize;
m_u.table->sizeMask = newTableSize - 1;
@@ -593,13 +596,13 @@
checkConsistency();
}
-void PropertyMap::remove(const Identifier& name)
+void PropertyMap::remove(const Identifier& propertyName)
{
- ASSERT(!name.isNull());
-
+ ASSERT(!propertyName.isNull());
+
checkConsistency();
- UString::Rep* rep = name._ustring.rep();
+ UString::Rep* rep = propertyName._ustring.rep();
if (!m_usingTable) {
#if USE_SINGLE_ENTRY
diff --git a/JavaScriptCore/kjs/PropertyMap.h b/JavaScriptCore/kjs/PropertyMap.h
index 0cd50a6..dcd7407 100644
--- a/JavaScriptCore/kjs/PropertyMap.h
+++ b/JavaScriptCore/kjs/PropertyMap.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
*
@@ -23,15 +22,12 @@
#define PropertyMap_h
#include "identifier.h"
-#include "protect.h"
-#include <wtf/OwnArrayPtr.h>
namespace KJS {
class JSObject;
class JSValue;
class PropertyNameArray;
-
struct PropertyMapEntry;
struct PropertyMapHashTable;
@@ -39,15 +35,15 @@
public:
PropertyMap();
~PropertyMap();
-
+
void clear();
-
- void put(const Identifier&, JSValue*, unsigned attributes, bool checkReadOnly = false);
- void remove(const Identifier&);
- JSValue* get(const Identifier&) const;
- JSValue* get(const Identifier&, unsigned& attributes) const;
- JSValue** getLocation(const Identifier& name);
- JSValue** getLocation(const Identifier& name, bool& isWriteable);
+
+ void put(const Identifier& propertyName, JSValue*, unsigned attributes, bool checkReadOnly = false);
+ void remove(const Identifier& propertyName);
+ JSValue* get(const Identifier& propertyName) const;
+ JSValue* get(const Identifier& propertyName, unsigned& attributes) const;
+ JSValue** getLocation(const Identifier& propertyName);
+ JSValue** getLocation(const Identifier& propertyName, bool& isWriteable);
void mark() const;
void getEnumerablePropertyNames(PropertyNameArray&) const;
@@ -89,6 +85,7 @@
{
}
-} // namespace
-#endif // _KJS_PROPERTY_MAP_H_
+} // namespace KJS
+
+#endif // PropertyMap_h
diff --git a/JavaScriptCore/kjs/PropertyNameArray.cpp b/JavaScriptCore/kjs/PropertyNameArray.cpp
index d2bfbad..7fcb006 100644
--- a/JavaScriptCore/kjs/PropertyNameArray.cpp
+++ b/JavaScriptCore/kjs/PropertyNameArray.cpp
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
*
diff --git a/JavaScriptCore/kjs/PropertyNameArray.h b/JavaScriptCore/kjs/PropertyNameArray.h
index 3edef4f..94b89ac 100644
--- a/JavaScriptCore/kjs/PropertyNameArray.h
+++ b/JavaScriptCore/kjs/PropertyNameArray.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
*
@@ -34,8 +33,15 @@
typedef Identifier ValueType;
typedef Vector<Identifier>::const_iterator const_iterator;
- PropertyNameArray(JSGlobalData* globalData) : m_globalData(globalData) {}
- PropertyNameArray(ExecState* exec) : m_globalData(&exec->globalData()) {}
+ PropertyNameArray(JSGlobalData* globalData)
+ : m_globalData(globalData)
+ {
+ }
+
+ PropertyNameArray(ExecState* exec)
+ : m_globalData(&exec->globalData())
+ {
+ }
JSGlobalData* globalData() { return m_globalData; }
diff --git a/JavaScriptCore/kjs/PropertySlot.cpp b/JavaScriptCore/kjs/PropertySlot.cpp
index 9015f17..9206bde 100644
--- a/JavaScriptCore/kjs/PropertySlot.cpp
+++ b/JavaScriptCore/kjs/PropertySlot.cpp
@@ -1,4 +1,3 @@
-// -*- c-basic-offset: 4 -*-
/*
* Copyright (C) 2005, 2008 Apple Inc. All rights reserved.
*
@@ -19,7 +18,6 @@
*
*/
-
#include "config.h"
#include "PropertySlot.h"
diff --git a/JavaScriptCore/kjs/PropertySlot.h b/JavaScriptCore/kjs/PropertySlot.h
index 5921b84..53b08a5 100644
--- a/JavaScriptCore/kjs/PropertySlot.h
+++ b/JavaScriptCore/kjs/PropertySlot.h
@@ -1,4 +1,3 @@
-// -*- c-basic-offset: 4 -*-
/*
* Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved.
*
@@ -22,150 +21,153 @@
#ifndef PropertySlot_h
#define PropertySlot_h
-#include "identifier.h"
#include "JSValue.h"
+#include "identifier.h"
#include <wtf/Assertions.h>
namespace KJS {
-class ExecState;
-class JSObject;
-
-struct HashEntry;
+ class ExecState;
+ class JSObject;
+ struct HashEntry;
#define KJS_VALUE_SLOT_MARKER 0
#define KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER reinterpret_cast<GetValueFunc>(1)
-class PropertySlot {
-public:
- PropertySlot()
- {
- clearBase();
- }
+ class PropertySlot {
+ public:
+ PropertySlot()
+ {
+ clearBase();
+ }
- explicit PropertySlot(JSValue* base)
- : m_slotBase(base)
- {
- }
+ explicit PropertySlot(JSValue* base)
+ : m_slotBase(base)
+ {
+ }
- typedef JSValue* (*GetValueFunc)(ExecState*, const Identifier&, const PropertySlot&);
- typedef JSValue* (*GetValueNumericFunc)(ExecState*, unsigned index, const PropertySlot&);
+ typedef JSValue* (*GetValueFunc)(ExecState*, const Identifier&, const PropertySlot&);
+ typedef JSValue* (*GetValueNumericFunc)(ExecState*, unsigned index, const PropertySlot&);
- JSValue* getValue(ExecState* exec, const Identifier& propertyName) const
- {
- if (m_getValue == KJS_VALUE_SLOT_MARKER)
- return *m_data.valueSlot;
- ASSERT(m_getValue != KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER);
- return m_getValue(exec, propertyName, *this);
- }
+ JSValue* getValue(ExecState* exec, const Identifier& propertyName) const
+ {
+ if (m_getValue == KJS_VALUE_SLOT_MARKER)
+ return *m_data.valueSlot;
+ ASSERT(m_getValue != KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER);
+ return m_getValue(exec, propertyName, *this);
+ }
- JSValue* getValue(ExecState* exec, unsigned propertyName) const
- {
- if (m_getValue == KJS_VALUE_SLOT_MARKER)
- return *m_data.valueSlot;
- if (m_getValue == KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER)
- return m_data.numericFunc(exec, propertyName, *this);
- return m_getValue(exec, Identifier::from(exec, propertyName), *this);
- }
+ JSValue* getValue(ExecState* exec, unsigned propertyName) const
+ {
+ if (m_getValue == KJS_VALUE_SLOT_MARKER)
+ return *m_data.valueSlot;
+ if (m_getValue == KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER)
+ return m_data.numericFunc(exec, propertyName, *this);
+ return m_getValue(exec, Identifier::from(exec, propertyName), *this);
+ }
- void putValue(JSValue* value)
- {
- ASSERT(m_getValue == KJS_VALUE_SLOT_MARKER);
- *m_data.valueSlot = value;
- }
-
- void setValueSlot(JSValue** valueSlot)
- {
- ASSERT(valueSlot);
- m_getValue = KJS_VALUE_SLOT_MARKER;
- clearBase();
- m_data.valueSlot = valueSlot;
- }
+ void putValue(JSValue* value)
+ {
+ ASSERT(m_getValue == KJS_VALUE_SLOT_MARKER);
+ *m_data.valueSlot = value;
+ }
+
+ void setValueSlot(JSValue** valueSlot)
+ {
+ ASSERT(valueSlot);
+ m_getValue = KJS_VALUE_SLOT_MARKER;
+ clearBase();
+ m_data.valueSlot = valueSlot;
+ }
- void setStaticEntry(JSValue* slotBase, const HashEntry* staticEntry, GetValueFunc getValue)
- {
- ASSERT(slotBase);
- ASSERT(staticEntry);
- ASSERT(getValue);
- m_getValue = getValue;
- m_slotBase = slotBase;
- m_data.staticEntry = staticEntry;
- }
+ void setStaticEntry(JSValue* slotBase, const HashEntry* staticEntry, GetValueFunc getValue)
+ {
+ ASSERT(slotBase);
+ ASSERT(staticEntry);
+ ASSERT(getValue);
+ m_getValue = getValue;
+ m_slotBase = slotBase;
+ m_data.staticEntry = staticEntry;
+ }
- void setCustom(JSValue* slotBase, GetValueFunc getValue)
- {
- ASSERT(slotBase);
- ASSERT(getValue);
- m_getValue = getValue;
- m_slotBase = slotBase;
- }
+ void setCustom(JSValue* slotBase, GetValueFunc getValue)
+ {
+ ASSERT(slotBase);
+ ASSERT(getValue);
+ m_getValue = getValue;
+ m_slotBase = slotBase;
+ }
- void setCustomIndex(JSValue* slotBase, unsigned index, GetValueFunc getValue)
- {
- ASSERT(slotBase);
- ASSERT(getValue);
- m_getValue = getValue;
- m_slotBase = slotBase;
- m_data.index = index;
- }
-
- void setCustomNumeric(JSValue* slotBase, GetValueNumericFunc getValue)
- {
- ASSERT(slotBase);
- ASSERT(getValue);
- m_slotBase = slotBase;
- m_getValue = KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER;
- m_data.numericFunc = getValue;
- }
-
- void setGetterSlot(JSObject* getterFunc)
- {
- ASSERT(getterFunc);
- m_getValue = functionGetter;
- m_data.getterFunc = getterFunc;
- }
-
- void setUndefined()
- {
- clearBase();
- m_getValue = undefinedGetter;
- }
+ void setCustomIndex(JSValue* slotBase, unsigned index, GetValueFunc getValue)
+ {
+ ASSERT(slotBase);
+ ASSERT(getValue);
+ m_getValue = getValue;
+ m_slotBase = slotBase;
+ m_data.index = index;
+ }
+
+ void setCustomNumeric(JSValue* slotBase, GetValueNumericFunc getValue)
+ {
+ ASSERT(slotBase);
+ ASSERT(getValue);
+ m_slotBase = slotBase;
+ m_getValue = KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER;
+ m_data.numericFunc = getValue;
+ }
+
+ void setGetterSlot(JSObject* getterFunc)
+ {
+ ASSERT(getterFunc);
+ m_getValue = functionGetter;
+ m_data.getterFunc = getterFunc;
+ }
+
+ void setUndefined()
+ {
+ clearBase();
+ m_getValue = undefinedGetter;
+ }
- JSValue* slotBase() const { ASSERT(m_slotBase); return m_slotBase; }
+ JSValue* slotBase() const
+ {
+ ASSERT(m_slotBase);
+ return m_slotBase;
+ }
- void setBase(JSValue* base)
- {
- ASSERT(m_slotBase);
- ASSERT(base);
- m_slotBase = base;
- }
+ void setBase(JSValue* base)
+ {
+ ASSERT(m_slotBase);
+ ASSERT(base);
+ m_slotBase = base;
+ }
- void clearBase()
- {
+ void clearBase()
+ {
#ifndef NDEBUG
- m_slotBase = 0;
+ m_slotBase = 0;
#endif
- }
+ }
- const HashEntry* staticEntry() const { return m_data.staticEntry; }
- unsigned index() const { return m_data.index; }
+ const HashEntry* staticEntry() const { return m_data.staticEntry; }
+ unsigned index() const { return m_data.index; }
-private:
- static JSValue* undefinedGetter(ExecState*, const Identifier&, const PropertySlot&);
- static JSValue* functionGetter(ExecState*, const Identifier&, const PropertySlot&);
-
- GetValueFunc m_getValue;
+ private:
+ static JSValue* undefinedGetter(ExecState*, const Identifier&, const PropertySlot&);
+ static JSValue* functionGetter(ExecState*, const Identifier&, const PropertySlot&);
- JSValue* m_slotBase;
- union {
- JSObject* getterFunc;
- JSValue** valueSlot;
- const HashEntry* staticEntry;
- unsigned index;
- GetValueNumericFunc numericFunc;
- } m_data;
-};
+ GetValueFunc m_getValue;
-}
+ JSValue* m_slotBase;
+ union {
+ JSObject* getterFunc;
+ JSValue** valueSlot;
+ const HashEntry* staticEntry;
+ unsigned index;
+ GetValueNumericFunc numericFunc;
+ } m_data;
+ };
+
+} // namespace KJS
#endif // PropertySlot_h
diff --git a/JavaScriptCore/kjs/PrototypeFunction.cpp b/JavaScriptCore/kjs/PrototypeFunction.cpp
index 169dfa0..1e4a01c 100644
--- a/JavaScriptCore/kjs/PrototypeFunction.cpp
+++ b/JavaScriptCore/kjs/PrototypeFunction.cpp
@@ -31,20 +31,20 @@
namespace KJS {
-PrototypeFunction::PrototypeFunction(ExecState* exec, int len, const Identifier& name, NativeFunction function)
+PrototypeFunction::PrototypeFunction(ExecState* exec, int length, const Identifier& name, NativeFunction function)
: InternalFunction(exec->lexicalGlobalObject()->functionPrototype(), name)
, m_function(function)
{
ASSERT_ARG(function, function);
- putDirect(exec->propertyNames().length, jsNumber(exec, len), DontDelete | ReadOnly | DontEnum);
+ putDirect(exec->propertyNames().length, jsNumber(exec, length), DontDelete | ReadOnly | DontEnum);
}
-PrototypeFunction::PrototypeFunction(ExecState* exec, FunctionPrototype* functionPrototype, int len, const Identifier& name, NativeFunction function)
+PrototypeFunction::PrototypeFunction(ExecState* exec, FunctionPrototype* functionPrototype, int length, const Identifier& name, NativeFunction function)
: InternalFunction(functionPrototype, name)
, m_function(function)
{
ASSERT_ARG(function, function);
- putDirect(exec->propertyNames().length, jsNumber(exec, len), DontDelete | ReadOnly | DontEnum);
+ putDirect(exec->propertyNames().length, jsNumber(exec, length), DontDelete | ReadOnly | DontEnum);
}
CallType PrototypeFunction::getCallData(CallData& callData)
diff --git a/JavaScriptCore/kjs/PrototypeFunction.h b/JavaScriptCore/kjs/PrototypeFunction.h
index 5a003e4..0affbf7 100644
--- a/JavaScriptCore/kjs/PrototypeFunction.h
+++ b/JavaScriptCore/kjs/PrototypeFunction.h
@@ -29,16 +29,16 @@
namespace KJS {
- class PrototypeFunction : public InternalFunction {
- public:
- PrototypeFunction(ExecState*, int len, const Identifier&, NativeFunction);
- PrototypeFunction(ExecState*, FunctionPrototype*, int len, const Identifier&, NativeFunction);
+ class PrototypeFunction : public InternalFunction {
+ public:
+ PrototypeFunction(ExecState*, int length, const Identifier&, NativeFunction);
+ PrototypeFunction(ExecState*, FunctionPrototype*, int length, const Identifier&, NativeFunction);
- private:
- virtual CallType getCallData(CallData&);
+ private:
+ virtual CallType getCallData(CallData&);
- const NativeFunction m_function;
- };
+ const NativeFunction m_function;
+ };
} // namespace KJS
diff --git a/JavaScriptCore/kjs/RegExpConstructor.cpp b/JavaScriptCore/kjs/RegExpConstructor.cpp
index b461351..ce148bb 100644
--- a/JavaScriptCore/kjs/RegExpConstructor.cpp
+++ b/JavaScriptCore/kjs/RegExpConstructor.cpp
@@ -37,48 +37,53 @@
/* Source for RegExpConstructor.lut.h
@begin regExpConstructorTable
- input RegExpConstructor::Input None
- $_ RegExpConstructor::Input DontEnum
- multiline RegExpConstructor::Multiline None
- $* RegExpConstructor::Multiline DontEnum
- lastMatch RegExpConstructor::LastMatch DontDelete|ReadOnly
- $& RegExpConstructor::LastMatch DontDelete|ReadOnly|DontEnum
- lastParen RegExpConstructor::LastParen DontDelete|ReadOnly
- $+ RegExpConstructor::LastParen DontDelete|ReadOnly|DontEnum
- leftContext RegExpConstructor::LeftContext DontDelete|ReadOnly
- $` RegExpConstructor::LeftContext DontDelete|ReadOnly|DontEnum
- rightContext RegExpConstructor::RightContext DontDelete|ReadOnly
- $' RegExpConstructor::RightContext DontDelete|ReadOnly|DontEnum
- $1 RegExpConstructor::Dollar1 DontDelete|ReadOnly
- $2 RegExpConstructor::Dollar2 DontDelete|ReadOnly
- $3 RegExpConstructor::Dollar3 DontDelete|ReadOnly
- $4 RegExpConstructor::Dollar4 DontDelete|ReadOnly
- $5 RegExpConstructor::Dollar5 DontDelete|ReadOnly
- $6 RegExpConstructor::Dollar6 DontDelete|ReadOnly
- $7 RegExpConstructor::Dollar7 DontDelete|ReadOnly
- $8 RegExpConstructor::Dollar8 DontDelete|ReadOnly
- $9 RegExpConstructor::Dollar9 DontDelete|ReadOnly
+ input RegExpConstructor::Input None
+ $_ RegExpConstructor::Input DontEnum
+ multiline RegExpConstructor::Multiline None
+ $* RegExpConstructor::Multiline DontEnum
+ lastMatch RegExpConstructor::LastMatch DontDelete|ReadOnly
+ $& RegExpConstructor::LastMatch DontDelete|ReadOnly|DontEnum
+ lastParen RegExpConstructor::LastParen DontDelete|ReadOnly
+ $+ RegExpConstructor::LastParen DontDelete|ReadOnly|DontEnum
+ leftContext RegExpConstructor::LeftContext DontDelete|ReadOnly
+ $` RegExpConstructor::LeftContext DontDelete|ReadOnly|DontEnum
+ rightContext RegExpConstructor::RightContext DontDelete|ReadOnly
+ $' RegExpConstructor::RightContext DontDelete|ReadOnly|DontEnum
+ $1 RegExpConstructor::Dollar1 DontDelete|ReadOnly
+ $2 RegExpConstructor::Dollar2 DontDelete|ReadOnly
+ $3 RegExpConstructor::Dollar3 DontDelete|ReadOnly
+ $4 RegExpConstructor::Dollar4 DontDelete|ReadOnly
+ $5 RegExpConstructor::Dollar5 DontDelete|ReadOnly
+ $6 RegExpConstructor::Dollar6 DontDelete|ReadOnly
+ $7 RegExpConstructor::Dollar7 DontDelete|ReadOnly
+ $8 RegExpConstructor::Dollar8 DontDelete|ReadOnly
+ $9 RegExpConstructor::Dollar9 DontDelete|ReadOnly
@end
*/
struct RegExpConstructorPrivate {
- // Global search cache / settings
- RegExpConstructorPrivate() : lastNumSubPatterns(0), multiline(false) { }
- UString lastInput;
- OwnArrayPtr<int> lastOvector;
- unsigned lastNumSubPatterns : 31;
- bool multiline : 1;
+ // Global search cache / settings
+ RegExpConstructorPrivate()
+ : lastNumSubPatterns(0)
+ , multiline(false)
+ {
+ }
+
+ UString lastInput;
+ OwnArrayPtr<int> lastOvector;
+ unsigned lastNumSubPatterns : 31;
+ bool multiline : 1;
};
-RegExpConstructor::RegExpConstructor(ExecState* exec, FunctionPrototype* funcProto, RegExpPrototype* regProto)
- : InternalFunction(funcProto, Identifier(exec, "RegExp"))
- , d(new RegExpConstructorPrivate)
+RegExpConstructor::RegExpConstructor(ExecState* exec, FunctionPrototype* functionPrototype, RegExpPrototype* regExpPrototype)
+ : InternalFunction(functionPrototype, Identifier(exec, "RegExp"))
+ , d(new RegExpConstructorPrivate)
{
- // ECMA 15.10.5.1 RegExp.prototype
- putDirect(exec->propertyNames().prototype, regProto, DontEnum | DontDelete | ReadOnly);
+ // ECMA 15.10.5.1 RegExp.prototype
+ putDirect(exec->propertyNames().prototype, regExpPrototype, DontEnum | DontDelete | ReadOnly);
- // no. of arguments for constructor
- putDirect(exec->propertyNames().length, jsNumber(exec, 2), ReadOnly | DontDelete | DontEnum);
+ // no. of arguments for constructor
+ putDirect(exec->propertyNames().length, jsNumber(exec, 2), ReadOnly | DontDelete | DontEnum);
}
/*
@@ -88,21 +93,21 @@
*/
void RegExpConstructor::performMatch(RegExp* r, const UString& s, int startOffset, int& position, int& length, int** ovector)
{
- OwnArrayPtr<int> tmpOvector;
- position = r->match(s, startOffset, &tmpOvector);
+ OwnArrayPtr<int> tmpOvector;
+ position = r->match(s, startOffset, &tmpOvector);
- if (ovector)
- *ovector = tmpOvector.get();
-
- if (position != -1) {
- ASSERT(tmpOvector);
+ if (ovector)
+ *ovector = tmpOvector.get();
- length = tmpOvector[1] - tmpOvector[0];
+ if (position != -1) {
+ ASSERT(tmpOvector);
- d->lastInput = s;
- d->lastOvector.set(tmpOvector.release());
- d->lastNumSubPatterns = r->numSubpatterns();
- }
+ length = tmpOvector[1] - tmpOvector[0];
+
+ d->lastInput = s;
+ d->lastOvector.set(tmpOvector.release());
+ d->lastNumSubPatterns = r->numSubpatterns();
+ }
}
class RegExpMatchesArray : public JSArray {
@@ -167,120 +172,120 @@
JSValue* RegExpConstructor::getBackref(ExecState* exec, unsigned i) const
{
- if (d->lastOvector && i <= d->lastNumSubPatterns)
- return jsString(exec, d->lastInput.substr(d->lastOvector[2 * i], d->lastOvector[2 * i + 1] - d->lastOvector[2 * i]));
- return jsString(exec, "");
+ if (d->lastOvector && i <= d->lastNumSubPatterns)
+ return jsString(exec, d->lastInput.substr(d->lastOvector[2 * i], d->lastOvector[2 * i + 1] - d->lastOvector[2 * i]));
+ return jsString(exec, "");
}
JSValue* RegExpConstructor::getLastParen(ExecState* exec) const
{
- unsigned i = d->lastNumSubPatterns;
- if (i > 0) {
- ASSERT(d->lastOvector);
- return jsString(exec, d->lastInput.substr(d->lastOvector[2 * i], d->lastOvector[2 * i + 1] - d->lastOvector[2 * i]));
- }
- return jsString(exec, "");
+ unsigned i = d->lastNumSubPatterns;
+ if (i > 0) {
+ ASSERT(d->lastOvector);
+ return jsString(exec, d->lastInput.substr(d->lastOvector[2 * i], d->lastOvector[2 * i + 1] - d->lastOvector[2 * i]));
+ }
+ return jsString(exec, "");
}
JSValue* RegExpConstructor::getLeftContext(ExecState* exec) const
{
- if (d->lastOvector)
- return jsString(exec, d->lastInput.substr(0, d->lastOvector[0]));
- return jsString(exec, "");
+ if (d->lastOvector)
+ return jsString(exec, d->lastInput.substr(0, d->lastOvector[0]));
+ return jsString(exec, "");
}
JSValue* RegExpConstructor::getRightContext(ExecState* exec) const
{
- if (d->lastOvector) {
- UString s = d->lastInput;
- return jsString(exec, s.substr(d->lastOvector[1], s.size() - d->lastOvector[1]));
- }
- return jsString(exec, "");
+ if (d->lastOvector) {
+ UString s = d->lastInput;
+ return jsString(exec, s.substr(d->lastOvector[1], s.size() - d->lastOvector[1]));
+ }
+ return jsString(exec, "");
}
-
-bool RegExpConstructor::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
+
+bool RegExpConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
- return getStaticValueSlot<RegExpConstructor, InternalFunction>(exec, ExecState::regExpConstructorTable(exec), this, propertyName, slot);
+ return getStaticValueSlot<RegExpConstructor, InternalFunction>(exec, ExecState::regExpConstructorTable(exec), this, propertyName, slot);
}
-JSValue *RegExpConstructor::getValueProperty(ExecState* exec, int token) const
+JSValue* RegExpConstructor::getValueProperty(ExecState* exec, int token) const
{
- switch (token) {
- case Dollar1:
- return getBackref(exec, 1);
- case Dollar2:
- return getBackref(exec, 2);
- case Dollar3:
- return getBackref(exec, 3);
- case Dollar4:
- return getBackref(exec, 4);
- case Dollar5:
- return getBackref(exec, 5);
- case Dollar6:
- return getBackref(exec, 6);
- case Dollar7:
- return getBackref(exec, 7);
- case Dollar8:
- return getBackref(exec, 8);
- case Dollar9:
- return getBackref(exec, 9);
- case Input:
- return jsString(exec, d->lastInput);
- case Multiline:
- return jsBoolean(d->multiline);
- case LastMatch:
- return getBackref(exec, 0);
- case LastParen:
- return getLastParen(exec);
- case LeftContext:
- return getLeftContext(exec);
- case RightContext:
- return getRightContext(exec);
- default:
- ASSERT_NOT_REACHED();
- }
+ switch (token) {
+ case Dollar1:
+ return getBackref(exec, 1);
+ case Dollar2:
+ return getBackref(exec, 2);
+ case Dollar3:
+ return getBackref(exec, 3);
+ case Dollar4:
+ return getBackref(exec, 4);
+ case Dollar5:
+ return getBackref(exec, 5);
+ case Dollar6:
+ return getBackref(exec, 6);
+ case Dollar7:
+ return getBackref(exec, 7);
+ case Dollar8:
+ return getBackref(exec, 8);
+ case Dollar9:
+ return getBackref(exec, 9);
+ case Input:
+ return jsString(exec, d->lastInput);
+ case Multiline:
+ return jsBoolean(d->multiline);
+ case LastMatch:
+ return getBackref(exec, 0);
+ case LastParen:
+ return getLastParen(exec);
+ case LeftContext:
+ return getLeftContext(exec);
+ case RightContext:
+ return getRightContext(exec);
+ default:
+ ASSERT_NOT_REACHED();
+ }
- return jsString(exec, "");
+ return jsString(exec, "");
}
-void RegExpConstructor::put(ExecState *exec, const Identifier &propertyName, JSValue *value)
+void RegExpConstructor::put(ExecState* exec, const Identifier& propertyName, JSValue* value)
{
lookupPut<RegExpConstructor, InternalFunction>(exec, propertyName, value, ExecState::regExpConstructorTable(exec), this);
}
-void RegExpConstructor::putValueProperty(ExecState *exec, int token, JSValue *value)
+void RegExpConstructor::putValueProperty(ExecState* exec, int token, JSValue* value)
{
- switch (token) {
- case Input:
- d->lastInput = value->toString(exec);
- break;
- case Multiline:
- d->multiline = value->toBoolean(exec);
- break;
- default:
- ASSERT(0);
- }
+ switch (token) {
+ case Input:
+ d->lastInput = value->toString(exec);
+ break;
+ case Multiline:
+ d->multiline = value->toBoolean(exec);
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
}
// ECMA 15.10.4
static JSObject* constructRegExp(ExecState* exec, const ArgList& args)
{
- JSValue* arg0 = args[0];
- JSValue* arg1 = args[1];
-
- if (arg0->isObject(&RegExpObject::info)) {
- if (!arg1->isUndefined())
- return throwError(exec, TypeError, "Cannot supply flags when constructing one RegExp from another.");
- return static_cast<JSObject*>(arg0);
- }
-
- UString pattern = arg0->isUndefined() ? UString("") : arg0->toString(exec);
- UString flags = arg1->isUndefined() ? UString("") : arg1->toString(exec);
-
- RefPtr<RegExp> regExp = RegExp::create(pattern, flags);
- return regExp->isValid()
- ? new (exec) RegExpObject(exec->lexicalGlobalObject()->regExpPrototype(), regExp.release())
- : throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(regExp->errorMessage()));
+ JSValue* arg0 = args[0];
+ JSValue* arg1 = args[1];
+
+ if (arg0->isObject(&RegExpObject::info)) {
+ if (!arg1->isUndefined())
+ return throwError(exec, TypeError, "Cannot supply flags when constructing one RegExp from another.");
+ return static_cast<JSObject*>(arg0);
+ }
+
+ UString pattern = arg0->isUndefined() ? UString("") : arg0->toString(exec);
+ UString flags = arg1->isUndefined() ? UString("") : arg1->toString(exec);
+
+ RefPtr<RegExp> regExp = RegExp::create(pattern, flags);
+ if (!regExp->isValid())
+ return throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(regExp->errorMessage()));
+ return new (exec) RegExpObject(exec->lexicalGlobalObject()->regExpPrototype(), regExp.release());
}
static JSObject* constructWithRegExpConstructor(ExecState* exec, JSObject*, const ArgList& args)
diff --git a/JavaScriptCore/kjs/RegExpConstructor.h b/JavaScriptCore/kjs/RegExpConstructor.h
index 018872d..1355f32 100644
--- a/JavaScriptCore/kjs/RegExpConstructor.h
+++ b/JavaScriptCore/kjs/RegExpConstructor.h
@@ -27,20 +27,35 @@
namespace KJS {
class FunctionPrototype;
- class RegExpPrototype;
class RegExp;
+ class RegExpPrototype;
struct RegExpConstructorPrivate;
class RegExpConstructor : public InternalFunction {
public:
- enum { Dollar1, Dollar2, Dollar3, Dollar4, Dollar5, Dollar6, Dollar7, Dollar8, Dollar9,
- Input, Multiline, LastMatch, LastParen, LeftContext, RightContext };
+ enum {
+ Dollar1,
+ Dollar2,
+ Dollar3,
+ Dollar4,
+ Dollar5,
+ Dollar6,
+ Dollar7,
+ Dollar8,
+ Dollar9,
+ Input,
+ Multiline,
+ LastMatch,
+ LastParen,
+ LeftContext,
+ RightContext
+ };
RegExpConstructor(ExecState*, FunctionPrototype*, RegExpPrototype*);
- virtual void put(ExecState*, const Identifier&, JSValue*);
+ virtual void put(ExecState*, const Identifier& propertyName, JSValue*);
void putValueProperty(ExecState*, int token, JSValue*);
- virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
+ virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
JSValue* getValueProperty(ExecState*, int token) const;
static const ClassInfo info;
@@ -52,6 +67,7 @@
private:
virtual ConstructType getConstructData(ConstructData&);
virtual CallType getCallData(CallData&);
+
virtual const ClassInfo* classInfo() const { return &info; }
JSValue* getBackref(ExecState*, unsigned) const;
@@ -62,6 +78,6 @@
OwnPtr<RegExpConstructorPrivate> d;
};
-} // namespace
+} // namespace KJS
-#endif
+#endif // RegExpConstructor_h
diff --git a/JavaScriptCore/kjs/RegExpObject.cpp b/JavaScriptCore/kjs/RegExpObject.cpp
index a066241..a210703 100644
--- a/JavaScriptCore/kjs/RegExpObject.cpp
+++ b/JavaScriptCore/kjs/RegExpObject.cpp
@@ -42,10 +42,10 @@
@end
*/
-RegExpObject::RegExpObject(RegExpPrototype* regexpProto, PassRefPtr<RegExp> regExp)
- : JSObject(regexpProto)
- , m_regExp(regExp)
- , m_lastIndex(0)
+RegExpObject::RegExpObject(RegExpPrototype* regExpPrototype, PassRefPtr<RegExp> regExp)
+ : JSObject(regExpPrototype)
+ , m_regExp(regExp)
+ , m_lastIndex(0)
{
}
@@ -55,7 +55,7 @@
bool RegExpObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
- return getStaticValueSlot<RegExpObject, JSObject>(exec, ExecState::regExpTable(exec), this, propertyName, slot);
+ return getStaticValueSlot<RegExpObject, JSObject>(exec, ExecState::regExpTable(exec), this, propertyName, slot);
}
JSValue* RegExpObject::getValueProperty(ExecState* exec, int token) const
@@ -133,9 +133,9 @@
JSValue* RegExpObject::exec(ExecState* exec, const ArgList& args)
{
- return match(exec, args)
- ? exec->lexicalGlobalObject()->regExpConstructor()->arrayOfMatches(exec)
- : jsNull();
+ if (match(exec, args))
+ return exec->lexicalGlobalObject()->regExpConstructor()->arrayOfMatches(exec);
+ return jsNull();
}
static JSValue* callRegExpObject(ExecState* exec, JSObject* function, JSValue*, const ArgList& args)
diff --git a/JavaScriptCore/kjs/RegExpObject.h b/JavaScriptCore/kjs/RegExpObject.h
index c200e97..9e84c9c 100644
--- a/JavaScriptCore/kjs/RegExpObject.h
+++ b/JavaScriptCore/kjs/RegExpObject.h
@@ -41,9 +41,9 @@
JSValue* test(ExecState*, const ArgList&);
JSValue* exec(ExecState*, const ArgList&);
- bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
+ bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
JSValue* getValueProperty(ExecState*, int token) const;
- void put(ExecState*, const Identifier&, JSValue*);
+ void put(ExecState*, const Identifier& propertyName, JSValue*);
void putValueProperty(ExecState*, int token, JSValue*);
virtual const ClassInfo* classInfo() const { return &info; }
diff --git a/JavaScriptCore/kjs/ScopeChain.cpp b/JavaScriptCore/kjs/ScopeChain.cpp
index 04594f8..08e230b 100644
--- a/JavaScriptCore/kjs/ScopeChain.cpp
+++ b/JavaScriptCore/kjs/ScopeChain.cpp
@@ -1,5 +1,4 @@
/*
- * This file is part of the KDE libraries
* Copyright (C) 2003, 2006, 2008 Apple Inc.
*
* This library is free software; you can redistribute it and/or
@@ -22,9 +21,9 @@
#include "config.h"
#include "ScopeChain.h"
-#include "PropertyNameArray.h"
-#include "JSObject.h"
#include "JSGlobalObject.h"
+#include "JSObject.h"
+#include "PropertyNameArray.h"
#include <stdio.h>
namespace KJS {
diff --git a/JavaScriptCore/kjs/ScopeChain.h b/JavaScriptCore/kjs/ScopeChain.h
index a48d0b0..e4d8ce3 100644
--- a/JavaScriptCore/kjs/ScopeChain.h
+++ b/JavaScriptCore/kjs/ScopeChain.h
@@ -1,5 +1,4 @@
/*
- * This file is part of the KDE libraries
* Copyright (C) 2003, 2008 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
@@ -67,10 +66,10 @@
ScopeChainIterator begin() const;
ScopeChainIterator end() const;
-
+
JSGlobalObject* globalObject() const; // defined in JSGlobalObject.h
JSObject* globalThisObject() const { return globalThis; }
-
+
#ifndef NDEBUG
void print() const;
#endif
@@ -86,12 +85,12 @@
{
ASSERT(next);
ScopeChainNode* result = next;
-
+
if (--refCount != 0)
++result->refCount;
else
delete this;
-
+
return result;
}
@@ -149,57 +148,57 @@
class ScopeChain {
public:
- ScopeChain(JSObject* o, JSObject* globalThis)
- : _node(new ScopeChainNode(0, o, globalThis))
+ ScopeChain(JSObject* o, JSObject* globalThis)
+ : m_node(new ScopeChainNode(0, o, globalThis))
{
}
ScopeChain(const ScopeChain& c)
- : _node(c._node->copy())
+ : m_node(c.m_node->copy())
{
}
ScopeChain& operator=(const ScopeChain& c);
explicit ScopeChain(ScopeChainNode* node)
- : _node(node->copy())
+ : m_node(node->copy())
{
}
- ~ScopeChain() { _node->deref(); }
+ ~ScopeChain() { m_node->deref(); }
void swap(ScopeChain&);
- ScopeChainNode* node() const { return _node; }
+ ScopeChainNode* node() const { return m_node; }
- JSObject* top() const { return _node->object; }
- JSObject* bottom() const { return _node->bottom(); }
+ JSObject* top() const { return m_node->object; }
+ JSObject* bottom() const { return m_node->bottom(); }
- ScopeChainIterator begin() const { return _node->begin(); }
- ScopeChainIterator end() const { return _node->end(); }
+ ScopeChainIterator begin() const { return m_node->begin(); }
+ ScopeChainIterator end() const { return m_node->end(); }
- void push(JSObject* o) { _node = _node->push(o); }
+ void push(JSObject* o) { m_node = m_node->push(o); }
- void pop() { _node = _node->pop(); }
- void clear() { _node->deref(); _node = 0; }
+ void pop() { m_node = m_node->pop(); }
+ void clear() { m_node->deref(); m_node = 0; }
- JSGlobalObject* globalObject() const { return _node->globalObject(); }
+ JSGlobalObject* globalObject() const { return m_node->globalObject(); }
void mark() const;
#ifndef NDEBUG
- void print() const { _node->print(); }
+ void print() const { m_node->print(); }
#endif
private:
- ScopeChainNode* _node;
+ ScopeChainNode* m_node;
};
inline void ScopeChain::swap(ScopeChain& o)
{
- ScopeChainNode* tmp = _node;
- _node = o._node;
- o._node = tmp;
+ ScopeChainNode* tmp = m_node;
+ m_node = o.m_node;
+ o.m_node = tmp;
}
inline ScopeChain& ScopeChain::operator=(const ScopeChain& c)
diff --git a/JavaScriptCore/kjs/ScopeChainMark.h b/JavaScriptCore/kjs/ScopeChainMark.h
index d03193e..968a43d 100644
--- a/JavaScriptCore/kjs/ScopeChainMark.h
+++ b/JavaScriptCore/kjs/ScopeChainMark.h
@@ -27,7 +27,7 @@
inline void ScopeChain::mark() const
{
- for (ScopeChainNode* n = _node; n; n = n->next) {
+ for (ScopeChainNode* n = m_node; n; n = n->next) {
JSObject* o = n->object;
if (!o->marked())
o->mark();
@@ -36,4 +36,4 @@
} // namespace KJS
-#endif
+#endif // ScopeChainMark_h
diff --git a/JavaScriptCore/kjs/SourceProvider.h b/JavaScriptCore/kjs/SourceProvider.h
index 3e3b23f..716dcdd 100644
--- a/JavaScriptCore/kjs/SourceProvider.h
+++ b/JavaScriptCore/kjs/SourceProvider.h
@@ -44,7 +44,10 @@
class UStringSourceProvider : public SourceProvider {
public:
- static PassRefPtr<UStringSourceProvider> create(const UString& source) { return adoptRef(new UStringSourceProvider(source)); }
+ static PassRefPtr<UStringSourceProvider> create(const UString& source)
+ {
+ return adoptRef(new UStringSourceProvider(source));
+ }
UString getRange(int start, int end) const { return m_source.substr(start, end - start); }
const UChar* data() const { return m_source.data(); }
diff --git a/JavaScriptCore/kjs/StringConstructor.cpp b/JavaScriptCore/kjs/StringConstructor.cpp
index 528312b..91f0c62 100644
--- a/JavaScriptCore/kjs/StringConstructor.cpp
+++ b/JavaScriptCore/kjs/StringConstructor.cpp
@@ -36,7 +36,7 @@
UChar* p = buf;
ArgList::const_iterator end = args.end();
for (ArgList::const_iterator it = args.begin(); it != end; ++it)
- *p++ = static_cast<UChar>((*it)->toUInt32(exec));
+ *p++ = static_cast<UChar>((*it)->toUInt32(exec));
s = UString(buf, args.size(), false);
} else
s = "";
@@ -44,17 +44,17 @@
return jsString(exec, s);
}
-StringConstructor::StringConstructor(ExecState* exec, FunctionPrototype* funcProto, StringPrototype* stringProto)
- : InternalFunction(funcProto, Identifier(exec, stringProto->classInfo()->className))
+StringConstructor::StringConstructor(ExecState* exec, FunctionPrototype* functionPrototype, StringPrototype* stringPrototype)
+ : InternalFunction(functionPrototype, Identifier(exec, stringPrototype->classInfo()->className))
{
- // ECMA 15.5.3.1 String.prototype
- putDirect(exec->propertyNames().prototype, stringProto, ReadOnly | DontEnum | DontDelete);
+ // ECMA 15.5.3.1 String.prototype
+ putDirect(exec->propertyNames().prototype, stringPrototype, ReadOnly | DontEnum | DontDelete);
- // ECMA 15.5.3.2 fromCharCode()
- putDirectFunction(new (exec) PrototypeFunction(exec, funcProto, 1, exec->propertyNames().fromCharCode, stringFromCharCode), DontEnum);
+ // ECMA 15.5.3.2 fromCharCode()
+ putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 1, exec->propertyNames().fromCharCode, stringFromCharCode), DontEnum);
- // no. of arguments for constructor
- putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete);
+ // no. of arguments for constructor
+ putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete);
}
// ECMA 15.5.2
diff --git a/JavaScriptCore/kjs/StringConstructor.h b/JavaScriptCore/kjs/StringConstructor.h
index a49900c..13f0a2e 100644
--- a/JavaScriptCore/kjs/StringConstructor.h
+++ b/JavaScriptCore/kjs/StringConstructor.h
@@ -25,20 +25,16 @@
namespace KJS {
- class FunctionPrototype;
- class StringPrototype;
+ class FunctionPrototype;
+ class StringPrototype;
- /**
- * @internal
- *
- * The initial value of the the global variable's "String" property
- */
- class StringConstructor : public InternalFunction {
- public:
- StringConstructor(ExecState*, FunctionPrototype*, StringPrototype*);
- virtual ConstructType getConstructData(ConstructData&);
- virtual CallType getCallData(CallData&);
- };
+ class StringConstructor : public InternalFunction {
+ public:
+ StringConstructor(ExecState*, FunctionPrototype*, StringPrototype*);
+
+ virtual ConstructType getConstructData(ConstructData&);
+ virtual CallType getCallData(CallData&);
+ };
} // namespace KJS
diff --git a/JavaScriptCore/kjs/StringObject.cpp b/JavaScriptCore/kjs/StringObject.cpp
index 05ff7d5..579f412 100644
--- a/JavaScriptCore/kjs/StringObject.cpp
+++ b/JavaScriptCore/kjs/StringObject.cpp
@@ -27,22 +27,22 @@
const ClassInfo StringObject::info = { "String", 0, 0, 0 };
-StringObject::StringObject(ExecState* exec, JSObject* proto)
- : JSWrapperObject(proto)
+StringObject::StringObject(ExecState* exec, JSObject* prototype)
+ : JSWrapperObject(prototype)
{
- setInternalValue(jsString(exec, ""));
+ setInternalValue(jsString(exec, ""));
}
-StringObject::StringObject(JSObject* proto, JSString* string)
- : JSWrapperObject(proto)
+StringObject::StringObject(JSObject* prototype, JSString* string)
+ : JSWrapperObject(prototype)
{
- setInternalValue(string);
+ setInternalValue(string);
}
-StringObject::StringObject(ExecState* exec, JSObject* proto, const UString& string)
- : JSWrapperObject(proto)
+StringObject::StringObject(ExecState* exec, JSObject* prototype, const UString& string)
+ : JSWrapperObject(prototype)
{
- setInternalValue(jsString(exec, string));
+ setInternalValue(jsString(exec, string));
}
bool StringObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
@@ -66,19 +66,19 @@
JSObject::put(exec, propertyName, value);
}
-bool StringObject::deleteProperty(ExecState *exec, const Identifier &propertyName)
+bool StringObject::deleteProperty(ExecState* exec, const Identifier& propertyName)
{
- if (propertyName == exec->propertyNames().length)
- return false;
- return JSObject::deleteProperty(exec, propertyName);
+ if (propertyName == exec->propertyNames().length)
+ return false;
+ return JSObject::deleteProperty(exec, propertyName);
}
void StringObject::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
{
- int size = internalValue()->value().size();
- for (int i = 0; i < size; i++)
- propertyNames.add(Identifier(exec, UString::from(i)));
- return JSObject::getPropertyNames(exec, propertyNames);
+ int size = internalValue()->value().size();
+ for (int i = 0; i < size; ++i)
+ propertyNames.add(Identifier(exec, UString::from(i)));
+ return JSObject::getPropertyNames(exec, propertyNames);
}
UString StringObject::toString(ExecState*) const
diff --git a/JavaScriptCore/kjs/StringObject.h b/JavaScriptCore/kjs/StringObject.h
index 7caddb6..2cd1a6a 100644
--- a/JavaScriptCore/kjs/StringObject.h
+++ b/JavaScriptCore/kjs/StringObject.h
@@ -26,32 +26,32 @@
namespace KJS {
- class StringObject : public JSWrapperObject {
- public:
- StringObject(ExecState*, JSObject* prototype);
- StringObject(ExecState*, JSObject* prototype, const UString&);
+ class StringObject : public JSWrapperObject {
+ public:
+ StringObject(ExecState*, JSObject* prototype);
+ StringObject(ExecState*, JSObject* prototype, const UString&);
- static StringObject* create(ExecState*, JSString*);
+ static StringObject* create(ExecState*, JSString*);
- virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
- virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
+ virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
+ virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
- virtual void put(ExecState* exec, const Identifier& propertyName, JSValue*);
- virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
- virtual void getPropertyNames(ExecState*, PropertyNameArray&);
+ virtual void put(ExecState* exec, const Identifier& propertyName, JSValue*);
+ virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
+ virtual void getPropertyNames(ExecState*, PropertyNameArray&);
- virtual const ClassInfo* classInfo() const { return &info; }
- static const ClassInfo info;
+ virtual const ClassInfo* classInfo() const { return &info; }
+ static const ClassInfo info;
- JSString* internalValue() const { return static_cast<JSString*>(JSWrapperObject::internalValue());}
+ JSString* internalValue() const { return static_cast<JSString*>(JSWrapperObject::internalValue());}
- protected:
- StringObject(JSObject* prototype, JSString*);
+ protected:
+ StringObject(JSObject* prototype, JSString*);
- private:
- virtual UString toString(ExecState*) const;
- virtual UString toThisString(ExecState*) const;
- virtual JSString* toThisJSString(ExecState*);
+ private:
+ virtual UString toString(ExecState*) const;
+ virtual UString toThisString(ExecState*) const;
+ virtual JSString* toThisJSString(ExecState*);
};
} // namespace KJS
diff --git a/JavaScriptCore/kjs/StringObjectThatMasqueradesAsUndefined.h b/JavaScriptCore/kjs/StringObjectThatMasqueradesAsUndefined.h
index 5e2f1f7..b837c74 100644
--- a/JavaScriptCore/kjs/StringObjectThatMasqueradesAsUndefined.h
+++ b/JavaScriptCore/kjs/StringObjectThatMasqueradesAsUndefined.h
@@ -26,14 +26,17 @@
namespace KJS {
- // WebCore uses this to make style.filter undetectable
- class StringObjectThatMasqueradesAsUndefined : public StringObject {
- public:
- StringObjectThatMasqueradesAsUndefined(ExecState* exec, JSObject* proto, const UString& string)
- : StringObject(exec, proto, string) { }
- virtual bool masqueradeAsUndefined() const { return true; }
- virtual bool toBoolean(ExecState*) const { return false; }
- };
+ // WebCore uses this to make style.filter undetectable
+ class StringObjectThatMasqueradesAsUndefined : public StringObject {
+ public:
+ StringObjectThatMasqueradesAsUndefined(ExecState* exec, JSObject* prototype, const UString& string)
+ : StringObject(exec, prototype, string)
+ {
+ }
+
+ virtual bool masqueradeAsUndefined() const { return true; }
+ virtual bool toBoolean(ExecState*) const { return false; }
+ };
} // namespace KJS
diff --git a/JavaScriptCore/kjs/StringPrototype.cpp b/JavaScriptCore/kjs/StringPrototype.cpp
index 5020557..5f3ea4f 100644
--- a/JavaScriptCore/kjs/StringPrototype.cpp
+++ b/JavaScriptCore/kjs/StringPrototype.cpp
@@ -77,122 +77,122 @@
/* Source for StringPrototype.lut.h
@begin stringTable 26
- toString stringProtoFuncToString DontEnum|Function 0
- valueOf stringProtoFuncToString DontEnum|Function 0
- charAt stringProtoFuncCharAt DontEnum|Function 1
- charCodeAt stringProtoFuncCharCodeAt DontEnum|Function 1
- concat stringProtoFuncConcat DontEnum|Function 1
- indexOf stringProtoFuncIndexOf DontEnum|Function 1
- lastIndexOf stringProtoFuncLastIndexOf DontEnum|Function 1
- match stringProtoFuncMatch DontEnum|Function 1
- replace stringProtoFuncReplace DontEnum|Function 2
- search stringProtoFuncSearch DontEnum|Function 1
- slice stringProtoFuncSlice DontEnum|Function 2
- split stringProtoFuncSplit DontEnum|Function 2
- substr stringProtoFuncSubstr DontEnum|Function 2
- substring stringProtoFuncSubstring DontEnum|Function 2
- toLowerCase stringProtoFuncToLowerCase DontEnum|Function 0
- toUpperCase stringProtoFuncToUpperCase DontEnum|Function 0
- toLocaleLowerCase stringProtoFuncToLocaleLowerCase DontEnum|Function 0
- toLocaleUpperCase stringProtoFuncToLocaleUpperCase DontEnum|Function 0
- localeCompare stringProtoFuncLocaleCompare DontEnum|Function 1
+ toString stringProtoFuncToString DontEnum|Function 0
+ valueOf stringProtoFuncToString DontEnum|Function 0
+ charAt stringProtoFuncCharAt DontEnum|Function 1
+ charCodeAt stringProtoFuncCharCodeAt DontEnum|Function 1
+ concat stringProtoFuncConcat DontEnum|Function 1
+ indexOf stringProtoFuncIndexOf DontEnum|Function 1
+ lastIndexOf stringProtoFuncLastIndexOf DontEnum|Function 1
+ match stringProtoFuncMatch DontEnum|Function 1
+ replace stringProtoFuncReplace DontEnum|Function 2
+ search stringProtoFuncSearch DontEnum|Function 1
+ slice stringProtoFuncSlice DontEnum|Function 2
+ split stringProtoFuncSplit DontEnum|Function 2
+ substr stringProtoFuncSubstr DontEnum|Function 2
+ substring stringProtoFuncSubstring DontEnum|Function 2
+ toLowerCase stringProtoFuncToLowerCase DontEnum|Function 0
+ toUpperCase stringProtoFuncToUpperCase DontEnum|Function 0
+ toLocaleLowerCase stringProtoFuncToLocaleLowerCase DontEnum|Function 0
+ toLocaleUpperCase stringProtoFuncToLocaleUpperCase DontEnum|Function 0
+ localeCompare stringProtoFuncLocaleCompare DontEnum|Function 1
- big stringProtoFuncBig DontEnum|Function 0
- small stringProtoFuncSmall DontEnum|Function 0
- blink stringProtoFuncBlink DontEnum|Function 0
- bold stringProtoFuncBold DontEnum|Function 0
- fixed stringProtoFuncFixed DontEnum|Function 0
- italics stringProtoFuncItalics DontEnum|Function 0
- strike stringProtoFuncStrike DontEnum|Function 0
- sub stringProtoFuncSub DontEnum|Function 0
- sup stringProtoFuncSup DontEnum|Function 0
- fontcolor stringProtoFuncFontcolor DontEnum|Function 1
- fontsize stringProtoFuncFontsize DontEnum|Function 1
- anchor stringProtoFuncAnchor DontEnum|Function 1
- link stringProtoFuncLink DontEnum|Function 1
+ big stringProtoFuncBig DontEnum|Function 0
+ small stringProtoFuncSmall DontEnum|Function 0
+ blink stringProtoFuncBlink DontEnum|Function 0
+ bold stringProtoFuncBold DontEnum|Function 0
+ fixed stringProtoFuncFixed DontEnum|Function 0
+ italics stringProtoFuncItalics DontEnum|Function 0
+ strike stringProtoFuncStrike DontEnum|Function 0
+ sub stringProtoFuncSub DontEnum|Function 0
+ sup stringProtoFuncSup DontEnum|Function 0
+ fontcolor stringProtoFuncFontcolor DontEnum|Function 1
+ fontsize stringProtoFuncFontsize DontEnum|Function 1
+ anchor stringProtoFuncAnchor DontEnum|Function 1
+ link stringProtoFuncLink DontEnum|Function 1
@end
*/
// ECMA 15.5.4
-StringPrototype::StringPrototype(ExecState* exec, ObjectPrototype* objProto)
- : StringObject(exec, objProto)
+StringPrototype::StringPrototype(ExecState* exec, ObjectPrototype* objectPrototype)
+ : StringObject(exec, objectPrototype)
{
- // The constructor will be added later, after StringConstructor has been built
- putDirect(exec->propertyNames().length, jsNumber(exec, 0), DontDelete | ReadOnly | DontEnum);
+ // The constructor will be added later, after StringConstructor has been built
+ putDirect(exec->propertyNames().length, jsNumber(exec, 0), DontDelete | ReadOnly | DontEnum);
}
-bool StringPrototype::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot)
+bool StringPrototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot &slot)
{
- return getStaticFunctionSlot<StringObject>(exec, ExecState::stringTable(exec), this, propertyName, slot);
+ return getStaticFunctionSlot<StringObject>(exec, ExecState::stringTable(exec), this, propertyName, slot);
}
// ------------------------------ Functions --------------------------
static inline UString substituteBackreferences(const UString& replacement, const UString& source, const int* ovector, RegExp* reg)
{
- UString substitutedReplacement;
- int offset = 0;
- int i = -1;
- while ((i = replacement.find('$', i + 1)) != -1) {
- if (i + 1 == replacement.size())
- break;
+ UString substitutedReplacement;
+ int offset = 0;
+ int i = -1;
+ while ((i = replacement.find('$', i + 1)) != -1) {
+ if (i + 1 == replacement.size())
+ break;
- unsigned short ref = replacement[i + 1];
- if (ref == '$') {
- // "$$" -> "$"
- ++i;
- substitutedReplacement.append(replacement.data() + offset, i - offset);
+ unsigned short ref = replacement[i + 1];
+ if (ref == '$') {
+ // "$$" -> "$"
+ ++i;
+ substitutedReplacement.append(replacement.data() + offset, i - offset);
+ offset = i + 1;
+ substitutedReplacement.append('$');
+ continue;
+ }
+
+ int backrefStart;
+ int backrefLength;
+ int advance = 0;
+ if (ref == '&') {
+ backrefStart = ovector[0];
+ backrefLength = ovector[1] - backrefStart;
+ } else if (ref == '`') {
+ backrefStart = 0;
+ backrefLength = ovector[0];
+ } else if (ref == '\'') {
+ backrefStart = ovector[1];
+ backrefLength = source.size() - backrefStart;
+ } else if (ref >= '0' && ref <= '9') {
+ // 1- and 2-digit back references are allowed
+ unsigned backrefIndex = ref - '0';
+ if (backrefIndex > reg->numSubpatterns())
+ continue;
+ if (replacement.size() > i + 2) {
+ ref = replacement[i + 2];
+ if (ref >= '0' && ref <= '9') {
+ backrefIndex = 10 * backrefIndex + ref - '0';
+ if (backrefIndex > reg->numSubpatterns())
+ backrefIndex = backrefIndex / 10; // Fall back to the 1-digit reference
+ else
+ advance = 1;
+ }
+ }
+ backrefStart = ovector[2 * backrefIndex];
+ backrefLength = ovector[2 * backrefIndex + 1] - backrefStart;
+ } else
+ continue;
+
+ if (i - offset)
+ substitutedReplacement.append(replacement.data() + offset, i - offset);
+ i += 1 + advance;
offset = i + 1;
- substitutedReplacement.append('$');
- continue;
+ substitutedReplacement.append(source.data() + backrefStart, backrefLength);
}
- int backrefStart;
- int backrefLength;
- int advance = 0;
- if (ref == '&') {
- backrefStart = ovector[0];
- backrefLength = ovector[1] - backrefStart;
- } else if (ref == '`') {
- backrefStart = 0;
- backrefLength = ovector[0];
- } else if (ref == '\'') {
- backrefStart = ovector[1];
- backrefLength = source.size() - backrefStart;
- } else if (ref >= '0' && ref <= '9') {
- // 1- and 2-digit back references are allowed
- unsigned backrefIndex = ref - '0';
- if (backrefIndex > reg->numSubpatterns())
- continue;
- if (replacement.size() > i + 2) {
- ref = replacement[i + 2];
- if (ref >= '0' && ref <= '9') {
- backrefIndex = 10 * backrefIndex + ref - '0';
- if (backrefIndex > reg->numSubpatterns())
- backrefIndex = backrefIndex / 10; // Fall back to the 1-digit reference
- else
- advance = 1;
- }
- }
- backrefStart = ovector[2 * backrefIndex];
- backrefLength = ovector[2 * backrefIndex + 1] - backrefStart;
- } else
- continue;
+ if (!offset)
+ return replacement;
- if (i - offset)
- substitutedReplacement.append(replacement.data() + offset, i - offset);
- i += 1 + advance;
- offset = i + 1;
- substitutedReplacement.append(source.data() + backrefStart, backrefLength);
- }
+ if (replacement.size() - offset)
+ substitutedReplacement.append(replacement.data() + offset, replacement.size() - offset);
- if (!offset)
- return replacement;
-
- if (replacement.size() - offset)
- substitutedReplacement.append(replacement.data() + offset, replacement.size() - offset);
-
- return substitutedReplacement;
+ return substitutedReplacement;
}
static inline int localeCompare(const UString& a, const UString& b)
@@ -202,103 +202,102 @@
JSValue* stringProtoFuncReplace(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)
{
- JSString* sourceVal = thisValue->toThisJSString(exec);
- const UString& source = sourceVal->value();
+ JSString* sourceVal = thisValue->toThisJSString(exec);
+ const UString& source = sourceVal->value();
- JSValue* pattern = args[0];
+ JSValue* pattern = args[0];
- JSValue* replacement = args[1];
- UString replacementString;
- CallData callData;
- CallType callType = replacement->getCallData(callData);
- if (callType == CallTypeNone)
- replacementString = replacement->toString(exec);
+ JSValue* replacement = args[1];
+ UString replacementString;
+ CallData callData;
+ CallType callType = replacement->getCallData(callData);
+ if (callType == CallTypeNone)
+ replacementString = replacement->toString(exec);
- if (pattern->isObject(&RegExpObject::info)) {
- RegExp* reg = static_cast<RegExpObject*>(pattern)->regExp();
- bool global = reg->global();
+ if (pattern->isObject(&RegExpObject::info)) {
+ RegExp* reg = static_cast<RegExpObject*>(pattern)->regExp();
+ bool global = reg->global();
- RegExpConstructor* regExpObj = exec->lexicalGlobalObject()->regExpConstructor();
+ RegExpConstructor* regExpObj = exec->lexicalGlobalObject()->regExpConstructor();
- int lastIndex = 0;
- int startPosition = 0;
+ int lastIndex = 0;
+ int startPosition = 0;
- Vector<UString::Range, 16> sourceRanges;
- Vector<UString, 16> replacements;
+ Vector<UString::Range, 16> sourceRanges;
+ Vector<UString, 16> replacements;
- // This is either a loop (if global is set) or a one-way (if not).
- do {
- int matchIndex;
- int matchLen;
- int* ovector;
- regExpObj->performMatch(reg, source, startPosition, matchIndex, matchLen, &ovector);
- if (matchIndex < 0)
- break;
+ // This is either a loop (if global is set) or a one-way (if not).
+ do {
+ int matchIndex;
+ int matchLen;
+ int* ovector;
+ regExpObj->performMatch(reg, source, startPosition, matchIndex, matchLen, &ovector);
+ if (matchIndex < 0)
+ break;
- sourceRanges.append(UString::Range(lastIndex, matchIndex - lastIndex));
+ sourceRanges.append(UString::Range(lastIndex, matchIndex - lastIndex));
- if (callType != CallTypeNone) {
- int completeMatchStart = ovector[0];
- ArgList args;
+ if (callType != CallTypeNone) {
+ int completeMatchStart = ovector[0];
+ ArgList args;
- for (unsigned i = 0; i < reg->numSubpatterns() + 1; i++) {
- int matchStart = ovector[i * 2];
- int matchLen = ovector[i * 2 + 1] - matchStart;
+ for (unsigned i = 0; i < reg->numSubpatterns() + 1; ++i) {
+ int matchStart = ovector[i * 2];
+ int matchLen = ovector[i * 2 + 1] - matchStart;
- if (matchStart < 0)
- args.append(jsUndefined());
- else
- args.append(jsString(exec, source.substr(matchStart, matchLen)));
- }
-
- args.append(jsNumber(exec, completeMatchStart));
- args.append(sourceVal);
+ if (matchStart < 0)
+ args.append(jsUndefined());
+ else
+ args.append(jsString(exec, source.substr(matchStart, matchLen)));
+ }
- replacements.append(call(exec, replacement, callType, callData, exec->globalThisValue(), args)->toString(exec));
- } else
- replacements.append(substituteBackreferences(replacementString, source, ovector, reg));
+ args.append(jsNumber(exec, completeMatchStart));
+ args.append(sourceVal);
- lastIndex = matchIndex + matchLen;
- startPosition = lastIndex;
+ replacements.append(call(exec, replacement, callType, callData, exec->globalThisValue(), args)->toString(exec));
+ } else
+ replacements.append(substituteBackreferences(replacementString, source, ovector, reg));
- // special case of empty match
- if (matchLen == 0) {
- startPosition++;
- if (startPosition > source.size())
- break;
- }
- } while (global);
+ lastIndex = matchIndex + matchLen;
+ startPosition = lastIndex;
- if (lastIndex < source.size())
- sourceRanges.append(UString::Range(lastIndex, source.size() - lastIndex));
+ // special case of empty match
+ if (matchLen == 0) {
+ startPosition++;
+ if (startPosition > source.size())
+ break;
+ }
+ } while (global);
- UString result = source.spliceSubstringsWithSeparators(sourceRanges.data(), sourceRanges.size(), replacements.data(), replacements.size());
+ if (lastIndex < source.size())
+ sourceRanges.append(UString::Range(lastIndex, source.size() - lastIndex));
- if (result == source)
- return sourceVal;
+ UString result = source.spliceSubstringsWithSeparators(sourceRanges.data(), sourceRanges.size(), replacements.data(), replacements.size());
- return jsString(exec, result);
- }
-
- // First arg is a string
- UString patternString = pattern->toString(exec);
- int matchPos = source.find(patternString);
- int matchLen = patternString.size();
- // Do the replacement
- if (matchPos == -1)
- return sourceVal;
-
- if (callType != CallTypeNone) {
- ArgList args;
-
- args.append(jsString(exec, source.substr(matchPos, matchLen)));
- args.append(jsNumber(exec, matchPos));
- args.append(sourceVal);
-
- replacementString = call(exec, replacement, callType, callData, exec->globalThisValue(), args)->toString(exec);
- }
+ if (result == source)
+ return sourceVal;
- return jsString(exec, source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen));
+ return jsString(exec, result);
+ }
+
+ // First arg is a string
+ UString patternString = pattern->toString(exec);
+ int matchPos = source.find(patternString);
+ int matchLen = patternString.size();
+ // Do the replacement
+ if (matchPos == -1)
+ return sourceVal;
+
+ if (callType != CallTypeNone) {
+ ArgList args;
+ args.append(jsString(exec, source.substr(matchPos, matchLen)));
+ args.append(jsNumber(exec, matchPos));
+ args.append(sourceVal);
+
+ replacementString = call(exec, replacement, callType, callData, exec->globalThisValue(), args)->toString(exec);
+ }
+
+ return jsString(exec, source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen));
}
JSValue* stringProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)
@@ -323,9 +322,9 @@
JSValue* a0 = args[0];
double dpos = a0->toInteger(exec);
if (dpos >= 0 && dpos < len)
- u = s.substr(static_cast<int>(dpos), 1);
+ u = s.substr(static_cast<int>(dpos), 1);
else
- u = "";
+ u = "";
return jsString(exec, u);
}
@@ -339,9 +338,9 @@
JSValue* a0 = args[0];
double dpos = a0->toInteger(exec);
if (dpos >= 0 && dpos < len)
- result = jsNumber(exec, s[static_cast<int>(dpos)]);
+ result = jsNumber(exec, s[static_cast<int>(dpos)]);
else
- result = jsNaN(exec);
+ result = jsNaN(exec);
return result;
}
@@ -350,9 +349,8 @@
UString s = thisValue->toThisString(exec);
ArgList::const_iterator end = args.end();
- for (ArgList::const_iterator it = args.begin(); it != end; ++it) {
+ for (ArgList::const_iterator it = args.begin(); it != end; ++it)
s += (*it)->toString(exec);
- }
return jsString(exec, s);
}
@@ -379,7 +377,7 @@
JSValue* a0 = args[0];
JSValue* a1 = args[1];
-
+
UString u2 = a0->toString(exec);
double dpos = a1->toIntegerPreserveNaN(exec);
if (dpos < 0)
@@ -398,49 +396,46 @@
UString u = s;
RefPtr<RegExp> reg;
RegExpObject* imp = 0;
- if (a0->isObject() && static_cast<JSObject *>(a0)->inherits(&RegExpObject::info)) {
- reg = static_cast<RegExpObject *>(a0)->regExp();
- } else {
- /*
- * ECMA 15.5.4.12 String.prototype.search (regexp)
- * If regexp is not an object whose [[Class]] property is "RegExp", it is
- * replaced with the result of the expression new RegExp(regexp).
- */
- reg = RegExp::create(a0->toString(exec));
+ if (a0->isObject() && static_cast<JSObject *>(a0)->inherits(&RegExpObject::info))
+ reg = static_cast<RegExpObject *>(a0)->regExp();
+ else {
+ /*
+ * ECMA 15.5.4.12 String.prototype.search (regexp)
+ * If regexp is not an object whose [[Class]] property is "RegExp", it is
+ * replaced with the result of the expression new RegExp(regexp).
+ */
+ reg = RegExp::create(a0->toString(exec));
}
RegExpConstructor* regExpObj = exec->lexicalGlobalObject()->regExpConstructor();
int pos;
int matchLength;
regExpObj->performMatch(reg.get(), u, 0, pos, matchLength);
- JSValue* result;
if (!(reg->global())) {
- // case without 'g' flag is handled like RegExp.prototype.exec
- if (pos < 0)
- result = jsNull();
- else
- result = regExpObj->arrayOfMatches(exec);
- } else {
- // return array of matches
- ArgList list;
- int lastIndex = 0;
- while (pos >= 0) {
+ // case without 'g' flag is handled like RegExp.prototype.exec
+ if (pos < 0)
+ return jsNull();
+ return regExpObj->arrayOfMatches(exec);
+ }
+
+ // return array of matches
+ ArgList list;
+ int lastIndex = 0;
+ while (pos >= 0) {
list.append(jsString(exec, u.substr(pos, matchLength)));
lastIndex = pos;
pos += matchLength == 0 ? 1 : matchLength;
regExpObj->performMatch(reg.get(), u, pos, pos, matchLength);
- }
- if (imp)
+ }
+ if (imp)
imp->setLastIndex(lastIndex);
- if (list.isEmpty()) {
+ if (list.isEmpty()) {
// if there are no matches at all, it's important to return
// Null instead of an empty array, because this matches
// other browsers and because Null is a false value.
- result = jsNull();
- } else {
- result = constructArray(exec, list);
- }
+ return jsNull();
}
- return result;
+
+ return constructArray(exec, list);
}
JSValue* stringProtoFuncSearch(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)
@@ -451,15 +446,15 @@
UString u = s;
RefPtr<RegExp> reg;
- if (a0->isObject() && static_cast<JSObject*>(a0)->inherits(&RegExpObject::info)) {
- reg = static_cast<RegExpObject*>(a0)->regExp();
- } else {
- /*
- * ECMA 15.5.4.12 String.prototype.search (regexp)
- * If regexp is not an object whose [[Class]] property is "RegExp", it is
- * replaced with the result of the expression new RegExp(regexp).
- */
- reg = RegExp::create(a0->toString(exec));
+ if (a0->isObject() && static_cast<JSObject*>(a0)->inherits(&RegExpObject::info))
+ reg = static_cast<RegExpObject*>(a0)->regExp();
+ else {
+ /*
+ * ECMA 15.5.4.12 String.prototype.search (regexp)
+ * If regexp is not an object whose [[Class]] property is "RegExp", it is
+ * replaced with the result of the expression new RegExp(regexp).
+ */
+ reg = RegExp::create(a0->toString(exec));
}
RegExpConstructor* regExpObj = exec->lexicalGlobalObject()->regExpConstructor();
int pos;
@@ -507,55 +502,56 @@
int p0 = 0;
uint32_t limit = a1->isUndefined() ? 0xFFFFFFFFU : a1->toUInt32(exec);
if (a0->isObject() && static_cast<JSObject *>(a0)->inherits(&RegExpObject::info)) {
- RegExp *reg = static_cast<RegExpObject *>(a0)->regExp();
- if (u.isEmpty() && reg->match(u, 0) >= 0) {
- // empty string matched by regexp -> empty array
- res->put(exec, exec->propertyNames().length, jsNumber(exec, 0));
- return result;
- }
- pos = 0;
- while (static_cast<uint32_t>(i) != limit && pos < u.size()) {
- OwnArrayPtr<int> ovector;
- int mpos = reg->match(u, pos, &ovector);
- if (mpos < 0)
- break;
- int mlen = ovector[1] - ovector[0];
- pos = mpos + (mlen == 0 ? 1 : mlen);
- if (mpos != p0 || mlen) {
- res->put(exec,i, jsString(exec, u.substr(p0, mpos-p0)));
- p0 = mpos + mlen;
- i++;
+ RegExp *reg = static_cast<RegExpObject *>(a0)->regExp();
+ if (u.isEmpty() && reg->match(u, 0) >= 0) {
+ // empty string matched by regexp -> empty array
+ res->put(exec, exec->propertyNames().length, jsNumber(exec, 0));
+ return result;
}
- for (unsigned si = 1; si <= reg->numSubpatterns(); ++si) {
- int spos = ovector[si * 2];
- if (spos < 0)
- res->put(exec, i++, jsUndefined());
- else
- res->put(exec, i++, jsString(exec, u.substr(spos, ovector[si * 2 + 1] - spos)));
+ pos = 0;
+ while (static_cast<uint32_t>(i) != limit && pos < u.size()) {
+ OwnArrayPtr<int> ovector;
+ int mpos = reg->match(u, pos, &ovector);
+ if (mpos < 0)
+ break;
+ int mlen = ovector[1] - ovector[0];
+ pos = mpos + (mlen == 0 ? 1 : mlen);
+ if (mpos != p0 || mlen) {
+ res->put(exec,i, jsString(exec, u.substr(p0, mpos - p0)));
+ p0 = mpos + mlen;
+ i++;
+ }
+ for (unsigned si = 1; si <= reg->numSubpatterns(); ++si) {
+ int spos = ovector[si * 2];
+ if (spos < 0)
+ res->put(exec, i++, jsUndefined());
+ else
+ res->put(exec, i++, jsString(exec, u.substr(spos, ovector[si * 2 + 1] - spos)));
+ }
}
- }
} else {
- UString u2 = a0->toString(exec);
- if (u2.isEmpty()) {
- if (u.isEmpty()) {
- // empty separator matches empty string -> empty array
- res->put(exec, exec->propertyNames().length, jsNumber(exec, 0));
- return result;
+ UString u2 = a0->toString(exec);
+ if (u2.isEmpty()) {
+ if (u.isEmpty()) {
+ // empty separator matches empty string -> empty array
+ res->put(exec, exec->propertyNames().length, jsNumber(exec, 0));
+ return result;
+ } else {
+ while (static_cast<uint32_t>(i) != limit && i < u.size() - 1)
+ res->put(exec, i++, jsString(exec, u.substr(p0++, 1)));
+ }
} else {
- while (static_cast<uint32_t>(i) != limit && i < u.size()-1)
- res->put(exec, i++, jsString(exec, u.substr(p0++, 1)));
+ while (static_cast<uint32_t>(i) != limit && (pos = u.find(u2, p0)) >= 0) {
+ res->put(exec, i, jsString(exec, u.substr(p0, pos - p0)));
+ p0 = pos + u2.size();
+ i++;
+ }
}
- } else {
- while (static_cast<uint32_t>(i) != limit && (pos = u.find(u2, p0)) >= 0) {
- res->put(exec, i, jsString(exec, u.substr(p0, pos - p0)));
- p0 = pos + u2.size();
- i++;
- }
- }
}
+
// add remaining string, if any
if (static_cast<uint32_t>(i) != limit)
- res->put(exec, i++, jsString(exec, u.substr(p0)));
+ res->put(exec, i++, jsString(exec, u.substr(p0)));
res->put(exec, exec->propertyNames().length, jsNumber(exec, i));
return result;
}
@@ -571,16 +567,16 @@
double start = a0->toInteger(exec);
double length = a1->isUndefined() ? len : a1->toInteger(exec);
if (start >= len)
- return jsString(exec, "");
+ return jsString(exec, "");
if (length < 0)
- return jsString(exec, "");
+ return jsString(exec, "");
if (start < 0) {
- start += len;
- if (start < 0)
- start = 0;
+ start += len;
+ if (start < 0)
+ start = 0;
}
if (length > len)
- length = len;
+ length = len;
return jsString(exec, s.substr(static_cast<int>(start), static_cast<int>(length)));
}
@@ -595,25 +591,25 @@
double start = a0->toNumber(exec);
double end = a1->toNumber(exec);
if (isnan(start))
- start = 0;
+ start = 0;
if (isnan(end))
- end = 0;
+ end = 0;
if (start < 0)
- start = 0;
+ start = 0;
if (end < 0)
- end = 0;
+ end = 0;
if (start > len)
- start = len;
+ start = len;
if (end > len)
- end = len;
+ end = len;
if (a1->isUndefined())
- end = len;
+ end = len;
if (start > end) {
- double temp = end;
- end = start;
- start = temp;
+ double temp = end;
+ end = start;
+ start = temp;
}
- return jsString(exec, s.substr((int)start, (int)end-(int)start));
+ return jsString(exec, s.substr(static_cast<int>(start), (static_cast<int>(end) - static_cast<int>(start))));
}
JSValue* stringProtoFuncToLowerCase(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)
diff --git a/JavaScriptCore/kjs/StringPrototype.h b/JavaScriptCore/kjs/StringPrototype.h
index 6fede2f..9020115 100644
--- a/JavaScriptCore/kjs/StringPrototype.h
+++ b/JavaScriptCore/kjs/StringPrototype.h
@@ -25,21 +25,17 @@
namespace KJS {
- class ObjectPrototype;
+ class ObjectPrototype;
- /**
- * @internal
- *
- * The initial value of String.prototype (and thus all objects created
- * with the String constructor
- */
- class StringPrototype : public StringObject {
- public:
- StringPrototype(ExecState* exec, ObjectPrototype*);
- virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- };
+ class StringPrototype : public StringObject {
+ public:
+ StringPrototype(ExecState*, ObjectPrototype*);
+
+ virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
+
+ virtual const ClassInfo* classInfo() const { return &info; }
+ static const ClassInfo info;
+ };
} // namespace KJS
diff --git a/JavaScriptCore/kjs/Tracing.h b/JavaScriptCore/kjs/Tracing.h
index ff6cb55..1471e10 100644
--- a/JavaScriptCore/kjs/Tracing.h
+++ b/JavaScriptCore/kjs/Tracing.h
@@ -23,6 +23,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef Tracing_h
+#define Tracing_h
+
#if HAVE(DTRACE)
#include "TracingDtrace.h"
#else
@@ -37,3 +40,5 @@
#define JAVASCRIPTCORE_GC_MARKED_ENABLED() 0
#endif
+
+#endif // Tracing_h
diff --git a/JavaScriptCore/kjs/identifier.h b/JavaScriptCore/kjs/identifier.h
index 35f2b91..8c69c5c 100644
--- a/JavaScriptCore/kjs/identifier.h
+++ b/JavaScriptCore/kjs/identifier.h
@@ -47,7 +47,6 @@
Identifier(PlacementNewAdoptType) : _ustring(PlacementNewAdopt) { }
const UString& ustring() const { return _ustring; }
- DOM::DOMString domString() const;
const UChar* data() const { return _ustring.data(); }
int size() const { return _ustring.size(); }
diff --git a/JavaScriptCore/kjs/lookup.cpp b/JavaScriptCore/kjs/lookup.cpp
index 5d0957f..ed86c9d 100644
--- a/JavaScriptCore/kjs/lookup.cpp
+++ b/JavaScriptCore/kjs/lookup.cpp
@@ -65,4 +65,4 @@
slot.setValueSlot(thisObj->getDirectLocation(propertyName));
}
-}
+} // namespace KJS
diff --git a/JavaScriptCore/kjs/lookup.h b/JavaScriptCore/kjs/lookup.h
index 8557e20..2a6cd62 100644
--- a/JavaScriptCore/kjs/lookup.h
+++ b/JavaScriptCore/kjs/lookup.h
@@ -24,9 +24,9 @@
#include "ExecState.h"
#include "JSFunction.h"
-#include "identifier.h"
#include "JSGlobalObject.h"
#include "JSObject.h"
+#include "identifier.h"
#include <stdio.h>
#include <wtf/Assertions.h>
@@ -81,7 +81,7 @@
return entry(identifier);
}
-private:
+ private:
ALWAYS_INLINE const HashEntry* entry(const Identifier& identifier) const
{
ASSERT(table);
@@ -95,155 +95,155 @@
void createTable(JSGlobalData*) const;
};
- /**
- * @internal
- * Helper for getStaticPropertySlot
- */
- JSValue* staticFunctionGetter(ExecState*, const Identifier& propertyName, const PropertySlot&);
+ /**
+ * @internal
+ * Helper for getStaticPropertySlot
+ */
+ JSValue* staticFunctionGetter(ExecState*, const Identifier& propertyName, const PropertySlot&);
- void setUpStaticFunctionSlot(ExecState*, const HashEntry*, JSObject* thisObject, const Identifier& propertyName, PropertySlot&);
+ void setUpStaticFunctionSlot(ExecState*, const HashEntry*, JSObject* thisObject, const Identifier& propertyName, PropertySlot&);
- /**
- * @internal
- * Helper for getStaticValueSlot and getStaticPropertySlot
- */
- template <class ThisImp>
- JSValue* staticValueGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)
- {
- ThisImp* thisObj = static_cast<ThisImp*>(slot.slotBase());
- const HashEntry* entry = slot.staticEntry();
- return thisObj->getValueProperty(exec, entry->integerValue);
- }
-
- /**
- * Helper method for property lookups
- *
- * This method does it all (looking in the hashtable, checking for function
- * overrides, creating the function or retrieving from cache, calling
- * getValueProperty in case of a non-function property, forwarding to parent if
- * unknown property).
- *
- * Template arguments:
- * @param FuncImp the class which implements this object's functions
- * @param ThisImp the class of "this". It must implement the getValueProperty(exec,token) method,
- * for non-function properties.
- * @param ParentImp the class of the parent, to propagate the lookup.
- *
- * Method arguments:
- * @param exec execution state, as usual
- * @param propertyName the property we're looking for
- * @param table the static hashtable for this class
- * @param thisObj "this"
- */
- template <class ThisImp, class ParentImp>
- inline bool getStaticPropertySlot(ExecState* exec, const HashTable* table, ThisImp* thisObj, const Identifier& propertyName, PropertySlot& slot)
- {
- const HashEntry* entry = table->entry(exec, propertyName);
-
- if (!entry) // not found, forward to parent
- return thisObj->ParentImp::getOwnPropertySlot(exec, propertyName, slot);
-
- if (entry->attributes & Function)
- slot.setStaticEntry(thisObj, entry, staticFunctionGetter);
- else
- slot.setStaticEntry(thisObj, entry, staticValueGetter<ThisImp>);
-
- return true;
- }
-
- /**
- * Simplified version of getStaticPropertySlot in case there are only functions.
- * Using this instead of getStaticPropertySlot allows 'this' to avoid implementing
- * a dummy getValueProperty.
- */
- template <class ParentImp>
- inline bool getStaticFunctionSlot(ExecState* exec, const HashTable* table, JSObject* thisObj, const Identifier& propertyName, PropertySlot& slot)
- {
- if (static_cast<ParentImp*>(thisObj)->ParentImp::getOwnPropertySlot(exec, propertyName, slot))
- return true;
-
- const HashEntry* entry = table->entry(exec, propertyName);
- if (!entry)
- return false;
-
- setUpStaticFunctionSlot(exec, entry, thisObj, propertyName, slot);
- return true;
- }
-
- /**
- * Simplified version of getStaticPropertySlot in case there are no functions, only "values".
- * Using this instead of getStaticPropertySlot removes the need for a FuncImp class.
- */
- template <class ThisImp, class ParentImp>
- inline bool getStaticValueSlot(ExecState* exec, const HashTable* table, ThisImp* thisObj, const Identifier& propertyName, PropertySlot& slot)
- {
- const HashEntry* entry = table->entry(exec, propertyName);
-
- if (!entry) // not found, forward to parent
- return thisObj->ParentImp::getOwnPropertySlot(exec, propertyName, slot);
-
- ASSERT(!(entry->attributes & Function));
-
- slot.setStaticEntry(thisObj, entry, staticValueGetter<ThisImp>);
- return true;
- }
-
- /**
- * This one is for "put".
- * It looks up a hash entry for the property to be set. If an entry
- * is found it sets the value and returns true, else it returns false.
- */
- template <class ThisImp>
- inline bool lookupPut(ExecState* exec, const Identifier& propertyName, JSValue* value, const HashTable* table, ThisImp* thisObj)
- {
- const HashEntry* entry = table->entry(exec, propertyName);
-
- if (!entry)
- return false;
-
- if (entry->attributes & Function) // function: put as override property
- thisObj->putDirect(propertyName, value);
- else if (!(entry->attributes & ReadOnly))
- thisObj->putValueProperty(exec, entry->integerValue, value);
-
- return true;
- }
-
- /**
- * This one is for "put".
- * It calls lookupPut<ThisImp>() to set the value. If that call
- * returns false (meaning no entry in the hash table was found),
- * then it calls put() on the ParentImp class.
- */
- template <class ThisImp, class ParentImp>
- inline void lookupPut(ExecState* exec, const Identifier& propertyName, JSValue* value, const HashTable* table, ThisImp* thisObj)
- {
- if (!lookupPut<ThisImp>(exec, propertyName, value, table, thisObj))
- thisObj->ParentImp::put(exec, propertyName, value); // not found: forward to parent
- }
-
- /**
- * This template method retrieves or create an object that is unique
- * (for a given global object) The first time this is called (for a given
- * property name), the Object will be constructed, and set as a property
- * of the global object. Later calls will simply retrieve that cached object.
- * Note that the object constructor must take 1 argument, exec.
- */
- template <class ClassCtor>
- inline JSObject* cacheGlobalObject(ExecState* exec, const Identifier& propertyName)
- {
- JSGlobalObject* globalObject = exec->lexicalGlobalObject();
- JSValue* obj = globalObject->getDirect(propertyName);
- if (obj) {
- ASSERT(obj->isObject());
- return static_cast<JSObject* >(obj);
+ /**
+ * @internal
+ * Helper for getStaticValueSlot and getStaticPropertySlot
+ */
+ template <class ThisImp>
+ JSValue* staticValueGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)
+ {
+ ThisImp* thisObj = static_cast<ThisImp*>(slot.slotBase());
+ const HashEntry* entry = slot.staticEntry();
+ return thisObj->getValueProperty(exec, entry->integerValue);
}
- JSObject* newObject = new (exec) ClassCtor(exec);
- globalObject->putDirect(propertyName, newObject, DontEnum);
- return newObject;
- }
-} // namespace
+ /**
+ * Helper method for property lookups
+ *
+ * This method does it all (looking in the hashtable, checking for function
+ * overrides, creating the function or retrieving from cache, calling
+ * getValueProperty in case of a non-function property, forwarding to parent if
+ * unknown property).
+ *
+ * Template arguments:
+ * @param FuncImp the class which implements this object's functions
+ * @param ThisImp the class of "this". It must implement the getValueProperty(exec,token) method,
+ * for non-function properties.
+ * @param ParentImp the class of the parent, to propagate the lookup.
+ *
+ * Method arguments:
+ * @param exec execution state, as usual
+ * @param propertyName the property we're looking for
+ * @param table the static hashtable for this class
+ * @param thisObj "this"
+ */
+ template <class ThisImp, class ParentImp>
+ inline bool getStaticPropertySlot(ExecState* exec, const HashTable* table, ThisImp* thisObj, const Identifier& propertyName, PropertySlot& slot)
+ {
+ const HashEntry* entry = table->entry(exec, propertyName);
+
+ if (!entry) // not found, forward to parent
+ return thisObj->ParentImp::getOwnPropertySlot(exec, propertyName, slot);
+
+ if (entry->attributes & Function)
+ slot.setStaticEntry(thisObj, entry, staticFunctionGetter);
+ else
+ slot.setStaticEntry(thisObj, entry, staticValueGetter<ThisImp>);
+
+ return true;
+ }
+
+ /**
+ * Simplified version of getStaticPropertySlot in case there are only functions.
+ * Using this instead of getStaticPropertySlot allows 'this' to avoid implementing
+ * a dummy getValueProperty.
+ */
+ template <class ParentImp>
+ inline bool getStaticFunctionSlot(ExecState* exec, const HashTable* table, JSObject* thisObj, const Identifier& propertyName, PropertySlot& slot)
+ {
+ if (static_cast<ParentImp*>(thisObj)->ParentImp::getOwnPropertySlot(exec, propertyName, slot))
+ return true;
+
+ const HashEntry* entry = table->entry(exec, propertyName);
+ if (!entry)
+ return false;
+
+ setUpStaticFunctionSlot(exec, entry, thisObj, propertyName, slot);
+ return true;
+ }
+
+ /**
+ * Simplified version of getStaticPropertySlot in case there are no functions, only "values".
+ * Using this instead of getStaticPropertySlot removes the need for a FuncImp class.
+ */
+ template <class ThisImp, class ParentImp>
+ inline bool getStaticValueSlot(ExecState* exec, const HashTable* table, ThisImp* thisObj, const Identifier& propertyName, PropertySlot& slot)
+ {
+ const HashEntry* entry = table->entry(exec, propertyName);
+
+ if (!entry) // not found, forward to parent
+ return thisObj->ParentImp::getOwnPropertySlot(exec, propertyName, slot);
+
+ ASSERT(!(entry->attributes & Function));
+
+ slot.setStaticEntry(thisObj, entry, staticValueGetter<ThisImp>);
+ return true;
+ }
+
+ /**
+ * This one is for "put".
+ * It looks up a hash entry for the property to be set. If an entry
+ * is found it sets the value and returns true, else it returns false.
+ */
+ template <class ThisImp>
+ inline bool lookupPut(ExecState* exec, const Identifier& propertyName, JSValue* value, const HashTable* table, ThisImp* thisObj)
+ {
+ const HashEntry* entry = table->entry(exec, propertyName);
+
+ if (!entry)
+ return false;
+
+ if (entry->attributes & Function) // function: put as override property
+ thisObj->putDirect(propertyName, value);
+ else if (!(entry->attributes & ReadOnly))
+ thisObj->putValueProperty(exec, entry->integerValue, value);
+
+ return true;
+ }
+
+ /**
+ * This one is for "put".
+ * It calls lookupPut<ThisImp>() to set the value. If that call
+ * returns false (meaning no entry in the hash table was found),
+ * then it calls put() on the ParentImp class.
+ */
+ template <class ThisImp, class ParentImp>
+ inline void lookupPut(ExecState* exec, const Identifier& propertyName, JSValue* value, const HashTable* table, ThisImp* thisObj)
+ {
+ if (!lookupPut<ThisImp>(exec, propertyName, value, table, thisObj))
+ thisObj->ParentImp::put(exec, propertyName, value); // not found: forward to parent
+ }
+
+ /**
+ * This template method retrieves or create an object that is unique
+ * (for a given global object) The first time this is called (for a given
+ * property name), the Object will be constructed, and set as a property
+ * of the global object. Later calls will simply retrieve that cached object.
+ * Note that the object constructor must take 1 argument, exec.
+ */
+ template <class ClassCtor>
+ inline JSObject* cacheGlobalObject(ExecState* exec, const Identifier& propertyName)
+ {
+ JSGlobalObject* globalObject = exec->lexicalGlobalObject();
+ JSValue* obj = globalObject->getDirect(propertyName);
+ if (obj) {
+ ASSERT(obj->isObject());
+ return static_cast<JSObject* >(obj);
+ }
+ JSObject* newObject = new (exec) ClassCtor(exec);
+ globalObject->putDirect(propertyName, newObject, DontEnum);
+ return newObject;
+ }
+
+} // namespace KJS
/**
* Helpers to define prototype objects (each of which simply implements
diff --git a/JavaScriptCore/kjs/operations.cpp b/JavaScriptCore/kjs/operations.cpp
index 9250ff5..6884843 100644
--- a/JavaScriptCore/kjs/operations.cpp
+++ b/JavaScriptCore/kjs/operations.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
@@ -122,4 +122,4 @@
return error;
}
-}
+} // namespace KJS
diff --git a/JavaScriptCore/kjs/protect.h b/JavaScriptCore/kjs/protect.h
index 2a8f054..2df203e 100644
--- a/JavaScriptCore/kjs/protect.h
+++ b/JavaScriptCore/kjs/protect.h
@@ -1,7 +1,5 @@
-// -*- c-basic-offset: 2 -*-
/*
- * This file is part of the KDE libraries
- * Copyright (C) 2004 Apple Computer, Inc.
+ * Copyright (C) 2004, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -21,8 +19,8 @@
*/
-#ifndef _KJS_PROTECT_H_
-#define _KJS_PROTECT_H_
+#ifndef protect_h
+#define protect_h
#include "JSValue.h"
#include "collector.h"
@@ -43,13 +41,13 @@
heap->unprotect(val);
}
- inline void gcProtectNullTolerant(JSValue *val)
+ inline void gcProtectNullTolerant(JSValue* val)
{
if (val)
gcProtect(val);
}
- inline void gcUnprotectNullTolerant(JSValue *val)
+ inline void gcUnprotectNullTolerant(JSValue* val)
{
if (val)
gcUnprotect(val);
@@ -59,16 +57,16 @@
// and the implicit conversion to raw pointer
template <class T> class ProtectedPtr {
public:
- ProtectedPtr() : m_ptr(NULL) { }
- ProtectedPtr(T *ptr);
+ ProtectedPtr() : m_ptr(0) { }
+ ProtectedPtr(T* ptr);
ProtectedPtr(const ProtectedPtr&);
~ProtectedPtr();
template <class U> ProtectedPtr(const ProtectedPtr<U>&);
- T *get() const { return m_ptr; }
- operator T *() const { return m_ptr; }
- T *operator->() const { return m_ptr; }
+ T* get() const { return m_ptr; }
+ operator T*() const { return m_ptr; }
+ T* operator->() const { return m_ptr; }
bool operator!() const { return m_ptr == NULL; }
@@ -76,10 +74,10 @@
ProtectedPtr& operator=(T*);
private:
- T *m_ptr;
+ T* m_ptr;
};
- template <class T> ProtectedPtr<T>::ProtectedPtr(T *ptr)
+ template <class T> ProtectedPtr<T>::ProtectedPtr(T* ptr)
: m_ptr(ptr)
{
if (ptr)
@@ -89,31 +87,31 @@
template <class T> ProtectedPtr<T>::ProtectedPtr(const ProtectedPtr& o)
: m_ptr(o.get())
{
- if (T *ptr = m_ptr)
+ if (T* ptr = m_ptr)
gcProtect(ptr);
}
template <class T> ProtectedPtr<T>::~ProtectedPtr()
{
- if (T *ptr = m_ptr)
+ if (T* ptr = m_ptr)
gcUnprotect(ptr);
}
template <class T> template <class U> ProtectedPtr<T>::ProtectedPtr(const ProtectedPtr<U>& o)
: m_ptr(o.get())
{
- if (T *ptr = m_ptr)
+ if (T* ptr = m_ptr)
gcProtect(ptr);
}
template <class T> ProtectedPtr<T>& ProtectedPtr<T>::operator=(const ProtectedPtr<T>& o)
{
- T *optr = o.m_ptr;
+ T* optr = o.m_ptr;
gcProtectNullTolerant(optr);
gcUnprotectNullTolerant(m_ptr);
m_ptr = optr;
- return *this;
- }
+ return *this;
+ }
template <class T> inline ProtectedPtr<T>& ProtectedPtr<T>::operator=(T* optr)
{
@@ -131,6 +129,6 @@
template <class T> inline bool operator!=(const ProtectedPtr<T>& a, const T* b) { return a.get() != b; }
template <class T> inline bool operator!=(const T* a, const ProtectedPtr<T>& b) { return a != b.get(); }
-} // namespace
+} // namespace KJS
-#endif
+#endif // protect_h
diff --git a/JavaScriptCore/kjs/regexp.cpp b/JavaScriptCore/kjs/regexp.cpp
index eaf0062..c44e300 100644
--- a/JavaScriptCore/kjs/regexp.cpp
+++ b/JavaScriptCore/kjs/regexp.cpp
@@ -1,4 +1,3 @@
-// -*- c-basic-offset: 2 -*-
/*
* Copyright (C) 1999-2001, 2004 Harri Porten (porten@kde.org)
* Copyright (c) 2007, 2008 Apple Inc. All rights reserved.
@@ -33,10 +32,10 @@
namespace KJS {
inline RegExp::RegExp(const UString& pattern)
- : m_pattern(pattern)
- , m_flagBits(0)
- , m_constructionError(0)
- , m_numSubpatterns(0)
+ : m_pattern(pattern)
+ , m_flagBits(0)
+ , m_constructionError(0)
+ , m_numSubpatterns(0)
{
m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(),
JSRegExpDoNotIgnoreCase, JSRegExpSingleLine, &m_numSubpatterns, &m_constructionError);
@@ -48,11 +47,11 @@
}
inline RegExp::RegExp(const UString& pattern, const UString& flags)
- : m_pattern(pattern)
- , m_flags(flags)
- , m_flagBits(0)
- , m_constructionError(0)
- , m_numSubpatterns(0)
+ : m_pattern(pattern)
+ , m_flags(flags)
+ , m_flagBits(0)
+ , m_constructionError(0)
+ , m_numSubpatterns(0)
{
// NOTE: The global flag is handled on a case-by-case basis by functions like
// String::match and RegExpObject::match.
@@ -71,7 +70,7 @@
m_flagBits |= Multiline;
multilineOption = JSRegExpMultiline;
}
-
+
m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(),
ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError);
}
@@ -88,44 +87,44 @@
int RegExp::match(const UString& s, int i, OwnArrayPtr<int>* ovector)
{
- if (i < 0)
- i = 0;
- if (ovector)
- ovector->clear();
-
- if (i > s.size() || s.isNull())
- return -1;
-
- if (!m_regExp)
- return -1;
-
- // Set up the offset vector for the result.
- // First 2/3 used for result, the last third used by PCRE.
- int* offsetVector;
- int offsetVectorSize;
- int fixedSizeOffsetVector[3];
- if (!ovector) {
- offsetVectorSize = 3;
- offsetVector = fixedSizeOffsetVector;
- } else {
- offsetVectorSize = (m_numSubpatterns + 1) * 3;
- offsetVector = new int [offsetVectorSize];
- ovector->set(offsetVector);
- }
-
- int numMatches = jsRegExpExecute(m_regExp, reinterpret_cast<const UChar*>(s.data()), s.size(), i, offsetVector, offsetVectorSize);
-
- if (numMatches < 0) {
-#ifndef NDEBUG
- if (numMatches != JSRegExpErrorNoMatch)
- fprintf(stderr, "jsRegExpExecute failed with result %d\n", numMatches);
-#endif
+ if (i < 0)
+ i = 0;
if (ovector)
- ovector->clear();
- return -1;
- }
+ ovector->clear();
- return offsetVector[0];
+ if (i > s.size() || s.isNull())
+ return -1;
+
+ if (!m_regExp)
+ return -1;
+
+ // Set up the offset vector for the result.
+ // First 2/3 used for result, the last third used by PCRE.
+ int* offsetVector;
+ int offsetVectorSize;
+ int fixedSizeOffsetVector[3];
+ if (!ovector) {
+ offsetVectorSize = 3;
+ offsetVector = fixedSizeOffsetVector;
+ } else {
+ offsetVectorSize = (m_numSubpatterns + 1) * 3;
+ offsetVector = new int [offsetVectorSize];
+ ovector->set(offsetVector);
+ }
+
+ int numMatches = jsRegExpExecute(m_regExp, reinterpret_cast<const UChar*>(s.data()), s.size(), i, offsetVector, offsetVectorSize);
+
+ if (numMatches < 0) {
+#ifndef NDEBUG
+ if (numMatches != JSRegExpErrorNoMatch)
+ fprintf(stderr, "jsRegExpExecute failed with result %d\n", numMatches);
+#endif
+ if (ovector)
+ ovector->clear();
+ return -1;
+ }
+
+ return offsetVector[0];
}
} // namespace KJS
diff --git a/JavaScriptCore/kjs/regexp.h b/JavaScriptCore/kjs/regexp.h
index 1930ac9..097ab9d 100644
--- a/JavaScriptCore/kjs/regexp.h
+++ b/JavaScriptCore/kjs/regexp.h
@@ -64,6 +64,6 @@
unsigned m_numSubpatterns;
};
-} // namespace
+} // namespace KJS
-#endif
+#endif // KJS_REGEXP_H
diff --git a/JavaScriptCore/kjs/ustring.cpp b/JavaScriptCore/kjs/ustring.cpp
index e10e211..9eb8cfa 100644
--- a/JavaScriptCore/kjs/ustring.cpp
+++ b/JavaScriptCore/kjs/ustring.cpp
@@ -1,4 +1,3 @@
-// -*- c-basic-offset: 2 -*-
/*
* Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
@@ -78,163 +77,161 @@
COMPILE_ASSERT(sizeof(UChar) == 2, uchar_is_2_bytes)
-CString::CString(const char *c)
+CString::CString(const char* c)
+ : m_length(strlen(c))
+ , m_data(new char[m_length + 1])
{
- length = strlen(c);
- data = new char[length+1];
- memcpy(data, c, length + 1);
+ memcpy(m_data, c, m_length + 1);
}
-CString::CString(const char *c, size_t len)
+CString::CString(const char* c, size_t length)
+ : m_length(length)
+ , m_data(new char[length + 1])
{
- length = len;
- data = new char[len+1];
- memcpy(data, c, len);
- data[len] = 0;
+ memcpy(m_data, c, m_length);
+ m_data[m_length] = 0;
}
-CString::CString(const CString &b)
+CString::CString(const CString& b)
{
- length = b.length;
- if (b.data) {
- data = new char[length+1];
- memcpy(data, b.data, length + 1);
- }
- else
- data = 0;
+ m_length = b.m_length;
+ if (b.m_data) {
+ m_data = new char[m_length + 1];
+ memcpy(m_data, b.m_data, m_length + 1);
+ } else
+ m_data = 0;
}
CString::~CString()
{
- delete [] data;
+ delete [] m_data;
}
-CString CString::adopt(char* c, size_t len)
+CString CString::adopt(char* c, size_t length)
{
CString s;
- s.data = c;
- s.length = len;
-
+ s.m_data = c;
+ s.m_length = length;
return s;
}
-CString &CString::append(const CString &t)
+CString& CString::append(const CString& t)
{
- char *n;
- n = new char[length+t.length+1];
- if (length)
- memcpy(n, data, length);
- if (t.length)
- memcpy(n+length, t.data, t.length);
- length += t.length;
- n[length] = 0;
+ char* n;
+ n = new char[m_length + t.m_length + 1];
+ if (m_length)
+ memcpy(n, m_data, m_length);
+ if (t.m_length)
+ memcpy(n + m_length, t.m_data, t.m_length);
+ m_length += t.m_length;
+ n[m_length] = 0;
- delete [] data;
- data = n;
+ delete [] m_data;
+ m_data = n;
- return *this;
-}
-
-CString &CString::operator=(const char *c)
-{
- if (data)
- delete [] data;
- length = strlen(c);
- data = new char[length+1];
- memcpy(data, c, length + 1);
-
- return *this;
-}
-
-CString &CString::operator=(const CString &str)
-{
- if (this == &str)
return *this;
+}
- if (data)
- delete [] data;
- length = str.length;
- if (str.data) {
- data = new char[length + 1];
- memcpy(data, str.data, length + 1);
- }
- else
- data = 0;
+CString& CString::operator=(const char* c)
+{
+ if (m_data)
+ delete [] m_data;
+ m_length = strlen(c);
+ m_data = new char[m_length + 1];
+ memcpy(m_data, c, m_length + 1);
- return *this;
+ return *this;
+}
+
+CString& CString::operator=(const CString& str)
+{
+ if (this == &str)
+ return *this;
+
+ if (m_data)
+ delete [] m_data;
+ m_length = str.m_length;
+ if (str.m_data) {
+ m_data = new char[m_length + 1];
+ memcpy(m_data, str.m_data, m_length + 1);
+ } else
+ m_data = 0;
+
+ return *this;
}
bool operator==(const CString& c1, const CString& c2)
{
- size_t len = c1.size();
- return len == c2.size() && (len == 0 || memcmp(c1.c_str(), c2.c_str(), len) == 0);
+ size_t len = c1.size();
+ return len == c2.size() && (len == 0 || memcmp(c1.c_str(), c2.c_str(), len) == 0);
}
-// These static strings are immutable, except for rc, whose initial value is chosen to reduce the possibility of it becoming zero due to ref/deref not being thread-safe.
+// These static strings are immutable, except for rc, whose initial value is chosen to
+// reduce the possibility of it becoming zero due to ref/deref not being thread-safe.
static UChar sharedEmptyChar;
UString::Rep UString::Rep::null = { 0, 0, INT_MAX / 2, 0, 0, &UString::Rep::null, true, 0, 0, 0, 0, 0, 0 };
UString::Rep UString::Rep::empty = { 0, 0, INT_MAX / 2, 0, 0, &UString::Rep::empty, true, 0, &sharedEmptyChar, 0, 0, 0, 0 };
static char* statBuffer = 0; // Only used for debugging via UString::ascii().
-PassRefPtr<UString::Rep> UString::Rep::createCopying(const UChar *d, int l)
+PassRefPtr<UString::Rep> UString::Rep::createCopying(const UChar* d, int l)
{
- int sizeInBytes = l * sizeof(UChar);
- UChar *copyD = static_cast<UChar *>(fastMalloc(sizeInBytes));
- memcpy(copyD, d, sizeInBytes);
+ int sizeInBytes = l * sizeof(UChar);
+ UChar* copyD = static_cast<UChar*>(fastMalloc(sizeInBytes));
+ memcpy(copyD, d, sizeInBytes);
- return create(copyD, l);
+ return create(copyD, l);
}
-PassRefPtr<UString::Rep> UString::Rep::create(UChar *d, int l)
+PassRefPtr<UString::Rep> UString::Rep::create(UChar* d, int l)
{
- Rep* r = new Rep;
- r->offset = 0;
- r->len = l;
- r->rc = 1;
- r->_hash = 0;
- r->identifierTable = 0;
- r->baseString = r;
- r->isStatic = false;
- r->reportedCost = 0;
- r->buf = d;
- r->usedCapacity = l;
- r->capacity = l;
- r->usedPreCapacity = 0;
- r->preCapacity = 0;
+ Rep* r = new Rep;
+ r->offset = 0;
+ r->len = l;
+ r->rc = 1;
+ r->_hash = 0;
+ r->identifierTable = 0;
+ r->baseString = r;
+ r->isStatic = false;
+ r->reportedCost = 0;
+ r->buf = d;
+ r->usedCapacity = l;
+ r->capacity = l;
+ r->usedPreCapacity = 0;
+ r->preCapacity = 0;
- // steal the single reference this Rep was created with
- return adoptRef(r);
+ // steal the single reference this Rep was created with
+ return adoptRef(r);
}
PassRefPtr<UString::Rep> UString::Rep::create(PassRefPtr<Rep> base, int offset, int length)
{
- ASSERT(base);
+ ASSERT(base);
- int baseOffset = base->offset;
+ int baseOffset = base->offset;
- base = base->baseString;
+ base = base->baseString;
- ASSERT(-(offset + baseOffset) <= base->usedPreCapacity);
- ASSERT(offset + baseOffset + length <= base->usedCapacity);
+ ASSERT(-(offset + baseOffset) <= base->usedPreCapacity);
+ ASSERT(offset + baseOffset + length <= base->usedCapacity);
- Rep *r = new Rep;
- r->offset = baseOffset + offset;
- r->len = length;
- r->rc = 1;
- r->_hash = 0;
- r->identifierTable = 0;
- r->baseString = base.releaseRef();
- r->isStatic = false;
- r->reportedCost = 0;
- r->buf = 0;
- r->usedCapacity = 0;
- r->capacity = 0;
- r->usedPreCapacity = 0;
- r->preCapacity = 0;
+ Rep* r = new Rep;
+ r->offset = baseOffset + offset;
+ r->len = length;
+ r->rc = 1;
+ r->_hash = 0;
+ r->identifierTable = 0;
+ r->baseString = base.releaseRef();
+ r->isStatic = false;
+ r->reportedCost = 0;
+ r->buf = 0;
+ r->usedCapacity = 0;
+ r->capacity = 0;
+ r->usedPreCapacity = 0;
+ r->preCapacity = 0;
- // steal the single reference this Rep was created with
- return adoptRef(r);
+ // steal the single reference this Rep was created with
+ return adoptRef(r);
}
PassRefPtr<UString::Rep> UString::Rep::createFromUTF8(const char* string)
@@ -253,17 +250,18 @@
void UString::Rep::destroy()
{
- // Static null and empty strings can never be destroyed, but we cannot rely on reference counting, because ref/deref are not thread-safe.
- if (!isStatic) {
- if (identifierTable)
- Identifier::remove(this);
- if (baseString == this)
- fastFree(buf);
- else
- baseString->deref();
+ // Static null and empty strings can never be destroyed, but we cannot rely on
+ // reference counting, because ref/deref are not thread-safe.
+ if (!isStatic) {
+ if (identifierTable)
+ Identifier::remove(this);
+ if (baseString == this)
+ fastFree(buf);
+ else
+ baseString->deref();
- delete this;
- }
+ delete this;
+ }
}
// Golden ratio - arbitrary start value to avoid mapping all 0's to all 0's
@@ -272,92 +270,92 @@
// Paul Hsieh's SuperFastHash
// http://www.azillionmonkeys.com/qed/hash.html
-unsigned UString::Rep::computeHash(const UChar *s, int len)
+unsigned UString::Rep::computeHash(const UChar* s, int len)
{
- unsigned l = len;
- uint32_t hash = PHI;
- uint32_t tmp;
+ unsigned l = len;
+ uint32_t hash = PHI;
+ uint32_t tmp;
- int rem = l & 1;
- l >>= 1;
+ int rem = l & 1;
+ l >>= 1;
- // Main loop
- for (; l > 0; l--) {
- hash += s[0];
- tmp = (s[1] << 11) ^ hash;
- hash = (hash << 16) ^ tmp;
- s += 2;
- hash += hash >> 11;
- }
+ // Main loop
+ for (; l > 0; l--) {
+ hash += s[0];
+ tmp = (s[1] << 11) ^ hash;
+ hash = (hash << 16) ^ tmp;
+ s += 2;
+ hash += hash >> 11;
+ }
- // Handle end case
- if (rem) {
- hash += s[0];
- hash ^= hash << 11;
- hash += hash >> 17;
- }
+ // Handle end case
+ if (rem) {
+ hash += s[0];
+ hash ^= hash << 11;
+ hash += hash >> 17;
+ }
- // Force "avalanching" of final 127 bits
- hash ^= hash << 3;
- hash += hash >> 5;
- hash ^= hash << 2;
- hash += hash >> 15;
- hash ^= hash << 10;
+ // Force "avalanching" of final 127 bits
+ hash ^= hash << 3;
+ hash += hash >> 5;
+ hash ^= hash << 2;
+ hash += hash >> 15;
+ hash ^= hash << 10;
- // this avoids ever returning a hash code of 0, since that is used to
- // signal "hash not computed yet", using a value that is likely to be
- // effectively the same as 0 when the low bits are masked
- if (hash == 0)
- hash = 0x80000000;
+ // this avoids ever returning a hash code of 0, since that is used to
+ // signal "hash not computed yet", using a value that is likely to be
+ // effectively the same as 0 when the low bits are masked
+ if (hash == 0)
+ hash = 0x80000000;
- return hash;
+ return hash;
}
// Paul Hsieh's SuperFastHash
// http://www.azillionmonkeys.com/qed/hash.html
-unsigned UString::Rep::computeHash(const char *s)
+unsigned UString::Rep::computeHash(const char* s)
{
- // This hash is designed to work on 16-bit chunks at a time. But since the normal case
- // (above) is to hash UTF-16 characters, we just treat the 8-bit chars as if they
- // were 16-bit chunks, which should give matching results
+ // This hash is designed to work on 16-bit chunks at a time. But since the normal case
+ // (above) is to hash UTF-16 characters, we just treat the 8-bit chars as if they
+ // were 16-bit chunks, which should give matching results
- uint32_t hash = PHI;
- uint32_t tmp;
- size_t l = strlen(s);
-
- size_t rem = l & 1;
- l >>= 1;
+ uint32_t hash = PHI;
+ uint32_t tmp;
+ size_t l = strlen(s);
- // Main loop
- for (; l > 0; l--) {
- hash += (unsigned char)s[0];
- tmp = ((unsigned char)s[1] << 11) ^ hash;
- hash = (hash << 16) ^ tmp;
- s += 2;
- hash += hash >> 11;
- }
+ size_t rem = l & 1;
+ l >>= 1;
- // Handle end case
- if (rem) {
- hash += (unsigned char)s[0];
- hash ^= hash << 11;
- hash += hash >> 17;
- }
+ // Main loop
+ for (; l > 0; l--) {
+ hash += static_cast<unsigned char>(s[0]);
+ tmp = (static_cast<unsigned char>(s[1]) << 11) ^ hash;
+ hash = (hash << 16) ^ tmp;
+ s += 2;
+ hash += hash >> 11;
+ }
- // Force "avalanching" of final 127 bits
- hash ^= hash << 3;
- hash += hash >> 5;
- hash ^= hash << 2;
- hash += hash >> 15;
- hash ^= hash << 10;
-
- // this avoids ever returning a hash code of 0, since that is used to
- // signal "hash not computed yet", using a value that is likely to be
- // effectively the same as 0 when the low bits are masked
- if (hash == 0)
- hash = 0x80000000;
+ // Handle end case
+ if (rem) {
+ hash += static_cast<unsigned char>(s[0]);
+ hash ^= hash << 11;
+ hash += hash >> 17;
+ }
- return hash;
+ // Force "avalanching" of final 127 bits
+ hash ^= hash << 3;
+ hash += hash >> 5;
+ hash ^= hash << 2;
+ hash += hash >> 15;
+ hash ^= hash << 10;
+
+ // this avoids ever returning a hash code of 0, since that is used to
+ // signal "hash not computed yet", using a value that is likely to be
+ // effectively the same as 0 when the low bits are masked
+ if (hash == 0)
+ hash = 0x80000000;
+
+ return hash;
}
// put these early so they can be inlined
@@ -378,97 +376,95 @@
inline int UString::usedCapacity() const
{
- return m_rep->baseString->usedCapacity;
+ return m_rep->baseString->usedCapacity;
}
inline int UString::usedPreCapacity() const
{
- return m_rep->baseString->usedPreCapacity;
+ return m_rep->baseString->usedPreCapacity;
}
void UString::expandCapacity(int requiredLength)
{
- Rep* r = m_rep->baseString;
+ Rep* r = m_rep->baseString;
- if (requiredLength > r->capacity) {
- size_t newCapacity = expandedSize(requiredLength, r->preCapacity);
- UChar* oldBuf = r->buf;
- r->buf = reallocChars(r->buf, newCapacity);
- if (!r->buf) {
- r->buf = oldBuf;
- m_rep = &Rep::null;
- return;
+ if (requiredLength > r->capacity) {
+ size_t newCapacity = expandedSize(requiredLength, r->preCapacity);
+ UChar* oldBuf = r->buf;
+ r->buf = reallocChars(r->buf, newCapacity);
+ if (!r->buf) {
+ r->buf = oldBuf;
+ m_rep = &Rep::null;
+ return;
+ }
+ r->capacity = newCapacity - r->preCapacity;
}
- r->capacity = newCapacity - r->preCapacity;
- }
- if (requiredLength > r->usedCapacity) {
- r->usedCapacity = requiredLength;
- }
+ if (requiredLength > r->usedCapacity)
+ r->usedCapacity = requiredLength;
}
void UString::expandPreCapacity(int requiredPreCap)
{
- Rep* r = m_rep->baseString;
+ Rep* r = m_rep->baseString;
- if (requiredPreCap > r->preCapacity) {
- size_t newCapacity = expandedSize(requiredPreCap, r->capacity);
- int delta = newCapacity - r->capacity - r->preCapacity;
+ if (requiredPreCap > r->preCapacity) {
+ size_t newCapacity = expandedSize(requiredPreCap, r->capacity);
+ int delta = newCapacity - r->capacity - r->preCapacity;
- UChar* newBuf = allocChars(newCapacity);
- if (!newBuf) {
+ UChar* newBuf = allocChars(newCapacity);
+ if (!newBuf) {
+ m_rep = &Rep::null;
+ return;
+ }
+ memcpy(newBuf + delta, r->buf, (r->capacity + r->preCapacity) * sizeof(UChar));
+ fastFree(r->buf);
+ r->buf = newBuf;
+
+ r->preCapacity = newCapacity - r->capacity;
+ }
+ if (requiredPreCap > r->usedPreCapacity)
+ r->usedPreCapacity = requiredPreCap;
+}
+
+UString::UString(const char* c)
+{
+ if (!c) {
m_rep = &Rep::null;
return;
}
- memcpy(newBuf + delta, r->buf, (r->capacity + r->preCapacity) * sizeof(UChar));
- fastFree(r->buf);
- r->buf = newBuf;
- r->preCapacity = newCapacity - r->capacity;
- }
- if (requiredPreCap > r->usedPreCapacity) {
- r->usedPreCapacity = requiredPreCap;
- }
+ if (!c[0]) {
+ m_rep = &Rep::empty;
+ return;
+ }
+
+ size_t length = strlen(c);
+ UChar* d = allocChars(length);
+ if (!d)
+ m_rep = &Rep::null;
+ else {
+ for (size_t i = 0; i < length; i++)
+ d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend
+ m_rep = Rep::create(d, static_cast<int>(length));
+ }
}
-UString::UString(const char *c)
+UString::UString(const UChar* c, int length)
{
- if (!c) {
- m_rep = &Rep::null;
- return;
- }
-
- if (!c[0]) {
- m_rep = &Rep::empty;
- return;
- }
-
- size_t length = strlen(c);
- UChar *d = allocChars(length);
- if (!d)
- m_rep = &Rep::null;
- else {
- for (size_t i = 0; i < length; i++)
- d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend
- m_rep = Rep::create(d, static_cast<int>(length));
- }
+ if (length == 0)
+ m_rep = &Rep::empty;
+ else
+ m_rep = Rep::createCopying(c, length);
}
-UString::UString(const UChar *c, int length)
+UString::UString(UChar* c, int length, bool copy)
{
- if (length == 0)
- m_rep = &Rep::empty;
- else
- m_rep = Rep::createCopying(c, length);
-}
-
-UString::UString(UChar *c, int length, bool copy)
-{
- if (length == 0)
- m_rep = &Rep::empty;
- else if (copy)
- m_rep = Rep::createCopying(c, length);
- else
- m_rep = Rep::create(c, length);
+ if (length == 0)
+ m_rep = &Rep::empty;
+ else if (copy)
+ m_rep = Rep::createCopying(c, length);
+ else
+ m_rep = Rep::create(c, length);
}
UString::UString(const Vector<UChar>& buffer)
@@ -480,209 +476,204 @@
}
-UString::UString(const UString &a, const UString &b)
+UString::UString(const UString& a, const UString& b)
{
- int aSize = a.size();
- int aOffset = a.m_rep->offset;
- int bSize = b.size();
- int bOffset = b.m_rep->offset;
- int length = aSize + bSize;
+ int aSize = a.size();
+ int aOffset = a.m_rep->offset;
+ int bSize = b.size();
+ int bOffset = b.m_rep->offset;
+ int length = aSize + bSize;
- // possible cases:
-
- if (aSize == 0) {
- // a is empty
- m_rep = b.m_rep;
- } else if (bSize == 0) {
- // b is empty
- m_rep = a.m_rep;
- } else if (aOffset + aSize == a.usedCapacity() && aSize >= minShareSize && 4 * aSize >= bSize &&
- (-bOffset != b.usedPreCapacity() || aSize >= bSize)) {
- // - a reaches the end of its buffer so it qualifies for shared append
- // - also, it's at least a quarter the length of b - appending to a much shorter
- // string does more harm than good
- // - however, if b qualifies for prepend and is longer than a, we'd rather prepend
- UString x(a);
- x.expandCapacity(aOffset + length);
- if (a.data() && x.data()) {
- memcpy(const_cast<UChar *>(a.data() + aSize), b.data(), bSize * sizeof(UChar));
- m_rep = Rep::create(a.m_rep, 0, length);
- } else
- m_rep = &Rep::null;
- } else if (-bOffset == b.usedPreCapacity() && bSize >= minShareSize && 4 * bSize >= aSize) {
- // - b reaches the beginning of its buffer so it qualifies for shared prepend
- // - also, it's at least a quarter the length of a - prepending to a much shorter
- // string does more harm than good
- UString y(b);
- y.expandPreCapacity(-bOffset + aSize);
- if (b.data() && y.data()) {
- memcpy(const_cast<UChar *>(b.data() - aSize), a.data(), aSize * sizeof(UChar));
- m_rep = Rep::create(b.m_rep, -aSize, length);
- } else
- m_rep = &Rep::null;
- } else {
- // a does not qualify for append, and b does not qualify for prepend, gotta make a whole new string
- size_t newCapacity = expandedSize(length, 0);
- UChar* d = allocChars(newCapacity);
- if (!d)
- m_rep = &Rep::null;
- else {
- memcpy(d, a.data(), aSize * sizeof(UChar));
- memcpy(d + aSize, b.data(), bSize * sizeof(UChar));
- m_rep = Rep::create(d, length);
- m_rep->capacity = newCapacity;
+ // possible cases:
+
+ if (aSize == 0) {
+ // a is empty
+ m_rep = b.m_rep;
+ } else if (bSize == 0) {
+ // b is empty
+ m_rep = a.m_rep;
+ } else if (aOffset + aSize == a.usedCapacity() && aSize >= minShareSize && 4 * aSize >= bSize &&
+ (-bOffset != b.usedPreCapacity() || aSize >= bSize)) {
+ // - a reaches the end of its buffer so it qualifies for shared append
+ // - also, it's at least a quarter the length of b - appending to a much shorter
+ // string does more harm than good
+ // - however, if b qualifies for prepend and is longer than a, we'd rather prepend
+ UString x(a);
+ x.expandCapacity(aOffset + length);
+ if (a.data() && x.data()) {
+ memcpy(const_cast<UChar*>(a.data() + aSize), b.data(), bSize * sizeof(UChar));
+ m_rep = Rep::create(a.m_rep, 0, length);
+ } else
+ m_rep = &Rep::null;
+ } else if (-bOffset == b.usedPreCapacity() && bSize >= minShareSize && 4 * bSize >= aSize) {
+ // - b reaches the beginning of its buffer so it qualifies for shared prepend
+ // - also, it's at least a quarter the length of a - prepending to a much shorter
+ // string does more harm than good
+ UString y(b);
+ y.expandPreCapacity(-bOffset + aSize);
+ if (b.data() && y.data()) {
+ memcpy(const_cast<UChar *>(b.data() - aSize), a.data(), aSize * sizeof(UChar));
+ m_rep = Rep::create(b.m_rep, -aSize, length);
+ } else
+ m_rep = &Rep::null;
+ } else {
+ // a does not qualify for append, and b does not qualify for prepend, gotta make a whole new string
+ size_t newCapacity = expandedSize(length, 0);
+ UChar* d = allocChars(newCapacity);
+ if (!d)
+ m_rep = &Rep::null;
+ else {
+ memcpy(d, a.data(), aSize * sizeof(UChar));
+ memcpy(d + aSize, b.data(), bSize * sizeof(UChar));
+ m_rep = Rep::create(d, length);
+ m_rep->capacity = newCapacity;
+ }
}
- }
}
const UString& UString::null()
{
- static UString* n = new UString; // Should be called from main thread at least once to be safely initialized.
- return *n;
+ static UString* n = new UString; // Should be called from main thread at least once to be safely initialized.
+ return *n;
}
UString UString::from(int i)
{
- UChar buf[1 + sizeof(i) * 3];
- UChar *end = buf + sizeof(buf) / sizeof(UChar);
- UChar *p = end;
+ UChar buf[1 + sizeof(i) * 3];
+ UChar* end = buf + sizeof(buf) / sizeof(UChar);
+ UChar* p = end;
- if (i == 0) {
- *--p = '0';
- } else if (i == INT_MIN) {
- char minBuf[1 + sizeof(i) * 3];
- sprintf(minBuf, "%d", INT_MIN);
- return UString(minBuf);
- } else {
- bool negative = false;
- if (i < 0) {
- negative = true;
- i = -i;
+ if (i == 0)
+ *--p = '0';
+ else if (i == INT_MIN) {
+ char minBuf[1 + sizeof(i) * 3];
+ sprintf(minBuf, "%d", INT_MIN);
+ return UString(minBuf);
+ } else {
+ bool negative = false;
+ if (i < 0) {
+ negative = true;
+ i = -i;
+ }
+ while (i) {
+ *--p = static_cast<unsigned short>((i % 10) + '0');
+ i /= 10;
+ }
+ if (negative)
+ *--p = '-';
}
- while (i) {
- *--p = (unsigned short)((i % 10) + '0');
- i /= 10;
- }
- if (negative) {
- *--p = '-';
- }
- }
-
- return UString(p, static_cast<int>(end - p));
+
+ return UString(p, static_cast<int>(end - p));
}
UString UString::from(unsigned int u)
{
- UChar buf[sizeof(u) * 3];
- UChar *end = buf + sizeof(buf) / sizeof(UChar);
- UChar *p = end;
-
- if (u == 0) {
- *--p = '0';
- } else {
- while (u) {
- *--p = (unsigned short)((u % 10) + '0');
- u /= 10;
+ UChar buf[sizeof(u) * 3];
+ UChar* end = buf + sizeof(buf) / sizeof(UChar);
+ UChar* p = end;
+
+ if (u == 0)
+ *--p = '0';
+ else {
+ while (u) {
+ *--p = static_cast<unsigned short>((u % 10) + '0');
+ u /= 10;
+ }
}
- }
-
- return UString(p, static_cast<int>(end - p));
+
+ return UString(p, static_cast<int>(end - p));
}
UString UString::from(long l)
{
- UChar buf[1 + sizeof(l) * 3];
- UChar *end = buf + sizeof(buf) / sizeof(UChar);
- UChar *p = end;
-
- if (l == 0) {
- *--p = '0';
- } else if (l == LONG_MIN) {
- char minBuf[1 + sizeof(l) * 3];
- sprintf(minBuf, "%ld", LONG_MIN);
- return UString(minBuf);
- } else {
- bool negative = false;
- if (l < 0) {
- negative = true;
- l = -l;
+ UChar buf[1 + sizeof(l) * 3];
+ UChar* end = buf + sizeof(buf) / sizeof(UChar);
+ UChar* p = end;
+
+ if (l == 0)
+ *--p = '0';
+ else if (l == LONG_MIN) {
+ char minBuf[1 + sizeof(l) * 3];
+ sprintf(minBuf, "%ld", LONG_MIN);
+ return UString(minBuf);
+ } else {
+ bool negative = false;
+ if (l < 0) {
+ negative = true;
+ l = -l;
+ }
+ while (l) {
+ *--p = static_cast<unsigned short>((l % 10) + '0');
+ l /= 10;
+ }
+ if (negative)
+ *--p = '-';
}
- while (l) {
- *--p = (unsigned short)((l % 10) + '0');
- l /= 10;
- }
- if (negative) {
- *--p = '-';
- }
- }
-
- return UString(p, static_cast<int>(end - p));
+
+ return UString(p, static_cast<int>(end - p));
}
UString UString::from(double d)
{
- // avoid ever printing -NaN, in JS conceptually there is only one NaN value
- if (isnan(d))
- return "NaN";
+ // avoid ever printing -NaN, in JS conceptually there is only one NaN value
+ if (isnan(d))
+ return "NaN";
- char buf[80];
- int decimalPoint;
- int sign;
+ char buf[80];
+ int decimalPoint;
+ int sign;
+
+ char* result = dtoa(d, 0, &decimalPoint, &sign, NULL);
+ int length = static_cast<int>(strlen(result));
- char *result = dtoa(d, 0, &decimalPoint, &sign, NULL);
- int length = static_cast<int>(strlen(result));
+ int i = 0;
+ if (sign)
+ buf[i++] = '-';
- int i = 0;
- if (sign) {
- buf[i++] = '-';
- }
-
- if (decimalPoint <= 0 && decimalPoint > -6) {
- buf[i++] = '0';
- buf[i++] = '.';
- for (int j = decimalPoint; j < 0; j++) {
- buf[i++] = '0';
- }
- strcpy(buf + i, result);
- } else if (decimalPoint <= 21 && decimalPoint > 0) {
- if (length <= decimalPoint) {
- strcpy(buf + i, result);
- i += length;
- for (int j = 0; j < decimalPoint - length; j++) {
+ if (decimalPoint <= 0 && decimalPoint > -6) {
buf[i++] = '0';
- }
- buf[i] = '\0';
- } else {
- strncpy(buf + i, result, decimalPoint);
- i += decimalPoint;
- buf[i++] = '.';
- strcpy(buf + i, result + decimalPoint);
- }
- } else if (result[0] < '0' || result[0] > '9') {
- strcpy(buf + i, result);
- } else {
- buf[i++] = result[0];
- if (length > 1) {
- buf[i++] = '.';
- strcpy(buf + i, result + 1);
- i += length - 1;
+ buf[i++] = '.';
+ for (int j = decimalPoint; j < 0; j++)
+ buf[i++] = '0';
+ strcpy(buf + i, result);
+ } else if (decimalPoint <= 21 && decimalPoint > 0) {
+ if (length <= decimalPoint) {
+ strcpy(buf + i, result);
+ i += length;
+ for (int j = 0; j < decimalPoint - length; j++)
+ buf[i++] = '0';
+ buf[i] = '\0';
+ } else {
+ strncpy(buf + i, result, decimalPoint);
+ i += decimalPoint;
+ buf[i++] = '.';
+ strcpy(buf + i, result + decimalPoint);
+ }
+ } else if (result[0] < '0' || result[0] > '9')
+ strcpy(buf + i, result);
+ else {
+ buf[i++] = result[0];
+ if (length > 1) {
+ buf[i++] = '.';
+ strcpy(buf + i, result + 1);
+ i += length - 1;
+ }
+
+ buf[i++] = 'e';
+ buf[i++] = (decimalPoint >= 0) ? '+' : '-';
+ // decimalPoint can't be more than 3 digits decimal given the
+ // nature of float representation
+ int exponential = decimalPoint - 1;
+ if (exponential < 0)
+ exponential = -exponential;
+ if (exponential >= 100)
+ buf[i++] = static_cast<char>('0' + exponential / 100);
+ if (exponential >= 10)
+ buf[i++] = static_cast<char>('0' + (exponential % 100) / 10);
+ buf[i++] = static_cast<char>('0' + exponential % 10);
+ buf[i++] = '\0';
}
- buf[i++] = 'e';
- buf[i++] = (decimalPoint >= 0) ? '+' : '-';
- // decimalPoint can't be more than 3 digits decimal given the
- // nature of float representation
- int exponential = decimalPoint - 1;
- if (exponential < 0)
- exponential = -exponential;
- if (exponential >= 100)
- buf[i++] = static_cast<char>('0' + exponential / 100);
- if (exponential >= 10)
- buf[i++] = static_cast<char>('0' + (exponential % 100) / 10);
- buf[i++] = static_cast<char>('0' + exponential % 10);
- buf[i++] = '\0';
- }
-
freedtoa(result);
return UString(buf);
@@ -690,232 +681,232 @@
UString UString::spliceSubstringsWithSeparators(const Range* substringRanges, int rangeCount, const UString* separators, int separatorCount) const
{
- if (rangeCount == 1 && separatorCount == 0) {
- int thisSize = size();
- int position = substringRanges[0].position;
- int length = substringRanges[0].length;
- if (position <= 0 && length >= thisSize)
- return *this;
- return UString::Rep::create(m_rep, max(0, position), min(thisSize, length));
- }
-
- int totalLength = 0;
- for (int i = 0; i < rangeCount; i++)
- totalLength += substringRanges[i].length;
- for (int i = 0; i < separatorCount; i++)
- totalLength += separators[i].size();
-
- if (totalLength == 0)
- return "";
-
- UChar* buffer = allocChars(totalLength);
- if (!buffer)
- return null();
-
- int maxCount = max(rangeCount, separatorCount);
- int bufferPos = 0;
- for (int i = 0; i < maxCount; i++) {
- if (i < rangeCount) {
- memcpy(buffer + bufferPos, data() + substringRanges[i].position, substringRanges[i].length * sizeof(UChar));
- bufferPos += substringRanges[i].length;
+ if (rangeCount == 1 && separatorCount == 0) {
+ int thisSize = size();
+ int position = substringRanges[0].position;
+ int length = substringRanges[0].length;
+ if (position <= 0 && length >= thisSize)
+ return *this;
+ return UString::Rep::create(m_rep, max(0, position), min(thisSize, length));
}
- if (i < separatorCount) {
- memcpy(buffer + bufferPos, separators[i].data(), separators[i].size() * sizeof(UChar));
- bufferPos += separators[i].size();
- }
- }
- return UString::Rep::create(buffer, totalLength);
+ int totalLength = 0;
+ for (int i = 0; i < rangeCount; i++)
+ totalLength += substringRanges[i].length;
+ for (int i = 0; i < separatorCount; i++)
+ totalLength += separators[i].size();
+
+ if (totalLength == 0)
+ return "";
+
+ UChar* buffer = allocChars(totalLength);
+ if (!buffer)
+ return null();
+
+ int maxCount = max(rangeCount, separatorCount);
+ int bufferPos = 0;
+ for (int i = 0; i < maxCount; i++) {
+ if (i < rangeCount) {
+ memcpy(buffer + bufferPos, data() + substringRanges[i].position, substringRanges[i].length * sizeof(UChar));
+ bufferPos += substringRanges[i].length;
+ }
+ if (i < separatorCount) {
+ memcpy(buffer + bufferPos, separators[i].data(), separators[i].size() * sizeof(UChar));
+ bufferPos += separators[i].size();
+ }
+ }
+
+ return UString::Rep::create(buffer, totalLength);
}
UString& UString::append(const UString &t)
{
- int thisSize = size();
- int thisOffset = m_rep->offset;
- int tSize = t.size();
- int length = thisSize + tSize;
+ int thisSize = size();
+ int thisOffset = m_rep->offset;
+ int tSize = t.size();
+ int length = thisSize + tSize;
- // possible cases:
- if (thisSize == 0) {
- // this is empty
- *this = t;
- } else if (tSize == 0) {
- // t is empty
- } else if (m_rep->baseIsSelf() && m_rep->rc == 1) {
- // this is direct and has refcount of 1 (so we can just alter it directly)
- expandCapacity(thisOffset + length);
- if (data()) {
- memcpy(const_cast<UChar*>(data() + thisSize), t.data(), tSize * sizeof(UChar));
- m_rep->len = length;
- m_rep->_hash = 0;
+ // possible cases:
+ if (thisSize == 0) {
+ // this is empty
+ *this = t;
+ } else if (tSize == 0) {
+ // t is empty
+ } else if (m_rep->baseIsSelf() && m_rep->rc == 1) {
+ // this is direct and has refcount of 1 (so we can just alter it directly)
+ expandCapacity(thisOffset + length);
+ if (data()) {
+ memcpy(const_cast<UChar*>(data() + thisSize), t.data(), tSize * sizeof(UChar));
+ m_rep->len = length;
+ m_rep->_hash = 0;
+ }
+ } else if (thisOffset + thisSize == usedCapacity() && thisSize >= minShareSize) {
+ // this reaches the end of the buffer - extend it if it's long enough to append to
+ expandCapacity(thisOffset + length);
+ if (data()) {
+ memcpy(const_cast<UChar*>(data() + thisSize), t.data(), tSize * sizeof(UChar));
+ m_rep = Rep::create(m_rep, 0, length);
+ }
+ } else {
+ // this is shared with someone using more capacity, gotta make a whole new string
+ size_t newCapacity = expandedSize(length, 0);
+ UChar* d = allocChars(newCapacity);
+ if (!d)
+ m_rep = &Rep::null;
+ else {
+ memcpy(d, data(), thisSize * sizeof(UChar));
+ memcpy(const_cast<UChar*>(d + thisSize), t.data(), tSize * sizeof(UChar));
+ m_rep = Rep::create(d, length);
+ m_rep->capacity = newCapacity;
+ }
}
- } else if (thisOffset + thisSize == usedCapacity() && thisSize >= minShareSize) {
- // this reaches the end of the buffer - extend it if it's long enough to append to
- expandCapacity(thisOffset + length);
- if (data()) {
- memcpy(const_cast<UChar*>(data() + thisSize), t.data(), tSize * sizeof(UChar));
- m_rep = Rep::create(m_rep, 0, length);
- }
- } else {
- // this is shared with someone using more capacity, gotta make a whole new string
- size_t newCapacity = expandedSize(length, 0);
- UChar* d = allocChars(newCapacity);
- if (!d)
- m_rep = &Rep::null;
- else {
- memcpy(d, data(), thisSize * sizeof(UChar));
- memcpy(const_cast<UChar*>(d + thisSize), t.data(), tSize * sizeof(UChar));
- m_rep = Rep::create(d, length);
- m_rep->capacity = newCapacity;
- }
- }
- return *this;
+ return *this;
}
UString& UString::append(const UChar* tData, int tSize)
{
- int thisSize = size();
- int thisOffset = m_rep->offset;
- int length = thisSize + tSize;
+ int thisSize = size();
+ int thisOffset = m_rep->offset;
+ int length = thisSize + tSize;
- // possible cases:
- if (tSize == 0) {
- // t is empty
- } else if (thisSize == 0) {
- // this is empty
- m_rep = Rep::createCopying(tData, tSize);
- } else if (m_rep->baseIsSelf() && m_rep->rc == 1) {
- // this is direct and has refcount of 1 (so we can just alter it directly)
- expandCapacity(thisOffset + length);
- if (data()) {
- memcpy(const_cast<UChar*>(data() + thisSize), tData, tSize * sizeof(UChar));
- m_rep->len = length;
- m_rep->_hash = 0;
+ // possible cases:
+ if (tSize == 0) {
+ // t is empty
+ } else if (thisSize == 0) {
+ // this is empty
+ m_rep = Rep::createCopying(tData, tSize);
+ } else if (m_rep->baseIsSelf() && m_rep->rc == 1) {
+ // this is direct and has refcount of 1 (so we can just alter it directly)
+ expandCapacity(thisOffset + length);
+ if (data()) {
+ memcpy(const_cast<UChar*>(data() + thisSize), tData, tSize * sizeof(UChar));
+ m_rep->len = length;
+ m_rep->_hash = 0;
+ }
+ } else if (thisOffset + thisSize == usedCapacity() && thisSize >= minShareSize) {
+ // this reaches the end of the buffer - extend it if it's long enough to append to
+ expandCapacity(thisOffset + length);
+ if (data()) {
+ memcpy(const_cast<UChar*>(data() + thisSize), tData, tSize * sizeof(UChar));
+ m_rep = Rep::create(m_rep, 0, length);
+ }
+ } else {
+ // this is shared with someone using more capacity, gotta make a whole new string
+ size_t newCapacity = expandedSize(length, 0);
+ UChar* d = allocChars(newCapacity);
+ if (!d)
+ m_rep = &Rep::null;
+ else {
+ memcpy(d, data(), thisSize * sizeof(UChar));
+ memcpy(const_cast<UChar*>(d + thisSize), tData, tSize * sizeof(UChar));
+ m_rep = Rep::create(d, length);
+ m_rep->capacity = newCapacity;
+ }
}
- } else if (thisOffset + thisSize == usedCapacity() && thisSize >= minShareSize) {
- // this reaches the end of the buffer - extend it if it's long enough to append to
- expandCapacity(thisOffset + length);
- if (data()) {
- memcpy(const_cast<UChar*>(data() + thisSize), tData, tSize * sizeof(UChar));
- m_rep = Rep::create(m_rep, 0, length);
- }
- } else {
- // this is shared with someone using more capacity, gotta make a whole new string
- size_t newCapacity = expandedSize(length, 0);
- UChar* d = allocChars(newCapacity);
- if (!d)
- m_rep = &Rep::null;
- else {
- memcpy(d, data(), thisSize * sizeof(UChar));
- memcpy(const_cast<UChar*>(d + thisSize), tData, tSize * sizeof(UChar));
- m_rep = Rep::create(d, length);
- m_rep->capacity = newCapacity;
- }
- }
- return *this;
+ return *this;
}
-UString& UString::append(const char *t)
+UString& UString::append(const char* t)
{
- int thisSize = size();
- int thisOffset = m_rep->offset;
- int tSize = static_cast<int>(strlen(t));
- int length = thisSize + tSize;
+ int thisSize = size();
+ int thisOffset = m_rep->offset;
+ int tSize = static_cast<int>(strlen(t));
+ int length = thisSize + tSize;
- // possible cases:
- if (thisSize == 0) {
- // this is empty
- *this = t;
- } else if (tSize == 0) {
- // t is empty, we'll just return *this below.
- } else if (m_rep->baseIsSelf() && m_rep->rc == 1) {
- // this is direct and has refcount of 1 (so we can just alter it directly)
- expandCapacity(thisOffset + length);
- UChar *d = const_cast<UChar *>(data());
- if (d) {
- for (int i = 0; i < tSize; ++i)
- d[thisSize + i] = static_cast<unsigned char>(t[i]); // use unsigned char to zero-extend instead of sign-extend
- m_rep->len = length;
- m_rep->_hash = 0;
+ // possible cases:
+ if (thisSize == 0) {
+ // this is empty
+ *this = t;
+ } else if (tSize == 0) {
+ // t is empty, we'll just return *this below.
+ } else if (m_rep->baseIsSelf() && m_rep->rc == 1) {
+ // this is direct and has refcount of 1 (so we can just alter it directly)
+ expandCapacity(thisOffset + length);
+ UChar* d = const_cast<UChar*>(data());
+ if (d) {
+ for (int i = 0; i < tSize; ++i)
+ d[thisSize + i] = static_cast<unsigned char>(t[i]); // use unsigned char to zero-extend instead of sign-extend
+ m_rep->len = length;
+ m_rep->_hash = 0;
+ }
+ } else if (thisOffset + thisSize == usedCapacity() && thisSize >= minShareSize) {
+ // this string reaches the end of the buffer - extend it
+ expandCapacity(thisOffset + length);
+ UChar* d = const_cast<UChar*>(data());
+ if (d) {
+ for (int i = 0; i < tSize; ++i)
+ d[thisSize + i] = static_cast<unsigned char>(t[i]); // use unsigned char to zero-extend instead of sign-extend
+ m_rep = Rep::create(m_rep, 0, length);
+ }
+ } else {
+ // this is shared with someone using more capacity, gotta make a whole new string
+ size_t newCapacity = expandedSize(length, 0);
+ UChar* d = allocChars(newCapacity);
+ if (!d)
+ m_rep = &Rep::null;
+ else {
+ memcpy(d, data(), thisSize * sizeof(UChar));
+ for (int i = 0; i < tSize; ++i)
+ d[thisSize + i] = static_cast<unsigned char>(t[i]); // use unsigned char to zero-extend instead of sign-extend
+ m_rep = Rep::create(d, length);
+ m_rep->capacity = newCapacity;
+ }
}
- } else if (thisOffset + thisSize == usedCapacity() && thisSize >= minShareSize) {
- // this string reaches the end of the buffer - extend it
- expandCapacity(thisOffset + length);
- UChar *d = const_cast<UChar *>(data());
- if (d) {
- for (int i = 0; i < tSize; ++i)
- d[thisSize + i] = static_cast<unsigned char>(t[i]); // use unsigned char to zero-extend instead of sign-extend
- m_rep = Rep::create(m_rep, 0, length);
- }
- } else {
- // this is shared with someone using more capacity, gotta make a whole new string
- size_t newCapacity = expandedSize(length, 0);
- UChar* d = allocChars(newCapacity);
- if (!d)
- m_rep = &Rep::null;
- else {
- memcpy(d, data(), thisSize * sizeof(UChar));
- for (int i = 0; i < tSize; ++i)
- d[thisSize + i] = static_cast<unsigned char>(t[i]); // use unsigned char to zero-extend instead of sign-extend
- m_rep = Rep::create(d, length);
- m_rep->capacity = newCapacity;
- }
- }
- return *this;
+ return *this;
}
UString& UString::append(UChar c)
{
- int thisOffset = m_rep->offset;
- int length = size();
+ int thisOffset = m_rep->offset;
+ int length = size();
- // possible cases:
- if (length == 0) {
- // this is empty - must make a new m_rep because we don't want to pollute the shared empty one
- size_t newCapacity = expandedSize(1, 0);
- UChar* d = allocChars(newCapacity);
- if (!d)
- m_rep = &Rep::null;
- else {
- d[0] = c;
- m_rep = Rep::create(d, 1);
- m_rep->capacity = newCapacity;
+ // possible cases:
+ if (length == 0) {
+ // this is empty - must make a new m_rep because we don't want to pollute the shared empty one
+ size_t newCapacity = expandedSize(1, 0);
+ UChar* d = allocChars(newCapacity);
+ if (!d)
+ m_rep = &Rep::null;
+ else {
+ d[0] = c;
+ m_rep = Rep::create(d, 1);
+ m_rep->capacity = newCapacity;
+ }
+ } else if (m_rep->baseIsSelf() && m_rep->rc == 1) {
+ // this is direct and has refcount of 1 (so we can just alter it directly)
+ expandCapacity(thisOffset + length + 1);
+ UChar* d = const_cast<UChar*>(data());
+ if (d) {
+ d[length] = c;
+ m_rep->len = length + 1;
+ m_rep->_hash = 0;
+ }
+ } else if (thisOffset + length == usedCapacity() && length >= minShareSize) {
+ // this reaches the end of the string - extend it and share
+ expandCapacity(thisOffset + length + 1);
+ UChar* d = const_cast<UChar*>(data());
+ if (d) {
+ d[length] = c;
+ m_rep = Rep::create(m_rep, 0, length + 1);
+ }
+ } else {
+ // this is shared with someone using more capacity, gotta make a whole new string
+ size_t newCapacity = expandedSize(length + 1, 0);
+ UChar* d = allocChars(newCapacity);
+ if (!d)
+ m_rep = &Rep::null;
+ else {
+ memcpy(d, data(), length * sizeof(UChar));
+ d[length] = c;
+ m_rep = Rep::create(d, length + 1);
+ m_rep->capacity = newCapacity;
+ }
}
- } else if (m_rep->baseIsSelf() && m_rep->rc == 1) {
- // this is direct and has refcount of 1 (so we can just alter it directly)
- expandCapacity(thisOffset + length + 1);
- UChar *d = const_cast<UChar *>(data());
- if (d) {
- d[length] = c;
- m_rep->len = length + 1;
- m_rep->_hash = 0;
- }
- } else if (thisOffset + length == usedCapacity() && length >= minShareSize) {
- // this reaches the end of the string - extend it and share
- expandCapacity(thisOffset + length + 1);
- UChar *d = const_cast<UChar *>(data());
- if (d) {
- d[length] = c;
- m_rep = Rep::create(m_rep, 0, length + 1);
- }
- } else {
- // this is shared with someone using more capacity, gotta make a whole new string
- size_t newCapacity = expandedSize(length + 1, 0);
- UChar* d = allocChars(newCapacity);
- if (!d)
- m_rep = &Rep::null;
- else {
- memcpy(d, data(), length * sizeof(UChar));
- d[length] = c;
- m_rep = Rep::create(d, length + 1);
- m_rep->capacity = newCapacity;
- }
- }
- return *this;
+ return *this;
}
bool UString::getCString(CStringBuffer& buffer) const
@@ -924,7 +915,7 @@
int neededSize = length + 1;
buffer.resize(neededSize);
char* buf = buffer.data();
-
+
UChar ored = 0;
const UChar* p = data();
char* q = buf;
@@ -937,31 +928,31 @@
++q;
}
*q = '\0';
-
+
return !(ored & 0xFF00);
}
-char *UString::ascii() const
+char* UString::ascii() const
{
- int length = size();
- int neededSize = length + 1;
- delete[] statBuffer;
- statBuffer = new char[neededSize];
-
- const UChar *p = data();
- char *q = statBuffer;
- const UChar *limit = p + length;
- while (p != limit) {
- *q = static_cast<char>(p[0]);
- ++p;
- ++q;
- }
- *q = '\0';
+ int length = size();
+ int neededSize = length + 1;
+ delete[] statBuffer;
+ statBuffer = new char[neededSize];
- return statBuffer;
+ const UChar* p = data();
+ char* q = statBuffer;
+ const UChar* limit = p + length;
+ while (p != limit) {
+ *q = static_cast<char>(p[0]);
+ ++p;
+ ++q;
+ }
+ *q = '\0';
+
+ return statBuffer;
}
-UString& UString::operator=(const char *c)
+UString& UString::operator=(const char* c)
{
if (!c) {
m_rep = &Rep::null;
@@ -973,389 +964,389 @@
return *this;
}
- int l = static_cast<int>(strlen(c));
- UChar *d;
- if (m_rep->rc == 1 && l <= m_rep->capacity && m_rep->baseIsSelf() && m_rep->offset == 0 && m_rep->preCapacity == 0) {
- d = m_rep->buf;
- m_rep->_hash = 0;
- m_rep->len = l;
- } else {
- d = allocChars(l);
- if (!d) {
- m_rep = &Rep::null;
- return *this;
+ int l = static_cast<int>(strlen(c));
+ UChar* d;
+ if (m_rep->rc == 1 && l <= m_rep->capacity && m_rep->baseIsSelf() && m_rep->offset == 0 && m_rep->preCapacity == 0) {
+ d = m_rep->buf;
+ m_rep->_hash = 0;
+ m_rep->len = l;
+ } else {
+ d = allocChars(l);
+ if (!d) {
+ m_rep = &Rep::null;
+ return *this;
+ }
+ m_rep = Rep::create(d, l);
}
- m_rep = Rep::create(d, l);
- }
- for (int i = 0; i < l; i++)
- d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend
+ for (int i = 0; i < l; i++)
+ d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend
- return *this;
+ return *this;
}
bool UString::is8Bit() const
{
- const UChar *u = data();
- const UChar *limit = u + size();
- while (u < limit) {
- if (u[0] > 0xFF)
- return false;
- ++u;
- }
+ const UChar* u = data();
+ const UChar* limit = u + size();
+ while (u < limit) {
+ if (u[0] > 0xFF)
+ return false;
+ ++u;
+ }
- return true;
+ return true;
}
UChar UString::operator[](int pos) const
{
- if (pos >= size())
- return '\0';
- return data()[pos];
+ if (pos >= size())
+ return '\0';
+ return data()[pos];
}
double UString::toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const
{
- double d;
+ double d;
- // FIXME: If tolerateTrailingJunk is true, then we want to tolerate non-8-bit junk
- // after the number, so this is too strict a check.
- CStringBuffer s;
- if (!getCString(s))
- return NaN;
- const char* c = s.data();
-
- // skip leading white space
- while (isASCIISpace(*c))
- c++;
-
- // empty string ?
- if (*c == '\0')
- return tolerateEmptyString ? 0.0 : NaN;
-
- // hex number ?
- if (*c == '0' && (*(c+1) == 'x' || *(c+1) == 'X')) {
- const char* firstDigitPosition = c + 2;
- c++;
- d = 0.0;
- while (*(++c)) {
- if (*c >= '0' && *c <= '9')
- d = d * 16.0 + *c - '0';
- else if ((*c >= 'A' && *c <= 'F') || (*c >= 'a' && *c <= 'f'))
- d = d * 16.0 + (*c & 0xdf) - 'A' + 10.0;
- else
- break;
- }
-
- if (d >= mantissaOverflowLowerBound)
- d = parseIntOverflow(firstDigitPosition, c - firstDigitPosition, 16);
- } else {
- // regular number ?
- char *end;
- d = strtod(c, &end);
- if ((d != 0.0 || end != c) && d != Inf && d != -Inf) {
- c = end;
- } else {
- double sign = 1.0;
-
- if (*c == '+')
- c++;
- else if (*c == '-') {
- sign = -1.0;
- c++;
- }
-
- // We used strtod() to do the conversion. However, strtod() handles
- // infinite values slightly differently than JavaScript in that it
- // converts the string "inf" with any capitalization to infinity,
- // whereas the ECMA spec requires that it be converted to NaN.
-
- if (c[0] == 'I' && c[1] == 'n' && c[2] == 'f' && c[3] == 'i' && c[4] == 'n' && c[5] == 'i' && c[6] == 't' && c[7] == 'y') {
- d = sign * Inf;
- c += 8;
- } else if ((d == Inf || d == -Inf) && *c != 'I' && *c != 'i')
- c = end;
- else
+ // FIXME: If tolerateTrailingJunk is true, then we want to tolerate non-8-bit junk
+ // after the number, so this is too strict a check.
+ CStringBuffer s;
+ if (!getCString(s))
return NaN;
+ const char* c = s.data();
+
+ // skip leading white space
+ while (isASCIISpace(*c))
+ c++;
+
+ // empty string ?
+ if (*c == '\0')
+ return tolerateEmptyString ? 0.0 : NaN;
+
+ // hex number ?
+ if (*c == '0' && (*(c + 1) == 'x' || *(c + 1) == 'X')) {
+ const char* firstDigitPosition = c + 2;
+ c++;
+ d = 0.0;
+ while (*(++c)) {
+ if (*c >= '0' && *c <= '9')
+ d = d * 16.0 + *c - '0';
+ else if ((*c >= 'A' && *c <= 'F') || (*c >= 'a' && *c <= 'f'))
+ d = d * 16.0 + (*c & 0xdf) - 'A' + 10.0;
+ else
+ break;
+ }
+
+ if (d >= mantissaOverflowLowerBound)
+ d = parseIntOverflow(firstDigitPosition, c - firstDigitPosition, 16);
+ } else {
+ // regular number ?
+ char* end;
+ d = strtod(c, &end);
+ if ((d != 0.0 || end != c) && d != Inf && d != -Inf) {
+ c = end;
+ } else {
+ double sign = 1.0;
+
+ if (*c == '+')
+ c++;
+ else if (*c == '-') {
+ sign = -1.0;
+ c++;
+ }
+
+ // We used strtod() to do the conversion. However, strtod() handles
+ // infinite values slightly differently than JavaScript in that it
+ // converts the string "inf" with any capitalization to infinity,
+ // whereas the ECMA spec requires that it be converted to NaN.
+
+ if (c[0] == 'I' && c[1] == 'n' && c[2] == 'f' && c[3] == 'i' && c[4] == 'n' && c[5] == 'i' && c[6] == 't' && c[7] == 'y') {
+ d = sign * Inf;
+ c += 8;
+ } else if ((d == Inf || d == -Inf) && *c != 'I' && *c != 'i')
+ c = end;
+ else
+ return NaN;
+ }
}
- }
- // allow trailing white space
- while (isASCIISpace(*c))
- c++;
- // don't allow anything after - unless tolerant=true
- if (!tolerateTrailingJunk && *c != '\0')
- d = NaN;
+ // allow trailing white space
+ while (isASCIISpace(*c))
+ c++;
+ // don't allow anything after - unless tolerant=true
+ if (!tolerateTrailingJunk && *c != '\0')
+ d = NaN;
- return d;
+ return d;
}
double UString::toDouble(bool tolerateTrailingJunk) const
{
- return toDouble(tolerateTrailingJunk, true);
+ return toDouble(tolerateTrailingJunk, true);
}
double UString::toDouble() const
{
- return toDouble(false, true);
+ return toDouble(false, true);
}
-uint32_t UString::toUInt32(bool *ok) const
+uint32_t UString::toUInt32(bool* ok) const
{
- double d = toDouble();
- bool b = true;
+ double d = toDouble();
+ bool b = true;
- if (d != static_cast<uint32_t>(d)) {
- b = false;
- d = 0;
- }
-
- if (ok)
- *ok = b;
-
- return static_cast<uint32_t>(d);
-}
-
-uint32_t UString::toUInt32(bool *ok, bool tolerateEmptyString) const
-{
- double d = toDouble(false, tolerateEmptyString);
- bool b = true;
-
- if (d != static_cast<uint32_t>(d)) {
- b = false;
- d = 0;
- }
-
- if (ok)
- *ok = b;
-
- return static_cast<uint32_t>(d);
-}
-
-uint32_t UString::toStrictUInt32(bool *ok) const
-{
- if (ok)
- *ok = false;
-
- // Empty string is not OK.
- int len = m_rep->len;
- if (len == 0)
- return 0;
- const UChar *p = m_rep->data();
- unsigned short c = p[0];
-
- // If the first digit is 0, only 0 itself is OK.
- if (c == '0') {
- if (len == 1 && ok)
- *ok = true;
- return 0;
- }
-
- // Convert to UInt32, checking for overflow.
- uint32_t i = 0;
- while (1) {
- // Process character, turning it into a digit.
- if (c < '0' || c > '9')
- return 0;
- const unsigned d = c - '0';
-
- // Multiply by 10, checking for overflow out of 32 bits.
- if (i > 0xFFFFFFFFU / 10)
- return 0;
- i *= 10;
-
- // Add in the digit, checking for overflow out of 32 bits.
- const unsigned max = 0xFFFFFFFFU - d;
- if (i > max)
- return 0;
- i += d;
-
- // Handle end of string.
- if (--len == 0) {
- if (ok)
- *ok = true;
- return i;
+ if (d != static_cast<uint32_t>(d)) {
+ b = false;
+ d = 0;
}
-
- // Get next character.
- c = *(++p);
- }
+
+ if (ok)
+ *ok = b;
+
+ return static_cast<uint32_t>(d);
}
-int UString::find(const UString &f, int pos) const
+uint32_t UString::toUInt32(bool* ok, bool tolerateEmptyString) const
{
- int sz = size();
- int fsz = f.size();
- if (sz < fsz)
- return -1;
- if (pos < 0)
- pos = 0;
- if (fsz == 0)
- return pos;
- const UChar *end = data() + sz - fsz;
- int fsizeminusone = (fsz - 1) * sizeof(UChar);
- const UChar *fdata = f.data();
- unsigned short fchar = fdata[0];
- ++fdata;
- for (const UChar *c = data() + pos; c <= end; c++)
- if (c[0] == fchar && !memcmp(c + 1, fdata, fsizeminusone))
- return static_cast<int>(c - data());
+ double d = toDouble(false, tolerateEmptyString);
+ bool b = true;
- return -1;
+ if (d != static_cast<uint32_t>(d)) {
+ b = false;
+ d = 0;
+ }
+
+ if (ok)
+ *ok = b;
+
+ return static_cast<uint32_t>(d);
+}
+
+uint32_t UString::toStrictUInt32(bool* ok) const
+{
+ if (ok)
+ *ok = false;
+
+ // Empty string is not OK.
+ int len = m_rep->len;
+ if (len == 0)
+ return 0;
+ const UChar* p = m_rep->data();
+ unsigned short c = p[0];
+
+ // If the first digit is 0, only 0 itself is OK.
+ if (c == '0') {
+ if (len == 1 && ok)
+ *ok = true;
+ return 0;
+ }
+
+ // Convert to UInt32, checking for overflow.
+ uint32_t i = 0;
+ while (1) {
+ // Process character, turning it into a digit.
+ if (c < '0' || c > '9')
+ return 0;
+ const unsigned d = c - '0';
+
+ // Multiply by 10, checking for overflow out of 32 bits.
+ if (i > 0xFFFFFFFFU / 10)
+ return 0;
+ i *= 10;
+
+ // Add in the digit, checking for overflow out of 32 bits.
+ const unsigned max = 0xFFFFFFFFU - d;
+ if (i > max)
+ return 0;
+ i += d;
+
+ // Handle end of string.
+ if (--len == 0) {
+ if (ok)
+ *ok = true;
+ return i;
+ }
+
+ // Get next character.
+ c = *(++p);
+ }
+}
+
+int UString::find(const UString& f, int pos) const
+{
+ int sz = size();
+ int fsz = f.size();
+ if (sz < fsz)
+ return -1;
+ if (pos < 0)
+ pos = 0;
+ if (fsz == 0)
+ return pos;
+ const UChar* end = data() + sz - fsz;
+ int fsizeminusone = (fsz - 1) * sizeof(UChar);
+ const UChar* fdata = f.data();
+ unsigned short fchar = fdata[0];
+ ++fdata;
+ for (const UChar* c = data() + pos; c <= end; c++) {
+ if (c[0] == fchar && !memcmp(c + 1, fdata, fsizeminusone))
+ return static_cast<int>(c - data());
+ }
+
+ return -1;
}
int UString::find(UChar ch, int pos) const
{
- if (pos < 0)
- pos = 0;
- const UChar *end = data() + size();
- for (const UChar *c = data() + pos; c < end; c++)
- if (*c == ch)
- return static_cast<int>(c - data());
-
- return -1;
+ if (pos < 0)
+ pos = 0;
+ const UChar* end = data() + size();
+ for (const UChar* c = data() + pos; c < end; c++) {
+ if (*c == ch)
+ return static_cast<int>(c - data());
+ }
+
+ return -1;
}
-int UString::rfind(const UString &f, int pos) const
+int UString::rfind(const UString& f, int pos) const
{
- int sz = size();
- int fsz = f.size();
- if (sz < fsz)
- return -1;
- if (pos < 0)
- pos = 0;
- if (pos > sz - fsz)
- pos = sz - fsz;
- if (fsz == 0)
- return pos;
- int fsizeminusone = (fsz - 1) * sizeof(UChar);
- const UChar *fdata = f.data();
- for (const UChar *c = data() + pos; c >= data(); c--) {
- if (*c == *fdata && !memcmp(c + 1, fdata + 1, fsizeminusone))
- return static_cast<int>(c - data());
- }
+ int sz = size();
+ int fsz = f.size();
+ if (sz < fsz)
+ return -1;
+ if (pos < 0)
+ pos = 0;
+ if (pos > sz - fsz)
+ pos = sz - fsz;
+ if (fsz == 0)
+ return pos;
+ int fsizeminusone = (fsz - 1) * sizeof(UChar);
+ const UChar* fdata = f.data();
+ for (const UChar* c = data() + pos; c >= data(); c--) {
+ if (*c == *fdata && !memcmp(c + 1, fdata + 1, fsizeminusone))
+ return static_cast<int>(c - data());
+ }
- return -1;
+ return -1;
}
int UString::rfind(UChar ch, int pos) const
{
- if (isEmpty())
- return -1;
- if (pos + 1 >= size())
- pos = size() - 1;
- for (const UChar *c = data() + pos; c >= data(); c--) {
- if (*c == ch)
- return static_cast<int>(c-data());
- }
+ if (isEmpty())
+ return -1;
+ if (pos + 1 >= size())
+ pos = size() - 1;
+ for (const UChar* c = data() + pos; c >= data(); c--) {
+ if (*c == ch)
+ return static_cast<int>(c - data());
+ }
- return -1;
+ return -1;
}
UString UString::substr(int pos, int len) const
{
- int s = size();
+ int s = size();
- if (pos < 0)
- pos = 0;
- else if (pos >= s)
- pos = s;
- if (len < 0)
- len = s;
- if (pos + len >= s)
- len = s - pos;
+ if (pos < 0)
+ pos = 0;
+ else if (pos >= s)
+ pos = s;
+ if (len < 0)
+ len = s;
+ if (pos + len >= s)
+ len = s - pos;
- if (pos == 0 && len == s)
- return *this;
+ if (pos == 0 && len == s)
+ return *this;
- return UString(Rep::create(m_rep, pos, len));
+ return UString(Rep::create(m_rep, pos, len));
}
bool operator==(const UString& s1, const UString& s2)
{
- if (s1.m_rep->len != s2.m_rep->len)
- return false;
+ if (s1.m_rep->len != s2.m_rep->len)
+ return false;
- return (memcmp(s1.m_rep->data(), s2.m_rep->data(),
- s1.m_rep->len * sizeof(UChar)) == 0);
+ return (memcmp(s1.m_rep->data(), s2.m_rep->data(), s1.m_rep->len * sizeof(UChar)) == 0);
}
bool operator==(const UString& s1, const char *s2)
{
- if (s2 == 0) {
- return s1.isEmpty();
- }
+ if (s2 == 0)
+ return s1.isEmpty();
- const UChar *u = s1.data();
- const UChar *uend = u + s1.size();
- while (u != uend && *s2) {
- if (u[0] != (unsigned char)*s2)
- return false;
- s2++;
- u++;
- }
+ const UChar* u = s1.data();
+ const UChar* uend = u + s1.size();
+ while (u != uend && *s2) {
+ if (u[0] != (unsigned char)*s2)
+ return false;
+ s2++;
+ u++;
+ }
- return u == uend && *s2 == 0;
+ return u == uend && *s2 == 0;
}
bool operator<(const UString& s1, const UString& s2)
{
- const int l1 = s1.size();
- const int l2 = s2.size();
- const int lmin = l1 < l2 ? l1 : l2;
- const UChar *c1 = s1.data();
- const UChar *c2 = s2.data();
- int l = 0;
- while (l < lmin && *c1 == *c2) {
- c1++;
- c2++;
- l++;
- }
- if (l < lmin)
- return (c1[0] < c2[0]);
+ const int l1 = s1.size();
+ const int l2 = s2.size();
+ const int lmin = l1 < l2 ? l1 : l2;
+ const UChar* c1 = s1.data();
+ const UChar* c2 = s2.data();
+ int l = 0;
+ while (l < lmin && *c1 == *c2) {
+ c1++;
+ c2++;
+ l++;
+ }
+ if (l < lmin)
+ return (c1[0] < c2[0]);
- return (l1 < l2);
+ return (l1 < l2);
}
bool operator>(const UString& s1, const UString& s2)
{
- const int l1 = s1.size();
- const int l2 = s2.size();
- const int lmin = l1 < l2 ? l1 : l2;
- const UChar *c1 = s1.data();
- const UChar *c2 = s2.data();
- int l = 0;
- while (l < lmin && *c1 == *c2) {
- c1++;
- c2++;
- l++;
- }
- if (l < lmin)
- return (c1[0] > c2[0]);
+ const int l1 = s1.size();
+ const int l2 = s2.size();
+ const int lmin = l1 < l2 ? l1 : l2;
+ const UChar* c1 = s1.data();
+ const UChar* c2 = s2.data();
+ int l = 0;
+ while (l < lmin && *c1 == *c2) {
+ c1++;
+ c2++;
+ l++;
+ }
+ if (l < lmin)
+ return (c1[0] > c2[0]);
- return (l1 > l2);
+ return (l1 > l2);
}
int compare(const UString& s1, const UString& s2)
{
- const int l1 = s1.size();
- const int l2 = s2.size();
- const int lmin = l1 < l2 ? l1 : l2;
- const UChar *c1 = s1.data();
- const UChar *c2 = s2.data();
- int l = 0;
- while (l < lmin && *c1 == *c2) {
- c1++;
- c2++;
- l++;
- }
+ const int l1 = s1.size();
+ const int l2 = s2.size();
+ const int lmin = l1 < l2 ? l1 : l2;
+ const UChar* c1 = s1.data();
+ const UChar* c2 = s2.data();
+ int l = 0;
+ while (l < lmin && *c1 == *c2) {
+ c1++;
+ c2++;
+ l++;
+ }
- if (l < lmin)
- return (c1[0] > c2[0]) ? 1 : -1;
+ if (l < lmin)
+ return (c1[0] > c2[0]) ? 1 : -1;
- if (l1 == l2)
- return 0;
+ if (l1 == l2)
+ return 0;
- return (l1 > l2) ? 1 : -1;
+ return (l1 > l2) ? 1 : -1;
}
bool equal(const UString::Rep* r, const UString::Rep* b)
@@ -1365,26 +1356,27 @@
return false;
const UChar* d = r->data();
const UChar* s = b->data();
- for (int i = 0; i != length; ++i)
+ for (int i = 0; i != length; ++i) {
if (d[i] != s[i])
return false;
+ }
return true;
}
CString UString::UTF8String(bool strict) const
{
- // Allocate a buffer big enough to hold all the characters.
- const int length = size();
- Vector<char, 1024> buffer(length * 3);
+ // Allocate a buffer big enough to hold all the characters.
+ const int length = size();
+ Vector<char, 1024> buffer(length * 3);
- // Convert to runs of 8-bit characters.
- char* p = buffer.data();
- const UChar* d = reinterpret_cast<const UChar*>(&data()[0]);
- ConversionResult result = convertUTF16ToUTF8(&d, d + length, &p, p + buffer.size(), strict);
- if (result != conversionOK)
- return CString();
+ // Convert to runs of 8-bit characters.
+ char* p = buffer.data();
+ const UChar* d = reinterpret_cast<const UChar*>(&data()[0]);
+ ConversionResult result = convertUTF16ToUTF8(&d, d + length, &p, p + buffer.size(), strict);
+ if (result != conversionOK)
+ return CString();
- return CString(buffer.data(), p - buffer.data());
+ return CString(buffer.data(), p - buffer.data());
}
} // namespace KJS
diff --git a/JavaScriptCore/kjs/ustring.h b/JavaScriptCore/kjs/ustring.h
index 3a5df69..b54e2f2 100644
--- a/JavaScriptCore/kjs/ustring.h
+++ b/JavaScriptCore/kjs/ustring.h
@@ -1,4 +1,3 @@
-// -*- c-basic-offset: 2 -*-
/*
* Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
@@ -32,390 +31,289 @@
#include <wtf/unicode/Unicode.h>
#include <wtf/Vector.h>
-/**
- * @internal
- */
-namespace DOM {
- class DOMString;
- class AtomicString;
-}
-class KJScript;
-
namespace KJS {
- using WTF::PlacementNewAdoptType;
- using WTF::PlacementNewAdopt;
+ using WTF::PlacementNewAdoptType;
+ using WTF::PlacementNewAdopt;
- class IdentifierTable;
- class UString;
+ class IdentifierTable;
- /**
- * @short 8 bit char based string class
- */
- class CString {
- public:
- CString() : data(0), length(0) { }
- CString(const char *c);
- CString(const char *c, size_t len);
- CString(const CString &);
+ class CString {
+ public:
+ CString()
+ : m_length(0)
+ , m_data(0)
+ {
+ }
- ~CString();
+ CString(const char*);
+ CString(const char*, size_t);
+ CString(const CString&);
- static CString adopt(char* c, size_t len); // c should be allocated with new[].
+ ~CString();
- CString &append(const CString &);
- CString &operator=(const char *c);
- CString &operator=(const CString &);
- CString &operator+=(const CString &c) { return append(c); }
+ static CString adopt(char*, size_t); // buffer should be allocated with new[].
- size_t size() const { return length; }
- const char *c_str() const { return data; }
- private:
- char *data;
- size_t length;
- };
+ CString& append(const CString&);
+ CString& operator=(const char* c);
+ CString& operator=(const CString&);
+ CString& operator+=(const CString& c) { return append(c); }
- typedef Vector<char, 32> CStringBuffer;
+ size_t size() const { return m_length; }
+ const char* c_str() const { return m_data; }
- /**
- * @short Unicode string class
- */
- class UString {
+ private:
+ size_t m_length;
+ char* m_data;
+ };
+
+ typedef Vector<char, 32> CStringBuffer;
+
+ class UString {
friend bool operator==(const UString&, const UString&);
- public:
- /**
- * @internal
- */
- struct Rep {
-
- static PassRefPtr<Rep> create(UChar *d, int l);
- static PassRefPtr<Rep> createCopying(const UChar *d, int l);
- static PassRefPtr<Rep> create(PassRefPtr<Rep> base, int offset, int length);
-
- // Constructs a string from a UTF-8 string, using strict conversion (see comments in UTF8.h).
- // Returns UString::Rep::null for null input or conversion failure.
- static PassRefPtr<Rep> createFromUTF8(const char*);
-
- void destroy();
-
- bool baseIsSelf() const { return baseString == this; }
- UChar* data() const { return baseString->buf + baseString->preCapacity + offset; }
- int size() const { return len; }
-
- unsigned hash() const { if (_hash == 0) _hash = computeHash(data(), len); return _hash; }
- unsigned computedHash() const { ASSERT(_hash); return _hash; } // fast path for Identifiers
-
- static unsigned computeHash(const UChar *, int length);
- static unsigned computeHash(const char *);
-
- Rep* ref() { ++rc; return this; }
- ALWAYS_INLINE void deref() { if (--rc == 0) destroy(); }
-
- // unshared data
- int offset;
- int len;
- int rc; // For null and empty static strings, this field does not reflect a correct count, because ref/deref are not thread-safe. A special case in destroy() guarantees that these do not get deleted.
- mutable unsigned _hash;
- IdentifierTable* identifierTable; // 0 if not an identifier. Since garbage collection can happen on a different thread, there is no other way to get to the table during destruction.
- UString::Rep* baseString;
- bool isStatic : 1;
- size_t reportedCost : 31;
-
- // potentially shared data
- UChar *buf;
- int usedCapacity;
- int capacity;
- int usedPreCapacity;
- int preCapacity;
-
- static Rep null;
- static Rep empty;
- };
-
- public:
-
- /**
- * Constructs a null string.
- */
- UString();
- /**
- * Constructs a string from a classical zero-terminated char string.
- */
- UString(const char *c);
- /**
- * Constructs a string from an array of Unicode characters of the specified
- * length.
- */
- UString(const UChar *c, int length);
- /**
- * If copy is false the string data will be adopted.
- * That means that the data will NOT be copied and the pointer will
- * be deleted when the UString object is modified or destroyed.
- * Behaviour defaults to a deep copy if copy is true.
- */
- UString(UChar *c, int length, bool copy);
- /**
- * Copy constructor. Makes a shallow copy only.
- */
- UString(const UString &s) : m_rep(s.m_rep) {}
-
- UString(const Vector<UChar>& buffer);
-
- /**
- * Convenience declaration only ! You'll be on your own to write the
- * implementation for a construction from DOM::DOMString.
- *
- * Note: feel free to contact me if you want to see a dummy header for
- * your favorite FooString class here !
- */
- UString(const DOM::DOMString&);
- /**
- * Convenience declaration only ! See UString(const DOM::DOMString&).
- */
- UString(const DOM::AtomicString&);
-
- /**
- * Concatenation constructor. Makes operator+ more efficient.
- */
- UString(const UString &, const UString &);
- /**
- * Destructor.
- */
- ~UString() {}
-
- // Special constructor for cases where we overwrite an object in place.
- UString(PlacementNewAdoptType) : m_rep(PlacementNewAdopt) { }
-
- /**
- * Constructs a string from an int.
- */
- static UString from(int i);
- /**
- * Constructs a string from an unsigned int.
- */
- static UString from(unsigned int u);
- /**
- * Constructs a string from a long int.
- */
- static UString from(long u);
- /**
- * Constructs a string from a double.
- */
- static UString from(double d);
-
- struct Range {
public:
- Range(int pos, int len) : position(pos), length(len) {}
- Range() {}
- int position;
- int length;
+ struct Rep {
+ static PassRefPtr<Rep> create(UChar*, int);
+ static PassRefPtr<Rep> createCopying(const UChar*, int);
+ static PassRefPtr<Rep> create(PassRefPtr<Rep> base, int offset, int length);
+
+ // Constructs a string from a UTF-8 string, using strict conversion (see comments in UTF8.h).
+ // Returns UString::Rep::null for null input or conversion failure.
+ static PassRefPtr<Rep> createFromUTF8(const char*);
+
+ void destroy();
+
+ bool baseIsSelf() const { return baseString == this; }
+ UChar* data() const { return baseString->buf + baseString->preCapacity + offset; }
+ int size() const { return len; }
+
+ unsigned hash() const { if (_hash == 0) _hash = computeHash(data(), len); return _hash; }
+ unsigned computedHash() const { ASSERT(_hash); return _hash; } // fast path for Identifiers
+
+ static unsigned computeHash(const UChar*, int length);
+ static unsigned computeHash(const char*);
+
+ Rep* ref() { ++rc; return this; }
+ ALWAYS_INLINE void deref() { if (--rc == 0) destroy(); }
+
+ // unshared data
+ int offset;
+ int len;
+ int rc; // For null and empty static strings, this field does not reflect a correct count, because ref/deref are not thread-safe. A special case in destroy() guarantees that these do not get deleted.
+ mutable unsigned _hash;
+ IdentifierTable* identifierTable; // 0 if not an identifier. Since garbage collection can happen on a different thread, there is no other way to get to the table during destruction.
+ UString::Rep* baseString;
+ bool isStatic : 1;
+ size_t reportedCost : 31;
+
+ // potentially shared data
+ UChar* buf;
+ int usedCapacity;
+ int capacity;
+ int usedPreCapacity;
+ int preCapacity;
+
+ static Rep null;
+ static Rep empty;
+ };
+
+ public:
+ UString();
+ UString(const char*);
+ UString(const UChar*, int length);
+ UString(UChar*, int length, bool copy);
+
+ UString(const UString& s)
+ : m_rep(s.m_rep)
+ {
+ }
+
+ UString(const Vector<UChar>& buffer);
+
+ // Concatenation constructor. Makes operator+ more efficient.
+ UString(const UString&, const UString&);
+
+ ~UString()
+ {
+ }
+
+ // Special constructor for cases where we overwrite an object in place.
+ UString(PlacementNewAdoptType)
+ : m_rep(PlacementNewAdopt)
+ {
+ }
+
+ static UString from(int);
+ static UString from(unsigned int);
+ static UString from(long);
+ static UString from(double);
+
+ struct Range {
+ public:
+ Range(int pos, int len)
+ : position(pos)
+ , length(len)
+ {
+ }
+
+ Range()
+ {
+ }
+
+ int position;
+ int length;
+ };
+
+ UString spliceSubstringsWithSeparators(const Range* substringRanges, int rangeCount, const UString* separators, int separatorCount) const;
+
+ UString& append(const UString&);
+ UString& append(const char*);
+ UString& append(UChar);
+ UString& append(char c) { return append(static_cast<UChar>(static_cast<unsigned char>(c))); }
+ UString& append(const UChar*, int size);
+
+ bool getCString(CStringBuffer&) const;
+
+ // NOTE: This method should only be used for *debugging* purposes as it
+ // is neither Unicode safe nor free from side effects nor thread-safe.
+ char* ascii() const;
+
+ /**
+ * Convert the string to UTF-8, assuming it is UTF-16 encoded.
+ * In non-strict mode, this function is tolerant of badly formed UTF-16, it
+ * can create UTF-8 strings that are invalid because they have characters in
+ * the range U+D800-U+DDFF, U+FFFE, or U+FFFF, but the UTF-8 string is
+ * guaranteed to be otherwise valid.
+ * In strict mode, error is returned as null CString.
+ */
+ CString UTF8String(bool strict = false) const;
+
+ UString& operator=(const char*c);
+
+ UString& operator+=(const UString& s) { return append(s); }
+ UString& operator+=(const char* s) { return append(s); }
+
+ const UChar* data() const { return m_rep->data(); }
+
+ bool isNull() const { return (m_rep == &Rep::null); }
+ bool isEmpty() const { return (!m_rep->len); }
+
+ bool is8Bit() const;
+
+ int size() const { return m_rep->size(); }
+
+ UChar operator[](int pos) const;
+
+ double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const;
+ double toDouble(bool tolerateTrailingJunk) const;
+ double toDouble() const;
+
+ uint32_t toUInt32(bool* ok = 0) const;
+ uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const;
+ uint32_t toStrictUInt32(bool* ok = 0) const;
+
+ unsigned toArrayIndex(bool* ok = 0) const;
+
+ int find(const UString& f, int pos = 0) const;
+ int find(UChar, int pos = 0) const;
+ int rfind(const UString& f, int pos) const;
+ int rfind(UChar, int pos) const;
+
+ UString substr(int pos = 0, int len = -1) const;
+
+ static const UString& null();
+
+ Rep* rep() const { return m_rep.get(); }
+
+ UString(PassRefPtr<Rep> r)
+ : m_rep(r)
+ {
+ ASSERT(m_rep);
+ }
+
+ size_t cost() const;
+
+ private:
+ size_t expandedSize(size_t size, size_t otherSize) const;
+ int usedCapacity() const;
+ int usedPreCapacity() const;
+ void expandCapacity(int requiredLength);
+ void expandPreCapacity(int requiredPreCap);
+
+ RefPtr<Rep> m_rep;
};
- UString spliceSubstringsWithSeparators(const Range* substringRanges, int rangeCount, const UString* separators, int separatorCount) const;
+ bool operator==(const UString& s1, const UString& s2);
- /**
- * Append another string.
- */
- UString& append(const UString&);
- UString& append(const char*);
- UString& append(UChar);
- UString& append(char c) { return append(static_cast<UChar>(static_cast<unsigned char>(c))); }
- UString& append(const UChar*, int size);
+ inline bool operator!=(const UString& s1, const UString& s2)
+ {
+ return !KJS::operator==(s1, s2);
+ }
- /**
- * @return The string converted to the 8-bit string type CString().
- * Returns false if any character is non-ASCII.
- */
- bool getCString(CStringBuffer&) const;
+ bool operator<(const UString& s1, const UString& s2);
+ bool operator>(const UString& s1, const UString& s2);
- /**
- * Convert the Unicode string to plain ASCII chars chopping off any higher
- * bytes. This method should only be used for *debugging* purposes as it
- * is neither Unicode safe nor free from side effects nor thread-safe.
- * In order not to waste any memory the char buffer is static and *shared*
- * by all UString instances.
- */
- char* ascii() const;
+ bool operator==(const UString& s1, const char* s2);
- /**
- * Convert the string to UTF-8, assuming it is UTF-16 encoded.
- * In non-strict mode, this function is tolerant of badly formed UTF-16, it
- * can create UTF-8 strings that are invalid because they have characters in
- * the range U+D800-U+DDFF, U+FFFE, or U+FFFF, but the UTF-8 string is
- * guaranteed to be otherwise valid.
- * In strict mode, error is returned as null CString.
- */
- CString UTF8String(bool strict = false) const;
+ inline bool operator!=(const UString& s1, const char* s2)
+ {
+ return !KJS::operator==(s1, s2);
+ }
- /**
- * @see UString(const DOM::DOMString&).
- */
- DOM::DOMString domString() const;
+ inline bool operator==(const char *s1, const UString& s2)
+ {
+ return operator==(s2, s1);
+ }
- /**
- * Assignment operator.
- */
- UString &operator=(const char *c);
- /**
- * Appends the specified string.
- */
- UString &operator+=(const UString &s) { return append(s); }
- UString &operator+=(const char *s) { return append(s); }
+ inline bool operator!=(const char *s1, const UString& s2)
+ {
+ return !KJS::operator==(s1, s2);
+ }
- /**
- * @return A pointer to the internal Unicode data.
- */
- const UChar* data() const { return m_rep->data(); }
- /**
- * @return True if null.
- */
- bool isNull() const { return (m_rep == &Rep::null); }
- /**
- * @return True if null or zero length.
- */
- bool isEmpty() const { return (!m_rep->len); }
- /**
- * Use this if you want to make sure that this string is a plain ASCII
- * string. For example, if you don't want to lose any information when
- * using cstring() or ascii().
- *
- * @return True if the string doesn't contain any non-ASCII characters.
- */
- bool is8Bit() const;
- /**
- * @return The length of the string.
- */
- int size() const { return m_rep->size(); }
- /**
- * Const character at specified position.
- */
- UChar operator[](int pos) const;
+ bool operator==(const CString& s1, const CString& s2);
- /**
- * Attempts an conversion to a number. Apart from floating point numbers,
- * the algorithm will recognize hexadecimal representations (as
- * indicated by a 0x or 0X prefix) and +/- Infinity.
- * Returns NaN if the conversion failed.
- * @param tolerateTrailingJunk if true, toDouble can tolerate garbage after the number.
- * @param tolerateEmptyString if false, toDouble will turn an empty string into NaN rather than 0.
- */
- double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const;
- double toDouble(bool tolerateTrailingJunk) const;
- double toDouble() const;
+ inline UString operator+(const UString& s1, const UString& s2)
+ {
+ return UString(s1, s2);
+ }
- /**
- * Attempts an conversion to a 32-bit integer. ok will be set
- * according to the success.
- * @param tolerateEmptyString if false, toUInt32 will return false for *ok for an empty string.
- */
- uint32_t toUInt32(bool *ok = 0) const;
- uint32_t toUInt32(bool *ok, bool tolerateEmptyString) const;
- uint32_t toStrictUInt32(bool *ok = 0) const;
+ int compare(const UString&, const UString&);
- /**
- * Attempts an conversion to an array index. The "ok" boolean will be set
- * to true if it is a valid array index according to the rule from
- * ECMA 15.2 about what an array index is. It must exactly match the string
- * form of an unsigned integer, and be less than 2^32 - 1.
- */
- unsigned toArrayIndex(bool *ok = 0) const;
+ bool equal(const UString::Rep*, const UString::Rep*);
- /**
- * @return Position of first occurrence of f starting at position pos.
- * -1 if the search was not successful.
- */
- int find(const UString &f, int pos = 0) const;
- int find(UChar, int pos = 0) const;
- /**
- * @return Position of first occurrence of f searching backwards from
- * position pos.
- * -1 if the search was not successful.
- */
- int rfind(const UString &f, int pos) const;
- int rfind(UChar, int pos) const;
- /**
- * @return The sub string starting at position pos and length len.
- */
- UString substr(int pos = 0, int len = -1) const;
- /**
- * Static instance of a null string.
- */
- static const UString &null();
+ inline UString::UString()
+ : m_rep(&Rep::null)
+ {
+ }
- Rep* rep() const { return m_rep.get(); }
- UString(PassRefPtr<Rep> r) : m_rep(r) { ASSERT(m_rep); }
+ // Rule from ECMA 15.2 about what an array index is.
+ // Must exactly match string form of an unsigned integer, and be less than 2^32 - 1.
+ inline unsigned UString::toArrayIndex(bool* ok) const
+ {
+ unsigned i = toStrictUInt32(ok);
+ if (ok && i >= 0xFFFFFFFFU)
+ *ok = false;
+ return i;
+ }
- size_t cost() const;
+ // We'd rather not do shared substring append for small strings, since
+ // this runs too much risk of a tiny initial string holding down a
+ // huge buffer.
+ // FIXME: this should be size_t but that would cause warnings until we
+ // fix UString sizes to be size_t instead of int
+ static const int minShareSize = Heap::minExtraCostSize / sizeof(UChar);
- private:
- size_t expandedSize(size_t size, size_t otherSize) const;
- int usedCapacity() const;
- int usedPreCapacity() const;
- void expandCapacity(int requiredLength);
- void expandPreCapacity(int requiredPreCap);
+ inline size_t UString::cost() const
+ {
+ size_t capacity = (m_rep->baseString->capacity + m_rep->baseString->preCapacity) * sizeof(UChar);
+ size_t reportedCost = m_rep->baseString->reportedCost;
+ ASSERT(capacity >= reportedCost);
- RefPtr<Rep> m_rep;
- };
+ size_t capacityDelta = capacity - reportedCost;
- bool operator==(const UString& s1, const UString& s2);
- inline bool operator!=(const UString& s1, const UString& s2) {
- return !KJS::operator==(s1, s2);
- }
- bool operator<(const UString& s1, const UString& s2);
- bool operator>(const UString& s1, const UString& s2);
- bool operator==(const UString& s1, const char *s2);
- inline bool operator!=(const UString& s1, const char *s2) {
- return !KJS::operator==(s1, s2);
- }
- inline bool operator==(const char *s1, const UString& s2) {
- return operator==(s2, s1);
- }
- inline bool operator!=(const char *s1, const UString& s2) {
- return !KJS::operator==(s1, s2);
- }
- bool operator==(const CString& s1, const CString& s2);
- inline UString operator+(const UString& s1, const UString& s2) {
- return UString(s1, s2);
- }
-
- int compare(const UString &, const UString &);
-
- bool equal(const UString::Rep*, const UString::Rep*);
-
-
-inline UString::UString()
- : m_rep(&Rep::null)
-{
-}
-
-// Rule from ECMA 15.2 about what an array index is.
-// Must exactly match string form of an unsigned integer, and be less than 2^32 - 1.
-inline unsigned UString::toArrayIndex(bool *ok) const
-{
- unsigned i = toStrictUInt32(ok);
- if (ok && i >= 0xFFFFFFFFU)
- *ok = false;
- return i;
-}
-
-// We'd rather not do shared substring append for small strings, since
-// this runs too much risk of a tiny initial string holding down a
-// huge buffer.
-// FIXME: this should be size_t but that would cause warnings until we
-// fix UString sizes to be size_t instead of int
-static const int minShareSize = Heap::minExtraCostSize / sizeof(UChar);
-
-inline size_t UString::cost() const
-{
- size_t capacity = (m_rep->baseString->capacity + m_rep->baseString->preCapacity) * sizeof(UChar);
- size_t reportedCost = m_rep->baseString->reportedCost;
- ASSERT(capacity >= reportedCost);
-
- size_t capacityDelta = capacity - reportedCost;
-
- if (capacityDelta < static_cast<size_t>(minShareSize))
- return 0;
+ if (capacityDelta < static_cast<size_t>(minShareSize))
+ return 0;
#if COMPILER(MSVC)
// MSVC complains about this assignment, since reportedCost is a 31-bit size_t.
@@ -423,18 +321,17 @@
#pragma warning(disable: 4267)
#endif
- m_rep->baseString->reportedCost = capacity;
+ m_rep->baseString->reportedCost = capacity;
#if COMPILER(MSVC)
#pragma warning(pop)
#endif
- return capacityDelta;
-}
+ return capacityDelta;
+ }
} // namespace KJS
-
namespace WTF {
template<typename T> struct DefaultHash;
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 4275261..bcd95b2 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,12 @@
+2008-07-06 Sam Weinig <sam@webkit.org>
+
+ Reviewed by Cameron Zwarich.
+
+ Add #include for kjs/protect.h.
+
+ * xml/XMLHttpRequest.cpp:
+ (WebCore::XMLHttpRequest::loadRequestAsynchronously):
+
2008-07-06 David Kilzer <ddkilzer@apple.com>
Save a few more bits in RenderStyle
diff --git a/WebCore/xml/XMLHttpRequest.cpp b/WebCore/xml/XMLHttpRequest.cpp
index 64f71f7..065bc18 100644
--- a/WebCore/xml/XMLHttpRequest.cpp
+++ b/WebCore/xml/XMLHttpRequest.cpp
@@ -42,6 +42,7 @@
#include "XMLHttpRequestProgressEvent.h"
#include "markup.h"
#include <kjs/JSLock.h>
+#include <kjs/protect.h>
namespace WebCore {
@@ -675,7 +676,7 @@
// and they are referenced by the JavaScript wrapper.
ref();
- gcProtectNullTolerant(ScriptInterpreter::getDOMObject(this));
+ KJS::gcProtectNullTolerant(ScriptInterpreter::getDOMObject(this));
}
}