From 022516fe63787fda84607aa74bbccf448cd3f07b Mon Sep 17 00:00:00 2001 From: "rogerl%netscape.com" Date: Mon, 12 May 2003 21:33:18 +0000 Subject: [PATCH] Fixed E3 bugs throughout. Added /Op to build for bug in numerics.cpp code inherited from SpiderMonkey. git-svn-id: svn://10.0.0.236/trunk@142342 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js2/src/js2engine.cpp | 3 +++ mozilla/js2/src/js2function.cpp | 8 ++------ mozilla/js2/src/js2math.cpp | 13 ++++++++++++- mozilla/js2/src/js2metadata.cpp | 24 ++++++++++++++++++------ mozilla/js2/src/js2op_invocation.cpp | 7 +++++-- 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/mozilla/js2/src/js2engine.cpp b/mozilla/js2/src/js2engine.cpp index a1f81a066f7..d285d7c5702 100644 --- a/mozilla/js2/src/js2engine.cpp +++ b/mozilla/js2/src/js2engine.cpp @@ -468,6 +468,9 @@ namespace MetaData { INIT_STRINGATOM(length), INIT_STRINGATOM(toString), INIT_STRINGATOM(valueOf), + packageFrame(NULL), + parameterFrame(NULL), + localFrame(NULL), traceInstructions(false) { for (int i = 0; i < 256; i++) diff --git a/mozilla/js2/src/js2function.cpp b/mozilla/js2/src/js2function.cpp index 85df698546a..e5d40036d3f 100644 --- a/mozilla/js2/src/js2function.cpp +++ b/mozilla/js2/src/js2function.cpp @@ -78,22 +78,16 @@ namespace MetaData { ASSERT(fnExpr); // otherwise, an exception would have been thrown out of here fnExpr->obj = NULL; DEFINE_ROOTKEEPER(rk, fnExpr->obj); -// JS2Class *exprType; meta->ValidateExpression(&meta->cxt, meta->env, fnExpr); Arena *oldArena = meta->referenceArena; meta->referenceArena = new Arena; try { -// meta->SetupExprNode(meta->env, RunPhase, fnExpr, &exprType); - - CompilationData *oldData = meta->startCompilationUnit(fnExpr->function.fWrap->bCon, *bodyStr, srcLoc); meta->env->addFrame(fnExpr->function.fWrap->compileFrame); meta->SetupStmt(meta->env, RunPhase, fnExpr->function.body); fnExpr->function.fWrap->bCon->emitOp(eReturnVoid, meta->engine->errorPos()); meta->env->removeTopFrame(); meta->restoreCompilationUnit(oldData); - - } catch (Exception &x) { meta->referenceArena->clear(); @@ -113,6 +107,8 @@ namespace MetaData { fnInst->fWrap->length = 0; fnInst->fWrap->bCon->emitOp(eReturnVoid, meta->engine->errorPos()); meta->createDynamicProperty(fnInst, meta->engine->length_StringAtom, INT_TO_JS2VAL(0), ReadAccess, true, false); + if (meta->cxt.E3compatibility) + meta->createDynamicProperty(fnInst, &meta->world.identifiers["arguments"], JS2VAL_NULL, ReadAccess, true, false); return thatValue; } } diff --git a/mozilla/js2/src/js2math.cpp b/mozilla/js2/src/js2math.cpp index 89e2125c1c5..f3810cb33f4 100644 --- a/mozilla/js2/src/js2math.cpp +++ b/mozilla/js2/src/js2math.cpp @@ -134,7 +134,18 @@ static js2val Math_exp(JS2Metadata *meta, const js2val /*thisValue*/, js2val *ar { if (argc == 0) return meta->engine->nanValue; - return meta->engine->allocNumber(fd::exp(meta->toFloat64(argv[0]))); + float64 x = meta->toFloat64(argv[0]); +#ifdef _WIN32 + if (!JSDOUBLE_IS_NaN(x)) { + if (x == positiveInfinity) { + return meta->engine->posInfValue; + } + if (x == negativeInfinity) { + return JS2VAL_ZERO; + } + } +#endif + return meta->engine->allocNumber(fd::exp(x)); } static js2val Math_floor(JS2Metadata *meta, const js2val /*thisValue*/, js2val *argv, uint32 argc) { diff --git a/mozilla/js2/src/js2metadata.cpp b/mozilla/js2/src/js2metadata.cpp index 9c794c4c670..2ebf22f4e6b 100644 --- a/mozilla/js2/src/js2metadata.cpp +++ b/mozilla/js2/src/js2metadata.cpp @@ -478,8 +478,10 @@ namespace MetaData { break; case StmtNode::Return: { - Frame *regionalFrame = *env->getRegionalFrame(); - if (regionalFrame->kind != ParameterFrameKind) + ParameterFrame *pFrame = env->getEnclosingParameterFrame(); + // If there isn't a parameter frame, or the parameter frame is + // only a runtime frame (for eval), then it's an orphan return + if ((pFrame->kind != ParameterFrameKind) || pFrame->pluralFrame) reportError(Exception::syntaxError, "Return statement not in function", p->pos); ExprStmtNode *e = checked_cast(p); if (e->expr) { @@ -3875,7 +3877,8 @@ bool nullClass_BracketDelete(JS2Metadata *meta, js2val base, JS2Class *limit, js // A 'forbidden' member, used to mark hidden bindings forbiddenMember = new LocalMember(Member::ForbiddenMember, true); - + + FunctionInstance *fInst; Variable *v; // XXX Built-in Attributes... XXX @@ -3908,6 +3911,8 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... env->addFrame(objectClass); v = new Variable(objectClass, OBJECT_TO_JS2VAL(objectClass->prototype), true); defineLocalMember(env, engine->prototype_StringAtom, NULL, Attribute::NoOverride, false, ReadWriteAccess, v, 0, false); + v = new Variable(objectClass, INT_TO_JS2VAL(1), true); + defineLocalMember(env, engine->length_StringAtom, NULL, Attribute::NoOverride, false, ReadWriteAccess, v, 0, false); env->removeTopFrame(); /*** ECMA 3 Function Class ***/ @@ -3930,7 +3935,7 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... // Add __proto__ as a getter/setter instance member to Object & class Multiname mn(&world.identifiers["__proto__"], publicNamespace); - FunctionInstance *fInst = new FunctionInstance(this, functionClass->prototype, functionClass); + fInst = new FunctionInstance(this, functionClass->prototype, functionClass); fInst->fWrap = new FunctionWrapper(true, new ParameterFrame(JS2VAL_VOID, true), class_underbarProtoGet, env); fInst->fWrap->length = 0; InstanceGetter *g = new InstanceGetter(&mn, fInst, objectClass, true, true); @@ -3965,6 +3970,13 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... fInst->fWrap->length = 0; createDynamicProperty(JS2VAL_TO_OBJECT(objectClass->prototype), engine->valueOf_StringAtom, OBJECT_TO_JS2VAL(fInst), ReadAccess, true, false); createDynamicProperty(fInst, engine->length_StringAtom, INT_TO_JS2VAL(0), ReadAccess, true, false); + // and 'constructor' + fInst = new FunctionInstance(this, functionClass->prototype, functionClass); + fInst->fWrap = new FunctionWrapper(true, new ParameterFrame(JS2VAL_INACCESSIBLE, true), Object_Constructor, env); + fInst->fWrap->length = 0; + createDynamicProperty(JS2VAL_TO_OBJECT(objectClass->prototype), &world.identifiers["constructor"], OBJECT_TO_JS2VAL(fInst), ReadWriteAccess, false, false); + createDynamicProperty(fInst, engine->length_StringAtom, INT_TO_JS2VAL(1), ReadAccess, true, false); + /*** ECMA 4 Integer Class ***/ v = new Variable(classClass, OBJECT_TO_JS2VAL(integerClass), true); @@ -4928,8 +4940,8 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... FunctionInstance::~FunctionInstance() { -// if (fWrap) -// delete fWrap; + if (fWrap) + delete fWrap; } /************************************************************************************ diff --git a/mozilla/js2/src/js2op_invocation.cpp b/mozilla/js2/src/js2op_invocation.cpp index 53186b384c4..282b6cd4c8a 100644 --- a/mozilla/js2/src/js2op_invocation.cpp +++ b/mozilla/js2/src/js2op_invocation.cpp @@ -137,7 +137,7 @@ push(a); } else { - if (length || fInst->isMethodClosure) { + if (length || fInst->isMethodClosure || fWrap->compileFrame->buildArguments) { pFrame = new ParameterFrame(fWrap->compileFrame); pFrame->instantiate(meta->env); pFrame->thisObject = a; @@ -155,7 +155,10 @@ // XXX constructing a parameterFrame only for the purpose of holding the 'this' // need to find a more efficient way of stashing 'this' // used to be : "meta->env->addFrame(fWrap->compileFrame->prototype);" - meta->env->addFrame(new ParameterFrame(a, fWrap->compileFrame->prototype)); + // Still need to mark the frame as a runtime frame (see stmtnode::return in validate) + pFrame = new ParameterFrame(a, fWrap->compileFrame->prototype); + pFrame->pluralFrame = fWrap->compileFrame; + meta->env->addFrame(pFrame); } } }