Revision: 9746
Author: [email protected]
Date: Mon Oct 24 00:47:22 2011
Log: Replace boolean indications of strict mode by an enum value.
Review URL: http://codereview.chromium.org/8344082
http://code.google.com/p/v8/source/detail?r=9746
Added:
/branches/bleeding_edge/test/mjsunit/compiler/strict-recompile.js
Modified:
/branches/bleeding_edge/src/arm/full-codegen-arm.cc
/branches/bleeding_edge/src/arm/lithium-arm.h
/branches/bleeding_edge/src/arm/lithium-codegen-arm.cc
/branches/bleeding_edge/src/arm/lithium-codegen-arm.h
/branches/bleeding_edge/src/ast-inl.h
/branches/bleeding_edge/src/ast.h
/branches/bleeding_edge/src/compiler.cc
/branches/bleeding_edge/src/compiler.h
/branches/bleeding_edge/src/full-codegen.cc
/branches/bleeding_edge/src/full-codegen.h
/branches/bleeding_edge/src/hydrogen-instructions.h
/branches/bleeding_edge/src/hydrogen.cc
/branches/bleeding_edge/src/hydrogen.h
/branches/bleeding_edge/src/ia32/full-codegen-ia32.cc
/branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc
/branches/bleeding_edge/src/ia32/lithium-codegen-ia32.h
/branches/bleeding_edge/src/ia32/lithium-ia32.h
/branches/bleeding_edge/src/objects-inl.h
/branches/bleeding_edge/src/objects.cc
/branches/bleeding_edge/src/objects.h
/branches/bleeding_edge/src/parser.cc
/branches/bleeding_edge/src/preparser.h
/branches/bleeding_edge/src/runtime.cc
/branches/bleeding_edge/src/runtime.h
/branches/bleeding_edge/src/scopes.cc
/branches/bleeding_edge/src/scopes.h
/branches/bleeding_edge/src/x64/full-codegen-x64.cc
/branches/bleeding_edge/src/x64/lithium-codegen-x64.cc
/branches/bleeding_edge/src/x64/lithium-codegen-x64.h
/branches/bleeding_edge/src/x64/lithium-x64.h
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/compiler/strict-recompile.js Mon
Oct 24 00:47:22 2011
@@ -0,0 +1,51 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Flags: --allow-natives-syntax
+
+function foo() {
+ try {
+ var o = {};
+ Object.defineProperty(o, 'x', {value: 12, writable: false});
+ o.x = 13;
+ } catch(e) {
+ return true;
+ }
+ return false;
+}
+
+assertFalse(foo());
+
+function do_eval(str) {
+ "use strict";
+ return eval(str);
+}
+
+var eval_foo = do_eval('(' + foo + ')');
+for (var i = 0; i < 5; i++) assertTrue(eval_foo());
+%OptimizeFunctionOnNextCall(eval_foo);
+assertTrue(eval_foo());
=======================================
--- /branches/bleeding_edge/src/arm/full-codegen-arm.cc Wed Oct 19 04:36:55
2011
+++ /branches/bleeding_edge/src/arm/full-codegen-arm.cc Mon Oct 24 00:47:22
2011
@@ -1097,7 +1097,7 @@
!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);
=======================================
--- /branches/bleeding_edge/src/arm/lithium-arm.h Wed Oct 19 05:10:18 2011
+++ /branches/bleeding_edge/src/arm/lithium-arm.h Mon Oct 24 00:47:22 2011
@@ -1582,7 +1582,8 @@
LOperand* object() { return inputs_[0]; }
LOperand* value() { return inputs_[1]; }
Handle<Object> 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; }
};
=======================================
--- /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Thu Oct 20
03:26:45 2011
+++ /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Mon Oct 24
00:47:22 2011
@@ -4416,8 +4416,7 @@
Handle<SharedFunctionInfo> 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);
=======================================
--- /branches/bleeding_edge/src/arm/lithium-codegen-arm.h Thu Oct 20
03:26:45 2011
+++ /branches/bleeding_edge/src/arm/lithium-codegen-arm.h Mon Oct 24
00:47:22 2011
@@ -140,8 +140,8 @@
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_; }
=======================================
--- /branches/bleeding_edge/src/ast-inl.h Fri Oct 21 03:26:59 2011
+++ /branches/bleeding_edge/src/ast-inl.h Mon Oct 24 00:47:22 2011
@@ -121,8 +121,8 @@
}
-bool FunctionLiteral::strict_mode() const {
- return scope()->is_strict_mode();
+StrictModeFlag FunctionLiteral::strict_mode_flag() const {
+ return scope()->strict_mode_flag();
}
=======================================
--- /branches/bleeding_edge/src/ast.h Fri Oct 21 03:26:59 2011
+++ /branches/bleeding_edge/src/ast.h Mon Oct 24 00:47:22 2011
@@ -1648,7 +1648,8 @@
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_; }
=======================================
--- /branches/bleeding_edge/src/compiler.cc Tue Oct 18 06:40:33 2011
+++ /branches/bleeding_edge/src/compiler.cc Mon Oct 24 00:47:22 2011
@@ -558,7 +558,7 @@
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 @@
// 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 @@
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 @@
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 @@
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());
}
=======================================
--- /branches/bleeding_edge/src/compiler.h Tue Oct 18 06:40:33 2011
+++ /branches/bleeding_edge/src/compiler.h Mon Oct 24 00:47:22 2011
@@ -52,7 +52,10 @@
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 @@
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 @@
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 @@
// Flags that can be set for lazy compilation.
class IsInLoop: public BitField<bool, 3, 1> {};
// Strict mode - used in eager compilation.
- class IsStrictMode: public BitField<bool, 4, 1> {};
+ class StrictModeFlagField: public BitField<StrictModeFlag, 4, 1> {};
// Is this a function from our natives.
class IsNative: public BitField<bool, 6, 1> {};
// Is this code being compiled with support for deoptimization..
=======================================
--- /branches/bleeding_edge/src/full-codegen.cc Tue Oct 18 06:40:33 2011
+++ /branches/bleeding_edge/src/full-codegen.cc Mon Oct 24 00:47:22 2011
@@ -547,11 +547,10 @@
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());
}
=======================================
--- /branches/bleeding_edge/src/full-codegen.h Tue Oct 11 01:41:19 2011
+++ /branches/bleeding_edge/src/full-codegen.h Mon Oct 24 00:47:22 2011
@@ -577,9 +577,11 @@
Handle<Script> script() { return info_->script(); }
bool is_eval() { return info_->is_eval(); }
bool is_native() { return info_->is_native(); }
- bool is_strict_mode() { return function()->strict_mode(); }
+ bool is_strict_mode() {
+ return strict_mode_flag() == kStrictMode;
+ }
StrictModeFlag strict_mode_flag() {
- return is_strict_mode() ? kStrictMode : kNonStrictMode;
+ return function()->strict_mode_flag();
}
FunctionLiteral* function() { return info_->function(); }
Scope* scope() { return scope_; }
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.h Wed Oct 19 05:10:18
2011
+++ /branches/bleeding_edge/src/hydrogen-instructions.h Mon Oct 24 00:47:22
2011
@@ -3720,9 +3720,9 @@
HValue* object,
Handle<String> name,
HValue* value,
- bool strict_mode)
+ StrictModeFlag strict_mode_flag)
: name_(name),
- strict_mode_(strict_mode) {
+ strict_mode_flag_(strict_mode_flag) {
SetOperandAt(0, object);
SetOperandAt(1, value);
SetOperandAt(2, context);
@@ -3733,7 +3733,7 @@
HValue* value() { return OperandAt(1); }
HValue* context() { return OperandAt(2); }
Handle<String> name() { return name_; }
- bool strict_mode() { return strict_mode_; }
+ StrictModeFlag strict_mode_flag() { return strict_mode_flag_; }
virtual void PrintDataTo(StringStream* stream);
@@ -3745,7 +3745,7 @@
private:
Handle<String> name_;
- bool strict_mode_;
+ StrictModeFlag strict_mode_flag_;
};
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc Thu Oct 20 01:49:01 2011
+++ /branches/bleeding_edge/src/hydrogen.cc Mon Oct 24 00:47:22 2011
@@ -3276,7 +3276,7 @@
literal,
name,
value,
- function_strict_mode());
+ function_strict_mode_flag());
AddInstruction(store);
AddSimulate(key->id());
} else {
@@ -3454,7 +3454,7 @@
object,
name,
value,
- function_strict_mode());
+ function_strict_mode_flag());
}
@@ -3639,7 +3639,7 @@
global_object,
var->name(),
value,
- function_strict_mode());
+ function_strict_mode_flag());
instr->set_position(position);
AddInstruction(instr);
ASSERT(instr->HasSideEffects());
@@ -4304,7 +4304,7 @@
object,
key,
value,
- function_strict_mode());
+ function_strict_mode_flag());
}
bool HGraphBuilder::TryArgumentsAccess(Property* expr) {
=======================================
--- /branches/bleeding_edge/src/hydrogen.h Thu Oct 20 01:41:38 2011
+++ /branches/bleeding_edge/src/hydrogen.h Mon Oct 24 00:47:22 2011
@@ -769,8 +769,8 @@
void ClearInlinedTestContext() {
function_state()->ClearInlinedTestContext();
}
- bool function_strict_mode() {
- return function_state()->compilation_info()->is_strict_mode();
+ StrictModeFlag function_strict_mode_flag() {
+ return function_state()->compilation_info()->strict_mode_flag();
}
// Generators for inline runtime functions.
=======================================
--- /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Wed Oct 19
04:36:55 2011
+++ /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Mon Oct 24
00:47:22 2011
@@ -1079,7 +1079,7 @@
!pretenure &&
scope()->is_function_scope() &&
info->num_literals() == 0) {
- FastNewClosureStub stub(info->strict_mode() ? kStrictMode :
kNonStrictMode);
+ FastNewClosureStub stub(info->strict_mode_flag());
__ push(Immediate(info));
__ CallStub(&stub);
} else {
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Thu Oct 20
03:26:45 2011
+++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Mon Oct 24
00:47:22 2011
@@ -4313,8 +4313,7 @@
Handle<SharedFunctionInfo> 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());
__ push(Immediate(shared_info));
CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
} else {
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.h Thu Oct 20
03:26:45 2011
+++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.h Mon Oct 24
00:47:22 2011
@@ -131,8 +131,8 @@
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();
}
bool dynamic_frame_alignment() const { return dynamic_frame_alignment_; }
void set_dynamic_frame_alignment(bool value) {
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-ia32.h Wed Oct 19 05:10:18 2011
+++ /branches/bleeding_edge/src/ia32/lithium-ia32.h Mon Oct 24 00:47:22 2011
@@ -1640,7 +1640,8 @@
LOperand* object() { return inputs_[1]; }
LOperand* value() { return inputs_[2]; }
Handle<Object> 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; }
};
=======================================
--- /branches/bleeding_edge/src/objects-inl.h Fri Oct 21 03:32:38 2011
+++ /branches/bleeding_edge/src/objects-inl.h Mon Oct 24 00:47:22 2011
@@ -3599,8 +3599,23 @@
}
-BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, strict_mode,
- kStrictModeFunction)
+StrictModeFlag SharedFunctionInfo::strict_mode_flag() {
+ return BooleanBit::get(compiler_hints(), kStrictModeFunction)
+ ? kStrictMode : kNonStrictMode;
+}
+
+
+void SharedFunctionInfo::set_strict_mode_flag(StrictModeFlag
strict_mode_flag) {
+ ASSERT(strict_mode_flag == kStrictMode ||
+ strict_mode_flag == kNonStrictMode);
+ bool value = strict_mode_flag == kStrictMode;
+ set_compiler_hints(
+ BooleanBit::set(compiler_hints(), kStrictModeFunction, value));
+}
+
+
+BOOL_GETTER(SharedFunctionInfo, compiler_hints, strict_mode,
+ kStrictModeFunction)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, native, kNative)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints,
name_should_print_as_anonymous,
=======================================
--- /branches/bleeding_edge/src/objects.cc Fri Oct 21 04:42:54 2011
+++ /branches/bleeding_edge/src/objects.cc Mon Oct 24 00:47:22 2011
@@ -11711,7 +11711,7 @@
SharedFunctionInfo* value) {
StringSharedKey key(src,
context->closure()->shared(),
- value->strict_mode() ? kStrictMode : kNonStrictMode);
+ value->strict_mode_flag());
Object* obj;
{ MaybeObject* maybe_obj = EnsureCapacity(1, &key);
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
=======================================
--- /branches/bleeding_edge/src/objects.h Fri Oct 21 04:42:54 2011
+++ /branches/bleeding_edge/src/objects.h Mon Oct 24 00:47:22 2011
@@ -4871,7 +4871,11 @@
DECL_BOOLEAN_ACCESSORS(optimization_disabled)
// Indicates whether the function is a strict mode function.
- DECL_BOOLEAN_ACCESSORS(strict_mode)
+ inline bool strict_mode();
+
+ // Indicates the mode of the function.
+ inline StrictModeFlag strict_mode_flag();
+ inline void set_strict_mode_flag(StrictModeFlag strict_mode_flag);
// False if the function definitely does not allocate an arguments
object.
DECL_BOOLEAN_ACCESSORS(uses_arguments)
=======================================
--- /branches/bleeding_edge/src/parser.cc Fri Oct 21 03:26:59 2011
+++ /branches/bleeding_edge/src/parser.cc Mon Oct 24 00:47:22 2011
@@ -636,6 +636,7 @@
bool in_global_context,
StrictModeFlag strict_mode,
ZoneScope* zone_scope) {
+ ASSERT(top_scope_ == NULL);
ASSERT(target_stack_ == NULL);
if (pre_data_ != NULL) pre_data_->Initialize();
@@ -651,9 +652,8 @@
scope->set_start_position(0);
scope->set_end_position(source->length());
LexicalScope lexical_scope(this, scope, isolate());
- if (strict_mode == kStrictMode) {
- top_scope_->EnableStrictMode();
- }
+ ASSERT(top_scope_->strict_mode_flag() == kNonStrictMode);
+ top_scope_->SetStrictModeFlag(strict_mode);
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16);
bool ok = true;
int beg_loc = scanner().location().beg_pos;
@@ -724,6 +724,7 @@
ZoneScope* zone_scope) {
Handle<SharedFunctionInfo> shared_info = info->shared_info();
scanner_.Initialize(source);
+ ASSERT(top_scope_ == NULL);
ASSERT(target_stack_ == NULL);
Handle<String> name(String::cast(shared_info->name()));
@@ -742,11 +743,10 @@
scope = Scope::DeserializeScopeChain(info, scope);
}
LexicalScope lexical_scope(this, scope, isolate());
-
- if (shared_info->strict_mode()) {
- top_scope_->EnableStrictMode();
- }
-
+ ASSERT(scope->strict_mode_flag() == kNonStrictMode ||
+ scope->strict_mode_flag() == info->strict_mode_flag());
+ ASSERT(info->strict_mode_flag() == shared_info->strict_mode_flag());
+ scope->SetStrictModeFlag(shared_info->strict_mode_flag());
FunctionLiteral::Type type = shared_info->is_expression()
? (shared_info->is_anonymous()
? FunctionLiteral::ANONYMOUS_EXPRESSION
@@ -1193,7 +1193,7 @@
directive->Equals(isolate()->heap()->use_strict()) &&
token_loc.end_pos - token_loc.beg_pos ==
isolate()->heap()->use_strict()->length() + 2) {
- top_scope_->EnableStrictMode();
+ top_scope_->SetStrictModeFlag(kStrictMode);
// "use strict" is the only directive for now.
directive_prologue = false;
}
@@ -1593,9 +1593,6 @@
// Construct block expecting 16 statements.
Block* body = new(zone()) Block(isolate(), labels, 16, false);
Scope* block_scope = NewScope(top_scope_, BLOCK_SCOPE);
- if (top_scope_->is_strict_mode()) {
- block_scope->EnableStrictMode();
- }
// Parse the statements and collect escaping labels.
Expect(Token::LBRACE, CHECK_OK);
@@ -1842,9 +1839,7 @@
} else {
// Add strict mode.
// We may want to pass singleton to avoid Literal allocations.
- StrictModeFlag flag = initialization_scope->is_strict_mode()
- ? kStrictMode
- : kNonStrictMode;
+ StrictModeFlag flag = initialization_scope->strict_mode_flag();
arguments->Add(NewNumberLiteral(flag));
// Be careful not to assign a value to the global variable if
@@ -2244,9 +2239,6 @@
Expect(Token::LPAREN, CHECK_OK);
catch_scope = NewScope(top_scope_, CATCH_SCOPE);
- if (top_scope_->is_strict_mode()) {
- catch_scope->EnableStrictMode();
- }
catch_scope->set_start_position(scanner().location().beg_pos);
name = ParseIdentifier(CHECK_OK);
@@ -2377,9 +2369,6 @@
// Create an in-between scope for let-bound iteration variables.
Scope* saved_scope = top_scope_;
Scope* for_scope = NewScope(top_scope_, BLOCK_SCOPE);
- if (top_scope_->is_strict_mode()) {
- for_scope->EnableStrictMode();
- }
top_scope_ = for_scope;
Expect(Token::FOR, CHECK_OK);
@@ -3978,7 +3967,7 @@
scanner().SeekForward(scope->end_position() - 1);
materialized_literal_count = entry.literal_count();
expected_property_count = entry.property_count();
- if (entry.strict_mode()) top_scope_->EnableStrictMode();
+ if (entry.strict_mode())
top_scope_->SetStrictModeFlag(kStrictMode);
only_simple_this_property_assignments = false;
this_property_assignments =
isolate()->factory()->empty_fixed_array();
Expect(Token::RBRACE, CHECK_OK);
@@ -5390,7 +5379,7 @@
Handle<String> source =
Handle<String>(String::cast(script->source()));
result = parser.ParseProgram(source,
info->is_global(),
- info->StrictMode());
+ info->strict_mode_flag());
}
}
info->SetFunction(result);
=======================================
--- /branches/bleeding_edge/src/preparser.h Mon Oct 17 05:45:52 2011
+++ /branches/bleeding_edge/src/preparser.h Mon Oct 24 00:47:22 2011
@@ -408,6 +408,16 @@
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)
@@ -417,7 +427,8 @@
materialized_literal_count_(0),
expected_properties_(0),
with_nesting_count_(0),
- strict_((prev_ != NULL) && prev_->is_strict()) {
+ strict_mode_flag_((prev_ != NULL) ? prev_->strict_mode_flag()
+ : kNonStrictMode) {
*variable = this;
}
~Scope() { *variable_ = prev_; }
@@ -427,8 +438,13 @@
int expected_properties() { return expected_properties_; }
int materialized_literal_count() { return materialized_literal_count_;
}
bool IsInsideWith() { return with_nesting_count_ != 0; }
- bool is_strict() { return strict_; }
- void set_strict() { strict_ = true; }
+ bool is_strict_mode() { return strict_mode_flag_ == kStrictMode; }
+ StrictModeFlag strict_mode_flag() {
+ return strict_mode_flag_;
+ }
+ void set_strict_mode_flag(StrictModeFlag strict_mode_flag) {
+ strict_mode_flag_ = strict_mode_flag;
+ }
void EnterWith() { with_nesting_count_++; }
void LeaveWith() { with_nesting_count_--; }
@@ -439,7 +455,7 @@
int materialized_literal_count_;
int expected_properties_;
int with_nesting_count_;
- bool strict_;
+ StrictModeFlag strict_mode_flag_;
};
// Private constructor only used in PreParseProgram.
@@ -470,7 +486,7 @@
if (stack_overflow_) return kPreParseStackOverflow;
if (!ok) {
ReportUnexpectedToken(scanner_->current_token());
- } else if (scope_->is_strict()) {
+ } else if (scope_->is_strict_mode()) {
CheckOctalLiteral(start_position, scanner_->location().end_pos, &ok);
}
return kPreParseSuccess;
@@ -575,10 +591,10 @@
bool peek_any_identifier();
void set_strict_mode() {
- scope_->set_strict();
+ scope_->set_strict_mode_flag(kStrictMode);
}
- bool strict_mode() { return scope_->is_strict(); }
+ bool strict_mode() { return scope_->strict_mode_flag() == kStrictMode; }
void Consume(i::Token::Value token) { Next(); }
=======================================
--- /branches/bleeding_edge/src/runtime.cc Fri Oct 21 03:26:59 2011
+++ /branches/bleeding_edge/src/runtime.cc Mon Oct 24 00:47:22 2011
@@ -1288,10 +1288,10 @@
// non-deletable. However, neither SpiderMonkey nor KJS creates the
// property as read-only, so we don't either.
int attr = NONE;
- if ((flags & kDeclareGlobalsEvalFlag) == 0) {
+ if (!DeclareGlobalsEvalFlag::decode(flags)) {
attr |= DONT_DELETE;
}
- bool is_native = (flags & kDeclareGlobalsNativeFlag) != 0;
+ bool is_native = DeclareGlobalsNativeFlag::decode(flags);
if (is_const_property || (is_native && is_function_declaration)) {
attr |= READ_ONLY;
}
@@ -1316,9 +1316,7 @@
value,
attributes));
} else {
- StrictModeFlag strict_mode =
- ((flags & kDeclareGlobalsStrictModeFlag) != 0) ? kStrictMode
- : kNonStrictMode;
+ StrictModeFlag strict_mode =
DeclareGlobalsStrictModeFlag::decode(flags);
RETURN_IF_EMPTY_HANDLE(isolate,
SetProperty(global,
name,
=======================================
--- /branches/bleeding_edge/src/runtime.h Thu Oct 20 02:38:24 2011
+++ /branches/bleeding_edge/src/runtime.h Mon Oct 24 00:47:22 2011
@@ -676,11 +676,9 @@
//---------------------------------------------------------------------------
// Constants used by interface to runtime functions.
-enum kDeclareGlobalsFlags {
- kDeclareGlobalsEvalFlag = 1 << 0,
- kDeclareGlobalsStrictModeFlag = 1 << 1,
- kDeclareGlobalsNativeFlag = 1 << 2
-};
+class DeclareGlobalsEvalFlag: public BitField<bool, 0, 1>
{};
+class DeclareGlobalsStrictModeFlag: public BitField<StrictModeFlag, 1, 1>
{};
+class DeclareGlobalsNativeFlag: public BitField<bool, 2, 1>
{};
} } // namespace v8::internal
=======================================
--- /branches/bleeding_edge/src/scopes.cc Fri Oct 21 03:26:59 2011
+++ /branches/bleeding_edge/src/scopes.cc Mon Oct 24 00:47:22 2011
@@ -200,7 +200,8 @@
scope_contains_with_ = false;
scope_calls_eval_ = false;
// Inherit the strict mode from the parent scope.
- strict_mode_ = (outer_scope != NULL) && outer_scope->strict_mode_;
+ strict_mode_flag_ = (outer_scope != NULL)
+ ? outer_scope->strict_mode_flag_ : kNonStrictMode;
outer_scope_calls_non_strict_eval_ = false;
inner_scope_calls_eval_ = false;
force_eager_compilation_ = false;
=======================================
--- /branches/bleeding_edge/src/scopes.h Fri Oct 21 03:26:59 2011
+++ /branches/bleeding_edge/src/scopes.h Mon Oct 24 00:47:22 2011
@@ -192,9 +192,9 @@
// Inform the scope that the corresponding code contains an eval call.
void RecordEvalCall() { if (!is_global_scope()) scope_calls_eval_ =
true; }
- // Enable strict mode for the scope (unless disabled by a global flag).
- void EnableStrictMode() {
- strict_mode_ = FLAG_strict_mode;
+ // Set the strict mode flag (unless disabled by a global flag).
+ void SetStrictModeFlag(StrictModeFlag strict_mode_flag) {
+ strict_mode_flag_ = FLAG_strict_mode ? strict_mode_flag :
kNonStrictMode;
}
// Position in the source where this scope begins and ends.
@@ -241,7 +241,7 @@
bool is_declaration_scope() const {
return is_eval_scope() || is_function_scope() || is_global_scope();
}
- bool is_strict_mode() const { return strict_mode_; }
+ bool is_strict_mode() const { return strict_mode_flag() == kStrictMode; }
bool is_strict_mode_eval_scope() const {
return is_eval_scope() && is_strict_mode();
}
@@ -268,6 +268,9 @@
// The type of this scope.
ScopeType type() const { return type_; }
+
+ // The strict mode of this scope.
+ StrictModeFlag strict_mode_flag() const { return strict_mode_flag_; }
// The variable corresponding the 'this' value.
Variable* receiver() { return receiver_; }
@@ -420,7 +423,7 @@
// the 'eval' call site this scope is the declaration scope.
bool scope_calls_eval_;
// This scope is a strict mode scope.
- bool strict_mode_;
+ StrictModeFlag strict_mode_flag_;
// Source positions.
int start_position_;
int end_position_;
=======================================
--- /branches/bleeding_edge/src/x64/full-codegen-x64.cc Wed Oct 19 04:36:55
2011
+++ /branches/bleeding_edge/src/x64/full-codegen-x64.cc Mon Oct 24 00:47:22
2011
@@ -1055,7 +1055,7 @@
!pretenure &&
scope()->is_function_scope() &&
info->num_literals() == 0) {
- FastNewClosureStub stub(info->strict_mode() ? kStrictMode :
kNonStrictMode);
+ FastNewClosureStub stub(info->strict_mode_flag());
__ Push(info);
__ CallStub(&stub);
} else {
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Thu Oct 20
03:26:45 2011
+++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Mon Oct 24
00:47:22 2011
@@ -4034,8 +4034,7 @@
Handle<SharedFunctionInfo> 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());
__ Push(shared_info);
CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
} else {
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.h Thu Oct 20
03:26:45 2011
+++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.h Mon Oct 24
00:47:22 2011
@@ -126,8 +126,8 @@
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_; }
=======================================
--- /branches/bleeding_edge/src/x64/lithium-x64.h Wed Oct 19 05:10:18 2011
+++ /branches/bleeding_edge/src/x64/lithium-x64.h Mon Oct 24 00:47:22 2011
@@ -1572,7 +1572,8 @@
LOperand* object() { return inputs_[0]; }
LOperand* value() { return inputs_[1]; }
Handle<Object> 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; }
};
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev