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

Side by Side Diff: src/ic.cc

Issue 12040039: Always fail when trying to store to an undeclared global variable, even if it was found. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix test to check for the exact reference error. Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « src/ic.h ('k') | src/stub-cache.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // Otherwise, it will fail in the lookup step. 535 // Otherwise, it will fail in the lookup step.
536 } 536 }
537 537
538 // Lookup the property in the object. 538 // Lookup the property in the object.
539 LookupResult lookup(isolate()); 539 LookupResult lookup(isolate());
540 LookupForRead(object, name, &lookup); 540 LookupForRead(object, name, &lookup);
541 541
542 if (!lookup.IsFound()) { 542 if (!lookup.IsFound()) {
543 // If the object does not have the requested property, check which 543 // If the object does not have the requested property, check which
544 // exception we need to throw. 544 // exception we need to throw.
545 return IsContextual(object) 545 return IsUndeclaredGlobal(object)
546 ? ReferenceError("not_defined", name) 546 ? ReferenceError("not_defined", name)
547 : TypeError("undefined_method", object, name); 547 : TypeError("undefined_method", object, name);
548 } 548 }
549 549
550 // Lookup is valid: Update inline cache and stub cache. 550 // Lookup is valid: Update inline cache and stub cache.
551 if (FLAG_use_ic) { 551 if (FLAG_use_ic) {
552 UpdateCaches(&lookup, state, extra_ic_state, object, name); 552 UpdateCaches(&lookup, state, extra_ic_state, object, name);
553 } 553 }
554 554
555 // Get the property. 555 // Get the property.
556 PropertyAttributes attr; 556 PropertyAttributes attr;
557 Handle<Object> result = 557 Handle<Object> result =
558 Object::GetProperty(object, object, &lookup, name, &attr); 558 Object::GetProperty(object, object, &lookup, name, &attr);
559 RETURN_IF_EMPTY_HANDLE(isolate(), result); 559 RETURN_IF_EMPTY_HANDLE(isolate(), result);
560 560
561 if (lookup.IsInterceptor() && attr == ABSENT) { 561 if (lookup.IsInterceptor() && attr == ABSENT) {
562 // If the object does not have the requested property, check which 562 // If the object does not have the requested property, check which
563 // exception we need to throw. 563 // exception we need to throw.
564 return IsContextual(object) 564 return IsUndeclaredGlobal(object)
565 ? ReferenceError("not_defined", name) 565 ? ReferenceError("not_defined", name)
566 : TypeError("undefined_method", object, name); 566 : TypeError("undefined_method", object, name);
567 } 567 }
568 568
569 ASSERT(!result->IsTheHole()); 569 ASSERT(!result->IsTheHole());
570 570
571 // Make receiver an object if the callee requires it. Strict mode or builtin 571 // Make receiver an object if the callee requires it. Strict mode or builtin
572 // functions do not wrap the receiver, non-strict functions and objects 572 // functions do not wrap the receiver, non-strict functions and objects
573 // called as functions do. 573 // called as functions do.
574 ReceiverToObjectIfRequired(result, object); 574 ReceiverToObjectIfRequired(result, object);
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 if (FLAG_use_ic) set_target(*generic_stub()); 926 if (FLAG_use_ic) set_target(*generic_stub());
927 return Runtime::GetElementOrCharAt(isolate(), object, index); 927 return Runtime::GetElementOrCharAt(isolate(), object, index);
928 } 928 }
929 929
930 // Named lookup in the object. 930 // Named lookup in the object.
931 LookupResult lookup(isolate()); 931 LookupResult lookup(isolate());
932 LookupForRead(object, name, &lookup); 932 LookupForRead(object, name, &lookup);
933 933
934 // If we did not find a property, check if we need to throw an exception. 934 // If we did not find a property, check if we need to throw an exception.
935 if (!lookup.IsFound()) { 935 if (!lookup.IsFound()) {
936 if (IsContextual(object)) { 936 if (IsUndeclaredGlobal(object)) {
937 return ReferenceError("not_defined", name); 937 return ReferenceError("not_defined", name);
938 } 938 }
939 LOG(isolate(), SuspectReadEvent(*name, *object)); 939 LOG(isolate(), SuspectReadEvent(*name, *object));
940 } 940 }
941 941
942 // Update inline cache and stub cache. 942 // Update inline cache and stub cache.
943 if (FLAG_use_ic) { 943 if (FLAG_use_ic) {
944 UpdateLoadCaches(&lookup, state, object, name); 944 UpdateLoadCaches(&lookup, state, object, name);
945 } 945 }
946 946
947 PropertyAttributes attr; 947 PropertyAttributes attr;
948 if (lookup.IsInterceptor() || lookup.IsHandler()) { 948 if (lookup.IsInterceptor() || lookup.IsHandler()) {
949 // Get the property. 949 // Get the property.
950 Handle<Object> result = 950 Handle<Object> result =
951 Object::GetProperty(object, object, &lookup, name, &attr); 951 Object::GetProperty(object, object, &lookup, name, &attr);
952 RETURN_IF_EMPTY_HANDLE(isolate(), result); 952 RETURN_IF_EMPTY_HANDLE(isolate(), result);
953 // If the property is not present, check if we need to throw an 953 // If the property is not present, check if we need to throw an
954 // exception. 954 // exception.
955 if (attr == ABSENT && IsContextual(object)) { 955 if (attr == ABSENT && IsUndeclaredGlobal(object)) {
956 return ReferenceError("not_defined", name); 956 return ReferenceError("not_defined", name);
957 } 957 }
958 return *result; 958 return *result;
959 } 959 }
960 960
961 // Get the property. 961 // Get the property.
962 return object->GetProperty(*object, &lookup, *name, &attr); 962 return object->GetProperty(*object, &lookup, *name, &attr);
963 } 963 }
964 964
965 965
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 TRACE_IC("StoreIC", name, state, *stub); 1456 TRACE_IC("StoreIC", name, state, *stub);
1457 } 1457 }
1458 return receiver->SetProperty(*name, *value, NONE, strict_mode, store_mode); 1458 return receiver->SetProperty(*name, *value, NONE, strict_mode, store_mode);
1459 } 1459 }
1460 1460
1461 LookupResult lookup(isolate()); 1461 LookupResult lookup(isolate());
1462 if (LookupForWrite(receiver, name, &lookup)) { 1462 if (LookupForWrite(receiver, name, &lookup)) {
1463 if (FLAG_use_ic) { 1463 if (FLAG_use_ic) {
1464 UpdateStoreCaches(&lookup, state, strict_mode, receiver, name, value); 1464 UpdateStoreCaches(&lookup, state, strict_mode, receiver, name, value);
1465 } 1465 }
1466 } else if (strict_mode == kStrictMode && 1466 } else if (strict_mode == kStrictMode && IsUndeclaredGlobal(object)) {
1467 !lookup.IsFound() && 1467 // Strict mode doesn't allow setting non-existent global property.
1468 IsContextual(object)) {
1469 // Strict mode doesn't allow setting non-existent global property
1470 // or an assignment to a read only property.
1471 return ReferenceError("not_defined", name); 1468 return ReferenceError("not_defined", name);
1472 } 1469 }
1473 1470
1474 // Set the property. 1471 // Set the property.
1475 return receiver->SetProperty(*name, *value, NONE, strict_mode, store_mode); 1472 return receiver->SetProperty(*name, *value, NONE, strict_mode, store_mode);
1476 } 1473 }
1477 1474
1478 1475
1479 void StoreIC::UpdateStoreCaches(LookupResult* lookup, 1476 void StoreIC::UpdateStoreCaches(LookupResult* lookup,
1480 State state, 1477 State state,
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2673 #undef ADDR 2670 #undef ADDR
2674 }; 2671 };
2675 2672
2676 2673
2677 Address IC::AddressFromUtilityId(IC::UtilityId id) { 2674 Address IC::AddressFromUtilityId(IC::UtilityId id) {
2678 return IC_utilities[id]; 2675 return IC_utilities[id];
2679 } 2676 }
2680 2677
2681 2678
2682 } } // namespace v8::internal 2679 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ic.h ('k') | src/stub-cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698