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

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

Issue 3569002: Backport r5553 "Do not invoke indexed interceptor getters for negative indice... (Closed) Base URL: http://v8.googlecode.com/svn/branches/2.3/
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 3042 matching lines...) Expand 10 before | Expand all | Expand 10 after
3053 result = interceptor_setter_script->Run(); 3053 result = interceptor_setter_script->Run();
3054 CHECK_EQ(v8_num(23), result); 3054 CHECK_EQ(v8_num(23), result);
3055 result = interceptor_getter_script->Run(); 3055 result = interceptor_getter_script->Run();
3056 CHECK_EQ(v8_num(625), result); 3056 CHECK_EQ(v8_num(625), result);
3057 } 3057 }
3058 3058
3059 3059
3060 static v8::Handle<Value> IdentityIndexedPropertyGetter( 3060 static v8::Handle<Value> IdentityIndexedPropertyGetter(
3061 uint32_t index, 3061 uint32_t index,
3062 const AccessorInfo& info) { 3062 const AccessorInfo& info) {
3063 return v8::Integer::New(index); 3063 return v8::Integer::NewFromUnsigned(index);
3064 } 3064 }
3065 3065
3066 3066
3067 THREADED_TEST(IndexedInterceptorWithGetOwnPropertyDescriptor) { 3067 THREADED_TEST(IndexedInterceptorWithGetOwnPropertyDescriptor) {
3068 v8::HandleScope scope; 3068 v8::HandleScope scope;
3069 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3069 Local<ObjectTemplate> templ = ObjectTemplate::New();
3070 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 3070 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
3071 3071
3072 LocalContext context; 3072 LocalContext context;
3073 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 3073 context->Global()->Set(v8_str("obj"), templ->NewInstance());
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
3178 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" 3178 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;"
3179 " }" 3179 " }"
3180 " 'PASSED'" 3180 " 'PASSED'"
3181 "} catch(e) {" 3181 "} catch(e) {"
3182 " e" 3182 " e"
3183 "}"; 3183 "}";
3184 ExpectString(code, "PASSED"); 3184 ExpectString(code, "PASSED");
3185 } 3185 }
3186 3186
3187 3187
3188 THREADED_TEST(IndexedInterceptorWithNegativeIndices) {
3189 v8::HandleScope scope;
3190 Local<ObjectTemplate> templ = ObjectTemplate::New();
3191 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
3192
3193 LocalContext context;
3194 Local<v8::Object> obj = templ->NewInstance();
3195 context->Global()->Set(v8_str("obj"), obj);
3196
3197 const char* code =
3198 "try {"
3199 " for (var i = 0; i < 100; i++) {"
3200 " var expected = i;"
3201 " var key = i;"
3202 " if (i == 25) {"
3203 " key = -1;"
3204 " expected = undefined;"
3205 " }"
3206 " if (i == 50) {"
3207 " /* probe minimal Smi number on 32-bit platforms */"
3208 " key = -(1 << 30);"
3209 " expected = undefined;"
3210 " }"
3211 " if (i == 75) {"
3212 " /* probe minimal Smi number on 64-bit platforms */"
3213 " key = 1 << 31;"
3214 " expected = undefined;"
3215 " }"
3216 " var v = obj[key];"
3217 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
3218 " }"
3219 " 'PASSED'"
3220 "} catch(e) {"
3221 " e"
3222 "}";
3223 ExpectString(code, "PASSED");
3224 }
3225
3226
3188 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) { 3227 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) {
3189 v8::HandleScope scope; 3228 v8::HandleScope scope;
3190 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3229 Local<ObjectTemplate> templ = ObjectTemplate::New();
3191 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 3230 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
3192 3231
3193 LocalContext context; 3232 LocalContext context;
3194 Local<v8::Object> obj = templ->NewInstance(); 3233 Local<v8::Object> obj = templ->NewInstance();
3195 context->Global()->Set(v8_str("obj"), obj); 3234 context->Global()->Set(v8_str("obj"), obj);
3196 3235
3197 const char* code = 3236 const char* code =
3198 "try {" 3237 "try {"
3199 " for (var i = 0; i < 100; i++) {" 3238 " for (var i = 0; i < 100; i++) {"
3200 " var expected = i;" 3239 " var expected = i;"
3240 " var key = i;"
3201 " if (i == 50) {" 3241 " if (i == 50) {"
3202 " i = 'foobar';" 3242 " key = 'foobar';"
3203 " expected = undefined;" 3243 " expected = undefined;"
3204 " }" 3244 " }"
3205 " var v = obj[i];" 3245 " var v = obj[key];"
3206 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" 3246 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
3207 " }" 3247 " }"
3208 " 'PASSED'" 3248 " 'PASSED'"
3209 "} catch(e) {" 3249 "} catch(e) {"
3210 " e" 3250 " e"
3211 "}"; 3251 "}";
3212 ExpectString(code, "PASSED"); 3252 ExpectString(code, "PASSED");
3213 } 3253 }
3214 3254
3215 3255
(...skipping 8195 matching lines...) Expand 10 before | Expand all | Expand 10 after
11411 11451
11412 { 11452 {
11413 // Change the Boolean.prototype in the second context and check 11453 // Change the Boolean.prototype in the second context and check
11414 // that the right function gets called. 11454 // that the right function gets called.
11415 v8::HandleScope scope; 11455 v8::HandleScope scope;
11416 LocalContext context2; 11456 LocalContext context2;
11417 CompileRun("Boolean.prototype.toString = function() { return \"\"; }"); 11457 CompileRun("Boolean.prototype.toString = function() { return \"\"; }");
11418 ExpectString(code, ""); 11458 ExpectString(code, "");
11419 } 11459 }
11420 } 11460 }
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