This commit is contained in:
rogerl%netscape.com 2001-09-01 01:10:57 +00:00
Родитель 72b986d4f0
Коммит 805e8131ff
17 изменённых файлов: 2679 добавлений и 145 удалений

Просмотреть файл

@ -840,109 +840,115 @@ bool ByteCodeGen::genCodeForStatement(StmtNode *p, ByteCodeGen *static_cg, uint3
case StmtNode::ForIn:
{
ForStmtNode *f = checked_cast<ForStmtNode *>(p);
Reference *value = NULL;
if (f->initializer->getKind() == StmtNode::Var) {
VariableStmtNode *vs = checked_cast<VariableStmtNode *>(f->initializer);
VariableBinding *v = vs->bindings;
Reference *value = mScopeChain->getName(*v->name, CURRENT_ATTR, Write);
uint32 breakLabel = getLabel(Label::BreakLabel);
uint32 labelAtTopOfBlock = getLabel();
uint32 labelAtIncrement = getLabel(Label::ContinueLabel);
uint32 labelAtTestCondition = getLabel();
uint32 labelAtEnd = getLabel();
value = mScopeChain->getName(*v->name, CURRENT_ATTR, Write);
}
else {
if (f->initializer->getKind() == StmtNode::expression) {
ExprStmtNode *e = checked_cast<ExprStmtNode *>(f->initializer);
value = genReference(e->expr, Write);
}
else
NOT_REACHED("what else??");
}
uint32 breakLabel = getLabel(Label::BreakLabel);
uint32 labelAtTopOfBlock = getLabel();
uint32 labelAtIncrement = getLabel(Label::ContinueLabel);
uint32 labelAtTestCondition = getLabel();
uint32 labelAtEnd = getLabel();
/*
iterator = object.forin()
goto test
top:
v = iterator.value
<statement body>
continue:
iterator = object.next(iterator)
test:
if (iterator == null)
goto end
goto top
break:
object.done(iterator)
end:
iterator = object.forin()
goto test
top:
v = iterator.value
<statement body>
continue:
iterator = object.next(iterator)
test:
if (iterator == null)
goto end
goto top
break:
object.done(iterator)
end:
*/
// acquire a local from the scopechain, and copy the target object
// into it.
Reference *objectReadRef, *objectWriteRef;
Reference *iteratorReadRef, *iteratorWriteRef;
mScopeChain->defineTempVariable(objectReadRef, objectWriteRef, Object_Type);
mScopeChain->defineTempVariable(iteratorReadRef, iteratorWriteRef, Object_Type);
// acquire a local from the scopechain, and copy the target object
// into it.
Reference *objectReadRef, *objectWriteRef;
Reference *iteratorReadRef, *iteratorWriteRef;
mScopeChain->defineTempVariable(m_cx, objectReadRef, objectWriteRef, Object_Type);
mScopeChain->defineTempVariable(m_cx, iteratorReadRef, iteratorWriteRef, Object_Type);
genExpr(f->expr2);
objectWriteRef->emitCodeSequence(this);
addOp(DupOp);
addOp(GetInvokePropertyOp);
// addIdentifierRef(widenCString("Iterator"), widenCString("forin"));
addStringRef(widenCString("forin"));
addOpAdjustDepth(InvokeOp, -1);
addLong(0);
addByte(Explicit);
iteratorWriteRef->emitCodeSequence(this);
addOp(JumpOp);
addFixup(labelAtTestCondition);
genExpr(f->expr2);
objectWriteRef->emitCodeSequence(this);
addOp(GetInvokePropertyOp);
// addIdentifierRef(widenCString("Iterator"), widenCString("forin"));
addStringRef(widenCString("forin"));
addOpAdjustDepth(InvokeOp, -1);
addLong(0);
addByte(Explicit);
iteratorWriteRef->emitCodeSequence(this);
addOp(PopOp);
addOp(JumpOp);
addFixup(labelAtTestCondition);
setLabel(labelAtTopOfBlock);
iteratorReadRef->emitCodeSequence(this);
addOp(GetPropertyOp);
addStringRef(widenCString("value"));
value->emitCodeSequence(this);
setLabel(labelAtTopOfBlock);
iteratorReadRef->emitCodeSequence(this);
addOp(GetPropertyOp);
addStringRef(widenCString("value"));
value->emitCodeSequence(this);
addOp(PopOp);
mLabelStack.push_back(breakLabel);
mLabelStack.push_back(labelAtIncrement);
genCodeForStatement(f->stmt, static_cg, finallyLabel);
mLabelStack.pop_back();
mLabelStack.pop_back();
mLabelStack.push_back(breakLabel);
mLabelStack.push_back(labelAtIncrement);
genCodeForStatement(f->stmt, static_cg, finallyLabel);
mLabelStack.pop_back();
mLabelStack.pop_back();
setLabel(labelAtIncrement);
objectReadRef->emitCodeSequence(this);
addOp(DupOp);
addOp(GetInvokePropertyOp);
addStringRef(widenCString("next"));
iteratorReadRef->emitCodeSequence(this);
addOpAdjustDepth(InvokeOp, -1);
addLong(1);
addByte(Explicit);
iteratorWriteRef->emitCodeSequence(this);
addOp(PopOp);
setLabel(labelAtIncrement);
objectReadRef->emitCodeSequence(this);
addOp(GetInvokePropertyOp);
addStringRef(widenCString("next"));
iteratorReadRef->emitCodeSequence(this);
addOpAdjustDepth(InvokeOp, -2);
addLong(1);
addByte(Explicit);
iteratorWriteRef->emitCodeSequence(this);
addOp(PopOp);
setLabel(labelAtTestCondition);
iteratorReadRef->emitCodeSequence(this);
addOp(LoadConstantNullOp);
addOp(DoOperatorOp);
addByte(Equal);
addOp(JumpTrueOp);
addFixup(labelAtEnd);
addOp(JumpOp);
addFixup(labelAtTopOfBlock);
setLabel(labelAtTestCondition);
iteratorReadRef->emitCodeSequence(this);
addOp(LoadConstantNullOp);
addOp(DoOperatorOp);
addByte(Equal);
addOp(JumpTrueOp);
addFixup(labelAtEnd);
addOp(JumpOp);
addFixup(labelAtTopOfBlock);
setLabel(breakLabel);
objectReadRef->emitCodeSequence(this);
addOp(DupOp);
addOp(GetInvokePropertyOp);
addStringRef(widenCString("done"));
iteratorReadRef->emitCodeSequence(this);
addOpAdjustDepth(InvokeOp, -2);
addLong(1);
addByte(Explicit);
addOp(PopOp);
setLabel(breakLabel);
objectReadRef->emitCodeSequence(this);
addOp(GetInvokePropertyOp);
addStringRef(widenCString("done"));
iteratorReadRef->emitCodeSequence(this);
addOpAdjustDepth(InvokeOp, -2);
addLong(1);
addByte(Explicit);
addOp(PopOp);
setLabel(labelAtEnd);
setLabel(labelAtEnd);
delete objectReadRef;
delete objectWriteRef;
delete iteratorReadRef;
delete iteratorWriteRef;
}
else
NOT_REACHED("implement me");
delete objectReadRef;
delete objectWriteRef;
delete iteratorReadRef;
delete iteratorWriteRef;
}
break;
case StmtNode::For:
@ -1052,7 +1058,7 @@ bool ByteCodeGen::genCodeForStatement(StmtNode *p, ByteCodeGen *static_cg, uint3
uint32 defaultLabel = toUInt32(-1);
Reference *switchTempReadRef, *switchTempWriteRef;
mScopeChain->defineTempVariable(switchTempReadRef, switchTempWriteRef, Object_Type);
mScopeChain->defineTempVariable(m_cx, switchTempReadRef, switchTempWriteRef, Object_Type);
SwitchStmtNode *sw = checked_cast<SwitchStmtNode *>(p);
genExpr(sw->expr);

Просмотреть файл

@ -138,3 +138,7 @@ namespace fd {
}
#endif
#if defined(_WIN32) && !defined(__MWERKS__)
#undef __STDC__
#endif

Просмотреть файл

@ -315,7 +315,7 @@ JSValue *Context::buildArgumentBlock(JSFunction *target, uint32 &argCount)
else {
if (target->hasRestParameter()) {
if (!restArgument.isUndefined()) {
String *id = numberToString(posArgIndex++);
const String *id = numberToString(posArgIndex++);
restArgument.object->setProperty(this, *id, (NamespaceList *)(NULL), v);
}
}
@ -1899,7 +1899,7 @@ JSValue JSValue::valueToNumber(Context *cx, const JSValue& value)
}
}
String *numberToString(float64 number)
const String *numberToString(float64 number)
{
char buf[dtosStandardBufferSize];
const char *chrp = doubleToStr(buf, dtosStandardBufferSize, number, dtosStandard, 0);
@ -2078,6 +2078,20 @@ int JSValue::operator==(const JSValue& value) const
return 0;
}
float64 JSValue::float64ToInteger(float64 d)
{
if (JSDOUBLE_IS_NaN(d))
return 0.0;
else
return (d >= 0.0) ? fd::floor(d) : -fd::floor(d);
}
JSValue JSValue::valueToInteger(Context *cx, const JSValue& value)
{
JSValue v = valueToNumber(cx, value);
v.f64 = float64ToInteger(v.f64);
return v;
}
JSValue JSValue::valueToInt32(Context *, const JSValue& value)
{

Просмотреть файл

@ -52,6 +52,7 @@
#include "jsstring.h"
#include "jsarray.h"
#include "jsmath.h"
#include "jsdate.h"
#include "fdlibm_ns.h"
@ -78,6 +79,7 @@ JSType *Unit_Type;
JSType *Attribute_Type;
JSType *NamedArgument_Type;
JSArrayType *Array_Type;
JSType *Date_Type;
Attribute *Context::executeAttributes(ExprNode *attr)
@ -210,6 +212,19 @@ void JSObject::defineSetterMethod(Context * /*cx*/, const String &name, Attribut
}
}
uint32 JSObject::tempVarCount = 0;
void JSObject::defineTempVariable(Context *cx, Reference *&readRef, Reference *&writeRef, JSType *type)
{
char buf[32];
sprintf(buf, "%%tempvar%%_%d", tempVarCount++);
const String &name = cx->mWorld.identifiers[buf];
/* Property *prop = */defineVariable(cx, name, (NamespaceList *)NULL, Object_Type);
readRef = new NameReference(name, Read, Object_Type, 0);
writeRef = new NameReference(name, Write, Object_Type, 0);
}
// add a property
Property *JSObject::defineVariable(Context *cx, const String &name, AttributeStmtNode *attr, JSType *type)
{
@ -217,10 +232,14 @@ Property *JSObject::defineVariable(Context *cx, const String &name, AttributeStm
PropertyAttribute attrFlags = (attr) ? attr->attributeValue->mTrueFlags : 0;
PropertyIterator it;
if (hasOwnProperty(name, names, Read, &it)) {
if (attr)
cx->reportError(Exception::typeError, "Duplicate definition '{0}'", attr->pos, name);
else
cx->reportError(Exception::typeError, "Duplicate definition '{0}'", name);
// not a problem if neither are consts
if ((attrFlags & Property::Const)
|| (PROPERTY_ATTR(it) & Property::Const)) {
if (attr)
cx->reportError(Exception::typeError, "Duplicate definition '{0}'", attr->pos, name);
else
cx->reportError(Exception::typeError, "Duplicate definition '{0}'", name);
}
}
Property *prop = new Property(new JSValue(), type, attrFlags);
@ -231,8 +250,12 @@ Property *JSObject::defineVariable(Context *cx, const String &name, AttributeStm
Property *JSObject::defineVariable(Context *cx, const String &name, NamespaceList *names, JSType *type)
{
PropertyIterator it;
if (hasOwnProperty(name, names, Read, &it))
cx->reportError(Exception::typeError, "Duplicate definition '{0}'", name);
if (hasOwnProperty(name, names, Read, &it)) {
// not a problem if neither are consts
if (PROPERTY_ATTR(it) & Property::Const) {
cx->reportError(Exception::typeError, "Duplicate definition '{0}'", name);
}
}
Property *prop = new Property(new JSValue(), type, 0);
const PropertyMap::value_type e(name, new NamespacedProperty(prop, names));
@ -244,15 +267,19 @@ Property *JSObject::defineVariable(Context *cx, const String &name, NamespaceLis
Property *JSObject::defineVariable(Context *cx, const String &name, AttributeStmtNode *attr, JSType *type, JSValue v)
{
NamespaceList *names = (attr) ? attr->attributeValue->mNamespaceList : NULL;
PropertyAttribute attrFlags = (attr) ? attr->attributeValue->mTrueFlags : 0;
PropertyIterator it;
if (hasOwnProperty(name, names, Read, &it)) {
if (attr)
cx->reportError(Exception::typeError, "Duplicate definition '{0}'", attr->pos, name);
else
cx->reportError(Exception::typeError, "Duplicate definition '{0}'", name);
// not a problem if neither are consts
if ((attrFlags & Property::Const)
|| (PROPERTY_ATTR(it) & Property::Const)) {
if (attr)
cx->reportError(Exception::typeError, "Duplicate definition '{0}'", attr->pos, name);
else
cx->reportError(Exception::typeError, "Duplicate definition '{0}'", name);
}
}
PropertyAttribute attrFlags = (attr) ? attr->attributeValue->mTrueFlags : 0;
Property *prop = new Property(new JSValue(v), type, attrFlags);
const PropertyMap::value_type e(name, new NamespacedProperty(prop, names));
mProperties.insert(e);
@ -261,8 +288,11 @@ Property *JSObject::defineVariable(Context *cx, const String &name, AttributeStm
Property *JSObject::defineVariable(Context *cx, const String &name, NamespaceList *names, JSType *type, JSValue v)
{
PropertyIterator it;
if (hasOwnProperty(name, names, Read, &it))
cx->reportError(Exception::typeError, "Duplicate definition '{0}'", name);
if (hasOwnProperty(name, names, Read, &it)) {
if (PROPERTY_ATTR(it) & Property::Const) {
cx->reportError(Exception::typeError, "Duplicate definition '{0}'", name);
}
}
Property *prop = new Property(new JSValue(v), type, 0);
const PropertyMap::value_type e(name, new NamespacedProperty(prop, names));
@ -467,7 +497,7 @@ void JSArrayInstance::setProperty(Context *cx, const String &name, NamespaceList
cx->reportError(Exception::rangeError, "out of range value for length");
for (uint32 i = newLength; i < mLength; i++) {
String *id = numberToString(i);
const String *id = numberToString(i);
if (findNamespacedProperty(*id, NULL) != mProperties.end())
deleteProperty(*id, NULL);
delete id;
@ -1354,7 +1384,7 @@ void JSType::setSuperType(JSType *super)
void Activation::defineTempVariable(Reference *&readRef, Reference *&writeRef, JSType *type)
void Activation::defineTempVariable(Context * /*cx*/, Reference *&readRef, Reference *&writeRef, JSType *type)
{
readRef = new LocalVarReference(mVariableCount, Read, type, Property::NoAttribute);
writeRef = new LocalVarReference(mVariableCount, Write, type, Property::NoAttribute);
@ -1619,6 +1649,53 @@ static JSValue Object_toString(Context *, const JSValue& thisValue, JSValue * /*
}
}
struct IteratorDongle {
JSObject *obj;
PropertyIterator it;
};
static JSValue Object_forin(Context *cx, const JSValue& thisValue, JSValue * /*argv*/, uint32 /*argc*/)
{
ASSERT(thisValue.isObject());
JSObject *iteratorObject = Object_Type->newInstance(cx);
IteratorDongle *itDude = new IteratorDongle();
itDude->obj = thisValue.object;
itDude->it = thisValue.object->mProperties.begin();
JSValue v(&PROPERTY_NAME(itDude->it));
iteratorObject->setProperty(cx, cx->mWorld.identifiers["value"], 0, v);
iteratorObject->mPrivate = itDude;
return JSValue(iteratorObject);
}
static JSValue Object_next(Context *cx, const JSValue& thisValue, JSValue *argv, uint32 /*argc*/)
{
JSValue iteratorValue = argv[0];
ASSERT(iteratorValue.isObject());
JSObject *iteratorObject = iteratorValue.object;
IteratorDongle *itDude = (IteratorDongle *)(iteratorObject->mPrivate);
itDude->it++;
if (itDude->it == itDude->obj->mProperties.end())
return kNullValue;
else {
JSValue v(&PROPERTY_NAME(itDude->it));
iteratorObject->setProperty(cx, cx->mWorld.identifiers["value"], 0, v);
return iteratorValue;
}
}
static JSValue Object_done(Context *, const JSValue& thisValue, JSValue * /*argv*/, uint32 /*argc*/)
{
return kUndefinedValue;
}
static JSValue Function_Constructor(Context *cx, const JSValue& thisValue, JSValue * /*argv*/, uint32 /*argc*/)
{
JSValue v = thisValue;
@ -1853,6 +1930,7 @@ void Context::initBuiltins()
{ "Unit", NULL, &kNullValue },
{ "Attribute", NULL, &kNullValue },
{ "NamedArgument", NULL, &kNullValue },
{ "Date", Date_Constructor, &kPositiveZero },
};
Object_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[0].name)], NULL);
@ -1870,6 +1948,7 @@ void Context::initBuiltins()
Unit_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[9].name)], Object_Type);
Attribute_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[10].name)], Object_Type);
NamedArgument_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[11].name)], Object_Type);
Date_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[12].name)], Object_Type);
String_Type->defineVariable(this, widenCString("fromCharCode"), NULL, String_Type, JSValue(new JSFunction(String_fromCharCode, String_Type)));
@ -1879,6 +1958,9 @@ void Context::initBuiltins()
{
{ "toString", String_Type, 0, Object_toString },
{ "toSource", String_Type, 0, Object_toString },
{ "forin", Object_Type, 0, Object_forin },
{ "next", Object_Type, 0, Object_next },
{ "done", Object_Type, 0, Object_done },
{ NULL }
};
ProtoFunDef functionProtos[] =
@ -1922,6 +2004,7 @@ void Context::initBuiltins()
initClass(Unit_Type, &builtInClasses[9], NULL);
initClass(Attribute_Type, &builtInClasses[10], NULL);
initClass(NamedArgument_Type, &builtInClasses[11], NULL);
initClass(Date_Type, &builtInClasses[12], getDateProtos() );
Type_Type->defineUnaryOperator(Index, new JSFunction(arrayMaker, Type_Type));
@ -2029,6 +2112,7 @@ Context::Context(JSObject **global, World &world, Arena &a, Pragma::Flags flags)
getGlobalObject()->defineVariable(this, widenCString("undefined"), (NamespaceList *)(NULL), Void_Type, kUndefinedValue);
getGlobalObject()->defineVariable(this, widenCString("NaN"), (NamespaceList *)(NULL), Void_Type, kNaNValue);
getGlobalObject()->defineVariable(this, widenCString("Infinity"), (NamespaceList *)(NULL), Void_Type, kPositiveInfinity);
initDateObject(this);
}
initOperators();

Просмотреть файл

@ -118,8 +118,10 @@ static const double two31 = 2147483648.0;
extern JSType *Attribute_Type; // used to define 'prototype' 'static' etc & Namespace values
extern JSType *NamedArgument_Type;
extern JSType *Date_Type;
String *numberToString(float64 number);
const String *numberToString(float64 number);
float64 stringToNumber(const String *string);
@ -142,7 +144,7 @@ static const double two31 = 2147483648.0;
type_tag,
boolean_tag,
string_tag,
null_tag
null_tag,
} Tag;
Tag tag;
@ -188,6 +190,7 @@ static const double two31 = 2147483648.0;
JSValue toString(Context *cx) const { return (isString() ? *this : valueToString(cx, *this)); }
JSValue toNumber(Context *cx) const { return (isNumber() ? *this : valueToNumber(cx, *this)); }
JSValue toInteger(Context *cx) const { return valueToInteger(cx, *this); }
JSValue toUInt32(Context *cx) const { return valueToUInt32(cx, *this); }
JSValue toUInt16(Context *cx) const { return valueToUInt16(cx, *this); }
JSValue toInt32(Context *cx) const { return valueToInt32(cx, *this); }
@ -202,6 +205,7 @@ static const double two31 = 2147483648.0;
JSValue toPrimitive(Context *cx, Hint hint = NoHint) const;
static JSValue valueToNumber(Context *cx, const JSValue& value);
static JSValue valueToInteger(Context *cx, const JSValue& value);
static JSValue valueToString(Context *cx, const JSValue& value);
static JSValue valueToObject(Context *cx, const JSValue& value);
static JSValue valueToUInt32(Context *cx, const JSValue& value);
@ -209,6 +213,9 @@ static const double two31 = 2147483648.0;
static JSValue valueToInt32(Context *cx, const JSValue& value);
static JSValue valueToBoolean(Context *cx, const JSValue& value);
static float64 float64ToInteger(float64 d);
int operator==(const JSValue& value) const;
};
@ -581,6 +588,8 @@ XXX ...couldn't get this to work...
virtual bool hasLocalVars() { return false; }
virtual uint32 localVarCount() { return 0; }
virtual void defineTempVariable(Context *cx, Reference *&readRef, Reference *&writeRef, JSType *type);
// debug only
void printProperties(Formatter &f) const
{
@ -590,7 +599,7 @@ XXX ...couldn't get this to work...
}
}
static uint32 tempVarCount;
};
Formatter& operator<<(Formatter& f, const JSObject& obj);
@ -958,7 +967,7 @@ XXX ...couldn't get this to work...
bool hasLocalVars() { return true; }
virtual uint32 localVarCount() { return mVariableCount; }
void defineTempVariable(Reference *&readRef, Reference *&writeRef, JSType *type);
void defineTempVariable(Context *cx, Reference *&readRef, Reference *&writeRef, JSType *type);
Reference *genReference(bool hasBase, const String& name, NamespaceList *names, Access acc, uint32 depth);
@ -1097,12 +1106,11 @@ XXX ...couldn't get this to work...
return obj->isNestedFunction();
}
bool isPossibleUncheckedFunction(FunctionDefinition *f);
bool isPossibleUncheckedFunction(FunctionDefinition *f);
void defineTempVariable(Reference *&readRef, Reference *&writeRef, JSType *type)
void defineTempVariable(Context *cx, Reference *&readRef, Reference *&writeRef, JSType *type)
{
ASSERT(dynamic_cast<Activation *>(mScopeStack.back()));
((Activation *)(mScopeStack.back()))->defineTempVariable(readRef, writeRef, type);
mScopeStack.back()->defineTempVariable(cx, readRef, writeRef, type);
}
// a compile time request to get the value for a name

Просмотреть файл

@ -68,7 +68,7 @@ JSValue Array_Constructor(Context *cx, const JSValue& thisValue, JSValue *argv,
else {
arrInst->mLength = argc;
for (uint32 i = 0; i < argc; i++) {
String *id = numberToString(i);
const String *id = numberToString(i);
arrInst->defineVariable(cx, *id, (NamespaceList *)(NULL), Object_Type, argv[i]);
delete id;
}
@ -92,7 +92,7 @@ static JSValue Array_toString(Context *cx, const JSValue& thisValue, JSValue * /
else {
String *s = new String();
for (uint32 i = 0; i < arrInst->mLength; i++) {
String *id = numberToString(i);
const String *id = numberToString(i);
arrInst->getProperty(cx, *id, NULL);
JSValue result = cx->popValue();
s->append(*result.toString(cx).string);
@ -118,7 +118,7 @@ static JSValue Array_toSource(Context *cx, const JSValue& thisValue, JSValue * /
else {
String *s = new String(widenCString("["));
for (uint32 i = 0; i < arrInst->mLength; i++) {
String *id = numberToString(i);
const String *id = numberToString(i);
arrInst->getProperty(cx, *id, NULL);
JSValue result = cx->popValue();
if (!result.isUndefined())
@ -140,7 +140,7 @@ static JSValue Array_push(Context *cx, const JSValue& thisValue, JSValue *argv,
JSArrayInstance *arrInst = (JSArrayInstance *)thisObj;
for (uint32 i = 0; i < argc; i++) {
String *id = numberToString(i + arrInst->mLength);
const String *id = numberToString(i + arrInst->mLength);
arrInst->defineVariable(cx, *id, (NamespaceList *)(NULL), Object_Type, argv[i]);
delete id;
}
@ -158,7 +158,7 @@ static JSValue Array_pop(Context *cx, const JSValue& thisValue, JSValue * /*argv
ContextStackReplacement csr(cx);
if (arrInst->mLength > 0) {
String *id = numberToString(arrInst->mLength - 1);
const String *id = numberToString(arrInst->mLength - 1);
arrInst->getProperty(cx, *id, NULL);
JSValue result = cx->popValue();
arrInst->deleteProperty(*id, NULL);
@ -182,14 +182,14 @@ JSValue Array_concat(Context *cx, const JSValue& thisValue, JSValue *argv, uint3
do {
if (E.getType() != Array_Type) {
String *id = numberToString(n++);
const String *id = numberToString(n++);
A->setProperty(cx, *id, CURRENT_ATTR, E);
}
else {
ASSERT(E.isObject() && dynamic_cast<JSArrayInstance *>(E.object));
JSArrayInstance *arrInst = (JSArrayInstance *)(E.object);
for (uint32 k = 0; k < arrInst->mLength; k++) {
String *id = numberToString(k);
const String *id = numberToString(k);
arrInst->getProperty(cx, *id, NULL);
JSValue result = cx->popValue();
id = numberToString(n++);
@ -251,8 +251,8 @@ static JSValue Array_reverse(Context *cx, const JSValue& thisValue, JSValue * /*
uint32 halfway = length / 2;
for (uint32 k = 0; k < halfway; k++) {
String *id1 = numberToString(k);
String *id2 = numberToString(length - k - 1);
const String *id1 = numberToString(k);
const String *id2 = numberToString(length - k - 1);
PropertyIterator it;
if (thisObj->hasOwnProperty(*id1, CURRENT_ATTR, Read, &it)) {
@ -304,8 +304,8 @@ static JSValue Array_shift(Context *cx, const JSValue& thisValue, JSValue * /*ar
result = cx->popValue();
for (uint32 k = 1; k < length; k++) {
String *id1 = numberToString(k);
String *id2 = numberToString(k - 1);
const String *id1 = numberToString(k);
const String *id2 = numberToString(k - 1);
PropertyIterator it;
if (thisObj->hasOwnProperty(*id1, CURRENT_ATTR, Read, &it)) {
@ -376,10 +376,10 @@ static JSValue Array_slice(Context *cx, const JSValue& thisValue, JSValue *argv,
uint32 n = 0;
while (start < end) {
String *id1 = numberToString(start);
const String *id1 = numberToString(start);
PropertyIterator it;
if (thisObj->hasOwnProperty(*id1, CURRENT_ATTR, Read, &it)) {
String *id2 = numberToString(n);
const String *id2 = numberToString(n);
thisObj->getProperty(cx, *id1, CURRENT_ATTR);
A->setProperty(cx, *id2, CURRENT_ATTR, cx->popValue());
}
@ -436,10 +436,10 @@ static JSValue Array_splice(Context *cx, const JSValue& thisValue, JSValue *argv
deleteCount = toUInt32(arg1);
for (k = 0; k < deleteCount; k++) {
String *id1 = numberToString(start + k);
const String *id1 = numberToString(start + k);
PropertyIterator it;
if (thisObj->hasOwnProperty(*id1, CURRENT_ATTR, Read, &it)) {
String *id2 = numberToString(k);
const String *id2 = numberToString(k);
thisObj->getProperty(cx, *id1, CURRENT_ATTR);
A->setProperty(cx, *id2, CURRENT_ATTR, cx->popValue());
}
@ -449,8 +449,8 @@ static JSValue Array_splice(Context *cx, const JSValue& thisValue, JSValue *argv
uint32 newItemCount = argc - 2;
if (newItemCount < deleteCount) {
for (k = start; k < (length - deleteCount); k++) {
String *id1 = numberToString(k + deleteCount);
String *id2 = numberToString(k + newItemCount);
const String *id1 = numberToString(k + deleteCount);
const String *id2 = numberToString(k + newItemCount);
PropertyIterator it;
if (thisObj->hasOwnProperty(*id1, CURRENT_ATTR, Read, &it)) {
thisObj->getProperty(cx, *id1, CURRENT_ATTR);
@ -460,15 +460,15 @@ static JSValue Array_splice(Context *cx, const JSValue& thisValue, JSValue *argv
thisObj->deleteProperty(*id2, CURRENT_ATTR);
}
for (k = length; k > (length - deleteCount + newItemCount); k--) {
String *id1 = numberToString(k - 1);
const String *id1 = numberToString(k - 1);
thisObj->deleteProperty(*id1, CURRENT_ATTR);
}
}
else {
if (newItemCount > deleteCount) {
for (k = length - deleteCount; k > start; k--) {
String *id1 = numberToString(k + deleteCount - 1);
String *id2 = numberToString(k + newItemCount - 1);
const String *id1 = numberToString(k + deleteCount - 1);
const String *id2 = numberToString(k + newItemCount - 1);
PropertyIterator it;
if (thisObj->hasOwnProperty(*id1, CURRENT_ATTR, Read, &it)) {
thisObj->getProperty(cx, *id1, CURRENT_ATTR);
@ -481,7 +481,7 @@ static JSValue Array_splice(Context *cx, const JSValue& thisValue, JSValue *argv
}
k = start;
for (uint32 i = 2; i < argc; i++) {
String *id1 = numberToString(k++);
const String *id1 = numberToString(k++);
thisObj->setProperty(cx, *id1, CURRENT_ATTR, argv[i]);
}
thisObj->setProperty(cx, widenCString("length"), CURRENT_ATTR, JSValue((float64)(length - deleteCount + newItemCount)) );
@ -503,8 +503,8 @@ static JSValue Array_unshift(Context *cx, const JSValue& thisValue, JSValue *arg
uint32 k;
for (k = length; k > 0; k--) {
String *id1 = numberToString(k - 1);
String *id2 = numberToString(k + argc - 1);
const String *id1 = numberToString(k - 1);
const String *id2 = numberToString(k + argc - 1);
PropertyIterator it;
if (thisObj->hasOwnProperty(*id1, CURRENT_ATTR, Read, &it)) {
thisObj->getProperty(cx, *id1, CURRENT_ATTR);
@ -515,7 +515,7 @@ static JSValue Array_unshift(Context *cx, const JSValue& thisValue, JSValue *arg
}
for (k = 0; k < argc; k++) {
String *id1 = numberToString(k);
const String *id1 = numberToString(k);
thisObj->setProperty(cx, *id1, CURRENT_ATTR, argv[k]);
}
thisObj->setProperty(cx, widenCString("length"), CURRENT_ATTR, JSValue((float64)(length + argc)) );
@ -547,4 +547,4 @@ Context::PrototypeFunctions *getArrayProtos()
}
}
}
}

1228
js2/src/jsdate.cpp Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

48
js2/src/jsdate.h Normal file
Просмотреть файл

@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the JavaScript 2 Prototype.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
namespace JavaScript {
namespace JS2Runtime {
extern JSValue Date_Constructor(Context *cx, const JSValue& thisValue, JSValue *argv, uint32 argc);
Context::PrototypeFunctions *getDateProtos();
void initDateObject(Context *cx);
}
}

417
js2/src/jslong.h Normal file
Просмотреть файл

@ -0,0 +1,417 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
/*
** File: jslong.h
** Description: Portable access to 64 bit numerics
**
** Long-long (64-bit signed integer type) support. Some C compilers
** don't support 64 bit integers yet, so we use these macros to
** support both machines that do and don't.
**/
#ifndef jslong_h___
#define jslong_h___
#include "systemtypes.h"
/***********************************************************************
** DEFINES: JSLL_MaxInt
** JSLL_MinInt
** JSLL_Zero
** DESCRIPTION:
** Various interesting constants and static variable
** initializer
***********************************************************************/
#define JSLL_MAXINT JSLL_MaxInt()
#define JSLL_MININT JSLL_MinInt()
#define JSLL_ZERO JSLL_Zero()
#ifdef JS_HAVE_LONG_LONG
#if JS_BYTES_PER_LONG == 8
#define JSLL_INIT(hi, lo) ((hi ## L << 32) + lo ## L)
#elif defined(WIN32) || defined(WIN16)
#define JSLL_INIT(hi, lo) ((hi ## i64 << 32) + lo ## i64)
#else
#define JSLL_INIT(hi, lo) ((hi ## LL << 32) + lo ## LL)
#endif
/***********************************************************************
** MACROS: JSLL_*
** DESCRIPTION:
** The following macros define portable access to the 64 bit
** math facilities.
**
***********************************************************************/
/***********************************************************************
** MACROS: JSLL_<relational operators>
**
** JSLL_IS_ZERO Test for zero
** JSLL_EQ Test for equality
** JSLL_NE Test for inequality
** JSLL_GE_ZERO Test for zero or positive
** JSLL_CMP Compare two values
***********************************************************************/
#define JSLL_IS_ZERO(a) ((a) == 0)
#define JSLL_EQ(a, b) ((a) == (b))
#define JSLL_NE(a, b) ((a) != (b))
#define JSLL_GE_ZERO(a) ((a) >= 0)
#define JSLL_CMP(a, op, b) ((int64)(a) op (int64)(b))
#define JSLL_UCMP(a, op, b) ((uint64)(a) op (uint64)(b))
/***********************************************************************
** MACROS: JSLL_<logical operators>
**
** JSLL_AND Logical and
** JSLL_OR Logical or
** JSLL_XOR Logical exclusion
** JSLL_OR2 A disgusting deviation
** JSLL_NOT Negation (one's compliment)
***********************************************************************/
#define JSLL_AND(r, a, b) ((r) = (a) & (b))
#define JSLL_OR(r, a, b) ((r) = (a) | (b))
#define JSLL_XOR(r, a, b) ((r) = (a) ^ (b))
#define JSLL_OR2(r, a) ((r) = (r) | (a))
#define JSLL_NOT(r, a) ((r) = ~(a))
/***********************************************************************
** MACROS: JSLL_<mathematical operators>
**
** JSLL_NEG Negation (two's compliment)
** JSLL_ADD Summation (two's compliment)
** JSLL_SUB Difference (two's compliment)
***********************************************************************/
#define JSLL_NEG(r, a) ((r) = -(a))
#define JSLL_ADD(r, a, b) ((r) = (a) + (b))
#define JSLL_SUB(r, a, b) ((r) = (a) - (b))
/***********************************************************************
** MACROS: JSLL_<mathematical operators>
**
** JSLL_MUL Product (two's compliment)
** JSLL_DIV Quotient (two's compliment)
** JSLL_MOD Modulus (two's compliment)
***********************************************************************/
#define JSLL_MUL(r, a, b) ((r) = (a) * (b))
#define JSLL_DIV(r, a, b) ((r) = (a) / (b))
#define JSLL_MOD(r, a, b) ((r) = (a) % (b))
/***********************************************************************
** MACROS: JSLL_<shifting operators>
**
** JSLL_SHL Shift left [0..64] bits
** JSLL_SHR Shift right [0..64] bits with sign extension
** JSLL_USHR Unsigned shift right [0..64] bits
** JSLL_ISHL Signed shift left [0..64] bits
***********************************************************************/
#define JSLL_SHL(r, a, b) ((r) = (int64)(a) << (b))
#define JSLL_SHR(r, a, b) ((r) = (int64)(a) >> (b))
#define JSLL_USHR(r, a, b) ((r) = (uint64)(a) >> (b))
#define JSLL_ISHL(r, a, b) ((r) = (int64)(a) << (b))
/***********************************************************************
** MACROS: JSLL_<conversion operators>
**
** JSLL_L2I Convert to signed 32 bit
** JSLL_L2UI Convert to unsigned 32 bit
** JSLL_L2F Convert to floating point
** JSLL_L2D Convert to floating point
** JSLL_I2L Convert signed to 64 bit
** JSLL_UI2L Convert unsigned to 64 bit
** JSLL_F2L Convert float to 64 bit
** JSLL_D2L Convert float to 64 bit
***********************************************************************/
#define JSLL_L2I(i, l) ((i) = (int32)(l))
#define JSLL_L2UI(ui, l) ((ui) = (uint32)(l))
#define JSLL_L2F(f, l) ((f) = (float64)(l))
#define JSLL_L2D(d, l) ((d) = (float64)(l))
#define JSLL_I2L(l, i) ((l) = (int64)(i))
#define JSLL_UI2L(l, ui) ((l) = (int64)(ui))
#define JSLL_F2L(l, f) ((l) = (int64)(f))
#define JSLL_D2L(l, d) ((l) = (int64)(d))
/***********************************************************************
** MACROS: JSLL_UDIVMOD
** DESCRIPTION:
** Produce both a quotient and a remainder given an unsigned
** INPUTS: uint64 a: The dividend of the operation
** uint64 b: The quotient of the operation
** OUTPUTS: uint64 *qp: pointer to quotient
** uint64 *rp: pointer to remainder
***********************************************************************/
#define JSLL_UDIVMOD(qp, rp, a, b) \
(*(qp) = ((uint64)(a) / (b)), \
*(rp) = ((uint64)(a) % (b)))
#else /* !JS_HAVE_LONG_LONG */
#ifdef IS_LITTLE_ENDIAN
#define JSLL_INIT(hi, lo) {int32(lo), int32(hi)}
#else
#define JSLL_INIT(hi, lo) {int32(hi), int32(lo)}
#endif
#define JSLL_IS_ZERO(a) (((a).hi == 0) && ((a).lo == 0))
#define JSLL_EQ(a, b) (((a).hi == (b).hi) && ((a).lo == (b).lo))
#define JSLL_NE(a, b) (((a).hi != (b).hi) || ((a).lo != (b).lo))
#define JSLL_GE_ZERO(a) (((a).hi >> 31) == 0)
#ifdef DEBUG
#define JSLL_CMP(a, op, b) (JS_ASSERT((#op)[1] != '='), JSLL_REAL_CMP(a, op, b))
#define JSLL_CMP(a, op, b) (JS_ASSERT((#op)[1] != '='), JSLL_REAL_CMP(a, op, b))
#else
#define JSLL_CMP(a, op, b) JSLL_REAL_CMP(a, op, b)
#define JSLL_CMP(a, op, b) JSLL_REAL_CMP(a, op, b)
#endif
#define JSLL_REAL_CMP(a,op,b) (((int32)(a).hi op (int32)(b).hi) || \
(((a).hi == (b).hi) && ((a).lo op (b).lo)))
#define JSLL_REAL_UCMP(a,op,b) (((a).hi op (b).hi) || \
(((a).hi == (b).hi) && ((a).lo op (b).lo)))
#define JSLL_AND(r, a, b) ((r).lo = (a).lo & (b).lo, \
(r).hi = (a).hi & (b).hi)
#define JSLL_OR(r, a, b) ((r).lo = (a).lo | (b).lo, \
(r).hi = (a).hi | (b).hi)
#define JSLL_XOR(r, a, b) ((r).lo = (a).lo ^ (b).lo, \
(r).hi = (a).hi ^ (b).hi)
#define JSLL_OR2(r, a) ((r).lo = (r).lo | (a).lo, \
(r).hi = (r).hi | (a).hi)
#define JSLL_NOT(r, a) ((r).lo = ~(a).lo, \
(r).hi = ~(a).hi)
#define JSLL_NEG(r, a) ((r).lo = -(int32)(a).lo, \
(r).hi = -(int32)(a).hi - ((r).lo != 0))
#define JSLL_ADD(r, a, b) { \
int64 _a, _b; \
_a = a; _b = b; \
(r).lo = _a.lo + _b.lo; \
(r).hi = _a.hi + _b.hi + ((r).lo < _b.lo); \
}
#define JSLL_SUB(r, a, b) { \
int64 _a, _b; \
_a = a; _b = b; \
(r).lo = _a.lo - _b.lo; \
(r).hi = _a.hi - _b.hi - (_a.lo < _b.lo); \
}
#define JSLL_MUL(r, a, b) { \
int64 _a, _b; \
_a = a; _b = b; \
JSLL_MUL32(r, _a.lo, _b.lo); \
(r).hi += _a.hi * _b.lo + _a.lo * _b.hi; \
}
#define jslo16(a) ((a) & JS_BITMASK(16))
#define jshi16(a) ((a) >> 16)
#define JSLL_MUL32(r, a, b) { \
uint32 _a1, _a0, _b1, _b0, _y0, _y1, _y2, _y3; \
_a1 = jshi16(a), _a0 = jslo16(a); \
_b1 = jshi16(b), _b0 = jslo16(b); \
_y0 = _a0 * _b0; \
_y1 = _a0 * _b1; \
_y2 = _a1 * _b0; \
_y3 = _a1 * _b1; \
_y1 += jshi16(_y0); /* can't carry */ \
_y1 += _y2; /* might carry */ \
if (_y1 < _y2) \
_y3 += (uint32)(JS_BIT(16)); /* propagate */ \
(r).lo = (jslo16(_y1) << 16) + jslo16(_y0); \
(r).hi = _y3 + jshi16(_y1); \
}
#define JSLL_UDIVMOD(qp, rp, a, b) jsll_udivmod(qp, rp, a, b)
extern void jsll_udivmod(uint64 *qp, uint64 *rp, uint64 a, uint64 b);
#define JSLL_DIV(r, a, b) { \
int64 _a, _b; \
uint32 _negative = (int32)(a).hi < 0; \
if (_negative) { \
JSLL_NEG(_a, a); \
} else { \
_a = a; \
} \
if ((int32)(b).hi < 0) { \
_negative ^= 1; \
JSLL_NEG(_b, b); \
} else { \
_b = b; \
} \
JSLL_UDIVMOD(&(r), 0, _a, _b); \
if (_negative) \
JSLL_NEG(r, r); \
}
#define JSLL_MOD(r, a, b) { \
int64 _a, _b; \
uint32 _negative = (int32)(a).hi < 0; \
if (_negative) { \
JSLL_NEG(_a, a); \
} else { \
_a = a; \
} \
if ((int32)(b).hi < 0) { \
JSLL_NEG(_b, b); \
} else { \
_b = b; \
} \
JSLL_UDIVMOD(0, &(r), _a, _b); \
if (_negative) \
JSLL_NEG(r, r); \
}
#define JSLL_SHL(r, a, b) { \
if (b) { \
int64 _a; \
_a = a; \
if ((b) < 32) { \
(r).lo = _a.lo << ((b) & 31); \
(r).hi = (_a.hi << ((b) & 31)) | (_a.lo >> (32 - (b))); \
} else { \
(r).lo = 0; \
(r).hi = _a.lo << ((b) & 31); \
} \
} else { \
(r) = (a); \
} \
}
/* a is an int32, b is int32, r is int64 */
#define JSLL_ISHL(r, a, b) { \
if (b) { \
int64 _a; \
_a.lo = (a); \
_a.hi = 0; \
if ((b) < 32) { \
(r).lo = (a) << ((b) & 31); \
(r).hi = ((a) >> (32 - (b))); \
} else { \
(r).lo = 0; \
(r).hi = (a) << ((b) & 31); \
} \
} else { \
(r).lo = (a); \
(r).hi = 0; \
} \
}
#define JSLL_SHR(r, a, b) { \
if (b) { \
int64 _a; \
_a = a; \
if ((b) < 32) { \
(r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
(r).hi = (int32)_a.hi >> ((b) & 31); \
} else { \
(r).lo = (int32)_a.hi >> ((b) & 31); \
(r).hi = (int32)_a.hi >> 31; \
} \
} else { \
(r) = (a); \
} \
}
#define JSLL_USHR(r, a, b) { \
if (b) { \
int64 _a; \
_a = a; \
if ((b) < 32) { \
(r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
(r).hi = _a.hi >> ((b) & 31); \
} else { \
(r).lo = _a.hi >> ((b) & 31); \
(r).hi = 0; \
} \
} else { \
(r) = (a); \
} \
}
#define JSLL_L2I(i, l) ((i) = (l).lo)
#define JSLL_L2UI(ui, l) ((ui) = (l).lo)
#define JSLL_L2F(f, l) { double _d; JSLL_L2D(_d, l); (f) = (JSFloat64)_d; }
#define JSLL_L2D(d, l) { \
int _negative; \
int64 _absval; \
\
_negative = (l).hi >> 31; \
if (_negative) { \
JSLL_NEG(_absval, l); \
} else { \
_absval = l; \
} \
(d) = (double)_absval.hi * 4.294967296e9 + _absval.lo; \
if (_negative) \
(d) = -(d); \
}
#define JSLL_I2L(l, i) { int32 _i = (i) >> 31; (l).lo = (i); (l).hi = _i; }
#define JSLL_UI2L(l, ui) ((l).lo = (ui), (l).hi = 0)
#define JSLL_F2L(l, f) { double _d = (double)f; JSLL_D2L(l, _d); }
#define JSLL_D2L(l, d) { \
int _negative; \
double _absval, _d_hi; \
int64 _lo_d; \
\
_negative = ((d) < 0); \
_absval = _negative ? -(d) : (d); \
\
(l).hi = _absval / 4.294967296e9; \
(l).lo = 0; \
JSLL_L2D(_d_hi, l); \
_absval -= _d_hi; \
_lo_d.hi = 0; \
if (_absval < 0) { \
_lo_d.lo = -_absval; \
JSLL_SUB(l, l, _lo_d); \
} else { \
_lo_d.lo = _absval; \
JSLL_ADD(l, l, _lo_d); \
} \
\
if (_negative) \
JSLL_NEG(l, l); \
}
#endif /* !JS_HAVE_LONG_LONG */
#endif /* jslong_h___ */

Просмотреть файл

@ -180,13 +180,13 @@ step11:
}
static JSValue String_valueOf(Context * /*cx*/, const JSValue& thisValue, JSValue * /*argv*/, uint32 /*argc*/)
static JSValue String_valueOf(Context *cx, const JSValue& thisValue, JSValue * /*argv*/, uint32 /*argc*/)
{
ASSERT(thisValue.isObject());
if (thisValue.isString())
return thisValue;
else
throw Exception(Exception::typeError, "String.valueOf called on");
cx->reportError(Exception::typeError, "String.valueOf called on something other than a string thing");
return kUndefinedValue;
}

590
js2/src/prmjtime.cpp Normal file
Просмотреть файл

@ -0,0 +1,590 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
/*
* PR time code.
*/
#ifdef MOZILLA_CLIENT
#include "platform.h"
#endif
#ifdef SOLARIS
#define _REENTRANT 1
#endif
#include <string.h>
#include <time.h>
#include "systemtypes.h"
#include "jslong.h"
#include "prmjtime.h"
// these are all we need from jslong.c
//
static int64 ll_zero = JSLL_INIT( 0x00000000,0x00000000 );
static int64 ll_maxint = JSLL_INIT( 0x7fffffff, 0xffffffff );
static int64 ll_minint = JSLL_INIT( 0x80000000, 0x00000000 );
int64 JSLL_Zero(void) { return ll_zero; }
int64 JSLL_MaxInt(void) { return ll_maxint; }
int64 JSLL_MinInt(void) { return ll_minint; }
//
//
#define PRMJ_DO_MILLISECONDS 1
#ifdef XP_PC
#ifndef __MWERKS__
#include <sys/timeb.h>
#else
#include <WINDEF.H>
#include <WINBASE.H>
#endif
#endif
#ifdef XP_MAC
#include <OSUtils.h>
#include <TextUtils.h>
#include <Resources.h>
#include <Timer.h>
#include <UTCUtils.h>
#endif
#if defined(XP_UNIX) || defined(XP_BEOS)
#ifdef _SVID_GETTOD /* Defined only on Solaris, see Solaris <sys/types.h> */
extern int gettimeofday(struct timeval *tv);
#endif
#include <sys/time.h>
#endif /* XP_UNIX */
#ifdef XP_MAC
static uint64 dstLocalBaseMicroseconds;
static unsigned long gJanuaryFirst1970Seconds;
static void MacintoshInitializeTime(void)
{
uint64 upTime;
unsigned long currentLocalTimeSeconds,
startupTimeSeconds;
uint64 startupTimeMicroSeconds;
uint32 upTimeSeconds;
uint64 oneMillion, upTimeSecondsLong, microSecondsToSeconds;
DateTimeRec firstSecondOfUnixTime;
/*
* Figure out in local time what time the machine started up. This information can be added to
* upTime to figure out the current local time as well as GMT.
*/
Microseconds((UnsignedWide*)&upTime);
GetDateTime(&currentLocalTimeSeconds);
JSLL_I2L(microSecondsToSeconds, PRMJ_USEC_PER_SEC);
JSLL_DIV(upTimeSecondsLong, upTime, microSecondsToSeconds);
JSLL_L2I(upTimeSeconds, upTimeSecondsLong);
startupTimeSeconds = currentLocalTimeSeconds - upTimeSeconds;
/* Make sure that we normalize the macintosh base seconds to the unix base of January 1, 1970.
*/
firstSecondOfUnixTime.year = 1970;
firstSecondOfUnixTime.month = 1;
firstSecondOfUnixTime.day = 1;
firstSecondOfUnixTime.hour = 0;
firstSecondOfUnixTime.minute = 0;
firstSecondOfUnixTime.second = 0;
firstSecondOfUnixTime.dayOfWeek = 0;
DateToSeconds(&firstSecondOfUnixTime, &gJanuaryFirst1970Seconds);
startupTimeSeconds -= gJanuaryFirst1970Seconds;
/* Now convert the startup time into a wide so that we can figure out GMT and DST.
*/
JSLL_I2L(startupTimeMicroSeconds, startupTimeSeconds);
JSLL_I2L(oneMillion, PRMJ_USEC_PER_SEC);
JSLL_MUL(dstLocalBaseMicroseconds, oneMillion, startupTimeMicroSeconds);
}
/* Because serial port and SLIP conflict with ReadXPram calls,
* we cache the call here
*/
static void MyReadLocation(MachineLocation * loc)
{
static MachineLocation storedLoc; /* InsideMac, OSUtilities, page 4-20 */
static JSBool didReadLocation = JS_FALSE;
if (!didReadLocation)
{
MacintoshInitializeTime();
ReadLocation(&storedLoc);
didReadLocation = JS_TRUE;
}
*loc = storedLoc;
}
#endif /* XP_MAC */
#define IS_LEAP(year) \
(year != 0 && ((((year & 0x3) == 0) && \
((year - ((year/100) * 100)) != 0)) || \
(year - ((year/400) * 400)) == 0))
#define PRMJ_HOUR_SECONDS 3600L
#define PRMJ_DAY_SECONDS (24L * PRMJ_HOUR_SECONDS)
#define PRMJ_YEAR_SECONDS (PRMJ_DAY_SECONDS * 365L)
#define PRMJ_MAX_UNIX_TIMET 2145859200L /*time_t value equiv. to 12/31/2037 */
/* function prototypes */
static void PRMJ_basetime(int64 tsecs, PRMJTime *prtm);
/*
* get the difference in seconds between this time zone and UTC (GMT)
*/
int32
PRMJ_LocalGMTDifference()
{
#if defined(XP_UNIX) || defined(XP_PC) || defined(XP_BEOS)
struct tm ltime;
/* get the difference between this time zone and GMT */
memset((char *)&ltime,0,sizeof(ltime));
ltime.tm_mday = 2;
ltime.tm_year = 70;
#ifdef SUNOS4
ltime.tm_zone = 0;
ltime.tm_gmtoff = 0;
return timelocal(&ltime) - (24 * 3600);
#else
return mktime(&ltime) - (24L * 3600L);
#endif
#endif
#if defined(XP_MAC)
static int32 zone = -1L;
MachineLocation machineLocation;
int32 gmtOffsetSeconds;
/* difference has been set no need to recalculate */
if (zone != -1)
return zone;
/* Get the information about the local machine, including
* its GMT offset and its daylight savings time info.
* Convert each into wides that we can add to
* startupTimeMicroSeconds.
*/
MyReadLocation(&machineLocation);
/* Mask off top eight bits of gmtDelta, sign extend lower three. */
gmtOffsetSeconds = (machineLocation.u.gmtDelta << 8);
gmtOffsetSeconds >>= 8;
/* Backout OS adjustment for DST, to give consistent GMT offset. */
if (machineLocation.u.dlsDelta != 0)
gmtOffsetSeconds -= PRMJ_HOUR_SECONDS;
return (zone = -gmtOffsetSeconds);
#endif
}
/* Constants for GMT offset from 1970 */
#define G1970GMTMICROHI 0x00dcdcad /* micro secs to 1970 hi */
#define G1970GMTMICROLOW 0x8b3fa000 /* micro secs to 1970 low */
#define G2037GMTMICROHI 0x00e45fab /* micro secs to 2037 high */
#define G2037GMTMICROLOW 0x7a238000 /* micro secs to 2037 low */
/* Convert from base time to extended time */
static int64
PRMJ_ToExtendedTime(int32 base_time)
{
int64 exttime;
int64 g1970GMTMicroSeconds;
int64 low;
int32 diff;
int64 tmp;
int64 tmp1;
diff = PRMJ_LocalGMTDifference();
JSLL_UI2L(tmp, PRMJ_USEC_PER_SEC);
JSLL_I2L(tmp1,diff);
JSLL_MUL(tmp,tmp,tmp1);
JSLL_UI2L(g1970GMTMicroSeconds,G1970GMTMICROHI);
JSLL_UI2L(low,G1970GMTMICROLOW);
#ifndef JS_HAVE_LONG_LONG
JSLL_SHL(g1970GMTMicroSeconds,g1970GMTMicroSeconds,16);
JSLL_SHL(g1970GMTMicroSeconds,g1970GMTMicroSeconds,16);
#else
JSLL_SHL(g1970GMTMicroSeconds,g1970GMTMicroSeconds,32);
#endif
JSLL_ADD(g1970GMTMicroSeconds,g1970GMTMicroSeconds,low);
JSLL_I2L(exttime,base_time);
JSLL_ADD(exttime,exttime,g1970GMTMicroSeconds);
JSLL_SUB(exttime,exttime,tmp);
return exttime;
}
int64
PRMJ_Now(void)
{
#ifdef XP_PC
int64 s, us, ms2us, s2us;
#ifndef __MWERKS__
struct timeb b;
#else
SYSTEMTIME time;
#endif /* __MWERKS__ */
#endif /* XP_PC */
#if defined(XP_UNIX) || defined(XP_BEOS)
struct timeval tv;
int64 s, us, s2us;
#endif /* XP_UNIX */
#ifdef XP_MAC
uint64 upTime;
int64 localTime;
int64 gmtOffset;
int64 dstOffset;
int32 gmtDiff;
int64 s2us;
#endif /* XP_MAC */
#ifdef XP_PC
#ifndef __MWERKS__
ftime(&b);
JSLL_UI2L(ms2us, PRMJ_USEC_PER_MSEC);
JSLL_UI2L(s2us, PRMJ_USEC_PER_SEC);
JSLL_UI2L(s, b.time);
JSLL_UI2L(us, b.millitm);
JSLL_MUL(us, us, ms2us);
JSLL_MUL(s, s, s2us);
JSLL_ADD(s, s, us);
return s;
#else
GetLocalTime(&time);
JSLL_UI2L(ms2us, PRMJ_USEC_PER_MSEC);
JSLL_UI2L(s2us, PRMJ_USEC_PER_SEC);
JSLL_UI2L(s, time.wSecond);
JSLL_UI2L(us, time.wMilliseconds);
JSLL_MUL(us, us, ms2us);
JSLL_MUL(s, s, s2us);
JSLL_ADD(s, s, us);
return s;
#endif /* __MWERKS__ */
#endif
#if defined(XP_UNIX) || defined(XP_BEOS)
#ifdef _SVID_GETTOD /* Defined only on Solaris, see Solaris <sys/types.h> */
gettimeofday(&tv);
#else
gettimeofday(&tv, 0);
#endif /* _SVID_GETTOD */
JSLL_UI2L(s2us, PRMJ_USEC_PER_SEC);
JSLL_UI2L(s, tv.tv_sec);
JSLL_UI2L(us, tv.tv_usec);
JSLL_MUL(s, s, s2us);
JSLL_ADD(s, s, us);
return s;
#endif /* XP_UNIX */
#ifdef XP_MAC
JSLL_UI2L(localTime,0);
gmtDiff = PRMJ_LocalGMTDifference();
JSLL_I2L(gmtOffset,gmtDiff);
JSLL_UI2L(s2us, PRMJ_USEC_PER_SEC);
JSLL_MUL(gmtOffset,gmtOffset,s2us);
/* don't adjust for DST since it sets ctime and gmtime off on the MAC */
Microseconds((UnsignedWide*)&upTime);
JSLL_ADD(localTime,localTime,gmtOffset);
JSLL_ADD(localTime,localTime, dstLocalBaseMicroseconds);
JSLL_ADD(localTime,localTime, upTime);
dstOffset = PRMJ_DSTOffset(localTime);
JSLL_SUB(localTime,localTime,dstOffset);
return *((uint64 *)&localTime);
#endif /* XP_MAC */
}
/* Get the DST timezone offset for the time passed in */
int64
PRMJ_DSTOffset(int64 local_time)
{
int64 us2s;
#ifdef XP_MAC
/*
* Convert the local time passed in to Macintosh epoch seconds. Use UTC utilities to convert
* to UTC time, then compare difference with our GMT offset. If they are the same, then
* DST must not be in effect for the input date/time.
*/
UInt32 macLocalSeconds = (local_time / PRMJ_USEC_PER_SEC) + gJanuaryFirst1970Seconds, utcSeconds;
ConvertLocalTimeToUTC(macLocalSeconds, &utcSeconds);
if ((utcSeconds - macLocalSeconds) == PRMJ_LocalGMTDifference())
return 0;
else {
int64 dlsOffset;
JSLL_UI2L(us2s, PRMJ_USEC_PER_SEC);
JSLL_UI2L(dlsOffset, PRMJ_HOUR_SECONDS);
JSLL_MUL(dlsOffset, dlsOffset, us2s);
return dlsOffset;
}
#else
time_t local;
int32 diff;
int64 maxtimet;
struct tm tm;
PRMJTime prtm;
#if ( defined( USE_AUTOCONF ) && !defined( HAVE_LOCALTIME_R) ) || ( !defined ( USE_AUTOCONF ) && ( defined( XP_PC ) || defined( __FreeBSD__ ) || defined ( HPUX9 ) || defined ( SNI ) || defined ( NETBSD ) || defined ( OPENBSD ) || defined( RHAPSODY ) ) )
struct tm *ptm;
#endif
JSLL_UI2L(us2s, PRMJ_USEC_PER_SEC);
JSLL_DIV(local_time, local_time, us2s);
/* get the maximum of time_t value */
JSLL_UI2L(maxtimet,PRMJ_MAX_UNIX_TIMET);
if(JSLL_CMP(local_time,>,maxtimet)){
JSLL_UI2L(local_time,PRMJ_MAX_UNIX_TIMET);
} else if(!JSLL_GE_ZERO(local_time)){
/*go ahead a day to make localtime work (does not work with 0) */
JSLL_UI2L(local_time,PRMJ_DAY_SECONDS);
}
JSLL_L2UI(local,local_time);
PRMJ_basetime(local_time,&prtm);
#if ( defined( USE_AUTOCONF ) && !defined( HAVE_LOCALTIME_R) ) || ( !defined ( USE_AUTOCONF ) && ( defined( XP_PC ) || defined( __FreeBSD__ ) || defined ( HPUX9 ) || defined ( SNI ) || defined ( NETBSD ) || defined ( OPENBSD ) || defined( RHAPSODY ) ) )
ptm = localtime(&local);
if(!ptm){
return JSLL_ZERO;
}
tm = *ptm;
#else
localtime_r(&local,&tm); /* get dst information */
#endif
diff = ((tm.tm_hour - prtm.tm_hour) * PRMJ_HOUR_SECONDS) +
((tm.tm_min - prtm.tm_min) * 60);
if(diff < 0){
diff += PRMJ_DAY_SECONDS;
}
JSLL_UI2L(local_time,diff);
JSLL_MUL(local_time,local_time,us2s);
return(local_time);
#endif
}
/* Format a time value into a buffer. Same semantics as strftime() */
size_t
PRMJ_FormatTime(char *buf, int buflen, char *fmt, PRMJTime *prtm)
{
#if defined(XP_UNIX) || defined(XP_PC) || defined(XP_MAC) || defined(XP_BEOS)
struct tm a;
/* Zero out the tm struct. Linux, SunOS 4 struct tm has extra members int
* tm_gmtoff, char *tm_zone; when tm_zone is garbage, strftime gets
* confused and dumps core. NSPR20 prtime.c attempts to fill these in by
* calling mktime on the partially filled struct, but this doesn't seem to
* work as well; the result string has "can't get timezone" for ECMA-valid
* years. Might still make sense to use this, but find the range of years
* for which valid tz information exists, and map (per ECMA hint) from the
* given year into that range.
* N.B. This hasn't been tested with anything that actually _uses_
* tm_gmtoff; zero might be the wrong thing to set it to if you really need
* to format a time. This fix is for jsdate.c, which only uses
* JS_FormatTime to get a string representing the time zone. */
memset(&a, 0, sizeof(struct tm));
a.tm_sec = prtm->tm_sec;
a.tm_min = prtm->tm_min;
a.tm_hour = prtm->tm_hour;
a.tm_mday = prtm->tm_mday;
a.tm_mon = prtm->tm_mon;
a.tm_wday = prtm->tm_wday;
a.tm_year = prtm->tm_year - 1900;
a.tm_yday = prtm->tm_yday;
a.tm_isdst = prtm->tm_isdst;
/* Even with the above, SunOS 4 seems to detonate if tm_zone and tm_gmtoff
* are null. This doesn't quite work, though - the timezone is off by
* tzoff + dst. (And mktime seems to return -1 for the exact dst
* changeover time.)
*/
#if defined(SUNOS4)
if (mktime(&a) == -1) {
/* Seems to fail whenever the requested date is outside of the 32-bit
* UNIX epoch. We could proceed at this point (setting a.tm_zone to
* "") but then strftime returns a string with a 2-digit field of
* garbage for the year. So we return 0 and hope jsdate.c
* will fall back on toString.
*/
return 0;
}
#endif
return strftime(buf, buflen, fmt, &a);
#endif
}
/* table for number of days in a month */
static int mtab[] = {
/* jan, feb,mar,apr,may,jun */
31,28,31,30,31,30,
/* july,aug,sep,oct,nov,dec */
31,31,30,31,30,31
};
/*
* basic time calculation functionality for localtime and gmtime
* setups up prtm argument with correct values based upon input number
* of seconds.
*/
static void
PRMJ_basetime(int64 tsecs, PRMJTime *prtm)
{
/* convert tsecs back to year,month,day,hour,secs */
int32 year = 0;
int32 month = 0;
int32 yday = 0;
int32 mday = 0;
int32 wday = 6; /* start on a Sunday */
int32 days = 0;
int32 seconds = 0;
int32 minutes = 0;
int32 hours = 0;
int32 isleap = 0;
int64 result;
int64 result1;
int64 result2;
int64 base;
JSLL_UI2L(result,0);
JSLL_UI2L(result1,0);
JSLL_UI2L(result2,0);
/* get the base time via UTC */
base = PRMJ_ToExtendedTime(0);
JSLL_UI2L(result, PRMJ_USEC_PER_SEC);
JSLL_DIV(base,base,result);
JSLL_ADD(tsecs,tsecs,base);
JSLL_UI2L(result, PRMJ_YEAR_SECONDS);
JSLL_UI2L(result1,PRMJ_DAY_SECONDS);
JSLL_ADD(result2,result,result1);
/* get the year */
while ((isleap == 0) ? !JSLL_CMP(tsecs,<,result) : !JSLL_CMP(tsecs,<,result2)) {
/* subtract a year from tsecs */
JSLL_SUB(tsecs,tsecs,result);
days += 365;
/* is it a leap year ? */
if(IS_LEAP(year)){
JSLL_SUB(tsecs,tsecs,result1);
days++;
}
year++;
isleap = IS_LEAP(year);
}
JSLL_UI2L(result1,PRMJ_DAY_SECONDS);
JSLL_DIV(result,tsecs,result1);
JSLL_L2I(mday,result);
/* let's find the month */
while(((month == 1 && isleap) ?
(mday >= mtab[month] + 1) :
(mday >= mtab[month]))){
yday += mtab[month];
days += mtab[month];
mday -= mtab[month];
/* it's a Feb, check if this is a leap year */
if(month == 1 && isleap != 0){
yday++;
days++;
mday--;
}
month++;
}
/* now adjust tsecs */
JSLL_MUL(result,result,result1);
JSLL_SUB(tsecs,tsecs,result);
mday++; /* day of month always start with 1 */
days += mday;
wday = (days + wday) % 7;
yday += mday;
/* get the hours */
JSLL_UI2L(result1,PRMJ_HOUR_SECONDS);
JSLL_DIV(result,tsecs,result1);
JSLL_L2I(hours,result);
JSLL_MUL(result,result,result1);
JSLL_SUB(tsecs,tsecs,result);
/* get minutes */
JSLL_UI2L(result1,60);
JSLL_DIV(result,tsecs,result1);
JSLL_L2I(minutes,result);
JSLL_MUL(result,result,result1);
JSLL_SUB(tsecs,tsecs,result);
JSLL_L2I(seconds,tsecs);
prtm->tm_usec = 0L;
prtm->tm_sec = (uint8)seconds;
prtm->tm_min = (uint8)minutes;
prtm->tm_hour = (uint8)hours;
prtm->tm_mday = (uint8)mday;
prtm->tm_mon = (uint8)month;
prtm->tm_wday = (uint8)wday;
prtm->tm_year = (uint16)year;
prtm->tm_yday = (uint16)yday;
}

84
js2/src/prmjtime.h Normal file
Просмотреть файл

@ -0,0 +1,84 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
#ifndef prmjtime_h___
#define prmjtime_h___
/*
* PR date stuff for mocha and java. Placed here temporarily not to break
* Navigator and localize changes to mocha.
*/
#include <time.h>
#include "jslong.h"
#ifdef MOZILLA_CLIENT
#include "jscompat.h"
#endif
/*
* Broken down form of 64 bit time value.
*/
typedef struct PRMJTime {
uint32 tm_usec; /* microseconds of second (0-999999) */
uint8 tm_sec; /* seconds of minute (0-59) */
uint8 tm_min; /* minutes of hour (0-59) */
uint8 tm_hour; /* hour of day (0-23) */
uint8 tm_mday; /* day of month (1-31) */
uint8 tm_mon; /* month of year (0-11) */
uint8 tm_wday; /* 0=sunday, 1=monday, ... */
uint16 tm_year; /* absolute year, AD */
uint16 tm_yday; /* day of year (0 to 365) */
uint8 tm_isdst; /* non-zero if DST in effect */
} PRMJTime;
/* Some handy constants */
#define PRMJ_USEC_PER_SEC 1000000L
#define PRMJ_USEC_PER_MSEC 1000L
/* Return the current local time in micro-seconds */
extern int64
PRMJ_Now(void);
/* get the difference between this time zone and gmt timezone in seconds */
extern int32
PRMJ_LocalGMTDifference(void);
/* Format a time value into a buffer. Same semantics as strftime() */
extern size_t
PRMJ_FormatTime(char *buf, int buflen, char *fmt, PRMJTime *tm);
/* Get the DST offset for the local time passed in */
extern int64
PRMJ_DSTOffset(int64 local_time);
#endif /* prmjtime_h___ */

Просмотреть файл

@ -102,6 +102,33 @@ JS::String JS::operator+(const char *cstr, const String &str)
return s;
}
// Compare a region of string 1, starting at offset 1 with string 2, offset 2
// for a maximum of count characters and return true or false if the regions match
bool JS::regionMatches(const String &str1, uint32 offset1, const String &str2, uint32 offset2, uint32 count, bool ignoreCase)
{
if (!ignoreCase)
return (str1.compare(offset1, count, str2, offset2, count) == 0);
else {
while ((count > 0) && (offset1 < str1.size()) && (offset2 < str2.size())) {
if (toLower(str1[offset1]) != toLower(str2[offset2])) {
break;
}
offset1++;
offset2++;
count--;
}
return (count == 0);
}
}
// ditto, only string 1 is a char* and offset 1 is zero
bool JS::regionMatches(const char *str1, const String &str2, uint32 offset2, uint32 count, bool ignoreCase)
{
String s = widenCString(str1);
return regionMatches(s, 0, str2, offset2, count, ignoreCase);
}
// From java.lang.Character:
//

Просмотреть файл

@ -133,6 +133,12 @@ namespace JavaScript
void insertChars(String &str, String::size_type pos, const char *cstr);
// Compare a region of string 1, starting at offset 1 with string 2, offset 2
// for a maximum of count characters and return true or false if the regions match
bool regionMatches(const String &str1, uint32 offset1, const String &str2, uint32 offset2, uint32 count, bool ignoreCase);
// ditto, only string 1 is a char* and offset 1 is zero
bool regionMatches(const char *str1, const String &str2, uint32 offset2, uint32 count, bool ignoreCase);
String &operator+=(String &str, const char *cstr);
String operator+(const String &str, const char *cstr);

Просмотреть файл

@ -43,6 +43,7 @@
#define MAX_UINT16 (65535)
// Define int8, int16, int32, int64, uint8, uint16, uint32, uint64, and uint.
typedef unsigned int uint;
typedef unsigned char uchar;
@ -67,6 +68,7 @@ typedef unsigned short uint16;
// Define this if the machine natively supports 64-bit integers
#define NATIVE_INT64
#define JS_HAVE_LONG_LONG
// Define float32 and float64.
typedef double float64;

Просмотреть файл

@ -41,7 +41,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /GX /O2 /Ob2 /D "_LIB" /D "NDEBUG" /D "WIN32" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /GX /O2 /Ob2 /D "_LIB" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "XP_PC" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
@ -64,7 +64,7 @@ LIB32=link.exe -lib
# PROP Intermediate_Dir "DikDik___Win32_Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GR /GX /ZI /Od /I "../../../js/src/fdlibm" /D "_LIB" /D "DEBUG" /D "_DEBUG" /D "WIN32" /D "_MBCS" /FR /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GR /GX /ZI /Od /I "../../../js/src/fdlibm" /D "_LIB" /D "DEBUG" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "XP_PC" /FR /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
@ -180,6 +180,10 @@ SOURCE=..\jsarray.cpp
# End Source File
# Begin Source File
SOURCE=..\jsdate.cpp
# End Source File
# Begin Source File
SOURCE=..\jsmath.cpp
!IF "$(CFG)" == "DikDik - Win32 Release"
@ -258,6 +262,10 @@ SOURCE=..\parser.cpp
# End Source File
# Begin Source File
SOURCE=..\prmjtime.cpp
# End Source File
# Begin Source File
SOURCE=..\reader.cpp
!IF "$(CFG)" == "DikDik - Win32 Release"
@ -367,6 +375,10 @@ SOURCE=..\jsarray.h
# End Source File
# Begin Source File
SOURCE=..\jsdate.h
# End Source File
# Begin Source File
SOURCE=..\jsmath.h
# End Source File
# Begin Source File
@ -391,6 +403,10 @@ SOURCE=..\parser.h
# End Source File
# Begin Source File
SOURCE=..\prmjtime.h
# End Source File
# Begin Source File
SOURCE=..\property.h
# End Source File
# Begin Source File

Просмотреть файл

@ -41,7 +41,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "_LIB" /D "WIN32" /D "_MBCS" /D "_IEEE_LIBM" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "_LIB" /D "_IEEE_LIBM" /D "WIN32" /D "_MBCS" /D "XP_PC" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
@ -64,7 +64,7 @@ LIB32=link.exe -lib
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "_LIB" /D "WIN32" /D "_MBCS" /D "_IEEE_LIBM" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "_LIB" /D "_IEEE_LIBM" /D "WIN32" /D "_MBCS" /D "XP_PC" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe