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

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

Issue 962613002: add interceptors which do not mask existing properties (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « src/objects-inl.h ('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 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
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(
3180 "outer = {};"
3181 "outer.__proto__ = obj;"
3182 "function f(obj) {"
3183 " var x;"
3184 " for (var i = 0; i < 4; i++) {"
3185 " x = obj.whatever;"
3186 " }"
3187 " return x;"
3188 "}");
3189
3190 // Receiver == holder.
3191 CompileRun("obj.__proto__ = null;");
3192 ExpectInt32("f(obj)", 239);
3193 ExpectInt32("f(outer)", 239);
3194
3195 // Receiver != holder.
3196 CompileRun("Object.setPrototypeOf(obj, {});");
3197 ExpectInt32("f(obj)", 239);
3198 ExpectInt32("f(outer)", 239);
3199
3200 // Masked value on prototype.
3201 CompileRun("obj.__proto__.whatever = 4;");
3202 CompileRun("obj.__proto__.__proto__ = { 'whatever' : 5 };");
3203 ExpectInt32("f(obj)", 4);
3204 ExpectInt32("f(outer)", 4);
3205
3206 // Masked value on prototype prototype.
3207 CompileRun("delete obj.__proto__.whatever;");
3208 ExpectInt32("f(obj)", 5);
3209 ExpectInt32("f(outer)", 5);
3210
3211 // Reset.
3212 CompileRun("delete obj.__proto__.__proto__.whatever;");
3213 ExpectInt32("f(obj)", 239);
3214 ExpectInt32("f(outer)", 239);
3215
3216 // Masked value on self.
3217 CompileRun("obj.whatever = 4;");
3218 ExpectInt32("f(obj)", 4);
3219 ExpectInt32("f(outer)", 4);
3220
3221 // Reset.
3222 CompileRun("delete obj.whatever;");
3223 ExpectInt32("f(obj)", 239);
3224 ExpectInt32("f(outer)", 239);
3225
3226 CompileRun("outer.whatever = 4;");
3227 ExpectInt32("f(obj)", 239);
3228 ExpectInt32("f(outer)", 4);
3229 }
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698