From 667f2a187de7666c5ca62a62e1e84c6c90e11760 Mon Sep 17 00:00:00 2001 From: "rogerl%netscape.com" Date: Tue, 20 Feb 2001 21:39:59 +0000 Subject: [PATCH] Fixed unused vars. Added string literal as alternative function name. Implemented invokeCall to use override. git-svn-id: svn://10.0.0.236/trunk@87471 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js2/src/icode_emitter.cpp | 2 -- mozilla/js2/src/interpreter.cpp | 35 +++++++++++++++++++++++++++++++ mozilla/js2/src/parser.cpp | 22 +++++++++++-------- mozilla/js2/src/vmtypes.cpp | 3 +++ 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/mozilla/js2/src/icode_emitter.cpp b/mozilla/js2/src/icode_emitter.cpp index 9fa21352346..c23f6e4ba44 100644 --- a/mozilla/js2/src/icode_emitter.cpp +++ b/mozilla/js2/src/icode_emitter.cpp @@ -229,7 +229,6 @@ bool ICodeGenerator::resolveIdentifier(const StringAtom &name, Reference &ref, b else { if (mClass) { // we're compiling a method of a class // look for static references first - bool isConstructor = false; if (isStaticName(mClass, name, ref)) { return true; } @@ -429,7 +428,6 @@ TypedRegister ICodeGenerator::genExpr(ExprNode *p, ICodeOp dblOp; JSTypes::Operator op; TypedRegister ret(NotARegister, &None_Type); - ICodeOp xOp = ADD; switch (p->getKind()) { case ExprNode::True: if (trueBranch || falseBranch) { diff --git a/mozilla/js2/src/interpreter.cpp b/mozilla/js2/src/interpreter.cpp index c921cb29c27..b9960bfd11e 100644 --- a/mozilla/js2/src/interpreter.cpp +++ b/mozilla/js2/src/interpreter.cpp @@ -813,6 +813,41 @@ JSValue Context::interpret(ICodeModule* iCode, const JSValues& args) break; case INVOKE_CALL: + { + // the call operator has been invoked, see if it's overridden + // for the target + InvokeCall* call = static_cast(instruction); + JSValue v = (*registers)[op2(call).first]; + JSClass *clazz = v.isObject() ? dynamic_cast(v.object->getType()) : NULL; + JSFunction *target = NULL; + if (clazz) { + JSOperator *candidate = clazz->findUnaryOperator(JSTypes::Call); + if (candidate) { + target = candidate->mFunction; + if (invokeFunction(target, registers, op1(call), v, op3(call))) { + endPC = mICode->its_iCode->end(); + continue; + } + } + } + if (v.isFunction()) + target = v.function; + else + if (v.isObject()) { + JSType *t = dynamic_cast(v.object); + if (t) + target = t->getInvokor(); + } + if (!target) + throw new JSException("Call to non callable object"); + + if (invokeFunction(target, registers, op1(call), target->getThis(), op3(call))) { + endPC = mICode->its_iCode->end(); + continue; + } + } + break; + case DIRECT_CALL: { DirectCall* call = static_cast(instruction); diff --git a/mozilla/js2/src/parser.cpp b/mozilla/js2/src/parser.cpp index faacf339c82..f78a57e9422 100644 --- a/mozilla/js2/src/parser.cpp +++ b/mozilla/js2/src/parser.cpp @@ -969,16 +969,20 @@ namespace JavaScript { fn.prefix = FunctionName::normal; const Token *t = &lexer.get(true); - if (t->hasKind(Token::Get) || t->hasKind(Token::Set)) { - const Token *t2 = &lexer.peek(true); - if (!lineBreakBefore(*t2) && t2->getFlag(Token::canFollowGet)) { - fn.prefix = t->hasKind(Token::Get) ? FunctionName::Get : - FunctionName::Set; - t = &lexer.get(true); - } + if (t->hasKind(Token::string)) { + fn.name = NodeFactory::LiteralString(t->getPos(),ExprNode::string,copyTokenChars(*t)); + } + else { + if (t->hasKind(Token::Get) || t->hasKind(Token::Set)) { + const Token *t2 = &lexer.peek(true); + if (!lineBreakBefore(*t2) && t2->getFlag(Token::canFollowGet)) { + fn.prefix = t->hasKind(Token::Get) ? FunctionName::Get : + FunctionName::Set; + t = &lexer.get(true); + } + } + fn.name = parseQualifiedIdentifier(*t, true); } - - fn.name = parseQualifiedIdentifier(*t, true); } diff --git a/mozilla/js2/src/vmtypes.cpp b/mozilla/js2/src/vmtypes.cpp index 9dd5d862f9e..1d52f0e7d49 100644 --- a/mozilla/js2/src/vmtypes.cpp +++ b/mozilla/js2/src/vmtypes.cpp @@ -181,6 +181,9 @@ Formatter& operator<< (Formatter& f, JSTypes::Operator& op) f << "BitXor"; break; case JSTypes::BitOr: f << "BitOr"; break; + default: + NOT_REACHED("Bad op"); + break; } return f; }