| 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 2988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2999 result = interceptor_setter_script->Run(); | 2999 result = interceptor_setter_script->Run(); |
| 3000 CHECK_EQ(v8_num(23), result); | 3000 CHECK_EQ(v8_num(23), result); |
| 3001 result = interceptor_getter_script->Run(); | 3001 result = interceptor_getter_script->Run(); |
| 3002 CHECK_EQ(v8_num(625), result); | 3002 CHECK_EQ(v8_num(625), result); |
| 3003 } | 3003 } |
| 3004 | 3004 |
| 3005 | 3005 |
| 3006 static v8::Handle<Value> IdentityIndexedPropertyGetter( | 3006 static v8::Handle<Value> IdentityIndexedPropertyGetter( |
| 3007 uint32_t index, | 3007 uint32_t index, |
| 3008 const AccessorInfo& info) { | 3008 const AccessorInfo& info) { |
| 3009 return v8::Integer::New(index); | 3009 return v8::Integer::NewFromUnsigned(index); |
| 3010 } | 3010 } |
| 3011 | 3011 |
| 3012 | 3012 |
| 3013 THREADED_TEST(IndexedInterceptorWithNoSetter) { | 3013 THREADED_TEST(IndexedInterceptorWithNoSetter) { |
| 3014 v8::HandleScope scope; | 3014 v8::HandleScope scope; |
| 3015 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 3015 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 3016 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); | 3016 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
| 3017 | 3017 |
| 3018 LocalContext context; | 3018 LocalContext context; |
| 3019 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 3019 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3103 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" | 3103 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" |
| 3104 " }" | 3104 " }" |
| 3105 " 'PASSED'" | 3105 " 'PASSED'" |
| 3106 "} catch(e) {" | 3106 "} catch(e) {" |
| 3107 " e" | 3107 " e" |
| 3108 "}"; | 3108 "}"; |
| 3109 ExpectString(code, "PASSED"); | 3109 ExpectString(code, "PASSED"); |
| 3110 } | 3110 } |
| 3111 | 3111 |
| 3112 | 3112 |
| 3113 THREADED_TEST(IndexedInterceptorWithNegativeIndices) { |
| 3114 v8::HandleScope scope; |
| 3115 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 3116 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
| 3117 |
| 3118 LocalContext context; |
| 3119 Local<v8::Object> obj = templ->NewInstance(); |
| 3120 context->Global()->Set(v8_str("obj"), obj); |
| 3121 |
| 3122 const char* code = |
| 3123 "try {" |
| 3124 " for (var i = 0; i < 100; i++) {" |
| 3125 " var expected = i;" |
| 3126 " var key = i;" |
| 3127 " if (i == 25) {" |
| 3128 " key = -1;" |
| 3129 " expected = undefined;" |
| 3130 " }" |
| 3131 " if (i == 50) {" |
| 3132 " /* probe minimal Smi number on 32-bit platforms */" |
| 3133 " key = -(1 << 30);" |
| 3134 " expected = undefined;" |
| 3135 " }" |
| 3136 " if (i == 75) {" |
| 3137 " /* probe minimal Smi number on 64-bit platforms */" |
| 3138 " key = 1 << 31;" |
| 3139 " expected = undefined;" |
| 3140 " }" |
| 3141 " var v = obj[key];" |
| 3142 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" |
| 3143 " }" |
| 3144 " 'PASSED'" |
| 3145 "} catch(e) {" |
| 3146 " e" |
| 3147 "}"; |
| 3148 ExpectString(code, "PASSED"); |
| 3149 } |
| 3150 |
| 3151 |
| 3113 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) { | 3152 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) { |
| 3114 v8::HandleScope scope; | 3153 v8::HandleScope scope; |
| 3115 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 3154 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 3116 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); | 3155 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
| 3117 | 3156 |
| 3118 LocalContext context; | 3157 LocalContext context; |
| 3119 Local<v8::Object> obj = templ->NewInstance(); | 3158 Local<v8::Object> obj = templ->NewInstance(); |
| 3120 context->Global()->Set(v8_str("obj"), obj); | 3159 context->Global()->Set(v8_str("obj"), obj); |
| 3121 | 3160 |
| 3122 const char* code = | 3161 const char* code = |
| 3123 "try {" | 3162 "try {" |
| 3124 " for (var i = 0; i < 100; i++) {" | 3163 " for (var i = 0; i < 100; i++) {" |
| 3125 " var expected = i;" | 3164 " var expected = i;" |
| 3165 " var key = i;" |
| 3126 " if (i == 50) {" | 3166 " if (i == 50) {" |
| 3127 " i = 'foobar';" | 3167 " key = 'foobar';" |
| 3128 " expected = undefined;" | 3168 " expected = undefined;" |
| 3129 " }" | 3169 " }" |
| 3130 " var v = obj[i];" | 3170 " var v = obj[key];" |
| 3131 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" | 3171 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" |
| 3132 " }" | 3172 " }" |
| 3133 " 'PASSED'" | 3173 " 'PASSED'" |
| 3134 "} catch(e) {" | 3174 "} catch(e) {" |
| 3135 " e" | 3175 " e" |
| 3136 "}"; | 3176 "}"; |
| 3137 ExpectString(code, "PASSED"); | 3177 ExpectString(code, "PASSED"); |
| 3138 } | 3178 } |
| 3139 | 3179 |
| 3140 | 3180 |
| (...skipping 8105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11246 | 11286 |
| 11247 { | 11287 { |
| 11248 // Change the Boolean.prototype in the second context and check | 11288 // Change the Boolean.prototype in the second context and check |
| 11249 // that the right function gets called. | 11289 // that the right function gets called. |
| 11250 v8::HandleScope scope; | 11290 v8::HandleScope scope; |
| 11251 LocalContext context2; | 11291 LocalContext context2; |
| 11252 CompileRun("Boolean.prototype.toString = function() { return \"\"; }"); | 11292 CompileRun("Boolean.prototype.toString = function() { return \"\"; }"); |
| 11253 ExpectString(code, ""); | 11293 ExpectString(code, ""); |
| 11254 } | 11294 } |
| 11255 } | 11295 } |
| OLD | NEW |