Moved strings to bytecodecontainer instead of pointers. Fixed construction

of non-functions.


git-svn-id: svn://10.0.0.236/trunk@132924 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rogerl%netscape.com 2002-11-04 04:53:17 +00:00
parent 615c041c85
commit 55e47e37a1
5 changed files with 63 additions and 48 deletions

View File

@ -141,10 +141,9 @@ public:
void setOffset(uint32 index, int32 v) { *((int32 *)(mBuffer.begin() + index)) = v; }
static int32 getOffset(void *pc) { return *((int32 *)pc); }
void addString(const StringAtom *x, size_t pos) { emitOp(eString, pos); addPointer(x); }
void addString(String &x, size_t pos) { emitOp(eString, pos); addPointer(&x); }
void addString(String *x, size_t pos) { emitOp(eString, pos); addPointer(x); }
static String *getString(void *pc) { return (String *)getPointer(pc); }
void addString(const StringAtom *x, size_t pos) { emitOp(eString, pos); mStringList.push_back(String(*x)); addShort((uint16)(mStringList.size() - 1)); }
void addString(String &x, size_t pos) { emitOp(eString, pos); mStringList.push_back(String(x)); addShort((uint16)(mStringList.size() - 1)); }
void addString(String *x, size_t pos) { emitOp(eString, pos); mStringList.push_back(String(*x)); addShort((uint16)(mStringList.size() - 1)); }
// XXX We lose StringAtom here (and is it safe to stash the address of a StringAtom?)
// - is there any way of keeping StringAtoms themselves in a bytecodeContainer?
@ -157,6 +156,8 @@ public:
std::vector<Multiname *> mMultinameList; // gc tracking
std::vector<Frame *> mFrameList; // gc tracking
std::vector<String> mStringList;
int32 mStackTop; // keep these as signed so as to...
int32 mStackMax; // ...track if they go negative.

View File

@ -619,6 +619,7 @@ namespace MetaData {
JS2Object::mark(object_StringAtom);
JS2Object::mark(Empty_StringAtom);
JS2Object::mark(Dollar_StringAtom);
JS2Object::mark(prototype_StringAtom);
JS2Object::mark(length_StringAtom);
JS2Object::mark(toString_StringAtom);
}
@ -691,10 +692,10 @@ namespace MetaData {
if (it == length) {
if (obj->kind == PrototypeInstanceKind) {
obj = (checked_cast<PrototypeInstance *>(obj))->parent;
return buildNameList();
if (obj)
return buildNameList();
}
else
return false;
return false;
}
else
return true;

View File

@ -3528,6 +3528,8 @@ deleteClassProperty:
// in the instance bindings. If not there, look in the super class.
bool JS2Metadata::findStaticMember(JS2Class *c, Multiname *multiname, Access access, Phase /* phase */, MemberDescriptor *result)
{
result->staticMember = NULL;
result->qname = NULL;
JS2Class *s = c;
while (s) {
StaticBindingIterator b, end;

View File

@ -48,50 +48,60 @@
}
else {
if ((obj->kind == FixedInstanceKind) || (obj->kind == DynamicInstanceKind)) {
FunctionWrapper *fWrap;
if (obj->kind == FixedInstanceKind)
fWrap = (checked_cast<FixedInstance *>(obj))->fWrap;
else
fWrap = (checked_cast<DynamicInstance *>(obj))->fWrap;
// XXX - I made this stuff up - extract the 'prototype' property from
// the function being invoked (defaulting to Object.prototype). Then
// contruct a new prototypeInstance, setting the acquired prototype
// parent. Finally invoke the function, but insert the constructed
// object at the bottom of the stack to be the 'return' value.
// XXX this won't last - if a non-primitive is returned from the function,
// it's supposed to supplant the constructed object. XXX and I think the
// stack is out of balance anyway...
js2val protoVal;
JS2Object *protoObj = meta->objectClass->prototype;
Multiname mn(prototype_StringAtom);
LookupKind lookup(false, JS2VAL_NULL);
if (meta->readProperty(a, &mn, &lookup, RunPhase, &protoVal)) {
if (!JS2VAL_IS_OBJECT(protoVal))
meta->reportError(Exception::badValueError, "Non-object prototype value", errorPos());
protoObj = JS2VAL_TO_OBJECT(protoVal);
}
ParameterFrame *runtimeFrame = new ParameterFrame(fWrap->compileFrame);
runtimeFrame->instantiate(&meta->env);
PrototypeInstance *pInst = new PrototypeInstance(protoObj, meta->objectClass);
baseVal = OBJECT_TO_JS2VAL(pInst);
runtimeFrame->thisObject = baseVal;
// assignArguments(runtimeFrame, fWrap->compileFrame->signature);
if (!fWrap->code)
jsr(phase, fWrap->bCon); // seems out of order, but we need to catch the current top frame
meta->env.addFrame(runtimeFrame);
if (fWrap->code) { // native code, pass pointer to argument base
a = fWrap->code(meta, a, base(argCount), argCount);
meta->env.removeTopFrame();
pop(argCount + 1);
push(a);
FunctionWrapper *fWrap = NULL;
if (obj->kind == FixedInstanceKind) {
FixedInstance *fInst = (checked_cast<FixedInstance *>(obj));
if (fInst->type == meta->functionClass)
fWrap = fInst->fWrap;
}
else {
insert(baseVal, argCount + 1);
DynamicInstance *dInst = (checked_cast<DynamicInstance *>(obj));
if (dInst->type == meta->functionClass)
fWrap = dInst->fWrap;
}
if (fWrap) {
// XXX - I made this stuff up - extract the 'prototype' property from
// the function being invoked (defaulting to Object.prototype). Then
// contruct a new prototypeInstance, setting the acquired prototype
// parent. Finally invoke the function, but insert the constructed
// object at the bottom of the stack to be the 'return' value.
// XXX this won't last - if a non-primitive is returned from the function,
// it's supposed to supplant the constructed object. XXX and I think the
// stack is out of balance anyway...
js2val protoVal;
JS2Object *protoObj = meta->objectClass->prototype;
Multiname mn(prototype_StringAtom); // gc safe because the content is rooted elsewhere
LookupKind lookup(false, JS2VAL_NULL);
if (meta->readProperty(a, &mn, &lookup, RunPhase, &protoVal)) {
if (!JS2VAL_IS_OBJECT(protoVal))
meta->reportError(Exception::badValueError, "Non-object prototype value", errorPos());
protoObj = JS2VAL_TO_OBJECT(protoVal);
}
ParameterFrame *runtimeFrame = new ParameterFrame(fWrap->compileFrame);
runtimeFrame->instantiate(&meta->env);
PrototypeInstance *pInst = new PrototypeInstance(protoObj, meta->objectClass);
baseVal = OBJECT_TO_JS2VAL(pInst);
runtimeFrame->thisObject = baseVal;
// assignArguments(runtimeFrame, fWrap->compileFrame->signature);
if (!fWrap->code)
jsr(phase, fWrap->bCon); // seems out of order, but we need to catch the current top frame
meta->env.addFrame(runtimeFrame);
if (fWrap->code) { // native code, pass pointer to argument base
a = fWrap->code(meta, a, base(argCount), argCount);
meta->env.removeTopFrame();
pop(argCount + 1);
push(a);
}
else {
insert(baseVal, argCount + 1);
}
}
else
meta->reportError(Exception::typeError, "object is not a constructor", errorPos());
}
else
ASSERT(false);
meta->reportError(Exception::typeError, "object is not a constructor", errorPos());
}
}
break;

View File

@ -68,8 +68,9 @@
case eString:
{
push(STRING_TO_JS2VAL(allocString(BytecodeContainer::getString(pc))));
pc += sizeof(String *);
uint16 index = BytecodeContainer::getShort(pc);
push(STRING_TO_JS2VAL(allocString(&bCon->mStringList[index])));
pc += sizeof(short);
}
break;