OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 9157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9168 CHECK(try_catch.HasCaught()); | 9168 CHECK(try_catch.HasCaught()); |
9169 CHECK(!try_catch.Message().IsEmpty()); | 9169 CHECK(!try_catch.Message().IsEmpty()); |
9170 String::Utf8Value finally_exception_value(try_catch.Exception()); | 9170 String::Utf8Value finally_exception_value(try_catch.Exception()); |
9171 CHECK_EQ(0, strcmp(*finally_exception_value, "2")); | 9171 CHECK_EQ(0, strcmp(*finally_exception_value, "2")); |
9172 } | 9172 } |
9173 | 9173 |
9174 | 9174 |
9175 // For use within the TestSecurityHandler() test. | 9175 // For use within the TestSecurityHandler() test. |
9176 static bool g_security_callback_result = false; | 9176 static bool g_security_callback_result = false; |
9177 static bool SecurityTestCallback(Local<v8::Context> accessing_context, | 9177 static bool SecurityTestCallback(Local<v8::Context> accessing_context, |
9178 Local<v8::Object> accessed_object) { | 9178 Local<v8::Object> accessed_object, |
| 9179 Local<v8::Value> data) { |
9179 printf("a\n"); | 9180 printf("a\n"); |
9180 return g_security_callback_result; | 9181 return g_security_callback_result; |
9181 } | 9182 } |
9182 | 9183 |
9183 | 9184 |
9184 // SecurityHandler can't be run twice | 9185 // SecurityHandler can't be run twice |
9185 TEST(SecurityHandler) { | 9186 TEST(SecurityHandler) { |
9186 v8::Isolate* isolate = CcTest::isolate(); | 9187 v8::Isolate* isolate = CcTest::isolate(); |
9187 v8::HandleScope scope0(isolate); | 9188 v8::HandleScope scope0(isolate); |
9188 v8::Local<v8::ObjectTemplate> global_template = | 9189 v8::Local<v8::ObjectTemplate> global_template = |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9366 for (int k = 0; k < 5; k++) { | 9367 for (int k = 0; k < 5; k++) { |
9367 CHECK(access_f2->Run(current.local()).IsEmpty()); | 9368 CHECK(access_f2->Run(current.local()).IsEmpty()); |
9368 CHECK(access_f3->Run(current.local()).IsEmpty()); | 9369 CHECK(access_f3->Run(current.local()).IsEmpty()); |
9369 } | 9370 } |
9370 } | 9371 } |
9371 | 9372 |
9372 | 9373 |
9373 static bool security_check_with_gc_called; | 9374 static bool security_check_with_gc_called; |
9374 | 9375 |
9375 static bool SecurityTestCallbackWithGC(Local<v8::Context> accessing_context, | 9376 static bool SecurityTestCallbackWithGC(Local<v8::Context> accessing_context, |
9376 Local<v8::Object> accessed_object) { | 9377 Local<v8::Object> accessed_object, |
| 9378 Local<v8::Value> data) { |
9377 CcTest::heap()->CollectAllGarbage(); | 9379 CcTest::heap()->CollectAllGarbage(); |
9378 security_check_with_gc_called = true; | 9380 security_check_with_gc_called = true; |
9379 return true; | 9381 return true; |
9380 } | 9382 } |
9381 | 9383 |
9382 | 9384 |
9383 TEST(SecurityTestGCAllowed) { | 9385 TEST(SecurityTestGCAllowed) { |
9384 v8::Isolate* isolate = CcTest::isolate(); | 9386 v8::Isolate* isolate = CcTest::isolate(); |
9385 v8::HandleScope handle_scope(isolate); | 9387 v8::HandleScope handle_scope(isolate); |
9386 v8::Local<v8::ObjectTemplate> object_template = | 9388 v8::Local<v8::ObjectTemplate> object_template = |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9853 CHECK(v8_str("env2_x") | 9855 CHECK(v8_str("env2_x") |
9854 ->Equals(env1.local(), | 9856 ->Equals(env1.local(), |
9855 results->Get(env1.local(), i + 3).ToLocalChecked()) | 9857 results->Get(env1.local(), i + 3).ToLocalChecked()) |
9856 .FromJust()); | 9858 .FromJust()); |
9857 } | 9859 } |
9858 } | 9860 } |
9859 | 9861 |
9860 | 9862 |
9861 static bool allowed_access = false; | 9863 static bool allowed_access = false; |
9862 static bool AccessBlocker(Local<v8::Context> accessing_context, | 9864 static bool AccessBlocker(Local<v8::Context> accessing_context, |
9863 Local<v8::Object> accessed_object) { | 9865 Local<v8::Object> accessed_object, |
| 9866 Local<v8::Value> data) { |
9864 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); | 9867 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); |
9865 return context->Global()->Equals(context, accessed_object).FromJust() || | 9868 return context->Global()->Equals(context, accessed_object).FromJust() || |
9866 allowed_access; | 9869 allowed_access; |
9867 } | 9870 } |
9868 | 9871 |
9869 | 9872 |
9870 static int g_echo_value = -1; | 9873 static int g_echo_value = -1; |
9871 | 9874 |
9872 | 9875 |
9873 static void EchoGetter( | 9876 static void EchoGetter( |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10147 CHECK_EQ(42, g_echo_value); | 10150 CHECK_EQ(42, g_echo_value); |
10148 | 10151 |
10149 // [[DefineOwnProperty]] always throws for access-checked objects. | 10152 // [[DefineOwnProperty]] always throws for access-checked objects. |
10150 CHECK( | 10153 CHECK( |
10151 CompileRun("Object.defineProperty(other, 'accessible_prop', {value: 43})") | 10154 CompileRun("Object.defineProperty(other, 'accessible_prop', {value: 43})") |
10152 .IsEmpty()); | 10155 .IsEmpty()); |
10153 CHECK(CompileRun("other.accessible_prop == 42")->IsTrue()); | 10156 CHECK(CompileRun("other.accessible_prop == 42")->IsTrue()); |
10154 CHECK_EQ(42, g_echo_value); // Make sure we didn't call the setter. | 10157 CHECK_EQ(42, g_echo_value); // Make sure we didn't call the setter. |
10155 } | 10158 } |
10156 | 10159 |
10157 | |
10158 static bool AccessAlwaysBlocked(Local<v8::Context> accessing_context, | 10160 static bool AccessAlwaysBlocked(Local<v8::Context> accessing_context, |
10159 Local<v8::Object> global) { | 10161 Local<v8::Object> global, |
| 10162 Local<v8::Value> data) { |
10160 i::PrintF("Access blocked.\n"); | 10163 i::PrintF("Access blocked.\n"); |
10161 return false; | 10164 return false; |
10162 } | 10165 } |
10163 | 10166 |
10164 | 10167 |
10165 THREADED_TEST(AccessControlGetOwnPropertyNames) { | 10168 THREADED_TEST(AccessControlGetOwnPropertyNames) { |
10166 v8::Isolate* isolate = CcTest::isolate(); | 10169 v8::Isolate* isolate = CcTest::isolate(); |
10167 v8::HandleScope handle_scope(isolate); | 10170 v8::HandleScope handle_scope(isolate); |
10168 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate); | 10171 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate); |
10169 | 10172 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10293 CHECK(maybe_value.IsEmpty()); | 10296 CHECK(maybe_value.IsEmpty()); |
10294 | 10297 |
10295 context1->Exit(); | 10298 context1->Exit(); |
10296 context0->Exit(); | 10299 context0->Exit(); |
10297 } | 10300 } |
10298 | 10301 |
10299 | 10302 |
10300 static int access_count = 0; | 10303 static int access_count = 0; |
10301 | 10304 |
10302 static bool AccessCounter(Local<v8::Context> accessing_context, | 10305 static bool AccessCounter(Local<v8::Context> accessing_context, |
10303 Local<v8::Object> accessed_object) { | 10306 Local<v8::Object> accessed_object, |
| 10307 Local<v8::Value> data) { |
10304 access_count++; | 10308 access_count++; |
10305 return true; | 10309 return true; |
10306 } | 10310 } |
10307 | 10311 |
10308 | 10312 |
10309 // This one is too easily disturbed by other tests. | 10313 // This one is too easily disturbed by other tests. |
10310 TEST(AccessControlIC) { | 10314 TEST(AccessControlIC) { |
10311 access_count = 0; | 10315 access_count = 0; |
10312 | 10316 |
10313 v8::Isolate* isolate = CcTest::isolate(); | 10317 v8::Isolate* isolate = CcTest::isolate(); |
(...skipping 13807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24121 // Should work | 24125 // Should work |
24122 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 24126 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
24123 | 24127 |
24124 USE(obj); | 24128 USE(obj); |
24125 } | 24129 } |
24126 } | 24130 } |
24127 | 24131 |
24128 | 24132 |
24129 static bool access_was_called = false; | 24133 static bool access_was_called = false; |
24130 | 24134 |
24131 | |
24132 static bool AccessAlwaysAllowedWithFlag(Local<v8::Context> accessing_context, | 24135 static bool AccessAlwaysAllowedWithFlag(Local<v8::Context> accessing_context, |
24133 Local<v8::Object> accessed_object) { | 24136 Local<v8::Object> accessed_object, |
| 24137 Local<v8::Value> data) { |
24134 access_was_called = true; | 24138 access_was_called = true; |
24135 return true; | 24139 return true; |
24136 } | 24140 } |
24137 | 24141 |
24138 | |
24139 static bool AccessAlwaysBlockedWithFlag(Local<v8::Context> accessing_context, | 24142 static bool AccessAlwaysBlockedWithFlag(Local<v8::Context> accessing_context, |
24140 Local<v8::Object> accessed_object) { | 24143 Local<v8::Object> accessed_object, |
| 24144 Local<v8::Value> data) { |
24141 access_was_called = true; | 24145 access_was_called = true; |
24142 return false; | 24146 return false; |
24143 } | 24147 } |
24144 | 24148 |
24145 | 24149 |
24146 TEST(StrongModeAccessCheckAllowed) { | 24150 TEST(StrongModeAccessCheckAllowed) { |
24147 i::FLAG_strong_mode = true; | 24151 i::FLAG_strong_mode = true; |
24148 v8::Isolate* isolate = CcTest::isolate(); | 24152 v8::Isolate* isolate = CcTest::isolate(); |
24149 v8::HandleScope handle_scope(isolate); | 24153 v8::HandleScope handle_scope(isolate); |
24150 v8::Local<Value> value; | 24154 v8::Local<Value> value; |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24879 CHECK(proxy->GetTarget()->SameValue(target)); | 24883 CHECK(proxy->GetTarget()->SameValue(target)); |
24880 CHECK(proxy->GetHandler()->SameValue(handler)); | 24884 CHECK(proxy->GetHandler()->SameValue(handler)); |
24881 | 24885 |
24882 proxy->Revoke(); | 24886 proxy->Revoke(); |
24883 CHECK(proxy->IsProxy()); | 24887 CHECK(proxy->IsProxy()); |
24884 CHECK(!target->IsProxy()); | 24888 CHECK(!target->IsProxy()); |
24885 CHECK(proxy->IsRevoked()); | 24889 CHECK(proxy->IsRevoked()); |
24886 CHECK(proxy->GetTarget()->SameValue(target)); | 24890 CHECK(proxy->GetTarget()->SameValue(target)); |
24887 CHECK(proxy->GetHandler()->IsNull()); | 24891 CHECK(proxy->GetHandler()->IsNull()); |
24888 } | 24892 } |
OLD | NEW |