From 6e767e3f2dcb8ff0f0c2bb2849e3efc2665b5dcb Mon Sep 17 00:00:00 2001 From: "keuchel@chromium.org" Date: Thu, 27 Oct 2011 13:08:51 +0000 Subject: [PATCH] Use StrictModeFlag in preparser and preparse data. Review URL: http://codereview.chromium.org/8396040 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9818 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/globals.h | 14 ++++++++++++++ src/parser.cc | 2 +- src/parser.h | 4 +++- src/preparse-data.h | 4 ++-- src/preparser.cc | 2 +- src/preparser.h | 26 +++++++++----------------- src/v8globals.h | 10 ---------- 7 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/globals.h b/src/globals.h index cbe7abd..26a0e5f 100644 --- a/src/globals.h +++ b/src/globals.h @@ -358,6 +358,20 @@ F FUNCTION_CAST(Address addr) { class FreeStoreAllocationPolicy; template class List; +// ----------------------------------------------------------------------------- +// Declarations for use in both the preparser and the rest of V8. + +// The Strict Mode (ECMA-262 5th edition, 4.2.2). +enum StrictModeFlag { + kNonStrictMode, + kStrictMode, + // This value is never used, but is needed to prevent GCC 4.5 from failing + // to compile when we assert that a flag is either kNonStrictMode or + // kStrictMode. + kInvalidStrictFlag +}; + + } } // namespace v8::internal #endif // V8_GLOBALS_H_ diff --git a/src/parser.cc b/src/parser.cc index 3c6c4ba..37204c9 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -4006,7 +4006,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle function_name, scanner().SeekForward(scope->end_position() - 1); materialized_literal_count = entry.literal_count(); expected_property_count = entry.property_count(); - if (entry.strict_mode()) top_scope_->SetStrictModeFlag(kStrictMode); + top_scope_->SetStrictModeFlag(entry.strict_mode_flag()); only_simple_this_property_assignments = false; this_property_assignments = isolate()->factory()->empty_fixed_array(); Expect(Token::RBRACE, CHECK_OK); diff --git a/src/parser.h b/src/parser.h index 268b094..eaae6f7 100644 --- a/src/parser.h +++ b/src/parser.h @@ -76,7 +76,9 @@ class FunctionEntry BASE_EMBEDDED { int end_pos() { return backing_[kEndPosOffset]; } int literal_count() { return backing_[kLiteralCountOffset]; } int property_count() { return backing_[kPropertyCountOffset]; } - bool strict_mode() { return backing_[kStrictModeOffset] != 0; } + StrictModeFlag strict_mode_flag() { + return static_cast(backing_[kStrictModeOffset]); + } bool is_valid() { return backing_.length() > 0; } diff --git a/src/preparse-data.h b/src/preparse-data.h index c6503c4..c4ddecd 100644 --- a/src/preparse-data.h +++ b/src/preparse-data.h @@ -49,7 +49,7 @@ class ParserRecorder { int end, int literals, int properties, - int strict_mode) = 0; + StrictModeFlag strict_mode) = 0; // Logs a symbol creation of a literal or identifier. virtual void LogAsciiSymbol(int start, Vector literal) { } @@ -89,7 +89,7 @@ class FunctionLoggingParserRecorder : public ParserRecorder { int end, int literals, int properties, - int strict_mode) { + StrictModeFlag strict_mode) { function_store_.Add(start); function_store_.Add(end); function_store_.Add(literals); diff --git a/src/preparser.cc b/src/preparser.cc index 3313658..b1628eb 100644 --- a/src/preparser.cc +++ b/src/preparser.cc @@ -1364,7 +1364,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral(bool* ok) { log_->LogFunction(function_block_pos, end_pos, function_scope.materialized_literal_count(), function_scope.expected_properties(), - strict_mode() ? 1 : 0); + strict_mode_flag()); } else { ParseSourceElements(i::Token::RBRACE, CHECK_OK); Expect(i::Token::RBRACE, CHECK_OK); diff --git a/src/preparser.h b/src/preparser.h index 6a0b97a..45e81e9 100644 --- a/src/preparser.h +++ b/src/preparser.h @@ -408,16 +408,6 @@ class PreParser { typedef int Arguments; - // The Strict Mode (ECMA-262 5th edition, 4.2.2). - enum StrictModeFlag { - kNonStrictMode, - kStrictMode, - // This value is never used, but is needed to prevent GCC 4.5 from failing - // to compile when we assert that a flag is either kNonStrictMode or - // kStrictMode. - kInvalidStrictFlag - }; - class Scope { public: Scope(Scope** variable, ScopeType type) @@ -428,7 +418,7 @@ class PreParser { expected_properties_(0), with_nesting_count_(0), strict_mode_flag_((prev_ != NULL) ? prev_->strict_mode_flag() - : kNonStrictMode) { + : i::kNonStrictMode) { *variable = this; } ~Scope() { *variable_ = prev_; } @@ -438,11 +428,11 @@ class PreParser { int expected_properties() { return expected_properties_; } int materialized_literal_count() { return materialized_literal_count_; } bool IsInsideWith() { return with_nesting_count_ != 0; } - bool is_strict_mode() { return strict_mode_flag_ == kStrictMode; } - StrictModeFlag strict_mode_flag() { + bool is_strict_mode() { return strict_mode_flag_ == i::kStrictMode; } + i::StrictModeFlag strict_mode_flag() { return strict_mode_flag_; } - void set_strict_mode_flag(StrictModeFlag strict_mode_flag) { + void set_strict_mode_flag(i::StrictModeFlag strict_mode_flag) { strict_mode_flag_ = strict_mode_flag; } void EnterWith() { with_nesting_count_++; } @@ -455,7 +445,7 @@ class PreParser { int materialized_literal_count_; int expected_properties_; int with_nesting_count_; - StrictModeFlag strict_mode_flag_; + i::StrictModeFlag strict_mode_flag_; }; // Private constructor only used in PreParseProgram. @@ -591,10 +581,12 @@ class PreParser { bool peek_any_identifier(); void set_strict_mode() { - scope_->set_strict_mode_flag(kStrictMode); + scope_->set_strict_mode_flag(i::kStrictMode); } - bool strict_mode() { return scope_->strict_mode_flag() == kStrictMode; } + bool strict_mode() { return scope_->strict_mode_flag() == i::kStrictMode; } + + i::StrictModeFlag strict_mode_flag() { return scope_->strict_mode_flag(); } void Consume(i::Token::Value token) { Next(); } diff --git a/src/v8globals.h b/src/v8globals.h index f4703ff..40ce30c 100644 --- a/src/v8globals.h +++ b/src/v8globals.h @@ -482,16 +482,6 @@ enum CpuFeature { SSE4_1 = 32 + 19, // x86 SAHF = 0, // x86 FPU = 1}; // MIPS -// The Strict Mode (ECMA-262 5th edition, 4.2.2). -enum StrictModeFlag { - kNonStrictMode, - kStrictMode, - // This value is never used, but is needed to prevent GCC 4.5 from failing - // to compile when we assert that a flag is either kNonStrictMode or - // kStrictMode. - kInvalidStrictFlag -}; - // Used to specify if a macro instruction must perform a smi check on tagged // values. -- 2.7.4