Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: src/runtime/runtime-scopes.cc

Issue 2206483004: Sloppy eval declarations should not shadow lexical function declarations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/contexts.cc ('k') | test/mjsunit/es6/block-eval-var-over-let.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/arguments.h" 10 #include "src/arguments.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 context->IsScriptContext() || 260 context->IsScriptContext() ||
261 (context->IsBlockContext() && context->has_extension())); 261 (context->IsBlockContext() && context->has_extension()));
262 262
263 bool is_function = value->IsJSFunction(); 263 bool is_function = value->IsJSFunction();
264 bool is_var = !is_function; 264 bool is_var = !is_function;
265 DCHECK(!is_var || value->IsUndefined(isolate)); 265 DCHECK(!is_var || value->IsUndefined(isolate));
266 266
267 int index; 267 int index;
268 PropertyAttributes attributes; 268 PropertyAttributes attributes;
269 BindingFlags binding_flags; 269 BindingFlags binding_flags;
270 VariableMode mode;
270 271
271 // Check for a conflict with a lexically scoped variable 272 // Check for a conflict with a lexically scoped variable
272 context_arg->Lookup(name, LEXICAL_TEST, &index, &attributes, &binding_flags); 273 context_arg->Lookup(name, LEXICAL_TEST, &index, &attributes, &binding_flags,
273 if (attributes != ABSENT && binding_flags == BINDING_CHECK_INITIALIZED) { 274 &mode);
275 if (attributes != ABSENT && IsLexicalVariableMode(mode)) {
274 // ES#sec-evaldeclarationinstantiation 5.a.i.1: 276 // ES#sec-evaldeclarationinstantiation 5.a.i.1:
275 // If varEnvRec.HasLexicalDeclaration(name) is true, throw a SyntaxError 277 // If varEnvRec.HasLexicalDeclaration(name) is true, throw a SyntaxError
276 // exception. 278 // exception.
277 // ES#sec-evaldeclarationinstantiation 5.d.ii.2.a.i: 279 // ES#sec-evaldeclarationinstantiation 5.d.ii.2.a.i:
278 // Throw a SyntaxError exception. 280 // Throw a SyntaxError exception.
279 return ThrowRedeclarationError(isolate, name, 281 return ThrowRedeclarationError(isolate, name,
280 RedeclarationType::kSyntaxError); 282 RedeclarationType::kSyntaxError);
281 } 283 }
282 284
283 Handle<Object> holder = context->Lookup(name, DONT_FOLLOW_CHAINS, &index, 285 Handle<Object> holder = context->Lookup(name, DONT_FOLLOW_CHAINS, &index,
284 &attributes, &binding_flags); 286 &attributes, &binding_flags, &mode);
285 DCHECK(!isolate->has_pending_exception()); 287 DCHECK(!isolate->has_pending_exception());
286 288
287 Handle<JSObject> object; 289 Handle<JSObject> object;
288 290
289 if (attributes != ABSENT && holder->IsJSGlobalObject()) { 291 if (attributes != ABSENT && holder->IsJSGlobalObject()) {
290 // ES#sec-evaldeclarationinstantiation 8.a.iv.1.b: 292 // ES#sec-evaldeclarationinstantiation 8.a.iv.1.b:
291 // If fnDefinable is false, throw a TypeError exception. 293 // If fnDefinable is false, throw a TypeError exception.
292 return DeclareGlobal(isolate, Handle<JSGlobalObject>::cast(holder), name, 294 return DeclareGlobal(isolate, Handle<JSGlobalObject>::cast(holder), name,
293 value, NONE, is_var, is_function, 295 value, NONE, is_var, is_function,
294 RedeclarationType::kTypeError); 296 RedeclarationType::kTypeError);
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 766
765 767
766 RUNTIME_FUNCTION(Runtime_DeleteLookupSlot) { 768 RUNTIME_FUNCTION(Runtime_DeleteLookupSlot) {
767 HandleScope scope(isolate); 769 HandleScope scope(isolate);
768 DCHECK_EQ(1, args.length()); 770 DCHECK_EQ(1, args.length());
769 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); 771 CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
770 772
771 int index; 773 int index;
772 PropertyAttributes attributes; 774 PropertyAttributes attributes;
773 BindingFlags flags; 775 BindingFlags flags;
776 VariableMode mode;
774 Handle<Object> holder = isolate->context()->Lookup( 777 Handle<Object> holder = isolate->context()->Lookup(
775 name, FOLLOW_CHAINS, &index, &attributes, &flags); 778 name, FOLLOW_CHAINS, &index, &attributes, &flags, &mode);
776 779
777 // If the slot was not found the result is true. 780 // If the slot was not found the result is true.
778 if (holder.is_null()) { 781 if (holder.is_null()) {
779 // In case of JSProxy, an exception might have been thrown. 782 // In case of JSProxy, an exception might have been thrown.
780 if (isolate->has_pending_exception()) return isolate->heap()->exception(); 783 if (isolate->has_pending_exception()) return isolate->heap()->exception();
781 return isolate->heap()->true_value(); 784 return isolate->heap()->true_value();
782 } 785 }
783 786
784 // If the slot was found in a context, it should be DONT_DELETE. 787 // If the slot was found in a context, it should be DONT_DELETE.
785 if (holder->IsContext()) { 788 if (holder->IsContext()) {
(...skipping 13 matching lines...) Expand all
799 namespace { 802 namespace {
800 803
801 MaybeHandle<Object> LoadLookupSlot(Handle<String> name, 804 MaybeHandle<Object> LoadLookupSlot(Handle<String> name,
802 Object::ShouldThrow should_throw, 805 Object::ShouldThrow should_throw,
803 Handle<Object>* receiver_return = nullptr) { 806 Handle<Object>* receiver_return = nullptr) {
804 Isolate* const isolate = name->GetIsolate(); 807 Isolate* const isolate = name->GetIsolate();
805 808
806 int index; 809 int index;
807 PropertyAttributes attributes; 810 PropertyAttributes attributes;
808 BindingFlags flags; 811 BindingFlags flags;
812 VariableMode mode;
809 Handle<Object> holder = isolate->context()->Lookup( 813 Handle<Object> holder = isolate->context()->Lookup(
810 name, FOLLOW_CHAINS, &index, &attributes, &flags); 814 name, FOLLOW_CHAINS, &index, &attributes, &flags, &mode);
811 if (isolate->has_pending_exception()) return MaybeHandle<Object>(); 815 if (isolate->has_pending_exception()) return MaybeHandle<Object>();
812 816
813 if (index != Context::kNotFound) { 817 if (index != Context::kNotFound) {
814 DCHECK(holder->IsContext()); 818 DCHECK(holder->IsContext());
815 // If the "property" we were looking for is a local variable, the 819 // If the "property" we were looking for is a local variable, the
816 // receiver is the global object; see ECMA-262, 3rd., 10.1.6 and 10.2.3. 820 // receiver is the global object; see ECMA-262, 3rd., 10.1.6 and 10.2.3.
817 Handle<Object> receiver = isolate->factory()->undefined_value(); 821 Handle<Object> receiver = isolate->factory()->undefined_value();
818 Handle<Object> value = handle(Context::cast(*holder)->get(index), isolate); 822 Handle<Object> value = handle(Context::cast(*holder)->get(index), isolate);
819 // Check for uninitialized bindings. 823 // Check for uninitialized bindings.
820 switch (flags) { 824 switch (flags) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 namespace { 906 namespace {
903 907
904 MaybeHandle<Object> StoreLookupSlot(Handle<String> name, Handle<Object> value, 908 MaybeHandle<Object> StoreLookupSlot(Handle<String> name, Handle<Object> value,
905 LanguageMode language_mode) { 909 LanguageMode language_mode) {
906 Isolate* const isolate = name->GetIsolate(); 910 Isolate* const isolate = name->GetIsolate();
907 Handle<Context> context(isolate->context(), isolate); 911 Handle<Context> context(isolate->context(), isolate);
908 912
909 int index; 913 int index;
910 PropertyAttributes attributes; 914 PropertyAttributes attributes;
911 BindingFlags flags; 915 BindingFlags flags;
916 VariableMode mode;
912 Handle<Object> holder = 917 Handle<Object> holder =
913 context->Lookup(name, FOLLOW_CHAINS, &index, &attributes, &flags); 918 context->Lookup(name, FOLLOW_CHAINS, &index, &attributes, &flags, &mode);
914 if (holder.is_null()) { 919 if (holder.is_null()) {
915 // In case of JSProxy, an exception might have been thrown. 920 // In case of JSProxy, an exception might have been thrown.
916 if (isolate->has_pending_exception()) return MaybeHandle<Object>(); 921 if (isolate->has_pending_exception()) return MaybeHandle<Object>();
917 } 922 }
918 923
919 // The property was found in a context slot. 924 // The property was found in a context slot.
920 if (index != Context::kNotFound) { 925 if (index != Context::kNotFound) {
921 if (flags == BINDING_CHECK_INITIALIZED && 926 if (flags == BINDING_CHECK_INITIALIZED &&
922 Handle<Context>::cast(holder)->is_the_hole(index)) { 927 Handle<Context>::cast(holder)->is_the_hole(index)) {
923 THROW_NEW_ERROR(isolate, 928 THROW_NEW_ERROR(isolate,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 RUNTIME_FUNCTION(Runtime_StoreLookupSlot_Strict) { 977 RUNTIME_FUNCTION(Runtime_StoreLookupSlot_Strict) {
973 HandleScope scope(isolate); 978 HandleScope scope(isolate);
974 DCHECK_EQ(2, args.length()); 979 DCHECK_EQ(2, args.length());
975 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); 980 CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
976 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); 981 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
977 RETURN_RESULT_OR_FAILURE(isolate, StoreLookupSlot(name, value, STRICT)); 982 RETURN_RESULT_OR_FAILURE(isolate, StoreLookupSlot(name, value, STRICT));
978 } 983 }
979 984
980 } // namespace internal 985 } // namespace internal
981 } // namespace v8 986 } // namespace v8
OLDNEW
« no previous file with comments | « src/contexts.cc ('k') | test/mjsunit/es6/block-eval-var-over-let.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698