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

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

Issue 1217893012: Remove deprecated v8::Object::TurnOnAccessCheck() from the V8 API. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Deoptimizer::DeoptimizeGlobalObject() removed Created 5 years, 5 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') | test/mjsunit/migrations.js » ('j') | 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 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;" 1651 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;"
1652 " }" 1652 " }"
1653 " 'PASSED'" 1653 " 'PASSED'"
1654 "} catch(e) {" 1654 "} catch(e) {"
1655 " e" 1655 " e"
1656 "}"; 1656 "}";
1657 ExpectString(code, "PASSED"); 1657 ExpectString(code, "PASSED");
1658 } 1658 }
1659 1659
1660 1660
1661 static bool AccessAlwaysBlocked(Local<v8::Object> global, Local<Value> name,
1662 v8::AccessType type, Local<Value> data) {
1663 return false;
1664 }
1665
1666
1661 THREADED_TEST(IndexedInterceptorWithAccessorCheck) { 1667 THREADED_TEST(IndexedInterceptorWithAccessorCheck) {
1662 v8::Isolate* isolate = CcTest::isolate(); 1668 v8::Isolate* isolate = CcTest::isolate();
1663 v8::HandleScope scope(isolate); 1669 v8::HandleScope scope(isolate);
1664 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 1670 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
1665 templ->SetHandler( 1671 templ->SetHandler(
1666 v8::IndexedPropertyHandlerConfiguration(IdentityIndexedPropertyGetter)); 1672 v8::IndexedPropertyHandlerConfiguration(IdentityIndexedPropertyGetter));
1667 1673
1674 templ->SetAccessCheckCallbacks(AccessAlwaysBlocked, nullptr);
1675
1668 LocalContext context; 1676 LocalContext context;
1669 Local<v8::Object> obj = templ->NewInstance(); 1677 Local<v8::Object> obj = templ->NewInstance();
1670 obj->TurnOnAccessCheck();
1671 context->Global()->Set(v8_str("obj"), obj); 1678 context->Global()->Set(v8_str("obj"), obj);
1672 1679
1673 const char* code = 1680 const char* code =
1674 "var result = 'PASSED';" 1681 "var result = 'PASSED';"
1675 "for (var i = 0; i < 100; i++) {" 1682 "for (var i = 0; i < 100; i++) {"
1676 " try {" 1683 " try {"
1677 " var v = obj[0];" 1684 " var v = obj[0];"
1678 " result = 'Wrong value ' + v + ' at iteration ' + i;" 1685 " result = 'Wrong value ' + v + ' at iteration ' + i;"
1679 " break;" 1686 " break;"
1680 " } catch (e) {" 1687 " } catch (e) {"
1681 " /* pass */" 1688 " /* pass */"
1682 " }" 1689 " }"
1683 "}" 1690 "}"
1684 "result"; 1691 "result";
1685 ExpectString(code, "PASSED"); 1692 ExpectString(code, "PASSED");
1686 } 1693 }
1687 1694
1688 1695
1689 THREADED_TEST(IndexedInterceptorWithAccessorCheckSwitchedOn) {
1690 i::FLAG_allow_natives_syntax = true;
1691 v8::Isolate* isolate = CcTest::isolate();
1692 v8::HandleScope scope(isolate);
1693 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
1694 templ->SetHandler(
1695 v8::IndexedPropertyHandlerConfiguration(IdentityIndexedPropertyGetter));
1696
1697 LocalContext context;
1698 Local<v8::Object> obj = templ->NewInstance();
1699 context->Global()->Set(v8_str("obj"), obj);
1700
1701 const char* code =
1702 "var result = 'PASSED';"
1703 "for (var i = 0; i < 100; i++) {"
1704 " var expected = i;"
1705 " if (i == 5) {"
1706 " %EnableAccessChecks(obj);"
1707 " }"
1708 " try {"
1709 " var v = obj[i];"
1710 " if (i == 5) {"
1711 " result = 'Should not have reached this!';"
1712 " break;"
1713 " } else if (v != expected) {"
1714 " result = 'Wrong value ' + v + ' at iteration ' + i;"
1715 " break;"
1716 " }"
1717 " } catch (e) {"
1718 " if (i != 5) {"
1719 " result = e;"
1720 " }"
1721 " }"
1722 " if (i == 5) %DisableAccessChecks(obj);"
1723 "}"
1724 "result";
1725 ExpectString(code, "PASSED");
1726 }
1727
1728
1729 THREADED_TEST(IndexedInterceptorWithDifferentIndices) { 1696 THREADED_TEST(IndexedInterceptorWithDifferentIndices) {
1730 v8::Isolate* isolate = CcTest::isolate(); 1697 v8::Isolate* isolate = CcTest::isolate();
1731 v8::HandleScope scope(isolate); 1698 v8::HandleScope scope(isolate);
1732 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 1699 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
1733 templ->SetHandler( 1700 templ->SetHandler(
1734 v8::IndexedPropertyHandlerConfiguration(IdentityIndexedPropertyGetter)); 1701 v8::IndexedPropertyHandlerConfiguration(IdentityIndexedPropertyGetter));
1735 1702
1736 LocalContext context; 1703 LocalContext context;
1737 Local<v8::Object> obj = templ->NewInstance(); 1704 Local<v8::Object> obj = templ->NewInstance();
1738 context->Global()->Set(v8_str("obj"), obj); 1705 context->Global()->Set(v8_str("obj"), obj);
(...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2968 2935
2969 } // namespace 2936 } // namespace
2970 2937
2971 2938
2972 THREADED_TEST(NamedAllCanReadInterceptor) { 2939 THREADED_TEST(NamedAllCanReadInterceptor) {
2973 auto isolate = CcTest::isolate(); 2940 auto isolate = CcTest::isolate();
2974 v8::HandleScope handle_scope(isolate); 2941 v8::HandleScope handle_scope(isolate);
2975 LocalContext context; 2942 LocalContext context;
2976 2943
2977 AccessCheckData access_check_data; 2944 AccessCheckData access_check_data;
2978 access_check_data.result = false; 2945 access_check_data.result = true;
2979 access_check_data.count = 0; 2946 access_check_data.count = 0;
2980 2947
2981 ShouldInterceptData intercept_data_0; 2948 ShouldInterceptData intercept_data_0;
2982 intercept_data_0.value = 239; 2949 intercept_data_0.value = 239;
2983 intercept_data_0.should_intercept = true; 2950 intercept_data_0.should_intercept = true;
2984 2951
2985 ShouldInterceptData intercept_data_1; 2952 ShouldInterceptData intercept_data_1;
2986 intercept_data_1.value = 165; 2953 intercept_data_1.value = 165;
2987 intercept_data_1.should_intercept = false; 2954 intercept_data_1.should_intercept = false;
2988 2955
(...skipping 11 matching lines...) Expand all
3000 v8::NamedPropertyHandlerConfiguration conf(ShouldNamedInterceptor); 2967 v8::NamedPropertyHandlerConfiguration conf(ShouldNamedInterceptor);
3001 conf.flags = v8::PropertyHandlerFlags::kAllCanRead; 2968 conf.flags = v8::PropertyHandlerFlags::kAllCanRead;
3002 conf.data = 2969 conf.data =
3003 BuildWrappedObject<ShouldInterceptData>(isolate, &intercept_data_1); 2970 BuildWrappedObject<ShouldInterceptData>(isolate, &intercept_data_1);
3004 intercepted_1->SetHandler(conf); 2971 intercepted_1->SetHandler(conf);
3005 } 2972 }
3006 2973
3007 auto checked = v8::ObjectTemplate::New(isolate); 2974 auto checked = v8::ObjectTemplate::New(isolate);
3008 checked->SetAccessCheckCallbacks( 2975 checked->SetAccessCheckCallbacks(
3009 SimpleAccessChecker, nullptr, 2976 SimpleAccessChecker, nullptr,
3010 BuildWrappedObject<AccessCheckData>(isolate, &access_check_data), false); 2977 BuildWrappedObject<AccessCheckData>(isolate, &access_check_data));
3011 2978
3012 context->Global()->Set(v8_str("intercepted_0"), intercepted_0->NewInstance()); 2979 context->Global()->Set(v8_str("intercepted_0"), intercepted_0->NewInstance());
3013 context->Global()->Set(v8_str("intercepted_1"), intercepted_1->NewInstance()); 2980 context->Global()->Set(v8_str("intercepted_1"), intercepted_1->NewInstance());
3014 auto checked_instance = checked->NewInstance(); 2981 auto checked_instance = checked->NewInstance();
3015 checked_instance->Set(v8_str("whatever"), v8_num(17)); 2982 checked_instance->Set(v8_str("whatever"), v8_num(17));
3016 context->Global()->Set(v8_str("checked"), checked_instance); 2983 context->Global()->Set(v8_str("checked"), checked_instance);
3017 CompileRun( 2984 CompileRun(
3018 "checked.__proto__ = intercepted_1;" 2985 "checked.__proto__ = intercepted_1;"
3019 "intercepted_1.__proto__ = intercepted_0;"); 2986 "intercepted_1.__proto__ = intercepted_0;");
3020 2987
3021 checked_instance->TurnOnAccessCheck(); 2988 CHECK_EQ(3, access_check_data.count);
3022 CHECK_EQ(0, access_check_data.count);
3023 2989
3024 access_check_data.result = true;
3025 ExpectInt32("checked.whatever", 17); 2990 ExpectInt32("checked.whatever", 17);
3026 CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')") 2991 CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')")
3027 ->IsUndefined()); 2992 ->IsUndefined());
3028 CHECK_EQ(2, access_check_data.count); 2993 CHECK_EQ(5, access_check_data.count);
3029 2994
3030 access_check_data.result = false; 2995 access_check_data.result = false;
3031 ExpectInt32("checked.whatever", intercept_data_0.value); 2996 ExpectInt32("checked.whatever", intercept_data_0.value);
3032 { 2997 {
3033 v8::TryCatch try_catch(isolate); 2998 v8::TryCatch try_catch(isolate);
3034 CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')"); 2999 CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')");
3035 CHECK(try_catch.HasCaught()); 3000 CHECK(try_catch.HasCaught());
3036 } 3001 }
3037 CHECK_EQ(4, access_check_data.count); 3002 CHECK_EQ(7, access_check_data.count);
3038 3003
3039 intercept_data_1.should_intercept = true; 3004 intercept_data_1.should_intercept = true;
3040 ExpectInt32("checked.whatever", intercept_data_1.value); 3005 ExpectInt32("checked.whatever", intercept_data_1.value);
3041 { 3006 {
3042 v8::TryCatch try_catch(isolate); 3007 v8::TryCatch try_catch(isolate);
3043 CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')"); 3008 CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')");
3044 CHECK(try_catch.HasCaught()); 3009 CHECK(try_catch.HasCaught());
3045 } 3010 }
3046 CHECK_EQ(6, access_check_data.count); 3011 CHECK_EQ(9, access_check_data.count);
3047 } 3012 }
3048 3013
3049 3014
3050 THREADED_TEST(IndexedAllCanReadInterceptor) { 3015 THREADED_TEST(IndexedAllCanReadInterceptor) {
3051 auto isolate = CcTest::isolate(); 3016 auto isolate = CcTest::isolate();
3052 v8::HandleScope handle_scope(isolate); 3017 v8::HandleScope handle_scope(isolate);
3053 LocalContext context; 3018 LocalContext context;
3054 3019
3055 AccessCheckData access_check_data; 3020 AccessCheckData access_check_data;
3056 access_check_data.result = false; 3021 access_check_data.result = true;
3057 access_check_data.count = 0; 3022 access_check_data.count = 0;
3058 3023
3059 ShouldInterceptData intercept_data_0; 3024 ShouldInterceptData intercept_data_0;
3060 intercept_data_0.value = 239; 3025 intercept_data_0.value = 239;
3061 intercept_data_0.should_intercept = true; 3026 intercept_data_0.should_intercept = true;
3062 3027
3063 ShouldInterceptData intercept_data_1; 3028 ShouldInterceptData intercept_data_1;
3064 intercept_data_1.value = 165; 3029 intercept_data_1.value = 165;
3065 intercept_data_1.should_intercept = false; 3030 intercept_data_1.should_intercept = false;
3066 3031
(...skipping 11 matching lines...) Expand all
3078 v8::IndexedPropertyHandlerConfiguration conf(ShouldIndexedInterceptor); 3043 v8::IndexedPropertyHandlerConfiguration conf(ShouldIndexedInterceptor);
3079 conf.flags = v8::PropertyHandlerFlags::kAllCanRead; 3044 conf.flags = v8::PropertyHandlerFlags::kAllCanRead;
3080 conf.data = 3045 conf.data =
3081 BuildWrappedObject<ShouldInterceptData>(isolate, &intercept_data_1); 3046 BuildWrappedObject<ShouldInterceptData>(isolate, &intercept_data_1);
3082 intercepted_1->SetHandler(conf); 3047 intercepted_1->SetHandler(conf);
3083 } 3048 }
3084 3049
3085 auto checked = v8::ObjectTemplate::New(isolate); 3050 auto checked = v8::ObjectTemplate::New(isolate);
3086 checked->SetAccessCheckCallbacks( 3051 checked->SetAccessCheckCallbacks(
3087 SimpleAccessChecker, nullptr, 3052 SimpleAccessChecker, nullptr,
3088 BuildWrappedObject<AccessCheckData>(isolate, &access_check_data), false); 3053 BuildWrappedObject<AccessCheckData>(isolate, &access_check_data));
3089 3054
3090 context->Global()->Set(v8_str("intercepted_0"), intercepted_0->NewInstance()); 3055 context->Global()->Set(v8_str("intercepted_0"), intercepted_0->NewInstance());
3091 context->Global()->Set(v8_str("intercepted_1"), intercepted_1->NewInstance()); 3056 context->Global()->Set(v8_str("intercepted_1"), intercepted_1->NewInstance());
3092 auto checked_instance = checked->NewInstance(); 3057 auto checked_instance = checked->NewInstance();
3093 context->Global()->Set(v8_str("checked"), checked_instance); 3058 context->Global()->Set(v8_str("checked"), checked_instance);
3094 checked_instance->Set(15, v8_num(17)); 3059 checked_instance->Set(15, v8_num(17));
3095 CompileRun( 3060 CompileRun(
3096 "checked.__proto__ = intercepted_1;" 3061 "checked.__proto__ = intercepted_1;"
3097 "intercepted_1.__proto__ = intercepted_0;"); 3062 "intercepted_1.__proto__ = intercepted_0;");
3098 3063
3099 checked_instance->TurnOnAccessCheck(); 3064 CHECK_EQ(3, access_check_data.count);
3100 CHECK_EQ(0, access_check_data.count);
3101 3065
3102 access_check_data.result = true; 3066 access_check_data.result = true;
3103 ExpectInt32("checked[15]", 17); 3067 ExpectInt32("checked[15]", 17);
3104 CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, '15')") 3068 CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, '15')")
3105 ->IsUndefined()); 3069 ->IsUndefined());
3106 CHECK_EQ(2, access_check_data.count); 3070 CHECK_EQ(5, access_check_data.count);
3107 3071
3108 access_check_data.result = false; 3072 access_check_data.result = false;
3109 ExpectInt32("checked[15]", intercept_data_0.value); 3073 ExpectInt32("checked[15]", intercept_data_0.value);
3110 { 3074 {
3111 v8::TryCatch try_catch(isolate); 3075 v8::TryCatch try_catch(isolate);
3112 CompileRun("Object.getOwnPropertyDescriptor(checked, '15')"); 3076 CompileRun("Object.getOwnPropertyDescriptor(checked, '15')");
3113 CHECK(try_catch.HasCaught()); 3077 CHECK(try_catch.HasCaught());
3114 } 3078 }
3115 CHECK_EQ(4, access_check_data.count); 3079 CHECK_EQ(7, access_check_data.count);
3116 3080
3117 intercept_data_1.should_intercept = true; 3081 intercept_data_1.should_intercept = true;
3118 ExpectInt32("checked[15]", intercept_data_1.value); 3082 ExpectInt32("checked[15]", intercept_data_1.value);
3119 { 3083 {
3120 v8::TryCatch try_catch(isolate); 3084 v8::TryCatch try_catch(isolate);
3121 CompileRun("Object.getOwnPropertyDescriptor(checked, '15')"); 3085 CompileRun("Object.getOwnPropertyDescriptor(checked, '15')");
3122 CHECK(try_catch.HasCaught()); 3086 CHECK(try_catch.HasCaught());
3123 } 3087 }
3124 CHECK_EQ(6, access_check_data.count); 3088 CHECK_EQ(9, access_check_data.count);
3125 } 3089 }
3126 3090
3127 3091
3128 THREADED_TEST(NonMaskingInterceptorOwnProperty) { 3092 THREADED_TEST(NonMaskingInterceptorOwnProperty) {
3129 auto isolate = CcTest::isolate(); 3093 auto isolate = CcTest::isolate();
3130 v8::HandleScope handle_scope(isolate); 3094 v8::HandleScope handle_scope(isolate);
3131 LocalContext context; 3095 LocalContext context;
3132 3096
3133 ShouldInterceptData intercept_data; 3097 ShouldInterceptData intercept_data;
3134 intercept_data.value = 239; 3098 intercept_data.value = 239;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
3306 "var obj = intercepted_1;" 3270 "var obj = intercepted_1;"
3307 "obj.x = 4;" 3271 "obj.x = 4;"
3308 "eval('obj.x');" 3272 "eval('obj.x');"
3309 "eval('obj.x');" 3273 "eval('obj.x');"
3310 "eval('obj.x');" 3274 "eval('obj.x');"
3311 "obj = intercepted_2;" 3275 "obj = intercepted_2;"
3312 "obj.x = 9;" 3276 "obj.x = 9;"
3313 "eval('obj.x');", 3277 "eval('obj.x');",
3314 9); 3278 9);
3315 } 3279 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/mjsunit/migrations.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698