Reviewers: Kevin Millikin, fschneider, Message: Only on x64 platform right now. What about when we are inside a function?
Description: Implement typeof in fast compiler. Please review this at http://codereview.chromium.org/354027 SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/ Affected files: M src/compiler.cc M src/x64/fast-codegen-x64.cc Index: src/compiler.cc =================================================================== --- src/compiler.cc (revision 3206) +++ src/compiler.cc (working copy) @@ -879,6 +879,9 @@ case Token::NOT: ProcessExpression(expr->expression(), Expression::kTest); break; + case Token::TYPEOF: + ProcessExpression(expr->expression(), Expression::kValue); + break; default: BAILOUT("UnaryOperation"); } Index: src/x64/fast-codegen-x64.cc =================================================================== --- src/x64/fast-codegen-x64.cc (revision 3206) +++ src/x64/fast-codegen-x64.cc (working copy) @@ -1010,7 +1010,8 @@ void FastCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { Comment cmnt(masm_, "[ UnaryOperation"); switch (expr->op()) { - case Token::VOID: + case Token::VOID: { + Comment cmnt(masm_, "[ UnaryOperationVOID"); Visit(expr->expression()); ASSERT_EQ(Expression::kEffect, expr->expression()->context()); switch (expr->context()) { @@ -1032,8 +1033,10 @@ break; } break; + } case Token::NOT: { + Comment cmnt(masm_, "[ UnaryOperationNOT"); ASSERT_EQ(Expression::kTest, expr->expression()->context()); Label push_true; @@ -1094,6 +1097,39 @@ break; } + case Token::TYPEOF: { + Comment cmnt(masm_, "[ UnaryOperationTYPEOF"); + VariableProxy* proxy = expr->expression()->AsVariableProxy(); + Expression* rewrite; + if (proxy != NULL && (rewrite = proxy->var()->rewrite()) == NULL) { + Comment cmnt(masm_, "Global variable"); + __ push(CodeGenerator::GlobalObject()); + __ Push(proxy->name()); + __ CallRuntime(Runtime::kHasProperty, 2); + // Do we need a pop here if runtime.h says "HasProperty, 2, 1"? + Label get_value; + Label dummy_undefined_produced; + __ CompareRoot(rax, Heap::kTrueValueRootIndex); + __ j(equal, &get_value); + // The identifier is not in the global object. Return undefined as + // the result of typeof, rather than a reference error. + __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); + __ jmp(&dummy_undefined_produced); + __ bind(&get_value); + __ push(CodeGenerator::GlobalObject()); + __ Push(proxy->name()); + __ CallRuntime(Runtime::kGetProperty, 2); + // Do we need a pop here if runtime.h says "GetProperty, 2, 1"? + __ bind(&dummy_undefined_produced); + __ push(rax); + } else { + Visit(expr->expression()); + } + __ CallRuntime(Runtime::kTypeof, 1); + Move(expr->context(), rax); + break; + } + default: UNREACHABLE(); } --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
