Revert "Clean up Context::Lookup and its uses."

This reverts commit 9241.  This change shows failures on Mac and Win
for the threading tests.  Reverting while I investigate.

R=fschneider@chromium.org
BUG=
TEST=

Review URL: http://codereview.chromium.org/7886002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9246 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 130b9d78
...@@ -86,14 +86,14 @@ void Context::set_global_proxy(JSObject* object) { ...@@ -86,14 +86,14 @@ void Context::set_global_proxy(JSObject* object) {
Handle<Object> Context::Lookup(Handle<String> name, Handle<Object> Context::Lookup(Handle<String> name,
ContextLookupFlags flags, ContextLookupFlags flags,
int* index, int* index_,
PropertyAttributes* attributes, PropertyAttributes* attributes,
BindingFlags* binding_flags) { BindingFlags* binding_flags) {
Isolate* isolate = GetIsolate(); Isolate* isolate = GetIsolate();
Handle<Context> context(this, isolate); Handle<Context> context(this, isolate);
bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0;
*index = -1; *index_ = -1;
*attributes = ABSENT; *attributes = ABSENT;
*binding_flags = MISSING_BINDING; *binding_flags = MISSING_BINDING;
...@@ -110,50 +110,70 @@ Handle<Object> Context::Lookup(Handle<String> name, ...@@ -110,50 +110,70 @@ Handle<Object> Context::Lookup(Handle<String> name,
PrintF("\n"); PrintF("\n");
} }
// 1. Check global objects, subjects of with, and extension objects. // Check extension/with/global object.
if (context->IsGlobalContext() || if (!context->IsBlockContext() && context->has_extension()) {
context->IsWithContext() || if (context->IsCatchContext()) {
(context->IsFunctionContext() && context->has_extension())) { // Catch contexts have the variable name in the extension slot.
Handle<JSObject> object(JSObject::cast(context->extension()), isolate); if (name->Equals(String::cast(context->extension()))) {
// Context extension objects needs to behave as if they have no if (FLAG_trace_contexts) {
// prototype. So even if we want to follow prototype chains, we need PrintF("=> found in catch context\n");
// to only do a local lookup for context extension objects. }
if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || *index_ = Context::THROWN_OBJECT_INDEX;
object->IsJSContextExtensionObject()) { *attributes = NONE;
*attributes = object->GetLocalPropertyAttribute(*name); *binding_flags = MUTABLE_IS_INITIALIZED;
return context;
}
} else { } else {
*attributes = object->GetPropertyAttribute(*name); ASSERT(context->IsGlobalContext() ||
} context->IsFunctionContext() ||
if (*attributes != ABSENT) { context->IsWithContext());
if (FLAG_trace_contexts) { // Global, function, and with contexts may have an object in the
PrintF("=> found property in context object %p\n", // extension slot.
reinterpret_cast<void*>(*object)); Handle<JSObject> extension(JSObject::cast(context->extension()),
isolate);
// Context extension objects needs to behave as if they have no
// prototype. So even if we want to follow prototype chains, we
// need to only do a local lookup for context extension objects.
if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 ||
extension->IsJSContextExtensionObject()) {
*attributes = extension->GetLocalPropertyAttribute(*name);
} else {
*attributes = extension->GetPropertyAttribute(*name);
}
if (*attributes != ABSENT) {
// property found
if (FLAG_trace_contexts) {
PrintF("=> found property in context object %p\n",
reinterpret_cast<void*>(*extension));
}
return extension;
} }
return object;
} }
} }
// 2. Check the context proper if it has slots. // Check serialized scope information of functions and blocks. Only
// functions can have parameters, and a function name.
if (context->IsFunctionContext() || context->IsBlockContext()) { if (context->IsFunctionContext() || context->IsBlockContext()) {
// Use serialized scope information of functions and blocks to search // We may have context-local slots. Check locals in the context.
// for the context index.
Handle<SerializedScopeInfo> scope_info; Handle<SerializedScopeInfo> scope_info;
if (context->IsFunctionContext()) { if (context->IsFunctionContext()) {
scope_info = Handle<SerializedScopeInfo>( scope_info = Handle<SerializedScopeInfo>(
context->closure()->shared()->scope_info(), isolate); context->closure()->shared()->scope_info(), isolate);
} else { } else {
ASSERT(context->IsBlockContext());
scope_info = Handle<SerializedScopeInfo>( scope_info = Handle<SerializedScopeInfo>(
SerializedScopeInfo::cast(context->extension()), isolate); SerializedScopeInfo::cast(context->extension()), isolate);
} }
Variable::Mode mode; Variable::Mode mode;
int slot_index = scope_info->ContextSlotIndex(*name, &mode); int index = scope_info->ContextSlotIndex(*name, &mode);
ASSERT(slot_index < 0 || slot_index >= MIN_CONTEXT_SLOTS); ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS);
if (slot_index >= 0) { if (index >= 0) {
if (FLAG_trace_contexts) { if (FLAG_trace_contexts) {
PrintF("=> found local in context slot %d (mode = %d)\n", PrintF("=> found local in context slot %d (mode = %d)\n",
slot_index, mode); index, mode);
} }
*index = slot_index; *index_ = index;
// Note: Fixed context slots are statically allocated by the compiler. // Note: Fixed context slots are statically allocated by the compiler.
// Statically allocated variables always have a statically known mode, // Statically allocated variables always have a statically known mode,
// which is the mode with which they were declared when added to the // which is the mode with which they were declared when added to the
...@@ -186,34 +206,22 @@ Handle<Object> Context::Lookup(Handle<String> name, ...@@ -186,34 +206,22 @@ Handle<Object> Context::Lookup(Handle<String> name,
// Check the slot corresponding to the intermediate context holding // Check the slot corresponding to the intermediate context holding
// only the function name variable. // only the function name variable.
if (follow_context_chain && context->IsFunctionContext()) { if (follow_context_chain) {
int function_index = scope_info->FunctionContextSlotIndex(*name); int index = scope_info->FunctionContextSlotIndex(*name);
if (function_index >= 0) { if (index >= 0) {
if (FLAG_trace_contexts) { if (FLAG_trace_contexts) {
PrintF("=> found intermediate function in context slot %d\n", PrintF("=> found intermediate function in context slot %d\n",
function_index); index);
} }
*index = function_index; *index_ = index;
*attributes = READ_ONLY; *attributes = READ_ONLY;
*binding_flags = IMMUTABLE_IS_INITIALIZED; *binding_flags = IMMUTABLE_IS_INITIALIZED;
return context; return context;
} }
} }
} else if (context->IsCatchContext()) {
// Catch contexts have the variable name in the extension slot.
if (name->Equals(String::cast(context->extension()))) {
if (FLAG_trace_contexts) {
PrintF("=> found in catch context\n");
}
*index = Context::THROWN_OBJECT_INDEX;
*attributes = NONE;
*binding_flags = MUTABLE_IS_INITIALIZED;
return context;
}
} }
// 3. Prepare to continue with the previous (next outermost) context. // Proceed with the previous context.
if (context->IsGlobalContext()) { if (context->IsGlobalContext()) {
follow_context_chain = false; follow_context_chain = false;
} else { } else {
......
...@@ -330,6 +330,12 @@ class Context: public FixedArray { ...@@ -330,6 +330,12 @@ class Context: public FixedArray {
// Mark the global context with out of memory. // Mark the global context with out of memory.
inline void mark_out_of_memory(); inline void mark_out_of_memory();
// The exception holder is the object used as a with object in
// the implementation of a catch block.
bool is_exception_holder(Object* object) {
return IsCatchContext() && extension() == object;
}
// A global context hold a list of all functions which have been optimized. // A global context hold a list of all functions which have been optimized.
void AddOptimizedFunction(JSFunction* function); void AddOptimizedFunction(JSFunction* function);
void RemoveOptimizedFunction(JSFunction* function); void RemoveOptimizedFunction(JSFunction* function);
...@@ -349,25 +355,29 @@ class Context: public FixedArray { ...@@ -349,25 +355,29 @@ class Context: public FixedArray {
#undef GLOBAL_CONTEXT_FIELD_ACCESSORS #undef GLOBAL_CONTEXT_FIELD_ACCESSORS
// Lookup the the slot called name, starting with the current context. // Lookup the the slot called name, starting with the current context.
// There are three possibilities: // There are 4 possible outcomes:
//
// 1) index_ >= 0 && result->IsContext():
// most common case, the result is a Context, and index is the
// context slot index, and the slot exists.
// attributes == READ_ONLY for the function name variable, NONE otherwise.
// //
// 1) result->IsContext(): // 2) index_ >= 0 && result->IsJSObject():
// The binding was found in a context. *index is always the // the result is the JSObject arguments object, the index is the parameter
// non-negative slot index. *attributes is NONE for var and let // index, i.e., key into the arguments object, and the property exists.
// declarations, READ_ONLY for const declarations (never ABSENT). // attributes != ABSENT.
// //
// 2) result->IsJSObject(): // 3) index_ < 0 && result->IsJSObject():
// The binding was found as a named property in a context extension // the result is the JSObject extension context or the global object,
// object (i.e., was introduced via eval), as a property on the subject // and the name is the property name, and the property exists.
// of with, or as a property of the global object. *index is -1 and // attributes != ABSENT.
// *attributes is not ABSENT.
// //
// 3) result.is_null(): // 4) index_ < 0 && result.is_null():
// There was no binding found, *index is always -1 and *attributes is // there was no context found with the corresponding property.
// always ABSENT. // attributes == ABSENT.
Handle<Object> Lookup(Handle<String> name, Handle<Object> Lookup(Handle<String> name,
ContextLookupFlags flags, ContextLookupFlags flags,
int* index, int* index_,
PropertyAttributes* attributes, PropertyAttributes* attributes,
BindingFlags* binding_flags); BindingFlags* binding_flags);
......
...@@ -4924,6 +4924,7 @@ void HGraphBuilder::VisitCall(Call* expr) { ...@@ -4924,6 +4924,7 @@ void HGraphBuilder::VisitCall(Call* expr) {
} else { } else {
VariableProxy* proxy = expr->expression()->AsVariableProxy(); VariableProxy* proxy = expr->expression()->AsVariableProxy();
// FIXME.
bool global_call = proxy != NULL && proxy->var()->IsUnallocated(); bool global_call = proxy != NULL && proxy->var()->IsUnallocated();
if (global_call) { if (global_call) {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment