Revision: 12384
Author: [email protected]
Date: Mon Aug 27 02:40:26 2012
Log: Introduce global contexts to represent lexical global scope(s).
They are yet unused; actual allocation of global lexical bindings in these
contexts is implemented in a separate follow-up CL.
[email protected]
BUG=
Review URL: https://chromiumcodereview.appspot.com/10876067
http://code.google.com/p/v8/source/detail?r=12384
Modified:
/branches/bleeding_edge/include/v8.h
/branches/bleeding_edge/src/arm/full-codegen-arm.cc
/branches/bleeding_edge/src/contexts.cc
/branches/bleeding_edge/src/contexts.h
/branches/bleeding_edge/src/factory.cc
/branches/bleeding_edge/src/factory.h
/branches/bleeding_edge/src/heap.cc
/branches/bleeding_edge/src/heap.h
/branches/bleeding_edge/src/ia32/full-codegen-ia32.cc
/branches/bleeding_edge/src/mips/full-codegen-mips.cc
/branches/bleeding_edge/src/objects-debug.cc
/branches/bleeding_edge/src/objects-inl.h
/branches/bleeding_edge/src/objects.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/include/v8.h Fri Aug 24 06:01:52 2012
+++ /branches/bleeding_edge/include/v8.h Mon Aug 27 02:40:26 2012
@@ -3968,7 +3968,7 @@
static const int kNullValueRootIndex = 7;
static const int kTrueValueRootIndex = 8;
static const int kFalseValueRootIndex = 9;
- static const int kEmptySymbolRootIndex = 113;
+ static const int kEmptySymbolRootIndex = 114;
static const int kJSObjectType = 0xaa;
static const int kFirstNonstringType = 0x80;
=======================================
--- /branches/bleeding_edge/src/arm/full-codegen-arm.cc Wed Aug 22 08:08:48
2012
+++ /branches/bleeding_edge/src/arm/full-codegen-arm.cc Mon Aug 27 02:40:26
2012
@@ -184,10 +184,13 @@
// Possibly allocate a local context.
int heap_slots = info->scope()->num_heap_slots() -
Context::MIN_CONTEXT_SLOTS;
if (heap_slots > 0) {
- Comment cmnt(masm_, "[ Allocate local context");
- // Argument to NewContext is the function, which is in r1.
+ // Argument to NewContext is the function, which is still in r1.
+ Comment cmnt(masm_, "[ Allocate context");
__ push(r1);
- if (heap_slots <= FastNewContextStub::kMaximumSlots) {
+ if (FLAG_harmony_scoping && info->scope()->is_global_scope()) {
+ __ Push(info->scope()->GetScopeInfo());
+ __ CallRuntime(Runtime::kNewGlobalContext, 2);
+ } else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
FastNewContextStub stub(heap_slots);
__ CallStub(&stub);
} else {
=======================================
--- /branches/bleeding_edge/src/contexts.cc Fri Aug 17 05:59:00 2012
+++ /branches/bleeding_edge/src/contexts.cc Mon Aug 27 02:40:26 2012
@@ -313,8 +313,8 @@
if (Isolate::Current()->bootstrapper()->IsActive()) return true;
if (!object->IsContext()) return false;
Context* context = Context::cast(object);
- return context->IsNativeContext() || context->IsModuleContext() ||
- !child->IsModuleContext();
+ return context->IsNativeContext() || context->IsGlobalContext() ||
+ context->IsModuleContext() || !child->IsModuleContext();
}
=======================================
--- /branches/bleeding_edge/src/contexts.h Fri Aug 17 05:59:00 2012
+++ /branches/bleeding_edge/src/contexts.h Mon Aug 27 02:40:26 2012
@@ -190,7 +190,8 @@
// Dynamically declared variables/functions are also added
// to lazily allocated extension object. Context::Lookup
// searches the extension object for properties.
-// For block contexts, contains the respective ScopeInfo.
+// For global and block contexts, contains the respective
+// ScopeInfo.
// For module contexts, points back to the respective
JSModule.
//
// [ global_object ] A pointer to the global object. Provided for quick
@@ -363,6 +364,10 @@
Map* map = this->map();
return map == map->GetHeap()->module_context_map();
}
+ bool IsGlobalContext() {
+ Map* map = this->map();
+ return map == map->GetHeap()->global_context_map();
+ }
// Tells whether the native context is marked with out of memory.
inline bool has_out_of_memory();
=======================================
--- /branches/bleeding_edge/src/factory.cc Fri Aug 17 02:03:08 2012
+++ /branches/bleeding_edge/src/factory.cc Mon Aug 27 02:40:26 2012
@@ -290,6 +290,15 @@
isolate()->heap()->AllocateNativeContext(),
Context);
}
+
+
+Handle<Context> Factory::NewGlobalContext(Handle<JSFunction> function,
+ Handle<ScopeInfo> scope_info) {
+ CALL_HEAP_FUNCTION(
+ isolate(),
+ isolate()->heap()->AllocateGlobalContext(*function, *scope_info),
+ Context);
+}
Handle<Context> Factory::NewModuleContext(Handle<ScopeInfo> scope_info) {
=======================================
--- /branches/bleeding_edge/src/factory.h Fri Aug 17 02:03:08 2012
+++ /branches/bleeding_edge/src/factory.h Mon Aug 27 02:40:26 2012
@@ -162,6 +162,10 @@
// Create a global (but otherwise uninitialized) context.
Handle<Context> NewNativeContext();
+ // Create a global context.
+ Handle<Context> NewGlobalContext(Handle<JSFunction> function,
+ Handle<ScopeInfo> scope_info);
+
// Create a module context.
Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
=======================================
--- /branches/bleeding_edge/src/heap.cc Thu Aug 23 14:08:58 2012
+++ /branches/bleeding_edge/src/heap.cc Mon Aug 27 02:40:26 2012
@@ -2437,6 +2437,12 @@
}
set_module_context_map(Map::cast(obj));
+ { MaybeObject* maybe_obj =
+ AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
+ if (!maybe_obj->ToObject(&obj)) return false;
+ }
+ set_global_context_map(Map::cast(obj));
+
{ MaybeObject* maybe_obj =
AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
if (!maybe_obj->ToObject(&obj)) return false;
@@ -4903,6 +4909,23 @@
ASSERT(result->IsContext());
return result;
}
+
+
+MaybeObject* Heap::AllocateGlobalContext(JSFunction* function,
+ ScopeInfo* scope_info) {
+ Object* result;
+ { MaybeObject* maybe_result =
+ AllocateFixedArray(scope_info->ContextLength(), TENURED);
+ if (!maybe_result->ToObject(&result)) return maybe_result;
+ }
+ Context* context = reinterpret_cast<Context*>(result);
+ context->set_map_no_write_barrier(global_context_map());
+ context->set_closure(function);
+ context->set_extension(scope_info);
+ ASSERT(context->IsGlobalContext());
+ ASSERT(result->IsContext());
+ return context;
+}
MaybeObject* Heap::AllocateModuleContext(ScopeInfo* scope_info) {
=======================================
--- /branches/bleeding_edge/src/heap.h Mon Aug 20 05:09:03 2012
+++ /branches/bleeding_edge/src/heap.h Mon Aug 27 02:40:26 2012
@@ -130,6 +130,7 @@
V(Map, with_context_map,
WithContextMap) \
V(Map, block_context_map,
BlockContextMap) \
V(Map, module_context_map,
ModuleContextMap) \
+ V(Map, global_context_map,
GlobalContextMap) \
V(Map, oddball_map,
OddballMap) \
V(Map, message_object_map,
JSMessageObjectMap) \
V(Map, foreign_map,
ForeignMap) \
@@ -826,6 +827,10 @@
// Allocate a native (but otherwise uninitialized) context.
MUST_USE_RESULT MaybeObject* AllocateNativeContext();
+ // Allocate a global context.
+ MUST_USE_RESULT MaybeObject* AllocateGlobalContext(JSFunction* function,
+ ScopeInfo*
scope_info);
+
// Allocate a module context.
MUST_USE_RESULT MaybeObject* AllocateModuleContext(ScopeInfo*
scope_info);
=======================================
--- /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Wed Aug 22
08:08:48 2012
+++ /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Mon Aug 27
02:40:26 2012
@@ -178,10 +178,13 @@
// Possibly allocate a local context.
int heap_slots = info->scope()->num_heap_slots() -
Context::MIN_CONTEXT_SLOTS;
if (heap_slots > 0) {
- Comment cmnt(masm_, "[ Allocate local context");
+ Comment cmnt(masm_, "[ Allocate context");
// Argument to NewContext is the function, which is still in edi.
__ push(edi);
- if (heap_slots <= FastNewContextStub::kMaximumSlots) {
+ if (FLAG_harmony_scoping && info->scope()->is_global_scope()) {
+ __ Push(info->scope()->GetScopeInfo());
+ __ CallRuntime(Runtime::kNewGlobalContext, 2);
+ } else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
FastNewContextStub stub(heap_slots);
__ CallStub(&stub);
} else {
=======================================
--- /branches/bleeding_edge/src/mips/full-codegen-mips.cc Wed Aug 22
08:08:48 2012
+++ /branches/bleeding_edge/src/mips/full-codegen-mips.cc Mon Aug 27
02:40:26 2012
@@ -192,10 +192,13 @@
// Possibly allocate a local context.
int heap_slots = info->scope()->num_heap_slots() -
Context::MIN_CONTEXT_SLOTS;
if (heap_slots > 0) {
- Comment cmnt(masm_, "[ Allocate local context");
- // Argument to NewContext is the function, which is in a1.
+ Comment cmnt(masm_, "[ Allocate context");
+ // Argument to NewContext is the function, which is still in a1.
__ push(a1);
- if (heap_slots <= FastNewContextStub::kMaximumSlots) {
+ if (FLAG_harmony_scoping && info->scope()->is_global_scope()) {
+ __ Push(info->scope()->GetScopeInfo());
+ __ CallRuntime(Runtime::kNewGlobalContext, 2);
+ } else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
FastNewContextStub stub(heap_slots);
__ CallStub(&stub);
} else {
=======================================
--- /branches/bleeding_edge/src/objects-debug.cc Thu Aug 23 14:08:58 2012
+++ /branches/bleeding_edge/src/objects-debug.cc Mon Aug 27 02:40:26 2012
@@ -382,7 +382,8 @@
void JSModule::JSModuleVerify() {
VerifyObjectField(kContextOffset);
VerifyObjectField(kScopeInfoOffset);
- CHECK(context()->IsUndefined() || context()->IsModuleContext());
+ CHECK(context()->IsUndefined() ||
+ Context::cast(context())->IsModuleContext());
}
=======================================
--- /branches/bleeding_edge/src/objects-inl.h Thu Aug 23 14:08:58 2012
+++ /branches/bleeding_edge/src/objects-inl.h Mon Aug 27 02:40:26 2012
@@ -568,17 +568,16 @@
bool Object::IsContext() {
- if (Object::IsHeapObject()) {
- Map* map = HeapObject::cast(this)->map();
- Heap* heap = map->GetHeap();
- return (map == heap->function_context_map() ||
- map == heap->catch_context_map() ||
- map == heap->with_context_map() ||
- map == heap->native_context_map() ||
- map == heap->block_context_map() ||
- map == heap->module_context_map());
- }
- return false;
+ if (!Object::IsHeapObject()) return false;
+ Map* map = HeapObject::cast(this)->map();
+ Heap* heap = map->GetHeap();
+ return (map == heap->function_context_map() ||
+ map == heap->catch_context_map() ||
+ map == heap->with_context_map() ||
+ map == heap->native_context_map() ||
+ map == heap->block_context_map() ||
+ map == heap->module_context_map() ||
+ map == heap->global_context_map());
}
@@ -587,13 +586,6 @@
HeapObject::cast(this)->map() ==
HeapObject::cast(this)->GetHeap()->native_context_map();
}
-
-
-bool Object::IsModuleContext() {
- return Object::IsHeapObject() &&
- HeapObject::cast(this)->map() ==
- HeapObject::cast(this)->GetHeap()->module_context_map();
-}
bool Object::IsScopeInfo() {
=======================================
--- /branches/bleeding_edge/src/objects.h Thu Aug 23 14:08:58 2012
+++ /branches/bleeding_edge/src/objects.h Mon Aug 27 02:40:26 2012
@@ -809,7 +809,6 @@
V(FixedDoubleArray) \
V(Context) \
V(NativeContext) \
- V(ModuleContext) \
V(ScopeInfo) \
V(JSFunction) \
V(Code) \
=======================================
--- /branches/bleeding_edge/src/runtime.cc Tue Aug 21 02:46:23 2012
+++ /branches/bleeding_edge/src/runtime.cc Mon Aug 27 02:40:26 2012
@@ -8736,6 +8736,23 @@
RUNTIME_ASSERT(!args[0]->IsJSFunction());
return *Execution::GetConstructorDelegate(args.at<Object>(0));
}
+
+
+RUNTIME_FUNCTION(MaybeObject*, Runtime_NewGlobalContext) {
+ NoHandleAllocation ha;
+ ASSERT(args.length() == 2);
+
+ CONVERT_ARG_CHECKED(JSFunction, function, 0);
+ CONVERT_ARG_CHECKED(ScopeInfo, scope_info, 1);
+ Context* result;
+ MaybeObject* maybe_result =
+ isolate->heap()->AllocateGlobalContext(function, scope_info);
+ if (!maybe_result->To(&result)) return maybe_result;
+
+ isolate->set_context(result);
+
+ return result; // non-failure
+}
RUNTIME_FUNCTION(MaybeObject*, Runtime_NewFunctionContext) {
@@ -8744,13 +8761,12 @@
CONVERT_ARG_CHECKED(JSFunction, function, 0);
int length = function->shared()->scope_info()->ContextLength();
- Object* result;
- { MaybeObject* maybe_result =
- isolate->heap()->AllocateFunctionContext(length, function);
- if (!maybe_result->ToObject(&result)) return maybe_result;
- }
+ Context* result;
+ MaybeObject* maybe_result =
+ isolate->heap()->AllocateFunctionContext(length, function);
+ if (!maybe_result->To(&result)) return maybe_result;
- isolate->set_context(Context::cast(result));
+ isolate->set_context(result);
return result; // non-failure
}
=======================================
--- /branches/bleeding_edge/src/runtime.h Thu Jul 19 11:58:23 2012
+++ /branches/bleeding_edge/src/runtime.h Mon Aug 27 02:40:26 2012
@@ -330,6 +330,7 @@
F(PromoteScheduledException, 0, 1) \
\
/* Contexts */ \
+ F(NewGlobalContext, 2, 1) \
F(NewFunctionContext, 1, 1) \
F(PushWithContext, 2, 1) \
F(PushCatchContext, 3, 1) \
=======================================
--- /branches/bleeding_edge/src/scopes.cc Thu Aug 23 01:15:38 2012
+++ /branches/bleeding_edge/src/scopes.cc Mon Aug 27 02:40:26 2012
@@ -227,6 +227,12 @@
for (Scope* s = innermost_scope; s != NULL; s = s->outer_scope()) {
s->scope_inside_with_ = true;
}
+ } else if (context->IsGlobalContext()) {
+ ScopeInfo* scope_info = ScopeInfo::cast(context->extension());
+ current_scope = new(zone) Scope(current_scope,
+ GLOBAL_SCOPE,
+ Handle<ScopeInfo>(scope_info),
+ zone);
} else if (context->IsModuleContext()) {
ScopeInfo* scope_info =
ScopeInfo::cast(context->module()->scope_info());
current_scope = new(zone) Scope(current_scope,
@@ -491,7 +497,7 @@
}
-Variable* Scope::DeclareGlobal(Handle<String> name) {
+Variable* Scope::DeclareDynamicGlobal(Handle<String> name) {
ASSERT(is_global_scope());
return variables_.Declare(this,
name,
@@ -1047,8 +1053,8 @@
break;
case UNBOUND:
- // No binding has been found. Declare a variable in global scope.
- var = info->global_scope()->DeclareGlobal(proxy->name());
+ // No binding has been found. Declare a variable on the global
object.
+ var = info->global_scope()->DeclareDynamicGlobal(proxy->name());
break;
case UNBOUND_EVAL_SHADOWED:
=======================================
--- /branches/bleeding_edge/src/scopes.h Fri Aug 17 02:03:08 2012
+++ /branches/bleeding_edge/src/scopes.h Mon Aug 27 02:40:26 2012
@@ -160,7 +160,7 @@
// global scope. The variable was introduced (possibly from an inner
// scope) by a reference to an unresolved variable with no intervening
// with statements or eval calls.
- Variable* DeclareGlobal(Handle<String> name);
+ Variable* DeclareDynamicGlobal(Handle<String> name);
// Create a new unresolved variable.
template<class Visitor>
=======================================
--- /branches/bleeding_edge/src/x64/full-codegen-x64.cc Wed Aug 22 08:08:48
2012
+++ /branches/bleeding_edge/src/x64/full-codegen-x64.cc Mon Aug 27 02:40:26
2012
@@ -174,10 +174,13 @@
// Possibly allocate a local context.
int heap_slots = info->scope()->num_heap_slots() -
Context::MIN_CONTEXT_SLOTS;
if (heap_slots > 0) {
- Comment cmnt(masm_, "[ Allocate local context");
+ Comment cmnt(masm_, "[ Allocate context");
// Argument to NewContext is the function, which is still in rdi.
__ push(rdi);
- if (heap_slots <= FastNewContextStub::kMaximumSlots) {
+ if (FLAG_harmony_scoping && info->scope()->is_global_scope()) {
+ __ Push(info->scope()->GetScopeInfo());
+ __ CallRuntime(Runtime::kNewGlobalContext, 2);
+ } else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
FastNewContextStub stub(heap_slots);
__ CallStub(&stub);
} else {
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev