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

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

Issue 942963004: Remove internal use of v8::AccessType, always pass v8::ACCESS_HAS instead. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove the distinction between named/indexed access checks, always pass "undefined" as "name" Created 5 years, 10 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 | « test/cctest/test-api.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 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 2916 matching lines...) Expand 10 before | Expand all | Expand 10 after
2927 Object::Cast(*data)->GetAlignedPointerFromInternalField(0)); 2927 Object::Cast(*data)->GetAlignedPointerFromInternalField(0));
2928 } 2928 }
2929 2929
2930 2930
2931 struct AccessCheckData { 2931 struct AccessCheckData {
2932 int count; 2932 int count;
2933 bool result; 2933 bool result;
2934 }; 2934 };
2935 2935
2936 2936
2937 bool SimpleNamedAccessChecker(Local<v8::Object> global, Local<Value> name, 2937 bool SimpleAccessChecker(Local<v8::Object> global, Local<Value> name,
2938 v8::AccessType type, Local<Value> data) { 2938 v8::AccessType type, Local<Value> data) {
2939 auto access_check_data = GetWrappedObject<AccessCheckData>(data); 2939 auto access_check_data = GetWrappedObject<AccessCheckData>(data);
2940 access_check_data->count++; 2940 access_check_data->count++;
2941 return access_check_data->result; 2941 return access_check_data->result;
2942 }
2943
2944
2945 bool SimpleIndexedAccessChecker(Local<v8::Object> global, uint32_t index,
2946 v8::AccessType type, Local<Value> data) {
2947 auto access_check_data = GetWrappedObject<AccessCheckData>(data);
2948 access_check_data->count++;
2949 return access_check_data->result;
2950 } 2942 }
2951 2943
2952 2944
2953 struct ShouldInterceptData { 2945 struct ShouldInterceptData {
2954 int value; 2946 int value;
2955 bool should_intercept; 2947 bool should_intercept;
2956 }; 2948 };
2957 2949
2958 2950
2959 void ShouldNamedInterceptor(Local<Name> name, 2951 void ShouldNamedInterceptor(Local<Name> name,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3008 { 3000 {
3009 v8::NamedPropertyHandlerConfiguration conf(ShouldNamedInterceptor); 3001 v8::NamedPropertyHandlerConfiguration conf(ShouldNamedInterceptor);
3010 conf.flags = v8::PropertyHandlerFlags::kAllCanRead; 3002 conf.flags = v8::PropertyHandlerFlags::kAllCanRead;
3011 conf.data = 3003 conf.data =
3012 BuildWrappedObject<ShouldInterceptData>(isolate, &intercept_data_1); 3004 BuildWrappedObject<ShouldInterceptData>(isolate, &intercept_data_1);
3013 intercepted_1->SetHandler(conf); 3005 intercepted_1->SetHandler(conf);
3014 } 3006 }
3015 3007
3016 auto checked = v8::ObjectTemplate::New(isolate); 3008 auto checked = v8::ObjectTemplate::New(isolate);
3017 checked->SetAccessCheckCallbacks( 3009 checked->SetAccessCheckCallbacks(
3018 SimpleNamedAccessChecker, nullptr, 3010 SimpleAccessChecker, nullptr,
3019 BuildWrappedObject<AccessCheckData>(isolate, &access_check_data), false); 3011 BuildWrappedObject<AccessCheckData>(isolate, &access_check_data), false);
3020 3012
3021 context->Global()->Set(v8_str("intercepted_0"), intercepted_0->NewInstance()); 3013 context->Global()->Set(v8_str("intercepted_0"), intercepted_0->NewInstance());
3022 context->Global()->Set(v8_str("intercepted_1"), intercepted_1->NewInstance()); 3014 context->Global()->Set(v8_str("intercepted_1"), intercepted_1->NewInstance());
3023 auto checked_instance = checked->NewInstance(); 3015 auto checked_instance = checked->NewInstance();
3024 checked_instance->Set(v8_str("whatever"), v8_num(17)); 3016 checked_instance->Set(v8_str("whatever"), v8_num(17));
3025 context->Global()->Set(v8_str("checked"), checked_instance); 3017 context->Global()->Set(v8_str("checked"), checked_instance);
3026 CompileRun( 3018 CompileRun(
3027 "checked.__proto__ = intercepted_1;" 3019 "checked.__proto__ = intercepted_1;"
3028 "intercepted_1.__proto__ = intercepted_0;"); 3020 "intercepted_1.__proto__ = intercepted_0;");
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3074 { 3066 {
3075 v8::IndexedPropertyHandlerConfiguration conf(ShouldIndexedInterceptor); 3067 v8::IndexedPropertyHandlerConfiguration conf(ShouldIndexedInterceptor);
3076 conf.flags = v8::PropertyHandlerFlags::kAllCanRead; 3068 conf.flags = v8::PropertyHandlerFlags::kAllCanRead;
3077 conf.data = 3069 conf.data =
3078 BuildWrappedObject<ShouldInterceptData>(isolate, &intercept_data_1); 3070 BuildWrappedObject<ShouldInterceptData>(isolate, &intercept_data_1);
3079 intercepted_1->SetHandler(conf); 3071 intercepted_1->SetHandler(conf);
3080 } 3072 }
3081 3073
3082 auto checked = v8::ObjectTemplate::New(isolate); 3074 auto checked = v8::ObjectTemplate::New(isolate);
3083 checked->SetAccessCheckCallbacks( 3075 checked->SetAccessCheckCallbacks(
3084 nullptr, SimpleIndexedAccessChecker, 3076 SimpleAccessChecker, nullptr,
3085 BuildWrappedObject<AccessCheckData>(isolate, &access_check_data), false); 3077 BuildWrappedObject<AccessCheckData>(isolate, &access_check_data), false);
3086 3078
3087 context->Global()->Set(v8_str("intercepted_0"), intercepted_0->NewInstance()); 3079 context->Global()->Set(v8_str("intercepted_0"), intercepted_0->NewInstance());
3088 context->Global()->Set(v8_str("intercepted_1"), intercepted_1->NewInstance()); 3080 context->Global()->Set(v8_str("intercepted_1"), intercepted_1->NewInstance());
3089 auto checked_instance = checked->NewInstance(); 3081 auto checked_instance = checked->NewInstance();
3090 context->Global()->Set(v8_str("checked"), checked_instance); 3082 context->Global()->Set(v8_str("checked"), checked_instance);
3091 checked_instance->Set(15, v8_num(17)); 3083 checked_instance->Set(15, v8_num(17));
3092 CompileRun( 3084 CompileRun(
3093 "checked.__proto__ = intercepted_1;" 3085 "checked.__proto__ = intercepted_1;"
3094 "intercepted_1.__proto__ = intercepted_0;"); 3086 "intercepted_1.__proto__ = intercepted_0;");
3095 3087
3096 checked_instance->TurnOnAccessCheck(); 3088 checked_instance->TurnOnAccessCheck();
3097 CHECK_EQ(0, access_check_data.count); 3089 CHECK_EQ(0, access_check_data.count);
3098 3090
3099 access_check_data.result = true; 3091 access_check_data.result = true;
3100 ExpectInt32("checked[15]", 17); 3092 ExpectInt32("checked[15]", 17);
3101 CHECK_EQ(1, access_check_data.count); 3093 CHECK_EQ(1, access_check_data.count);
3102 3094
3103 access_check_data.result = false; 3095 access_check_data.result = false;
3104 ExpectInt32("checked[15]", intercept_data_0.value); 3096 ExpectInt32("checked[15]", intercept_data_0.value);
3105 CHECK_EQ(2, access_check_data.count); 3097 CHECK_EQ(2, access_check_data.count);
3106 3098
3107 intercept_data_1.should_intercept = true; 3099 intercept_data_1.should_intercept = true;
3108 ExpectInt32("checked[15]", intercept_data_1.value); 3100 ExpectInt32("checked[15]", intercept_data_1.value);
3109 CHECK_EQ(3, access_check_data.count); 3101 CHECK_EQ(3, access_check_data.count);
3110 } 3102 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698