Skip to content

Commit ef01bf0

Browse files
A collection of context-related refactoring changes.
Introduce separate maps for function and with contexts. Use the function context map for testing whether a context is a function context (global contexts are no longer function contexts). Split the paths for allocating with and catch contexts. Rename some functions. Generally refactor code to make it simpler. [email protected] BUG= TEST= Review URL: http://codereview.chromium.org/7003058 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@8231 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
1 parent e1eb6fb commit ef01bf0

27 files changed

+218
-295
lines changed

src/arm/code-stubs-arm.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void FastNewContextStub::Generate(MacroAssembler* masm) {
158158
__ ldr(r3, MemOperand(sp, 0));
159159

160160
// Setup the object header.
161-
__ LoadRoot(r2, Heap::kContextMapRootIndex);
161+
__ LoadRoot(r2, Heap::kFunctionContextMapRootIndex);
162162
__ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
163163
__ mov(r2, Operand(Smi::FromInt(length)));
164164
__ str(r2, FieldMemOperand(r0, FixedArray::kLengthOffset));
@@ -187,7 +187,7 @@ void FastNewContextStub::Generate(MacroAssembler* masm) {
187187

188188
// Need to collect. Call into runtime system.
189189
__ bind(&gc);
190-
__ TailCallRuntime(Runtime::kNewContext, 1, 1);
190+
__ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1);
191191
}
192192

193193

src/arm/full-codegen-arm.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
182182
FastNewContextStub stub(heap_slots);
183183
__ CallStub(&stub);
184184
} else {
185-
__ CallRuntime(Runtime::kNewContext, 1);
185+
__ CallRuntime(Runtime::kNewFunctionContext, 1);
186186
}
187187
function_in_register = false;
188188
// Context is returned in both r0 and cp. It replaces the context

src/arm/lithium-codegen-arm.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ bool LCodeGen::GeneratePrologue() {
189189
FastNewContextStub stub(heap_slots);
190190
__ CallStub(&stub);
191191
} else {
192-
__ CallRuntime(Runtime::kNewContext, 1);
192+
__ CallRuntime(Runtime::kNewFunctionContext, 1);
193193
}
194194
RecordSafepoint(Safepoint::kNoDeoptimizationIndex);
195195
// Context is returned in both r0 and cp. It replaces the context

src/ast.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,12 @@ bool ForInStatement::IsInlineable() const {
362362
}
363363

364364

365-
bool WithEnterStatement::IsInlineable() const {
365+
bool EnterWithContextStatement::IsInlineable() const {
366366
return false;
367367
}
368368

369369

370-
bool WithExitStatement::IsInlineable() const {
370+
bool ExitContextStatement::IsInlineable() const {
371371
return false;
372372
}
373373

src/ast.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ namespace internal {
6060
V(ContinueStatement) \
6161
V(BreakStatement) \
6262
V(ReturnStatement) \
63-
V(WithEnterStatement) \
64-
V(WithExitStatement) \
63+
V(EnterWithContextStatement) \
64+
V(ExitContextStatement) \
6565
V(SwitchStatement) \
6666
V(DoWhileStatement) \
6767
V(WhileStatement) \
@@ -611,12 +611,12 @@ class ReturnStatement: public Statement {
611611
};
612612

613613

614-
class WithEnterStatement: public Statement {
614+
class EnterWithContextStatement: public Statement {
615615
public:
616-
explicit WithEnterStatement(Expression* expression)
616+
explicit EnterWithContextStatement(Expression* expression)
617617
: expression_(expression) { }
618618

619-
DECLARE_NODE_TYPE(WithEnterStatement)
619+
DECLARE_NODE_TYPE(EnterWithContextStatement)
620620

621621
Expression* expression() const { return expression_; }
622622

@@ -627,13 +627,11 @@ class WithEnterStatement: public Statement {
627627
};
628628

629629

630-
class WithExitStatement: public Statement {
630+
class ExitContextStatement: public Statement {
631631
public:
632-
WithExitStatement() { }
633-
634632
virtual bool IsInlineable() const;
635633

636-
DECLARE_NODE_TYPE(WithExitStatement)
634+
DECLARE_NODE_TYPE(ExitContextStatement)
637635
};
638636

639637

src/contexts.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags,
9696
PrintF("\n");
9797
}
9898

99-
// check extension/with object
99+
// Check extension/with/global object.
100100
if (context->has_extension()) {
101101
Handle<JSObject> extension = Handle<JSObject>(context->extension(),
102102
isolate);
@@ -119,7 +119,8 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags,
119119
}
120120
}
121121

122-
if (context->is_function_context()) {
122+
// Only functions can have locals, parameters, and a function name.
123+
if (context->IsFunctionContext()) {
123124
// we have context-local slots
124125

125126
// check non-parameter locals in context
@@ -189,9 +190,8 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags,
189190
// proceed with enclosing context
190191
if (context->IsGlobalContext()) {
191192
follow_context_chain = false;
192-
} else if (context->is_function_context()) {
193-
context = Handle<Context>(Context::cast(context->closure()->context()),
194-
isolate);
193+
} else if (context->IsFunctionContext()) {
194+
context = Handle<Context>(context->closure()->context(), isolate);
195195
} else {
196196
context = Handle<Context>(context->previous(), isolate);
197197
}
@@ -212,11 +212,12 @@ bool Context::GlobalIfNotShadowedByEval(Handle<String> name) {
212212
// before the global context and check that there are no context
213213
// extension objects (conservative check for with statements).
214214
while (!context->IsGlobalContext()) {
215-
// Check if the context is a potentially a with context.
215+
// Check if the context is a catch or with context, or has called
216+
// non-strict eval.
216217
if (context->has_extension()) return false;
217218

218219
// Not a with context so it must be a function context.
219-
ASSERT(context->is_function_context());
220+
ASSERT(context->IsFunctionContext());
220221

221222
// Check non-parameter locals.
222223
Handle<SerializedScopeInfo> scope_info(

src/contexts.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,17 @@ class Context: public FixedArray {
289289
// Compute the global context by traversing the context chain.
290290
Context* global_context();
291291

292-
// Tells if this is a function context (as opposed to a 'with' context).
293-
bool is_function_context() { return unchecked_previous() == NULL; }
292+
// Predicates for context types. IsGlobalContext is defined on Object
293+
// because we frequently have to know if arbitrary objects are global
294+
// contexts.
295+
bool IsFunctionContext() {
296+
Map* map = this->map();
297+
return map == map->GetHeap()->function_context_map();
298+
}
299+
bool IsCatchContext() {
300+
Map* map = this->map();
301+
return map == map->GetHeap()->catch_context_map();
302+
}
294303

295304
// Tells whether the global context is marked with out of memory.
296305
inline bool has_out_of_memory();

src/factory.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,20 @@ Handle<Context> Factory::NewFunctionContext(int length,
249249
}
250250

251251

252+
Handle<Context> Factory::NewCatchContext(Handle<Context> previous,
253+
Handle<JSObject> extension) {
254+
CALL_HEAP_FUNCTION(
255+
isolate(),
256+
isolate()->heap()->AllocateCatchContext(*previous, *extension),
257+
Context);
258+
}
259+
260+
252261
Handle<Context> Factory::NewWithContext(Handle<Context> previous,
253-
Handle<JSObject> extension,
254-
bool is_catch_context) {
262+
Handle<JSObject> extension) {
255263
CALL_HEAP_FUNCTION(
256264
isolate(),
257-
isolate()->heap()->AllocateWithContext(*previous,
258-
*extension,
259-
is_catch_context),
265+
isolate()->heap()->AllocateWithContext(*previous, *extension),
260266
Context);
261267
}
262268

src/factory.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,13 @@ class Factory {
149149
Handle<Context> NewFunctionContext(int length,
150150
Handle<JSFunction> closure);
151151

152+
// Create a catch context.
153+
Handle<Context> NewCatchContext(Handle<Context> previous,
154+
Handle<JSObject> extension);
155+
152156
// Create a 'with' context.
153157
Handle<Context> NewWithContext(Handle<Context> previous,
154-
Handle<JSObject> extension,
155-
bool is_catch_context);
158+
Handle<JSObject> extension);
156159

157160
// Return the Symbol matching the passed in string.
158161
Handle<String> SymbolFromString(Handle<String> value);

src/full-codegen.cc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ void BreakableStatementChecker::VisitReturnStatement(ReturnStatement* stmt) {
9090
}
9191

9292

93-
void BreakableStatementChecker::VisitWithEnterStatement(
94-
WithEnterStatement* stmt) {
93+
void BreakableStatementChecker::VisitEnterWithContextStatement(
94+
EnterWithContextStatement* stmt) {
9595
Visit(stmt->expression());
9696
}
9797

9898

99-
void BreakableStatementChecker::VisitWithExitStatement(
100-
WithExitStatement* stmt) {
99+
void BreakableStatementChecker::VisitExitContextStatement(
100+
ExitContextStatement* stmt) {
101101
}
102102

103103

@@ -952,18 +952,19 @@ void FullCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) {
952952
}
953953

954954

955-
void FullCodeGenerator::VisitWithEnterStatement(WithEnterStatement* stmt) {
956-
Comment cmnt(masm_, "[ WithEnterStatement");
955+
void FullCodeGenerator::VisitEnterWithContextStatement(
956+
EnterWithContextStatement* stmt) {
957+
Comment cmnt(masm_, "[ EnterWithContextStatement");
957958
SetStatementPosition(stmt);
958959

959960
VisitForStackValue(stmt->expression());
960-
__ CallRuntime(Runtime::kPushContext, 1);
961+
__ CallRuntime(Runtime::kPushWithContext, 1);
961962
StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
962963
}
963964

964965

965-
void FullCodeGenerator::VisitWithExitStatement(WithExitStatement* stmt) {
966-
Comment cmnt(masm_, "[ WithExitStatement");
966+
void FullCodeGenerator::VisitExitContextStatement(ExitContextStatement* stmt) {
967+
Comment cmnt(masm_, "[ ExitContextStatement");
967968
SetStatementPosition(stmt);
968969

969970
// Pop context.

0 commit comments

Comments
 (0)