From 87d54fa2f3d3d1911dbc69930a0888323d92e4bf Mon Sep 17 00:00:00 2001 From: "rogerl%netscape.com" Date: Wed, 5 Feb 2003 23:58:52 +0000 Subject: [PATCH] Fixed eval scope, comma expression. git-svn-id: svn://10.0.0.236/trunk@137443 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js2/src/js2metadata.cpp | 16 +++++++ mozilla/js2/src/js2op_invocation.cpp | 62 ++++++++++++++-------------- mozilla/js2/src/reader.cpp | 8 +++- 3 files changed, 55 insertions(+), 31 deletions(-) diff --git a/mozilla/js2/src/js2metadata.cpp b/mozilla/js2/src/js2metadata.cpp index 221aeffbc6e..6dcab03719e 100644 --- a/mozilla/js2/src/js2metadata.cpp +++ b/mozilla/js2/src/js2metadata.cpp @@ -493,6 +493,8 @@ namespace MetaData { if (vb->type) ValidateTypeExpression(cxt, env, vb->type); vb->member = NULL; + if (vb->initializer) + ValidateExpression(cxt, env, vb->initializer); if (!cxt->strict && ((regionalFrame->kind == GlobalObjectKind) || (regionalFrame->kind == ParameterKind)) @@ -1654,6 +1656,13 @@ namespace MetaData { } } break; + case ExprNode::comma: + { + BinaryExprNode *b = checked_cast(p); + ValidateExpression(cxt, env, b->op1); + ValidateExpression(cxt, env, b->op2); + } + break; default: NOT_REACHED("Not Yet Implemented"); } // switch (p->getKind()) @@ -2251,6 +2260,13 @@ doUnary: bCon->addShort(argCount); } break; + case ExprNode::comma: + { + BinaryExprNode *b = checked_cast(p); + SetupExprNode(env, phase, b->op1, exprType); + SetupExprNode(env, phase, b->op2, exprType); + } + break; default: NOT_REACHED("Not Yet Implemented"); } diff --git a/mozilla/js2/src/js2op_invocation.cpp b/mozilla/js2/src/js2op_invocation.cpp index ff646bb3381..44f30105a2d 100644 --- a/mozilla/js2/src/js2op_invocation.cpp +++ b/mozilla/js2/src/js2op_invocation.cpp @@ -78,21 +78,22 @@ 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; - runtimeFrame->assignArguments(base(argCount), argCount); - if (!fWrap->code) - jsr(phase, fWrap->bCon, base(argCount + 1), baseVal); // 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 { + 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; + runtimeFrame->assignArguments(base(argCount), argCount); + jsr(phase, fWrap->bCon, base(argCount + 1), baseVal); // seems out of order, but we need to catch the current top frame + meta->env->addFrame(runtimeFrame); + } } else meta->reportError(Exception::typeError, "object is not a constructor", errorPos()); @@ -134,42 +135,43 @@ } } - ParameterFrame *runtimeFrame = new ParameterFrame(fWrap->compileFrame); - runtimeFrame->instantiate(meta->env); - runtimeFrame->thisObject = a; -// assignArguments(runtimeFrame, fWrap->compileFrame->signature); - // XXX - runtimeFrame->assignArguments(base(argCount), argCount); - if (!fWrap->code) - jsr(phase, fWrap->bCon, base(argCount + 2), JS2VAL_VOID); // 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 + if (fWrap->code) { // native code a = fWrap->code(meta, a, base(argCount), argCount); - meta->env->removeTopFrame(); pop(argCount + 2); push(a); } + else { + ParameterFrame *runtimeFrame = new ParameterFrame(fWrap->compileFrame); + runtimeFrame->instantiate(meta->env); + runtimeFrame->thisObject = a; + // assignArguments(runtimeFrame, fWrap->compileFrame->signature); + // XXX + runtimeFrame->assignArguments(base(argCount), argCount); + jsr(phase, fWrap->bCon, base(argCount + 2), JS2VAL_VOID); // seems out of order, but we need to catch the current top frame + meta->env->addFrame(runtimeFrame); + } } else if (fObj->kind == MethodClosureKind) { // XXX I made this up (particularly the frame push of the objectType) MethodClosure *mc = checked_cast(fObj); SimpleInstance *fInst = mc->method->fInst; FunctionWrapper *fWrap = fInst->fWrap; - ParameterFrame *runtimeFrame = new ParameterFrame(fWrap->compileFrame); - runtimeFrame->instantiate(meta->env); - runtimeFrame->thisObject = mc->thisObject; -// assignArguments(runtimeFrame, fWrap->compileFrame->signature); - if (!fWrap->code) - jsr(phase, fWrap->bCon, base(argCount + 2), JS2VAL_VOID); // seems out of order, but we need to catch the current top frame - meta->env->addFrame(meta->objectType(mc->thisObject)); - meta->env->addFrame(runtimeFrame); + if (fWrap->code) { a = fWrap->code(meta, mc->thisObject, base(argCount), argCount); - meta->env->removeTopFrame(); - meta->env->removeTopFrame(); pop(argCount + 2); push(a); } + else { + ParameterFrame *runtimeFrame = new ParameterFrame(fWrap->compileFrame); + runtimeFrame->instantiate(meta->env); + runtimeFrame->thisObject = mc->thisObject; +// assignArguments(runtimeFrame, fWrap->compileFrame->signature); + jsr(phase, fWrap->bCon, base(argCount + 2), JS2VAL_VOID); // seems out of order, but we need to catch the current top frame + meta->env->addFrame(meta->objectType(mc->thisObject)); + meta->env->addFrame(runtimeFrame); + } + } else if (fObj->kind == ClassKind) { diff --git a/mozilla/js2/src/reader.cpp b/mozilla/js2/src/reader.cpp index 85043550988..163e3773321 100644 --- a/mozilla/js2/src/reader.cpp +++ b/mozilla/js2/src/reader.cpp @@ -188,6 +188,12 @@ size_t JS::LineReader::readLine(string &str) crWasLast = false; str.resize(0); +#ifdef XP_UNIX + char line[256]; + if (fgets(line, sizeof line, file) == NULL) + return 0; + str = line; +#else while ((ch = getc(in)) != EOF) { if (ch == '\n') { if (!str.size() && oldCRWasLast) @@ -202,7 +208,7 @@ size_t JS::LineReader::readLine(string &str) } str += static_cast(ch); } - +#endif return str.size(); }