OLD | NEW |
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 3043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3054 result = interceptor_setter_script->Run(); | 3054 result = interceptor_setter_script->Run(); |
3055 CHECK_EQ(v8_num(23), result); | 3055 CHECK_EQ(v8_num(23), result); |
3056 result = interceptor_getter_script->Run(); | 3056 result = interceptor_getter_script->Run(); |
3057 CHECK_EQ(v8_num(625), result); | 3057 CHECK_EQ(v8_num(625), result); |
3058 } | 3058 } |
3059 | 3059 |
3060 | 3060 |
3061 static v8::Handle<Value> IdentityIndexedPropertyGetter( | 3061 static v8::Handle<Value> IdentityIndexedPropertyGetter( |
3062 uint32_t index, | 3062 uint32_t index, |
3063 const AccessorInfo& info) { | 3063 const AccessorInfo& info) { |
3064 return v8::Integer::New(index); | 3064 return v8::Integer::NewFromUnsigned(index); |
3065 } | 3065 } |
3066 | 3066 |
3067 | 3067 |
3068 THREADED_TEST(IndexedInterceptorWithGetOwnPropertyDescriptor) { | 3068 THREADED_TEST(IndexedInterceptorWithGetOwnPropertyDescriptor) { |
3069 v8::HandleScope scope; | 3069 v8::HandleScope scope; |
3070 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 3070 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
3071 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); | 3071 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
3072 | 3072 |
3073 LocalContext context; | 3073 LocalContext context; |
3074 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 3074 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3179 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" | 3179 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" |
3180 " }" | 3180 " }" |
3181 " 'PASSED'" | 3181 " 'PASSED'" |
3182 "} catch(e) {" | 3182 "} catch(e) {" |
3183 " e" | 3183 " e" |
3184 "}"; | 3184 "}"; |
3185 ExpectString(code, "PASSED"); | 3185 ExpectString(code, "PASSED"); |
3186 } | 3186 } |
3187 | 3187 |
3188 | 3188 |
| 3189 THREADED_TEST(IndexedInterceptorWithNegativeIndices) { |
| 3190 v8::HandleScope scope; |
| 3191 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 3192 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
| 3193 |
| 3194 LocalContext context; |
| 3195 Local<v8::Object> obj = templ->NewInstance(); |
| 3196 context->Global()->Set(v8_str("obj"), obj); |
| 3197 |
| 3198 const char* code = |
| 3199 "try {" |
| 3200 " for (var i = 0; i < 100; i++) {" |
| 3201 " var expected = i;" |
| 3202 " var key = i;" |
| 3203 " if (i == 25) {" |
| 3204 " key = -1;" |
| 3205 " expected = undefined;" |
| 3206 " }" |
| 3207 " if (i == 50) {" |
| 3208 " /* probe minimal Smi number on 32-bit platforms */" |
| 3209 " key = -(1 << 30);" |
| 3210 " expected = undefined;" |
| 3211 " }" |
| 3212 " if (i == 75) {" |
| 3213 " /* probe minimal Smi number on 64-bit platforms */" |
| 3214 " key = 1 << 31;" |
| 3215 " expected = undefined;" |
| 3216 " }" |
| 3217 " var v = obj[key];" |
| 3218 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" |
| 3219 " }" |
| 3220 " 'PASSED'" |
| 3221 "} catch(e) {" |
| 3222 " e" |
| 3223 "}"; |
| 3224 ExpectString(code, "PASSED"); |
| 3225 } |
| 3226 |
| 3227 |
3189 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) { | 3228 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) { |
3190 v8::HandleScope scope; | 3229 v8::HandleScope scope; |
3191 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 3230 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
3192 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); | 3231 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
3193 | 3232 |
3194 LocalContext context; | 3233 LocalContext context; |
3195 Local<v8::Object> obj = templ->NewInstance(); | 3234 Local<v8::Object> obj = templ->NewInstance(); |
3196 context->Global()->Set(v8_str("obj"), obj); | 3235 context->Global()->Set(v8_str("obj"), obj); |
3197 | 3236 |
3198 const char* code = | 3237 const char* code = |
3199 "try {" | 3238 "try {" |
3200 " for (var i = 0; i < 100; i++) {" | 3239 " for (var i = 0; i < 100; i++) {" |
3201 " var expected = i;" | 3240 " var expected = i;" |
| 3241 " var key = i;" |
3202 " if (i == 50) {" | 3242 " if (i == 50) {" |
3203 " i = 'foobar';" | 3243 " key = 'foobar';" |
3204 " expected = undefined;" | 3244 " expected = undefined;" |
3205 " }" | 3245 " }" |
3206 " var v = obj[i];" | 3246 " var v = obj[key];" |
3207 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" | 3247 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" |
3208 " }" | 3248 " }" |
3209 " 'PASSED'" | 3249 " 'PASSED'" |
3210 "} catch(e) {" | 3250 "} catch(e) {" |
3211 " e" | 3251 " e" |
3212 "}"; | 3252 "}"; |
3213 ExpectString(code, "PASSED"); | 3253 ExpectString(code, "PASSED"); |
3214 } | 3254 } |
3215 | 3255 |
3216 | 3256 |
(...skipping 8219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11436 | 11476 |
11437 { | 11477 { |
11438 // Change the Boolean.prototype in the second context and check | 11478 // Change the Boolean.prototype in the second context and check |
11439 // that the right function gets called. | 11479 // that the right function gets called. |
11440 v8::HandleScope scope; | 11480 v8::HandleScope scope; |
11441 LocalContext context2; | 11481 LocalContext context2; |
11442 CompileRun("Boolean.prototype.toString = function() { return \"\"; }"); | 11482 CompileRun("Boolean.prototype.toString = function() { return \"\"; }"); |
11443 ExpectString(code, ""); | 11483 ExpectString(code, ""); |
11444 } | 11484 } |
11445 } | 11485 } |
OLD | NEW |