Index: src/runtime/runtime-scopes.cc |
diff --git a/src/runtime/runtime-scopes.cc b/src/runtime/runtime-scopes.cc |
index c0b7efe1dca13d53843a6a3d5423764817baf381..92dfcad66ec78a9c55e143663434e5140fdd2509 100644 |
--- a/src/runtime/runtime-scopes.cc |
+++ b/src/runtime/runtime-scopes.cc |
@@ -44,7 +44,7 @@ Object* ThrowRedeclarationError(Isolate* isolate, Handle<String> name, |
Object* DeclareGlobal( |
Isolate* isolate, Handle<JSGlobalObject> global, Handle<String> name, |
Handle<Object> value, PropertyAttributes attr, bool is_var, |
- bool is_function, RedeclarationType redeclaration_type, |
+ bool is_function_declaration, RedeclarationType redeclaration_type, |
Handle<TypeFeedbackVector> feedback_vector = Handle<TypeFeedbackVector>(), |
FeedbackVectorSlot slot = FeedbackVectorSlot::Invalid()) { |
Handle<ScriptContextTable> script_contexts( |
@@ -60,7 +60,14 @@ Object* DeclareGlobal( |
} |
// Do the lookup own properties only, see ES5 erratum. |
- LookupIterator it(global, name, global, LookupIterator::OWN_SKIP_INTERCEPTOR); |
+ LookupIterator::Configuration lookup_config( |
+ LookupIterator::Configuration::OWN_SKIP_INTERCEPTOR); |
+ if (is_function_declaration) { |
+ // For function declarations, use the interceptor on the declaration. For |
+ // non-functions, use it only on initialization. |
+ lookup_config = LookupIterator::Configuration::OWN; |
+ } |
+ LookupIterator it(global, name, global, lookup_config); |
Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
if (!maybe.IsJust()) return isolate->heap()->exception(); |
@@ -71,7 +78,7 @@ Object* DeclareGlobal( |
// Skip var re-declarations. |
if (is_var) return isolate->heap()->undefined_value(); |
- DCHECK(is_function); |
+ DCHECK(is_function_declaration); |
if ((old_attributes & DONT_DELETE) != 0) { |
// Only allow reconfiguring globals to functions in user code (no |
// natives, which are marked as read-only). |
@@ -83,9 +90,9 @@ Object* DeclareGlobal( |
if (old_details.IsReadOnly() || old_details.IsDontEnum() || |
(it.state() == LookupIterator::ACCESSOR && |
it.GetAccessors()->IsAccessorPair())) { |
- // ES#sec-globaldeclarationinstantiation 5.d: |
+ // ECMA-262 section 15.1.11 GlobalDeclarationInstantiation 5.d: |
// If hasRestrictedGlobal is true, throw a SyntaxError exception. |
- // ES#sec-evaldeclarationinstantiation 8.a.iv.1.b: |
+ // ECMA-262 section 18.2.1.3 EvalDeclarationInstantiation 8.a.iv.1.b: |
// If fnDefinable is false, throw a TypeError exception. |
return ThrowRedeclarationError(isolate, name, redeclaration_type); |
} |
@@ -102,6 +109,10 @@ Object* DeclareGlobal( |
if (it.state() == LookupIterator::ACCESSOR) it.Delete(); |
} |
+ if (is_function_declaration) { |
+ it.Restart(); |
+ } |
+ |
// Define or redefine own property. |
RETURN_FAILURE_ON_EXCEPTION( |
isolate, JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, attr)); |