OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "test/cctest/test-api.h" | 7 #include "test/cctest/test-api.h" |
8 | 8 |
9 #include "include/v8-util.h" | 9 #include "include/v8-util.h" |
10 #include "src/api.h" | 10 #include "src/api.h" |
(...skipping 3082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3093 CHECK_EQ(1, access_check_data.count); | 3093 CHECK_EQ(1, access_check_data.count); |
3094 | 3094 |
3095 access_check_data.result = false; | 3095 access_check_data.result = false; |
3096 ExpectInt32("checked[15]", intercept_data_0.value); | 3096 ExpectInt32("checked[15]", intercept_data_0.value); |
3097 CHECK_EQ(2, access_check_data.count); | 3097 CHECK_EQ(2, access_check_data.count); |
3098 | 3098 |
3099 intercept_data_1.should_intercept = true; | 3099 intercept_data_1.should_intercept = true; |
3100 ExpectInt32("checked[15]", intercept_data_1.value); | 3100 ExpectInt32("checked[15]", intercept_data_1.value); |
3101 CHECK_EQ(3, access_check_data.count); | 3101 CHECK_EQ(3, access_check_data.count); |
3102 } | 3102 } |
| 3103 |
| 3104 |
| 3105 THREADED_TEST(NonMaskingInterceptorOwnProperty) { |
| 3106 auto isolate = CcTest::isolate(); |
| 3107 v8::HandleScope handle_scope(isolate); |
| 3108 LocalContext context; |
| 3109 |
| 3110 ShouldInterceptData intercept_data; |
| 3111 intercept_data.value = 239; |
| 3112 intercept_data.should_intercept = true; |
| 3113 |
| 3114 auto interceptor_templ = v8::ObjectTemplate::New(isolate); |
| 3115 v8::NamedPropertyHandlerConfiguration conf(ShouldNamedInterceptor); |
| 3116 conf.flags = v8::PropertyHandlerFlags::kNonMasking; |
| 3117 conf.data = BuildWrappedObject<ShouldInterceptData>(isolate, &intercept_data); |
| 3118 interceptor_templ->SetHandler(conf); |
| 3119 |
| 3120 auto interceptor = interceptor_templ->NewInstance(); |
| 3121 context->Global()->Set(v8_str("obj"), interceptor); |
| 3122 |
| 3123 ExpectInt32("obj.whatever", 239); |
| 3124 |
| 3125 CompileRun("obj.whatever = 4;"); |
| 3126 ExpectInt32("obj.whatever", 4); |
| 3127 |
| 3128 CompileRun("delete obj.whatever;"); |
| 3129 ExpectInt32("obj.whatever", 239); |
| 3130 } |
| 3131 |
| 3132 |
| 3133 THREADED_TEST(NonMaskingInterceptorPrototypeProperty) { |
| 3134 auto isolate = CcTest::isolate(); |
| 3135 v8::HandleScope handle_scope(isolate); |
| 3136 LocalContext context; |
| 3137 |
| 3138 ShouldInterceptData intercept_data; |
| 3139 intercept_data.value = 239; |
| 3140 intercept_data.should_intercept = true; |
| 3141 |
| 3142 auto interceptor_templ = v8::ObjectTemplate::New(isolate); |
| 3143 v8::NamedPropertyHandlerConfiguration conf(ShouldNamedInterceptor); |
| 3144 conf.flags = v8::PropertyHandlerFlags::kNonMasking; |
| 3145 conf.data = BuildWrappedObject<ShouldInterceptData>(isolate, &intercept_data); |
| 3146 interceptor_templ->SetHandler(conf); |
| 3147 |
| 3148 auto interceptor = interceptor_templ->NewInstance(); |
| 3149 context->Global()->Set(v8_str("obj"), interceptor); |
| 3150 |
| 3151 ExpectInt32("obj.whatever", 239); |
| 3152 |
| 3153 CompileRun("obj.__proto__ = {'whatever': 4};"); |
| 3154 ExpectInt32("obj.whatever", 4); |
| 3155 |
| 3156 CompileRun("delete obj.__proto__.whatever;"); |
| 3157 ExpectInt32("obj.whatever", 239); |
| 3158 } |
| 3159 |
| 3160 |
| 3161 THREADED_TEST(NonMaskingInterceptorPrototypePropertyIC) { |
| 3162 auto isolate = CcTest::isolate(); |
| 3163 v8::HandleScope handle_scope(isolate); |
| 3164 LocalContext context; |
| 3165 |
| 3166 ShouldInterceptData intercept_data; |
| 3167 intercept_data.value = 239; |
| 3168 intercept_data.should_intercept = true; |
| 3169 |
| 3170 auto interceptor_templ = v8::ObjectTemplate::New(isolate); |
| 3171 v8::NamedPropertyHandlerConfiguration conf(ShouldNamedInterceptor); |
| 3172 conf.flags = v8::PropertyHandlerFlags::kNonMasking; |
| 3173 conf.data = BuildWrappedObject<ShouldInterceptData>(isolate, &intercept_data); |
| 3174 interceptor_templ->SetHandler(conf); |
| 3175 |
| 3176 auto interceptor = interceptor_templ->NewInstance(); |
| 3177 context->Global()->Set(v8_str("obj"), interceptor); |
| 3178 |
| 3179 CompileRun("obj.__proto__ = {};"); |
| 3180 CompileRun( |
| 3181 "function f() {" |
| 3182 " var x;" |
| 3183 " for (var i = 0; i < 4; i++) {" |
| 3184 " x = obj.whatever;" |
| 3185 " }" |
| 3186 " return x;" |
| 3187 "}"); |
| 3188 ExpectInt32("f()", 239); |
| 3189 CompileRun("obj.__proto__.whatever = 4;"); |
| 3190 ExpectInt32("f()", 4); |
| 3191 CompileRun("delete obj.__proto__.whatever;"); |
| 3192 ExpectInt32("f()", 239); |
| 3193 } |
OLD | NEW |