From: keuchel@chromium.org Date: Mon, 24 Oct 2011 07:47:22 +0000 (+0000) Subject: Replace boolean indications of strict mode by an enum value. X-Git-Tag: upstream/4.7.83~18117 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c6464d500b72c35e1520e300b5783aa2f263fc11;p=platform%2Fupstream%2Fv8.git Replace boolean indications of strict mode by an enum value. Review URL: http://codereview.chromium.org/8344082 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9746 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc index 30e8ea6..7ac6ce9 100644 --- a/src/arm/full-codegen-arm.cc +++ b/src/arm/full-codegen-arm.cc @@ -1097,7 +1097,7 @@ void FullCodeGenerator::EmitNewClosure(Handle info, !pretenure && scope()->is_function_scope() && info->num_literals() == 0) { - FastNewClosureStub stub(info->strict_mode() ? kStrictMode : kNonStrictMode); + FastNewClosureStub stub(info->strict_mode_flag()); __ mov(r0, Operand(info)); __ push(r0); __ CallStub(&stub); diff --git a/src/arm/lithium-arm.h b/src/arm/lithium-arm.h index 34b4adc..5733bd0 100644 --- a/src/arm/lithium-arm.h +++ b/src/arm/lithium-arm.h @@ -1582,7 +1582,8 @@ class LStoreNamedGeneric: public LTemplateInstruction<0, 2, 0> { LOperand* object() { return inputs_[0]; } LOperand* value() { return inputs_[1]; } Handle name() const { return hydrogen()->name(); } - bool strict_mode() { return hydrogen()->strict_mode(); } + StrictModeFlag strict_mode_flag() { return hydrogen()->strict_mode_flag(); } + bool strict_mode() { return strict_mode_flag() == kStrictMode; } }; diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index 0265382..4cf7df4 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -4416,8 +4416,7 @@ void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { Handle shared_info = instr->shared_info(); bool pretenure = instr->hydrogen()->pretenure(); if (!pretenure && shared_info->num_literals() == 0) { - FastNewClosureStub stub( - shared_info->strict_mode() ? kStrictMode : kNonStrictMode); + FastNewClosureStub stub(shared_info->strict_mode_flag()); __ mov(r1, Operand(shared_info)); __ push(r1); CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); diff --git a/src/arm/lithium-codegen-arm.h b/src/arm/lithium-codegen-arm.h index d13e7d4..b01e496 100644 --- a/src/arm/lithium-codegen-arm.h +++ b/src/arm/lithium-codegen-arm.h @@ -140,8 +140,8 @@ class LCodeGen BASE_EMBEDDED { bool is_done() const { return status_ == DONE; } bool is_aborted() const { return status_ == ABORTED; } - int strict_mode_flag() const { - return info()->is_strict_mode() ? kStrictMode : kNonStrictMode; + StrictModeFlag strict_mode_flag() const { + return info()->strict_mode_flag(); } LChunk* chunk() const { return chunk_; } diff --git a/src/ast-inl.h b/src/ast-inl.h index a3af259..f8b460d 100644 --- a/src/ast-inl.h +++ b/src/ast-inl.h @@ -121,8 +121,8 @@ int FunctionLiteral::end_position() const { } -bool FunctionLiteral::strict_mode() const { - return scope()->is_strict_mode(); +StrictModeFlag FunctionLiteral::strict_mode_flag() const { + return scope()->strict_mode_flag(); } diff --git a/src/ast.h b/src/ast.h index cb7763b..e5aa57e 100644 --- a/src/ast.h +++ b/src/ast.h @@ -1648,7 +1648,8 @@ class FunctionLiteral: public Expression { int end_position() const; bool is_expression() const { return is_expression_; } bool is_anonymous() const { return is_anonymous_; } - bool strict_mode() const; + bool strict_mode() const { return strict_mode_flag() == kStrictMode; } + StrictModeFlag strict_mode_flag() const; int materialized_literal_count() { return materialized_literal_count_; } int expected_property_count() { return expected_property_count_; } diff --git a/src/compiler.cc b/src/compiler.cc index 7f04aae..88db467 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -558,7 +558,7 @@ Handle Compiler::CompileEval(Handle source, CompilationInfo info(script); info.MarkAsEval(); if (is_global) info.MarkAsGlobal(); - if (strict_mode == kStrictMode) info.MarkAsStrictMode(); + info.SetStrictModeFlag(strict_mode); info.SetCallingContext(context); result = MakeFunctionInfo(&info); if (!result.is_null()) { @@ -566,6 +566,7 @@ Handle Compiler::CompileEval(Handle source, // If caller is strict mode, the result must be strict as well, // but not the other way around. Consider: // eval("'use strict'; ..."); + // TODO(keuchel): adapt this for extended mode. ASSERT(strict_mode == kNonStrictMode || result->strict_mode()); compilation_cache->PutEval(source, context, is_global, result); } @@ -597,10 +598,13 @@ bool Compiler::CompileLazy(CompilationInfo* info) { HistogramTimerScope timer(isolate->counters()->compile_lazy()); // After parsing we know function's strict mode. Remember it. - if (info->function()->strict_mode()) { - shared->set_strict_mode(true); - info->MarkAsStrictMode(); - } + StrictModeFlag strict_mode = info->function()->strict_mode_flag(); + ASSERT(info->strict_mode_flag() == kNonStrictMode || + info->strict_mode_flag() == strict_mode); + ASSERT(shared->strict_mode_flag() == kNonStrictMode || + shared->strict_mode_flag() == strict_mode); + info->SetStrictModeFlag(strict_mode); + shared->set_strict_mode_flag(strict_mode); // Compile the code. if (!MakeCode(info)) { @@ -680,7 +684,7 @@ Handle Compiler::BuildFunctionInfo(FunctionLiteral* literal, CompilationInfo info(script); info.SetFunction(literal); info.SetScope(literal->scope()); - if (literal->scope()->is_strict_mode()) info.MarkAsStrictMode(); + info.SetStrictModeFlag(literal->scope()->strict_mode_flag()); LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); // Determine if the function can be lazily compiled. This is necessary to @@ -746,7 +750,7 @@ void Compiler::SetFunctionInfo(Handle function_info, lit->has_only_simple_this_property_assignments(), *lit->this_property_assignments()); function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); - function_info->set_strict_mode(lit->strict_mode()); + function_info->set_strict_mode_flag(lit->strict_mode_flag()); function_info->set_uses_arguments(lit->scope()->arguments() != NULL); function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); } diff --git a/src/compiler.h b/src/compiler.h index 6d77a98..bedf5ee 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -52,7 +52,10 @@ class CompilationInfo BASE_EMBEDDED { bool is_lazy() const { return IsLazy::decode(flags_); } bool is_eval() const { return IsEval::decode(flags_); } bool is_global() const { return IsGlobal::decode(flags_); } - bool is_strict_mode() const { return IsStrictMode::decode(flags_); } + bool is_strict_mode() const { return strict_mode_flag() == kStrictMode; } + StrictModeFlag strict_mode_flag() const { + return StrictModeFlagField::decode(flags_); + } bool is_in_loop() const { return IsInLoop::decode(flags_); } FunctionLiteral* function() const { return function_; } Scope* scope() const { return scope_; } @@ -73,11 +76,10 @@ class CompilationInfo BASE_EMBEDDED { ASSERT(!is_lazy()); flags_ |= IsGlobal::encode(true); } - void MarkAsStrictMode() { - flags_ |= IsStrictMode::encode(true); - } - StrictModeFlag StrictMode() { - return is_strict_mode() ? kStrictMode : kNonStrictMode; + void SetStrictModeFlag(StrictModeFlag strict_mode_flag) { + ASSERT(StrictModeFlagField::decode(flags_) == kNonStrictMode || + StrictModeFlagField::decode(flags_) == strict_mode_flag); + flags_ = StrictModeFlagField::update(flags_, strict_mode_flag); } void MarkAsInLoop() { ASSERT(is_lazy()); @@ -186,8 +188,9 @@ class CompilationInfo BASE_EMBEDDED { if (script_->type()->value() == Script::TYPE_NATIVE) { MarkAsNative(); } - if (!shared_info_.is_null() && shared_info_->strict_mode()) { - MarkAsStrictMode(); + if (!shared_info_.is_null()) { + ASSERT(strict_mode_flag() == kNonStrictMode); + SetStrictModeFlag(shared_info_->strict_mode_flag()); } } @@ -207,7 +210,7 @@ class CompilationInfo BASE_EMBEDDED { // Flags that can be set for lazy compilation. class IsInLoop: public BitField {}; // Strict mode - used in eager compilation. - class IsStrictMode: public BitField {}; + class StrictModeFlagField: public BitField {}; // Is this a function from our natives. class IsNative: public BitField {}; // Is this code being compiled with support for deoptimization.. diff --git a/src/full-codegen.cc b/src/full-codegen.cc index 0eb36f4..efcd346 100644 --- a/src/full-codegen.cc +++ b/src/full-codegen.cc @@ -547,11 +547,10 @@ void FullCodeGenerator::VisitDeclarations( int FullCodeGenerator::DeclareGlobalsFlags() { - int flags = 0; - if (is_eval()) flags |= kDeclareGlobalsEvalFlag; - if (is_strict_mode()) flags |= kDeclareGlobalsStrictModeFlag; - if (is_native()) flags |= kDeclareGlobalsNativeFlag; - return flags; + ASSERT(DeclareGlobalsStrictModeFlag::is_valid(strict_mode_flag())); + return DeclareGlobalsEvalFlag::encode(is_eval()) | + DeclareGlobalsStrictModeFlag::encode(strict_mode_flag()) | + DeclareGlobalsNativeFlag::encode(is_native()); } diff --git a/src/full-codegen.h b/src/full-codegen.h index 081192a..9132502 100644 --- a/src/full-codegen.h +++ b/src/full-codegen.h @@ -577,9 +577,11 @@ class FullCodeGenerator: public AstVisitor { Handle