Fixed bypasss of error checking for initialization. Added AlienInstance

methods that were MIA.
This commit is contained in:
rogerl%netscape.com 2003-01-31 17:42:49 +00:00
Родитель 050ac8d5bf
Коммит 7d1480bb0b
5 изменённых файлов: 39 добавлений и 33 удалений

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

@ -169,6 +169,7 @@ namespace MetaData {
}
sp = hndlr->mStackTop;
pc = hndlr->mPC;
meta->env->setTopFrame(hndlr->mFrame);
push(x);
}
else
@ -457,6 +458,7 @@ namespace MetaData {
{ eLexicalRead, "LexicalRead", NAME_INDEX }, // <multiname index:u16>
{ eLexicalWrite, "LexicalWrite", NAME_INDEX }, // <multiname index:u16>
{ eLexicalInit, "LexicalInit", NAME_INDEX }, // <multiname index:u16>
{ eLexicalRef, "LexicalRef", NAME_INDEX }, // <multiname index:u16>
{ eLexicalDelete, "LexicalDelete", NAME_INDEX }, // <multiname index:u16>
{ eDotRead, "DotRead", NAME_INDEX }, // <multiname index:u16>
@ -661,6 +663,8 @@ namespace MetaData {
case eSlotRead: // push the value
return 1;
case eLexicalInit:
return -1; // pop the value
case eLexicalRead:
return 1; // push the value
case eLexicalWrite:
@ -854,7 +858,7 @@ namespace MetaData {
void JS2Engine::pushHandler(uint8 *pc)
{
ActivationFrame *curAct = (activationStackEmpty()) ? NULL : (activationStackTop - 1);
mTryStack.push(new HandlerData(pc, sp, curAct));
mTryStack.push(new HandlerData(pc, sp, curAct, meta->env->getTopFrame()));
}
void JS2Engine::popHandler()

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

@ -289,12 +289,13 @@ public:
void insert(js2val x, int count);
struct HandlerData {
HandlerData(uint8 *pc, js2val *stackTop, ActivationFrame *curAct)
: mPC(pc), mStackTop(stackTop), mActivation(curAct) { }
HandlerData(uint8 *pc, js2val *stackTop, ActivationFrame *curAct, Frame *frame)
: mPC(pc), mStackTop(stackTop), mActivation(curAct), mFrame(frame) { }
uint8 *mPC;
js2val *mStackTop;
ActivationFrame *mActivation;
Frame *mFrame;
};
std::stack<HandlerData *> mTryStack;

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

@ -1149,13 +1149,11 @@ namespace MetaData {
bCon->addType(v->type);
LexicalReference *lVal = new LexicalReference(vb->mn, cxt.strict);
lVal->emitInitBytecode(bCon, p->pos);
bCon->emitOp(ePop, p->pos);
}
else {
v->type->emitDefaultValue(bCon, p->pos);
LexicalReference *lVal = new LexicalReference(vb->mn, cxt.strict);
lVal->emitInitBytecode(bCon, p->pos);
bCon->emitOp(ePop, p->pos);
}
}
}
@ -2342,39 +2340,27 @@ doUnary:
LookupKind lookup(true, findThis(false));
FrameListIterator fi = getBegin();
while (fi != getEnd()) {
if (meta->writeProperty(*fi, multiname, &lookup, false, newValue, phase))
if (meta->writeProperty(*fi, multiname, &lookup, false, newValue, phase, false))
return;
fi++;
}
if (createIfMissing) {
Frame *pf = getPackageOrGlobalFrame();
if (pf->kind == GlobalObjectKind) {
if (meta->writeProperty(pf, multiname, &lookup, true, newValue, phase))
if (meta->writeProperty(pf, multiname, &lookup, true, newValue, phase, false))
return;
}
}
meta->reportError(Exception::referenceError, "{0} is undefined", meta->engine->errorPos(), multiname->name);
}
// Attempt the write in the top frame in the current environment - if the property
// exists, then fine. Otherwise create the property there.
// Attempt the write in the top frame in the current environment, the property must exist
// as this is the initialization of a previously defined member.
void Environment::lexicalInit(JS2Metadata *meta, Multiname *multiname, js2val newValue, bool createIfMissing, Phase phase)
{
LookupKind lookup(true, findThis(false));
FrameListIterator fi = getBegin();
while (fi != getEnd()) {
if (meta->writeProperty(*fi, multiname, &lookup, false, newValue, phase))
return;
fi++;
}
if (createIfMissing) {
Frame *pf = getPackageOrGlobalFrame();
if (pf->kind == GlobalObjectKind) {
if (meta->writeProperty(pf, multiname, &lookup, true, newValue, phase))
return;
}
}
meta->reportError(Exception::referenceError, "{0} is undefined", meta->engine->errorPos(), multiname->name);
if (!meta->writeProperty(*getBegin(), multiname, &lookup, false, newValue, phase, true))
ASSERT(false);
}
// Delete the named property in the current environment, return true if the property
@ -3373,7 +3359,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, Phase /* phase */) // phase not used?
bool JS2Metadata::writeLocalMember(LocalMember *m, js2val newValue, Phase /* phase */, bool initFlag) // phase not used?
{
if (m == NULL)
return false; // 'None'
@ -3385,8 +3371,9 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now...
case LocalMember::Variable:
{
Variable *v = checked_cast<Variable *>(m);
if (JS2VAL_IS_INACCESSIBLE(v->value)
|| (v->immutable && !JS2VAL_IS_UNINITIALIZED(v->value)))
if (!initFlag
&& (JS2VAL_IS_INACCESSIBLE(v->value)
|| (v->immutable && !JS2VAL_IS_UNINITIALIZED(v->value))))
reportError(Exception::propertyAccessError, "Forbidden access", engine->errorPos());
v->value = v->type->implicitCoerce(this, newValue);
}
@ -3558,7 +3545,7 @@ readClassProperty:
case ParameterKind:
case BlockKind:
case ClassKind:
return writeProperty(checked_cast<Frame *>(container), multiname, lookupKind, createIfMissing, newValue, phase);
return writeProperty(checked_cast<Frame *>(container), multiname, lookupKind, createIfMissing, newValue, phase, false);
case PrototypeInstanceKind:
return writeDynamicProperty(container, multiname, createIfMissing, newValue, phase);
@ -3601,7 +3588,7 @@ readClassProperty:
// Write the value of a property in the frame. Return true/false if that frame has
// the property or not.
bool JS2Metadata::writeProperty(Frame *container, Multiname *multiname, LookupKind *lookupKind, bool createIfMissing, js2val newValue, Phase phase)
bool JS2Metadata::writeProperty(Frame *container, Multiname *multiname, LookupKind *lookupKind, bool createIfMissing, js2val newValue, Phase phase, bool initFlag)
{
if (container->kind != ClassKind) {
// Must be System, Global, Package, Parameter or Block
@ -3609,7 +3596,7 @@ readClassProperty:
if (!m && (container->kind == GlobalObjectKind))
return writeDynamicProperty(container, multiname, createIfMissing, newValue, phase);
else
return writeLocalMember(m, newValue, phase);
return writeLocalMember(m, newValue, phase, initFlag);
}
else {
// XXX using JS2VAL_UNINITIALIZED to signal generic 'this'
@ -3621,7 +3608,7 @@ readClassProperty:
MemberDescriptor m2;
if (!findLocalMember(checked_cast<JS2Class *>(container), multiname, WriteAccess, phase, &m2)
|| m2.localMember)
return writeLocalMember(m2.localMember, newValue, phase);
return writeLocalMember(m2.localMember, newValue, phase, initFlag);
else {
if (JS2VAL_IS_NULL(thisObject))
reportError(Exception::propertyAccessError, "Null 'this' object", engine->errorPos());
@ -4409,6 +4396,20 @@ deleteClassProperty:
}
}
/************************************************************************************
*
* AlienInstance
*
************************************************************************************/
bool AlienInstance::readProperty(Multiname *m, js2val *rval)
{
return false;
}
void AlienInstance::writeProperty(Multiname *m, js2val rval)
{
}
/************************************************************************************
*

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

@ -1079,9 +1079,9 @@ public:
bool JS2Metadata::hasOwnProperty(JS2Object *obj, const String *name);
bool writeProperty(js2val container, Multiname *multiname, LookupKind *lookupKind, bool createIfMissing, js2val newValue, Phase phase);
bool writeProperty(Frame *container, Multiname *multiname, LookupKind *lookupKind, bool createIfMissing, js2val newValue, Phase phase);
bool writeProperty(Frame *container, Multiname *multiname, LookupKind *lookupKind, bool createIfMissing, js2val newValue, Phase phase, bool initFlag);
bool writeDynamicProperty(JS2Object *container, Multiname *multiname, bool createIfMissing, js2val newValue, Phase phase);
bool writeLocalMember(LocalMember *m, js2val newValue, Phase phase);
bool writeLocalMember(LocalMember *m, js2val newValue, Phase phase, bool initFlag);
bool writeInstanceMember(js2val containerVal, JS2Class *c, QualifiedName *qname, js2val newValue, Phase phase);
bool deleteProperty(Frame *container, Multiname *multiname, LookupKind *lookupKind, Phase phase, bool *result);

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

@ -117,7 +117,7 @@
// the value on the stack top.
case eLexicalInit:
{
a = top();
a = pop();
Multiname *mn = bCon->mMultinameList[BytecodeContainer::getShort(pc)];
pc += sizeof(short);
meta->env->lexicalInit(meta, mn, a, true, phase);