Index: src/runtime/runtime-scopes.cc |
diff --git a/src/runtime/runtime-scopes.cc b/src/runtime/runtime-scopes.cc |
index 85148b2991542a33633d0164c979d2ce87e4a387..4363190e3d029c10eb0e3c7c2831cbbe7e124244 100644 |
--- a/src/runtime/runtime-scopes.cc |
+++ b/src/runtime/runtime-scopes.cc |
@@ -16,18 +16,10 @@ |
namespace v8 { |
namespace internal { |
-enum class RedeclarationType { kSyntaxError = 0, kTypeError = 1 }; |
- |
-static Object* ThrowRedeclarationError(Isolate* isolate, Handle<String> name, |
- RedeclarationType redeclaration_type) { |
- HandleScope scope(isolate); |
- if (redeclaration_type == RedeclarationType::kSyntaxError) { |
- THROW_NEW_ERROR_RETURN_FAILURE( |
- isolate, NewSyntaxError(MessageTemplate::kVarRedeclaration, name)); |
- } else { |
- THROW_NEW_ERROR_RETURN_FAILURE( |
- isolate, NewTypeError(MessageTemplate::kVarRedeclaration, name)); |
- } |
+static Object* ThrowRedeclarationError(Isolate* isolate, Handle<String> name) { |
+ HandleScope scope(isolate); |
+ THROW_NEW_ERROR_RETURN_FAILURE( |
+ isolate, NewTypeError(MessageTemplate::kVarRedeclaration, name)); |
} |
@@ -42,18 +34,13 @@ |
static Object* DeclareGlobals(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) { |
Handle<ScriptContextTable> script_contexts( |
global->native_context()->script_context_table()); |
ScriptContextTable::LookupResult lookup; |
if (ScriptContextTable::Lookup(script_contexts, name, &lookup) && |
IsLexicalVariableMode(lookup.mode)) { |
- // ES#sec-globaldeclarationinstantiation 6.a: |
- // If envRec.HasLexicalDeclaration(name) is true, throw a SyntaxError |
- // exception. |
- return ThrowRedeclarationError(isolate, name, |
- RedeclarationType::kSyntaxError); |
+ return ThrowRedeclarationError(isolate, name); |
} |
// Do the lookup own properties only, see ES5 erratum. |
@@ -80,11 +67,7 @@ |
if (old_details.IsReadOnly() || old_details.IsDontEnum() || |
(it.state() == LookupIterator::ACCESSOR && |
it.GetAccessors()->IsAccessorPair())) { |
- // ES#sec-globaldeclarationinstantiation 5.d: |
- // If hasRestrictedGlobal is true, throw a SyntaxError exception. |
- // ES#sec-evaldeclarationinstantiation 8.a.iv.1.b: |
- // If fnDefinable is false, throw a TypeError exception. |
- return ThrowRedeclarationError(isolate, name, redeclaration_type); |
+ return ThrowRedeclarationError(isolate, name); |
} |
// If the existing property is not configurable, keep its attributes. Do |
attr = old_attributes; |
@@ -147,11 +130,9 @@ |
if (is_function && is_native) attr |= READ_ONLY; |
if (!is_eval) attr |= DONT_DELETE; |
- // ES#sec-globaldeclarationinstantiation 5.d: |
- // If hasRestrictedGlobal is true, throw a SyntaxError exception. |
- Object* result = DeclareGlobals( |
- isolate, global, name, value, static_cast<PropertyAttributes>(attr), |
- is_var, is_function, RedeclarationType::kSyntaxError); |
+ Object* result = DeclareGlobals(isolate, global, name, value, |
+ static_cast<PropertyAttributes>(attr), |
+ is_var, is_function); |
if (isolate->has_pending_exception()) return result; |
}); |
@@ -234,13 +215,7 @@ |
context_arg->Lookup(name, LEXICAL_TEST, &index, &attributes, |
&binding_flags); |
if (attributes != ABSENT && binding_flags == BINDING_CHECK_INITIALIZED) { |
- // ES#sec-evaldeclarationinstantiation 5.a.i.1: |
- // If varEnvRec.HasLexicalDeclaration(name) is true, throw a SyntaxError |
- // exception. |
- // ES#sec-evaldeclarationinstantiation 5.d.ii.2.a.i: |
- // Throw a SyntaxError exception. |
- return ThrowRedeclarationError(isolate, name, |
- RedeclarationType::kSyntaxError); |
+ return ThrowRedeclarationError(isolate, name); |
} |
attr = static_cast<PropertyAttributes>(attr & ~EVAL_DECLARED); |
} |
@@ -260,30 +235,26 @@ |
// TODO(verwaest): This case should probably not be covered by this function, |
// but by DeclareGlobals instead. |
if (attributes != ABSENT && holder->IsJSGlobalObject()) { |
- // ES#sec-evaldeclarationinstantiation 8.a.iv.1.b: |
- // If fnDefinable is false, throw a TypeError exception. |
return DeclareGlobals(isolate, Handle<JSGlobalObject>::cast(holder), name, |
- value, attr, is_var, is_function, |
- RedeclarationType::kTypeError); |
+ value, attr, is_var, is_function); |
} |
if (context_arg->extension()->IsJSGlobalObject()) { |
Handle<JSGlobalObject> global( |
JSGlobalObject::cast(context_arg->extension()), isolate); |
return DeclareGlobals(isolate, global, name, value, attr, is_var, |
- is_function, RedeclarationType::kTypeError); |
+ is_function); |
} else if (context->IsScriptContext()) { |
DCHECK(context->global_object()->IsJSGlobalObject()); |
Handle<JSGlobalObject> global( |
JSGlobalObject::cast(context->global_object()), isolate); |
return DeclareGlobals(isolate, global, name, value, attr, is_var, |
- is_function, RedeclarationType::kTypeError); |
+ is_function); |
} |
if (attributes != ABSENT) { |
// The name was declared before; check for conflicting re-declarations. |
if ((attributes & READ_ONLY) != 0) { |
- return ThrowRedeclarationError(isolate, name, |
- RedeclarationType::kSyntaxError); |
+ return ThrowRedeclarationError(isolate, name); |
} |
// Skip var re-declarations. |
@@ -622,11 +593,7 @@ |
ScriptContextTable::LookupResult lookup; |
if (ScriptContextTable::Lookup(script_context, name, &lookup)) { |
if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(lookup.mode)) { |
- // ES#sec-globaldeclarationinstantiation 5.b: |
- // If envRec.HasLexicalDeclaration(name) is true, throw a SyntaxError |
- // exception. |
- return ThrowRedeclarationError(isolate, name, |
- RedeclarationType::kSyntaxError); |
+ return ThrowRedeclarationError(isolate, name); |
} |
} |
@@ -636,13 +603,7 @@ |
Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
if (!maybe.IsJust()) return isolate->heap()->exception(); |
if ((maybe.FromJust() & DONT_DELETE) != 0) { |
- // ES#sec-globaldeclarationinstantiation 5.a: |
- // If envRec.HasVarDeclaration(name) is true, throw a SyntaxError |
- // exception. |
- // ES#sec-globaldeclarationinstantiation 5.d: |
- // If hasRestrictedGlobal is true, throw a SyntaxError exception. |
- return ThrowRedeclarationError(isolate, name, |
- RedeclarationType::kSyntaxError); |
+ return ThrowRedeclarationError(isolate, name); |
} |
JSGlobalObject::InvalidatePropertyCell(global_object, name); |