Commit 2947a916 authored by weinig@apple.com's avatar weinig@apple.com

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
parent e875c5bb
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.
......@@ -170,8 +170,8 @@ __ZN3KJS6JSCell3putEPNS_9ExecStateERKNS_10IdentifierEPNS_7JSValueE
__ZN3KJS6JSCell3putEPNS_9ExecStateEjPNS_7JSValueE
__ZN3KJS6JSCell9getObjectEv
__ZN3KJS6JSCellnwEmPNS_9ExecStateE
__ZN3KJS6JSLock12DropAllLocksC1Eb
__ZN3KJS6JSLock12DropAllLocksC1EPNS_9ExecStateE
__ZN3KJS6JSLock12DropAllLocksC1Eb
__ZN3KJS6JSLock12DropAllLocksD1Ev
__ZN3KJS6JSLock14registerThreadEv
__ZN3KJS6JSLock4lockEb
......@@ -210,7 +210,7 @@ __ZN3KJS8JSObject12lookupSetterEPNS_9ExecStateERKNS_10IdentifierE
__ZN3KJS8JSObject14deletePropertyEPNS_9ExecStateERKNS_10IdentifierE
__ZN3KJS8JSObject14deletePropertyEPNS_9ExecStateEj
__ZN3KJS8JSObject16getPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayE
__ZN3KJS8JSObject17putDirectFunctionEPNS_16InternalFunctionEi
__ZN3KJS8JSObject17putDirectFunctionEPNS_16InternalFunctionEj
__ZN3KJS8JSObject17putWithAttributesEPNS_9ExecStateERKNS_10IdentifierEPNS_7JSValueEj
__ZN3KJS8JSObject17putWithAttributesEPNS_9ExecStateEjPNS_7JSValueEj
__ZN3KJS8JSObject18getOwnPropertySlotEPNS_9ExecStateEjRNS_12PropertySlotE
......
......@@ -76,7 +76,7 @@ bool JSActivation::getOwnPropertySlot(ExecState* exec, const Identifier& propert
// 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 @@ void JSActivation::put(ExecState*, const Identifier& propertyName, JSValue* valu
// 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 @@ void JSActivation::putWithAttributes(ExecState*, const Identifier& propertyName,
// 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)
......
......@@ -90,7 +90,7 @@ namespace KJS {
static JSGlobalData*& sharedInstanceInternal();
struct DataInstance {
DataInstance() : m_data(0) {}
DataInstance() : m_data(0) { }
~DataInstance() { delete m_data; }
operator JSGlobalData*&() { return m_data; }
......
......@@ -176,7 +176,7 @@ void JSGlobalObject::reset(JSValue* prototype)
// 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);
......
// -*- 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 {
} // namespace KJS
#endif // KJS_GlobalObject_h
#endif // JSGlobalObject_h
......@@ -48,89 +48,92 @@ using namespace Unicode;
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 @@ static int parseDigit(unsigned short c, int radix)
{
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 @@ static double parseInt(const UString& s, int radix)
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 @@ static double parseFloat(const UString& s)
// 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] == '-')) {
if (p < length && (s[p] == '+' || s[p] == '-'))
++p;
}
if (length - p >= 2 && s[p] == '0' && (s[p + 1] == 'x' || s[p + 1] == 'X')) {
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 */ );
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* globalFuncEval(ExecState* exec, JSObject* function, JSValue* thisValue,
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 @@ JSValue* globalFuncEscape(ExecState* exec, JSObject*, JSValue*, const ArgList& a
"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 @@ JSValue* globalFuncEscape(ExecState* exec, JSObject*, JSValue*, const ArgList& a
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 @@ JSValue* globalFuncUnescape(ExecState* exec, JSObject*, JSValue*, const ArgList&
k += 2;
}
k++;
s.append(*c);
result.append(*c);
}
return jsString(exec, s);
return jsString(exec, result);
}
#ifndef NDEBUG
......
This diff is collapsed.
// -*- 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 @@ JSLock::DropAllLocks::~DropAllLocks()
#endif // USE(MULTIPLE_THREADS)
}
} // namespace KJS
// -*- 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 @@ namespace KJS {
class JSLock : Noncopyable {
public:
JSLock(ExecState* exec);
JSLock(ExecState*);
JSLock(bool lockingForReal)
: m_lockingForReal(lockingForReal)
......
......@@ -44,7 +44,7 @@ namespace KJS {
}
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;
......
......@@ -41,33 +41,33 @@ JSValue* JSNumberCell::toPrimitive(ExecState*, JSType) const
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 @@ JSObject* JSNumberCell::toThisObject(ExecState* exec) const
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;
}
......
......@@ -34,127 +34,125 @@
namespace KJS {
class ExecState;
class Identifier;
class JSCell;
class JSObject;
class JSString;
class PropertySlot;
struct ClassInfo;
struct Instruction;
class JSNumberCell : public JSCell {
friend JSValue* jsNumberCell(ExecState*, double);
public:
double value() const { return val; }
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 UString toThisString(ExecState*) const;
virtual JSObject* toThisObject(ExecState*) const;
virtual JSValue* getJSNumber();
void* operator new(size_t size, ExecState* exec)
class ExecState;
class Identifier;
class JSCell;
class JSObject;
class JSString;
class PropertySlot;
struct ClassInfo;
struct Instruction;
class JSNumberCell : public JSCell {
friend JSValue* jsNumberCell(ExecState*, double);
public:
double value() const { return m_value; }
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 UString toThisString(ExecState*) const;
virtual JSObject* toThisObject(ExecState*) const;
virtual JSValue* getJSNumber();
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)