Index: src/runtime.cc |
diff --git a/src/runtime.cc b/src/runtime.cc |
index 2f1f54c6965cab37030644e5d29e3794a7c9c0cd..1ef2dad7396166213cd10df6ef1c585182d87cee 100644 |
--- a/src/runtime.cc |
+++ b/src/runtime.cc |
@@ -7049,7 +7049,7 @@ static MaybeObject* Runtime_PushCatchContext(Arguments args) { |
} |
-static MaybeObject* Runtime_LookupContext(Arguments args) { |
+static MaybeObject* Runtime_DeleteContextSlot(Arguments args) { |
HandleScope scope; |
ASSERT(args.length() == 2); |
@@ -7059,16 +7059,31 @@ static MaybeObject* Runtime_LookupContext(Arguments args) { |
int index; |
PropertyAttributes attributes; |
ContextLookupFlags flags = FOLLOW_CHAINS; |
- Handle<Object> holder = |
- context->Lookup(name, flags, &index, &attributes); |
+ Handle<Object> holder = context->Lookup(name, flags, &index, &attributes); |
+ |
+ // If the slot was not found the result is true. |
+ if (holder.is_null()) { |
+ return Heap::true_value(); |
+ } |
- if (index < 0 && !holder.is_null()) { |
- ASSERT(holder->IsJSObject()); |
- return *holder; |
+ // If the slot was found in a context, it should be DONT_DELETE. |
Mads Ager (chromium)
2011/01/24 13:15:19
Can we assert that this is always the case or is t
|
+ if (holder->IsContext()) { |
+ return Heap::false_value(); |
} |
- // No intermediate context found. Use global object by default. |
- return Top::context()->global(); |
+ // The slot was found in a JSObject, either a context extension object, |
+ // the global object, or an arguments object. Try to delete it |
+ // (respecting DONT_DELETE). For consistency with V8's usual behavior, |
+ // which allows deleting all parameters in functions that mention |
+ // 'arguments', we do this even for the case of slots found on an |
+ // arguments object. The slot was found on an arguments object if the |
+ // index is non-negative. |
+ Handle<JSObject> object = Handle<JSObject>::cast(holder); |
+ if (index >= 0) { |
+ return object->DeleteElement(index, JSObject::NORMAL_DELETION); |
+ } else { |
+ return object->DeleteProperty(*name, JSObject::NORMAL_DELETION); |
+ } |
} |
@@ -7141,8 +7156,7 @@ static ObjectPair LoadContextSlotHelper(Arguments args, bool throw_error) { |
int index; |
PropertyAttributes attributes; |
ContextLookupFlags flags = FOLLOW_CHAINS; |
- Handle<Object> holder = |
- context->Lookup(name, flags, &index, &attributes); |
+ Handle<Object> holder = context->Lookup(name, flags, &index, &attributes); |
// If the index is non-negative, the slot has been found in a local |
// variable or a parameter. Read it from the context object or the |
@@ -7209,8 +7223,7 @@ static MaybeObject* Runtime_StoreContextSlot(Arguments args) { |
int index; |
PropertyAttributes attributes; |
ContextLookupFlags flags = FOLLOW_CHAINS; |
- Handle<Object> holder = |
- context->Lookup(name, flags, &index, &attributes); |
+ Handle<Object> holder = context->Lookup(name, flags, &index, &attributes); |
if (index >= 0) { |
if (holder->IsContext()) { |