This commit is contained in:
rogerl%netscape.com 2003-05-18 08:39:59 +00:00
Родитель af5d241272
Коммит 1f4195b15c
10 изменённых файлов: 112 добавлений и 60 удалений

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

@ -187,10 +187,7 @@ public:
String mSource; // for error reporting
String mSourceLocation; // for error reporting
//#ifdef DEBUG
String fName; // relevant function name for trace output
//#endif
String fName; // relevant function name
};

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

@ -223,7 +223,7 @@ js2val print(JS2Metadata * /* meta */, const js2val /* thisValue */, js2val argv
return JS2VAL_UNDEFINED;
}
//#ifdef DEBUG
#ifdef DEBUG
js2val trees(JS2Metadata *meta, const js2val /* thisValue */, js2val /* argv */ [], uint32 /* argc */)
{
meta->showTrees = !meta->showTrees;
@ -436,7 +436,7 @@ js2val forceGC(JS2Metadata *meta, const js2val /* thisValue */, js2val /* argv *
return JS2VAL_VOID;
}
//#endif
#endif
js2val load(JS2Metadata *meta, const js2val /* thisValue */, js2val argv[], uint32 argc)
{
@ -483,13 +483,13 @@ int main(int argc, char **argv)
metadata->addGlobalObjectFunction("print", print, 1);
metadata->addGlobalObjectFunction("load", load, 1);
//#ifdef DEBUG
#ifdef DEBUG
metadata->addGlobalObjectFunction("dump", dump, 1);
metadata->addGlobalObjectFunction("dumpAt", dumpAt, 1);
metadata->addGlobalObjectFunction("trees", trees, 0);
metadata->addGlobalObjectFunction("trace", trace, 0);
metadata->addGlobalObjectFunction("gc", forceGC, 0);
//#endif
#endif
try {
bool doInteractive = true;

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

@ -590,7 +590,8 @@ static js2val Array_sort(JS2Metadata *meta, const js2val thisValue, js2val *argv
meta->reportError(Exception::internalError, "out of memory", meta->engine->errorPos());
js2val *vec = new js2val[length];
DEFINE_ARRAYROOTKEEPER(rk, vec, length);
JS2Class *c = meta->objectType(thisObj);
for (i = 0; i < length; i++) {
c->ReadPublic(meta, &thatValue, meta->engine->numberToString(i), RunPhase, &vec[i]);

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

@ -107,10 +107,10 @@ namespace MetaData {
try {
a = JS2VAL_VOID;
b = JS2VAL_VOID;
//#ifdef DEBUG
#ifdef DEBUG
if (traceInstructions)
printInstruction(pc, bCon->getCodeStart(), bCon, this);
//#endif
#endif
JS2Op op = (JS2Op)*pc++;
switch (op) {
#include "js2op_arithmetic.cpp"
@ -493,7 +493,7 @@ namespace MetaData {
delete [] activationStack;
}
//#ifdef DEBUG
#ifdef DEBUG
enum { BRANCH_OFFSET = 1, STR_PTR, TYPE_PTR, NAME_INDEX, FRAME_INDEX, BRANCH_PAIR, U16, FLOAT64, S32, BREAK_OFFSET_AND_COUNT };
struct {
@ -751,7 +751,7 @@ namespace MetaData {
}
}
//#endif // DEBUG
#endif // DEBUG
// Return the effect of an opcode on the execution stack.
// Some ops (e.g. eCall) have a variable effect, those are handled separately

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

@ -372,9 +372,9 @@ public:
};
//#ifdef DEBUG
#ifdef DEBUG
uint8 *printInstruction(uint8 *pc, uint8 *start, BytecodeContainer *bCon, JS2Engine *engine);
//#endif
#endif
}
}

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

@ -100,18 +100,28 @@ namespace MetaData {
js2val JS2Metadata::readEvalFile(const String& fileName)
{
String buffer;
int ch;
js2val result = JS2VAL_VOID;
std::string str(fileName.length(), char());
std::transform(fileName.begin(), fileName.end(), str.begin(), narrow);
FILE* f = fopen(str.c_str(), "r");
FILE* f = fopen(str.c_str(), "rb");
if (f) {
while ((ch = getc(f)) != EOF)
buffer += static_cast<char>(ch);
fclose(f);
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
fseek(f, 0, SEEK_SET);
char *buf = new char[fsize];
fread(buf, fsize, 1, f);
fclose(f);
String buffer(fsize, uni::null);
for (long i = 0; i < fsize; i++) {
if (!buf[i]) {
buffer.resize(i);
break;
}
buffer[i] = widen(buf[i]);
}
delete [] buf;
result = readEvalString(buffer, fileName);
}
return result;
@ -414,6 +424,7 @@ namespace MetaData {
// if that's not available or returns a non primitive, throw a TypeError
JS2Object *obj = JS2VAL_TO_OBJECT(x);
DEFINE_ROOTKEEPER(rk1, obj);
if (obj->kind == ClassKind) // therefore, not an E3 object, so just return
return engine->allocString("Function");// engine->typeofString(x); // the 'typeof' string
@ -783,14 +794,16 @@ namespace MetaData {
return false;
}
switch (m->memberKind) {
case Member::FrameVariableMember:
ASSERT(JS2VAL_IS_OBJECT(base));
return meta->writeLocalMember(checked_cast<LocalMember *>(m), newValue, initFlag, checked_cast<Frame *>(JS2VAL_TO_OBJECT(base)));
case Member::ForbiddenMember:
case Member::DynamicVariableMember:
case Member::FrameVariableMember:
case Member::VariableMember:
case Member::ConstructorMethodMember:
case Member::SetterMember:
case Member::GetterMember:
return meta->writeLocalMember(checked_cast<LocalMember *>(m), newValue, initFlag);
return meta->writeLocalMember(checked_cast<LocalMember *>(m), newValue, initFlag, NULL);
case Member::InstanceVariableMember:
case Member::InstanceMethodMember:
case Member::InstanceGetterMember:

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

@ -1087,6 +1087,8 @@ namespace MetaData {
Reference *r = SetupExprNode(env, phase, sw->expr, &exprType);
if (r) r->emitReadBytecode(bCon, p->pos);
switchTemp->emitWriteBytecode(bCon, p->pos);
bCon->emitOp(ePopv, p->pos);
// First time through, generate the conditional waterfall
StmtNode *s = sw->statements;
@ -1313,9 +1315,7 @@ namespace MetaData {
try {
oldData = startCompilationUnit(fnInst->fWrap->bCon, bCon->mSource, bCon->mSourceLocation);
env->addFrame(fnInst->fWrap->compileFrame);
//#ifdef DEBUG
bCon->fName = *f->function.name;
//#endif
VariableBinding *pb = f->function.parameters;
while (pb) {
FrameVariable *v = checked_cast<FrameVariable *>(pb->member);
@ -1792,7 +1792,6 @@ namespace MetaData {
case ExprNode::Null:
case ExprNode::number:
case ExprNode::regExp:
case ExprNode::arrayLiteral:
case ExprNode::numUnit:
case ExprNode::string:
case ExprNode::boolean:
@ -1824,7 +1823,27 @@ namespace MetaData {
}
break;
case ExprNode::objectLiteral:
{
PairListExprNode *plen = checked_cast<PairListExprNode *>(p);
ExprPairList *e = plen->pairs;
while (e) {
ASSERT(e->field && e->value);
ValidateExpression(cxt, env, e->value);
e = e->next;
}
}
break;
case ExprNode::arrayLiteral:
{
PairListExprNode *plen = checked_cast<PairListExprNode *>(p);
ExprPairList *e = plen->pairs;
while (e) {
if (e->value)
ValidateExpression(cxt, env, e->value);
e = e->next;
}
}
break;
case ExprNode::index:
{
InvokeExprNode *i = checked_cast<InvokeExprNode *>(p);
@ -2933,7 +2952,7 @@ doUnary:
{
LocalMember *m = meta->findLocalMember(f, multiname, WriteAccess);
if (m) {
meta->writeLocalMember(m, newValue, false);
meta->writeLocalMember(m, newValue, false, f);
result = true;
}
}
@ -2985,7 +3004,7 @@ doUnary:
{
LocalMember *m = meta->findLocalMember(f, multiname, WriteAccess);
if (m) {
meta->writeLocalMember(m, newValue, true);
meta->writeLocalMember(m, newValue, true, f);
result = true;
}
}
@ -3492,7 +3511,7 @@ rescan:
reportError(Exception::definitionError, "Illegal redefinition of {0}", pos, id);
else {
result = bindingResult->content;
writeLocalMember(result, initVal, true);
writeLocalMember(result, initVal, true, regionalFrame);
}
}
// At this point a hoisted binding of the same var already exists, so there is no need to create another one
@ -4357,7 +4376,7 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now...
}
// Write a value to the local member
bool JS2Metadata::writeLocalMember(LocalMember *m, js2val newValue, bool initFlag) // phase not used?
bool JS2Metadata::writeLocalMember(LocalMember *m, js2val newValue, bool initFlag, Frame *container)
{
switch (m->memberKind) {
case LocalMember::ForbiddenMember:
@ -4379,25 +4398,25 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now...
return true;
case LocalMember::FrameVariableMember:
{
FrameVariable *f = checked_cast<FrameVariable *>(m);
switch (f->kind) {
ASSERT(container);
FrameVariable *fv = checked_cast<FrameVariable *>(m);
switch (fv->kind) {
case FrameVariable::Package:
(*env->getPackageFrame()->slots)[f->frameSlot] = newValue;
{
ASSERT(container->kind == PackageKind);
(*(checked_cast<Package *>(container))->slots)[fv->frameSlot] = newValue;
}
break;
case FrameVariable::Local:
{
FrameListIterator fi = env->getRegionalFrame();
ASSERT((fi->first)->kind == ParameterFrameKind);
NonWithFrame *nwf = checked_cast<NonWithFrame *>((fi - 1)->first);
(*nwf->slots)[f->frameSlot] = newValue;
ASSERT(container->kind == BlockFrameKind);
(*(checked_cast<NonWithFrame *>(container))->slots)[fv->frameSlot] = newValue;
}
break;
case FrameVariable::Parameter:
{
FrameListIterator fi = env->getRegionalFrame();
ASSERT((fi->first)->kind == ParameterFrameKind);
ParameterFrame *pFrame = checked_cast<ParameterFrame *>(fi->first);
(*pFrame->slots)[f->frameSlot] = newValue;
ASSERT(container->kind == ParameterFrameKind);
(*(checked_cast<ParameterFrame *>(container))->slots)[fv->frameSlot] = newValue;
}
break;
}
@ -5183,8 +5202,15 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now...
RootKeeper *r = *i;
PondScum *scum = NULL;
if (r->is_js2val) {
js2val *valp = (js2val *)(r->p);
markJS2Value(*valp);
if (r->js2val_count) {
js2val *valp = *((js2val **)(r->p));
for (uint32 c = 0; c < r->js2val_count; c++)
markJS2Value(*valp++);
}
else {
js2val *valp = (js2val *)(r->p);
markJS2Value(*valp);
}
}
else {
JS2Object **objp = (JS2Object **)(r->p);
@ -5290,9 +5316,9 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now...
p->resetMark(); // might have lingering mark from previous gc
p->clearFlags();
p->setFlag(flag);
//#ifdef DEBUG
#ifdef DEBUG
memset((p + 1), 0xB7, p->getSize() - sizeof(PondScum));
//#endif
#endif
return (p + 1);
}
pre = p;
@ -5310,9 +5336,9 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now...
}
// there was room, so acquire it
PondScum *p = (PondScum *)pondTop;
//#ifdef DEBUG
#ifdef DEBUG
memset(p, 0xB7, sz);
//#endif
#endif
p->owner = this;
p->setSize(sz);
p->setFlag(flag);
@ -5326,9 +5352,9 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now...
{
p->owner = (Pond *)freeHeader;
uint8 *t = (uint8 *)(p + 1);
//#ifdef DEBUG
#ifdef DEBUG
memset(t, 0xB3, p->getSize() - sizeof(PondScum));
//#endif
#endif
freeHeader = p;
return p->getSize() - sizeof(PondScum);
}

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

@ -258,9 +258,11 @@ public:
#ifdef DEBUG
#define ROOTKEEPER_CONSTRUCTOR(type) RootKeeper(type **p, int line, char *pfile) : is_js2val(false), p(p) { init(line, pfile); }
#define DEFINE_ROOTKEEPER(rk_var, obj) RootKeeper rk_var(&obj, __LINE__, __FILE__);
#define DEFINE_ARRAYROOTKEEPER(rk_var, obj, count) RootKeeper rk_var(&obj, count, __LINE__, __FILE__);
#else
#define ROOTKEEPER_CONSTRUCTOR(type) RootKeeper(type **p) : is_js2val(false), p(p) { ri = JS2Object::addRoot(this); }
#define DEFINE_ROOTKEEPER(rk_var, obj) RootKeeper rk_var(&obj);
#define DEFINE_ARRAYROOTKEEPER(rk_var, obj, count) RootKeeper rk_var(&obj, count);
#endif
class RootKeeper {
@ -283,7 +285,8 @@ public:
ROOTKEEPER_CONSTRUCTOR(DateInstance)
#ifdef DEBUG
RootKeeper(js2val *p, int line, char *pfile) : is_js2val(true), p(p) { init(line, pfile); }
RootKeeper(js2val *p, int line, char *pfile) : is_js2val(true), js2val_count(0), p(p) { init(line, pfile); }
RootKeeper(js2val **p, uint32 count, int line, char *pfile) : is_js2val(true), js2val_count(count), p(p) { init(line, pfile); }
~RootKeeper() { JS2Object::removeRoot(ri); delete file; }
void RootKeeper::init(int ln, char *pfile)
{
@ -293,12 +296,14 @@ public:
ri = JS2Object::addRoot(this);
}
#else
RootKeeper(js2val *p) : is_js2val(true), p(p) { ri = JS2Object::addRoot(this); }
RootKeeper(js2val *p) : is_js2val(true), js2val_count(0), p(p) { ri = JS2Object::addRoot(this); }
RootKeeper(js2val **p, uint32 count) : is_js2val(true), js2val_count(count), p(p) { ri = JS2Object::addRoot(this); }
~RootKeeper() { JS2Object::removeRoot(ri); }
#endif
JS2Object::RootIterator ri;
bool is_js2val;
uint32 js2val_count;
void *p;
#ifdef DEBUG
@ -1496,7 +1501,7 @@ public:
bool readInstanceMember(js2val containerVal, JS2Class *c, InstanceMember *mBase, Phase phase, js2val *rval);
bool JS2Metadata::hasOwnProperty(JS2Object *obj, const String *name);
bool writeLocalMember(LocalMember *m, js2val newValue, bool initFlag);
bool writeLocalMember(LocalMember *m, js2val newValue, bool initFlag, Frame *container);
bool writeInstanceMember(js2val containerVal, JS2Class *c, InstanceMember *mBase, js2val newValue);
bool deleteLocalMember(LocalMember *m, bool *result);

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

@ -102,11 +102,9 @@
FunctionInstance *x = checked_cast<FunctionInstance *>(bCon->mObjectList[BytecodeContainer::getShort(pc)]);
pc += sizeof(short);
// x->fWrap->env = new Environment(meta->env);
/*
// For each active plural frame in the function definition environment, we need
// to find it's current singular counterpart and use that as the dohickey
FrameListIterator closure_fi = x->fWrap.env->getBegin();
FrameListIterator closure_fi = x->fWrap->env->getBegin();
FrameListIterator current_fi = meta->env->getBegin();
while (true) {
Frame *closure_fr = closure_fi->first;
@ -114,11 +112,10 @@
ASSERT(closure_fr->kind == current_fr->kind);
if ((closure_fr->kind == ClassKind) || (closure_fr->kind == PackageKind) || (closure_fr->kind == SystemKind))
break;
closure_fi++;
current_fi++;
}
*/
x->fWrap->env = new Environment(meta->env);
}
break;

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

@ -249,9 +249,22 @@ char16 JS::Lexer::lexEscape(bool unicodeOnly)
ch = peekChar();
if (!isASCIIDecimalDigit(ch))
return 0x00;
/*
// Point to the next character in the error message
getChar();
break;
*/
/* E3 compatibility, parse the sequence as octal */
{
uint32 n = 0;
while (isASCIIDecimalDigit(ch)) {
ch = getChar();
n = (n << 3) | (ch - '0');
ch = peekChar();
}
return static_cast<char16>(n);
}
case 'b':
return 0x08;