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

Side by Side Diff: test/cctest/test-api.cc

Issue 3587002: Backport r5553 "Do not invoke indexed interceptor getters for negative indice... (Closed) Base URL: http://v8.googlecode.com/svn/branches/2.1/
Patch Set: Created 10 years, 2 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/x64/ic-x64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 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 2737 matching lines...) Expand 10 before | Expand all | Expand 10 after
2748 result = interceptor_setter_script->Run(); 2748 result = interceptor_setter_script->Run();
2749 CHECK_EQ(v8_num(23), result); 2749 CHECK_EQ(v8_num(23), result);
2750 result = interceptor_getter_script->Run(); 2750 result = interceptor_getter_script->Run();
2751 CHECK_EQ(v8_num(625), result); 2751 CHECK_EQ(v8_num(625), result);
2752 } 2752 }
2753 2753
2754 2754
2755 static v8::Handle<Value> IdentityIndexedPropertyGetter( 2755 static v8::Handle<Value> IdentityIndexedPropertyGetter(
2756 uint32_t index, 2756 uint32_t index,
2757 const AccessorInfo& info) { 2757 const AccessorInfo& info) {
2758 return v8::Integer::New(index); 2758 return v8::Integer::NewFromUnsigned(index);
2759 } 2759 }
2760 2760
2761 2761
2762 THREADED_TEST(IndexedInterceptorWithNoSetter) { 2762 THREADED_TEST(IndexedInterceptorWithNoSetter) {
2763 v8::HandleScope scope; 2763 v8::HandleScope scope;
2764 Local<ObjectTemplate> templ = ObjectTemplate::New(); 2764 Local<ObjectTemplate> templ = ObjectTemplate::New();
2765 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 2765 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
2766 2766
2767 LocalContext context; 2767 LocalContext context;
2768 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 2768 context->Global()->Set(v8_str("obj"), templ->NewInstance());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2852 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" 2852 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;"
2853 " }" 2853 " }"
2854 " 'PASSED'" 2854 " 'PASSED'"
2855 "} catch(e) {" 2855 "} catch(e) {"
2856 " e" 2856 " e"
2857 "}"; 2857 "}";
2858 ExpectString(code, "PASSED"); 2858 ExpectString(code, "PASSED");
2859 } 2859 }
2860 2860
2861 2861
2862 THREADED_TEST(IndexedInterceptorWithNegativeIndices) {
2863 v8::HandleScope scope;
2864 Local<ObjectTemplate> templ = ObjectTemplate::New();
2865 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
2866
2867 LocalContext context;
2868 Local<v8::Object> obj = templ->NewInstance();
2869 context->Global()->Set(v8_str("obj"), obj);
2870
2871 const char* code =
2872 "try {"
2873 " for (var i = 0; i < 100; i++) {"
2874 " var expected = i;"
2875 " var key = i;"
2876 " if (i == 25) {"
2877 " key = -1;"
2878 " expected = undefined;"
2879 " }"
2880 " if (i == 50) {"
2881 " /* probe minimal Smi number on 32-bit platforms */"
2882 " key = -(1 << 30);"
2883 " expected = undefined;"
2884 " }"
2885 " if (i == 75) {"
2886 " /* probe minimal Smi number on 64-bit platforms */"
2887 " key = 1 << 31;"
2888 " expected = undefined;"
2889 " }"
2890 " var v = obj[key];"
2891 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
2892 " }"
2893 " 'PASSED'"
2894 "} catch(e) {"
2895 " e"
2896 "}";
2897 ExpectString(code, "PASSED");
2898 }
2899
2900
2862 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) { 2901 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) {
2863 v8::HandleScope scope; 2902 v8::HandleScope scope;
2864 Local<ObjectTemplate> templ = ObjectTemplate::New(); 2903 Local<ObjectTemplate> templ = ObjectTemplate::New();
2865 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 2904 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
2866 2905
2867 LocalContext context; 2906 LocalContext context;
2868 Local<v8::Object> obj = templ->NewInstance(); 2907 Local<v8::Object> obj = templ->NewInstance();
2869 context->Global()->Set(v8_str("obj"), obj); 2908 context->Global()->Set(v8_str("obj"), obj);
2870 2909
2871 const char* code = 2910 const char* code =
2872 "try {" 2911 "try {"
2873 " for (var i = 0; i < 100; i++) {" 2912 " for (var i = 0; i < 100; i++) {"
2874 " var expected = i;" 2913 " var expected = i;"
2914 " var key = i;"
2875 " if (i == 50) {" 2915 " if (i == 50) {"
2876 " i = 'foobar';" 2916 " key = 'foobar';"
2877 " expected = undefined;" 2917 " expected = undefined;"
2878 " }" 2918 " }"
2879 " var v = obj[i];" 2919 " var v = obj[key];"
2880 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" 2920 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
2881 " }" 2921 " }"
2882 " 'PASSED'" 2922 " 'PASSED'"
2883 "} catch(e) {" 2923 "} catch(e) {"
2884 " e" 2924 " e"
2885 "}"; 2925 "}";
2886 ExpectString(code, "PASSED"); 2926 ExpectString(code, "PASSED");
2887 } 2927 }
2888 2928
2889 2929
(...skipping 7254 matching lines...) Expand 10 before | Expand all | Expand 10 after
10144 CHECK_EQ(2, prologue_call_count_second); 10184 CHECK_EQ(2, prologue_call_count_second);
10145 CHECK_EQ(2, epilogue_call_count_second); 10185 CHECK_EQ(2, epilogue_call_count_second);
10146 v8::V8::RemoveGCPrologueCallback(PrologueCallbackSecond); 10186 v8::V8::RemoveGCPrologueCallback(PrologueCallbackSecond);
10147 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond); 10187 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond);
10148 i::Heap::CollectAllGarbage(false); 10188 i::Heap::CollectAllGarbage(false);
10149 CHECK_EQ(2, prologue_call_count); 10189 CHECK_EQ(2, prologue_call_count);
10150 CHECK_EQ(2, epilogue_call_count); 10190 CHECK_EQ(2, epilogue_call_count);
10151 CHECK_EQ(2, prologue_call_count_second); 10191 CHECK_EQ(2, prologue_call_count_second);
10152 CHECK_EQ(2, epilogue_call_count_second); 10192 CHECK_EQ(2, epilogue_call_count_second);
10153 } 10193 }
OLDNEW
« no previous file with comments | « src/x64/ic-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698