mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
General GC-related fixes.
This commit is contained in:
parent
1bf6cb18fb
commit
ac2a48efe5
@ -340,7 +340,7 @@ js2val load(JS2Metadata *meta, const js2val /* thisValue */, js2val argv[], uint
|
||||
if (argc) {
|
||||
// Save off the current top frame and root it.
|
||||
Environment *curEnv = meta->env;
|
||||
JS2Object::RootIterator ri = JS2Object::addRoot(&curEnv);
|
||||
RootKeeper rk(&curEnv);
|
||||
// Set the environment to global object and system frame so that the
|
||||
// load happens into the top frame.
|
||||
meta->env = new Environment(curEnv->getSystemFrame(), curEnv->getPackageOrGlobalFrame());
|
||||
@ -351,11 +351,9 @@ js2val load(JS2Metadata *meta, const js2val /* thisValue */, js2val argv[], uint
|
||||
}
|
||||
catch (Exception x) {
|
||||
meta->env = curEnv;
|
||||
JS2Object::removeRoot(ri);
|
||||
throw x;
|
||||
}
|
||||
meta->env = curEnv;
|
||||
JS2Object::removeRoot(ri);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
@ -376,7 +374,7 @@ int main(int argc, char **argv)
|
||||
stdOut << "Welcome to Epimetheus.\n";
|
||||
#endif
|
||||
|
||||
JS2Object::addRoot(&metadata);
|
||||
RootKeeper rk(&metadata);
|
||||
|
||||
metadata = new MetaData::JS2Metadata(world);
|
||||
|
||||
|
@ -110,7 +110,7 @@ js2val Array_Constructor(JS2Metadata *meta, const js2val /*thisValue*/, js2val *
|
||||
{
|
||||
js2val thatValue = OBJECT_TO_JS2VAL(new ArrayInstance(meta, meta->arrayClass->prototype, meta->arrayClass));
|
||||
ArrayInstance *arrInst = checked_cast<ArrayInstance *>(JS2VAL_TO_OBJECT(thatValue));
|
||||
JS2Object::RootIterator ri = JS2Object::addRoot(&arrInst);
|
||||
RootKeeper rk(&arrInst);
|
||||
if (argc > 0) {
|
||||
if (argc == 1) {
|
||||
if (JS2VAL_IS_NUMBER(argv[0])) {
|
||||
@ -134,7 +134,6 @@ js2val Array_Constructor(JS2Metadata *meta, const js2val /*thisValue*/, js2val *
|
||||
setLength(meta, arrInst, i);
|
||||
}
|
||||
}
|
||||
JS2Object::removeRoot(ri);
|
||||
return thatValue;
|
||||
}
|
||||
|
||||
|
@ -59,13 +59,12 @@ namespace MetaData {
|
||||
{
|
||||
js2val thatValue = OBJECT_TO_JS2VAL(new BooleanInstance(meta, meta->booleanClass->prototype, meta->booleanClass));
|
||||
BooleanInstance *boolInst = checked_cast<BooleanInstance *>(JS2VAL_TO_OBJECT(thatValue));
|
||||
JS2Object::RootIterator ri = JS2Object::addRoot(&boolInst);
|
||||
RootKeeper rk(&boolInst);
|
||||
|
||||
if (argc > 0)
|
||||
boolInst->mValue = meta->toBoolean(argv[0]);
|
||||
else
|
||||
boolInst->mValue = false;
|
||||
JS2Object::removeRoot(ri);
|
||||
return thatValue;
|
||||
}
|
||||
|
||||
|
@ -871,7 +871,7 @@ js2val Date_Constructor(JS2Metadata *meta, const js2val /* thisValue */, js2val
|
||||
{
|
||||
js2val thatValue = OBJECT_TO_JS2VAL(new DateInstance(meta, meta->dateClass->prototype, meta->dateClass));
|
||||
DateInstance *thisInst = checked_cast<DateInstance *>(JS2VAL_TO_OBJECT(thatValue));
|
||||
JS2Object::RootIterator ri = JS2Object::addRoot(&thisInst);
|
||||
RootKeeper rk(&thisInst);
|
||||
|
||||
/* Date called as constructor */
|
||||
if (argc == 0) {
|
||||
@ -911,7 +911,6 @@ js2val Date_Constructor(JS2Metadata *meta, const js2val /* thisValue */, js2val
|
||||
and return */
|
||||
if (!JSDOUBLE_IS_FINITE(double_arg)) {
|
||||
thisInst->ms = nan;
|
||||
JS2Object::removeRoot(ri);
|
||||
return thatValue;
|
||||
}
|
||||
array[loop] = JS2Engine::float64toInt32(double_arg);
|
||||
@ -934,7 +933,6 @@ js2val Date_Constructor(JS2Metadata *meta, const js2val /* thisValue */, js2val
|
||||
thisInst->ms = TIMECLIP(msec_time);
|
||||
}
|
||||
}
|
||||
JS2Object::removeRoot(ri);
|
||||
return thatValue;
|
||||
}
|
||||
|
||||
|
@ -88,6 +88,8 @@ namespace MetaData {
|
||||
retval = JS2VAL_VOID;
|
||||
baseVal = JS2VAL_VOID;
|
||||
indexVal = JS2VAL_VOID;
|
||||
astr = NULL;
|
||||
bstr = NULL;
|
||||
pFrame = NULL;
|
||||
while (true) {
|
||||
try {
|
||||
@ -393,6 +395,8 @@ namespace MetaData {
|
||||
baseVal(JS2VAL_VOID),
|
||||
indexVal(JS2VAL_VOID),
|
||||
pFrame(NULL),
|
||||
astr(NULL),
|
||||
bstr(NULL),
|
||||
INIT_STRINGATOM(true),
|
||||
INIT_STRINGATOM(false),
|
||||
INIT_STRINGATOM(null),
|
||||
@ -909,6 +913,9 @@ namespace MetaData {
|
||||
GCMARKVALUE(indexVal);
|
||||
GCMARKOBJECT(pFrame);
|
||||
|
||||
if (astr) JS2Object::mark(astr);
|
||||
if (bstr) JS2Object::mark(bstr);
|
||||
|
||||
JS2Object::mark(true_StringAtom);
|
||||
JS2Object::mark(false_StringAtom);
|
||||
JS2Object::mark(null_StringAtom);
|
||||
|
@ -239,7 +239,8 @@ private:
|
||||
|
||||
ParameterFrame *pFrame;
|
||||
|
||||
|
||||
const String *astr;
|
||||
const String *bstr;
|
||||
public:
|
||||
|
||||
|
||||
|
@ -324,7 +324,7 @@ namespace MetaData {
|
||||
|
||||
CompilationData *oldData = startCompilationUnit(bCon, bCon->mSource, bCon->mSourceLocation);
|
||||
ParameterFrame *runtimeFrame = new ParameterFrame(fWrap->compileFrame);
|
||||
JS2Object::RootIterator ri = JS2Object::addRoot(&runtimeFrame);
|
||||
RootKeeper rk(&runtimeFrame);
|
||||
runtimeFrame->instantiate(env);
|
||||
runtimeFrame->thisObject = thisValue;
|
||||
runtimeFrame->assignArguments(this, fnObj, argv, argc);
|
||||
@ -339,13 +339,11 @@ namespace MetaData {
|
||||
engine->pc = savePC;
|
||||
restoreCompilationUnit(oldData);
|
||||
env->setTopFrame(oldTopFrame);
|
||||
JS2Object::removeRoot(ri);
|
||||
throw x;
|
||||
}
|
||||
engine->pc = savePC;
|
||||
restoreCompilationUnit(oldData);
|
||||
env->setTopFrame(oldTopFrame);
|
||||
JS2Object::removeRoot(ri);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -103,7 +103,7 @@ namespace MetaData {
|
||||
result = sInst;
|
||||
}
|
||||
|
||||
JS2Object::RootIterator ri = JS2Object::addRoot(&result);
|
||||
RootKeeper rk(&result);
|
||||
Frame *curTopFrame = env->getTopFrame();
|
||||
CompilationData *oldData = startCompilationUnit(fnDef->fWrap->bCon, bCon->mSource, bCon->mSourceLocation);
|
||||
try {
|
||||
@ -137,11 +137,9 @@ namespace MetaData {
|
||||
catch (Exception x) {
|
||||
restoreCompilationUnit(oldData);
|
||||
env->setTopFrame(curTopFrame);
|
||||
JS2Object::removeRoot(ri);
|
||||
throw x;
|
||||
}
|
||||
restoreCompilationUnit(oldData);
|
||||
JS2Object::removeRoot(ri);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -151,7 +149,7 @@ namespace MetaData {
|
||||
void JS2Metadata::ValidateStmt(Context *cxt, Environment *env, Plurality pl, StmtNode *p)
|
||||
{
|
||||
CompoundAttribute *a = NULL;
|
||||
JS2Object::RootIterator ri = JS2Object::addRoot(&a);
|
||||
RootKeeper rk(&a);
|
||||
Frame *curTopFrame = env->getTopFrame();
|
||||
|
||||
try {
|
||||
@ -650,10 +648,8 @@ namespace MetaData {
|
||||
}
|
||||
catch (Exception x) {
|
||||
env->setTopFrame(curTopFrame);
|
||||
JS2Object::removeRoot(ri);
|
||||
throw x;
|
||||
}
|
||||
JS2Object::removeRoot(ri);
|
||||
}
|
||||
|
||||
|
||||
@ -4609,13 +4605,15 @@ deleteClassProperty:
|
||||
ParameterFrame *plural = checked_cast<ParameterFrame *>(pluralFrame);
|
||||
ASSERT((plural->positionalCount == 0) || (plural->positional != NULL));
|
||||
|
||||
PrototypeInstance *argsObj = new PrototypeInstance(meta, meta->objectClass->prototype, meta->objectClass);
|
||||
PrototypeInstance *argsObj = NULL;
|
||||
RootKeeper rk(&argsObj);
|
||||
argsObj = new PrototypeInstance(meta, meta->objectClass->prototype, meta->objectClass);
|
||||
|
||||
// Add the 'arguments' property
|
||||
LocalBinding *sb = new LocalBinding(ReadAccess, new Variable(meta->arrayClass, OBJECT_TO_JS2VAL(argsObj), true));
|
||||
String *name = &meta->world.identifiers["arguments"];
|
||||
ASSERT(localBindings[*name] == NULL);
|
||||
LocalBindingEntry *lbe = new LocalBindingEntry(*name);
|
||||
LocalBinding *sb = new LocalBinding(ReadAccess, new Variable(meta->arrayClass, OBJECT_TO_JS2VAL(argsObj), true));
|
||||
lbe->bindingList.push_back(LocalBindingEntry::NamespaceBinding(meta->publicNamespace, sb));
|
||||
|
||||
uint32 i;
|
||||
|
@ -142,12 +142,13 @@
|
||||
LookupKind lookup(false, JS2VAL_NULL);
|
||||
indexVal = pop();
|
||||
b = pop();
|
||||
const String *indexStr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*indexStr], meta->publicNamespace);
|
||||
astr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*astr], meta->publicNamespace);
|
||||
if (!meta->readProperty(&b, &mn, &lookup, RunPhase, &a))
|
||||
meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn.name);
|
||||
push(a);
|
||||
indexVal = JS2VAL_VOID;
|
||||
astr = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -156,14 +157,15 @@
|
||||
LookupKind lookup(false, JS2VAL_NULL);
|
||||
indexVal = pop();
|
||||
b = pop();
|
||||
const String *indexStr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*indexStr], meta->publicNamespace);
|
||||
astr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*astr], meta->publicNamespace);
|
||||
bool result;
|
||||
if (!meta->deleteProperty(b, &mn, &lookup, RunPhase, &result))
|
||||
push(JS2VAL_FALSE);
|
||||
else
|
||||
push(BOOLEAN_TO_JS2VAL(result));
|
||||
indexVal = JS2VAL_VOID;
|
||||
astr = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -175,11 +177,12 @@
|
||||
a = pop();
|
||||
indexVal = pop();
|
||||
b = pop();
|
||||
const String *indexStr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*indexStr], meta->publicNamespace);
|
||||
astr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*astr], meta->publicNamespace);
|
||||
meta->writeProperty(b, &mn, &lookup, true, a, RunPhase);
|
||||
push(a);
|
||||
indexVal = JS2VAL_VOID;
|
||||
astr = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -189,12 +192,13 @@
|
||||
LookupKind lookup(false, JS2VAL_NULL);
|
||||
indexVal = pop();
|
||||
b = top();
|
||||
const String *indexStr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*indexStr], meta->publicNamespace);
|
||||
astr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*astr], meta->publicNamespace);
|
||||
if (!meta->readProperty(&b, &mn, &lookup, RunPhase, &a))
|
||||
meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn.name);
|
||||
push(a);
|
||||
indexVal = JS2VAL_VOID;
|
||||
astr = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -204,13 +208,14 @@
|
||||
LookupKind lookup(false, JS2VAL_NULL);
|
||||
indexVal = pop();
|
||||
b = top();
|
||||
const String *indexStr = meta->toString(indexVal);
|
||||
push(STRING_TO_JS2VAL(indexStr));
|
||||
Multiname mn(&meta->world.identifiers[*indexStr], meta->publicNamespace);
|
||||
astr = meta->toString(indexVal);
|
||||
push(STRING_TO_JS2VAL(astr));
|
||||
Multiname mn(&meta->world.identifiers[*astr], meta->publicNamespace);
|
||||
if (!meta->readProperty(&b, &mn, &lookup, RunPhase, &a))
|
||||
meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn.name);
|
||||
push(a);
|
||||
indexVal = JS2VAL_VOID;
|
||||
astr = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -332,8 +332,8 @@
|
||||
a = meta->toPrimitive(a, NumberHint);
|
||||
b = meta->toPrimitive(b, NumberHint);
|
||||
if (JS2VAL_IS_STRING(a) || JS2VAL_IS_STRING(b)) {
|
||||
const String *astr = meta->toString(a);
|
||||
const String *bstr = meta->toString(b);
|
||||
astr = meta->toString(a);
|
||||
bstr = meta->toString(b);
|
||||
push(STRING_TO_JS2VAL(concatStrings(astr, bstr)));
|
||||
}
|
||||
else {
|
||||
@ -1007,8 +1007,8 @@
|
||||
LookupKind lookup(false, JS2VAL_NULL);
|
||||
indexVal = pop();
|
||||
baseVal = pop();
|
||||
const String *indexStr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*indexStr], meta->publicNamespace);
|
||||
astr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*astr], meta->publicNamespace);
|
||||
if (!meta->readProperty(&baseVal, &mn, &lookup, RunPhase, &a))
|
||||
meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn.name);
|
||||
float64 num = meta->toFloat64(a);
|
||||
@ -1016,6 +1016,7 @@
|
||||
pushNumber(num);
|
||||
baseVal = JS2VAL_VOID;
|
||||
indexVal = JS2VAL_VOID;
|
||||
astr = NULL;
|
||||
}
|
||||
break;
|
||||
case eBracketPostDec:
|
||||
@ -1023,8 +1024,8 @@
|
||||
LookupKind lookup(false, JS2VAL_NULL);
|
||||
indexVal = pop();
|
||||
baseVal = pop();
|
||||
const String *indexStr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*indexStr], meta->publicNamespace);
|
||||
astr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*astr], meta->publicNamespace);
|
||||
if (!meta->readProperty(&baseVal, &mn, &lookup, RunPhase, &a))
|
||||
meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn.name);
|
||||
float64 num = meta->toFloat64(a);
|
||||
@ -1032,6 +1033,7 @@
|
||||
pushNumber(num);
|
||||
baseVal = JS2VAL_VOID;
|
||||
indexVal = JS2VAL_VOID;
|
||||
astr = NULL;
|
||||
}
|
||||
break;
|
||||
case eBracketPreInc:
|
||||
@ -1039,8 +1041,8 @@
|
||||
LookupKind lookup(false, JS2VAL_NULL);
|
||||
indexVal = pop();
|
||||
baseVal = pop();
|
||||
const String *indexStr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*indexStr], meta->publicNamespace);
|
||||
astr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*astr], meta->publicNamespace);
|
||||
if (!meta->readProperty(&baseVal, &mn, &lookup, RunPhase, &a))
|
||||
meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn.name);
|
||||
float64 num = meta->toFloat64(a);
|
||||
@ -1048,6 +1050,7 @@
|
||||
meta->writeProperty(baseVal, &mn, &lookup, true, a, RunPhase);
|
||||
baseVal = JS2VAL_VOID;
|
||||
indexVal = JS2VAL_VOID;
|
||||
astr = NULL;
|
||||
}
|
||||
break;
|
||||
case eBracketPreDec:
|
||||
@ -1055,8 +1058,8 @@
|
||||
LookupKind lookup(false, JS2VAL_NULL);
|
||||
indexVal = pop();
|
||||
baseVal = pop();
|
||||
const String *indexStr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*indexStr], meta->publicNamespace);
|
||||
astr = meta->toString(indexVal);
|
||||
Multiname mn(&meta->world.identifiers[*astr], meta->publicNamespace);
|
||||
if (!meta->readProperty(&baseVal, &mn, &lookup, RunPhase, &a))
|
||||
meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn.name);
|
||||
float64 num = meta->toFloat64(a);
|
||||
@ -1064,6 +1067,7 @@
|
||||
meta->writeProperty(baseVal, &mn, &lookup, true, a, RunPhase);
|
||||
baseVal = JS2VAL_VOID;
|
||||
indexVal = JS2VAL_VOID;
|
||||
astr = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -120,14 +120,15 @@
|
||||
for (uint16 i = 0; i < argCount; i++) {
|
||||
a = pop();
|
||||
ASSERT(JS2VAL_IS_STRING(a));
|
||||
String *name = JS2VAL_TO_STRING(a);
|
||||
const StringAtom &nameAtom = meta->world.identifiers[*name];
|
||||
astr = JS2VAL_TO_STRING(a);
|
||||
const StringAtom &nameAtom = meta->world.identifiers[*astr];
|
||||
b = pop();
|
||||
DynamicPropertyBinding *dpb = new DynamicPropertyBinding(nameAtom, DynamicPropertyValue(b, DynamicPropertyValue::ENUMERATE));
|
||||
pInst->dynamicProperties.insert(dpb->name, dpb);
|
||||
}
|
||||
push(baseVal);
|
||||
baseVal = JS2VAL_VOID;
|
||||
astr = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -185,7 +185,7 @@ namespace MetaData {
|
||||
// XXX Change constructors to take js2val pointer for the result (which would be an already
|
||||
// rooted pointer).
|
||||
RegExpInstance *thisInst = new RegExpInstance(meta->regexpClass);
|
||||
JS2Object::RootIterator ri = JS2Object::addRoot(&thisInst);
|
||||
RootKeeper rk(&thisInst);
|
||||
js2val thatValue = OBJECT_TO_JS2VAL(thisInst);
|
||||
REuint32 flags = 0;
|
||||
|
||||
@ -223,7 +223,6 @@ namespace MetaData {
|
||||
}
|
||||
else
|
||||
meta->reportError(Exception::syntaxError, "Failed to parse RegExp : '{0}'", meta->engine->errorPos(), "/" + *regexpStr + "/" + *flagStr); // XXX what about the RE parser error message?
|
||||
JS2Object::removeRoot(ri);
|
||||
return thatValue;
|
||||
}
|
||||
|
||||
|
@ -57,11 +57,9 @@ namespace MetaData {
|
||||
|
||||
js2val String_Constructor(JS2Metadata *meta, const js2val /*thisValue*/, js2val *argv, uint32 argc)
|
||||
{
|
||||
// XXX GC might happen after the new StringInstance, but before the
|
||||
// object gets rooted somewhere - this is a general problem...
|
||||
js2val thatValue = OBJECT_TO_JS2VAL(new StringInstance(meta, meta->stringClass->prototype, meta->stringClass));
|
||||
StringInstance *strInst = checked_cast<StringInstance *>(JS2VAL_TO_OBJECT(thatValue));
|
||||
JS2Object::RootIterator ri = JS2Object::addRoot(&strInst);
|
||||
RootKeeper rk(&strInst);
|
||||
if (argc > 0)
|
||||
strInst->mValue = meta->engine->allocStringPtr(meta->toString(argv[0]));
|
||||
else
|
||||
@ -71,7 +69,6 @@ js2val String_Constructor(JS2Metadata *meta, const js2val /*thisValue*/, js2val
|
||||
DynamicPropertyValue(meta->engine->allocNumber(strInst->mValue->length()),
|
||||
DynamicPropertyValue::READONLY | DynamicPropertyValue::PERMANENT));
|
||||
strInst->dynamicProperties.insert(dpb->name, dpb);
|
||||
JS2Object::removeRoot(ri);
|
||||
return thatValue;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user