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

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

Issue 1773653002: [strong] Remove all remainders of strong mode (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Oversight Created 4 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 | « test/cctest/heap/test-heap.cc ('k') | test/cctest/test-parsing.cc » ('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 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 13058 matching lines...) Expand 10 before | Expand all | Expand 10 after
13069 Local<Boolean> should_throw_on_error_value = 13069 Local<Boolean> should_throw_on_error_value =
13070 Boolean::New(isolate, info.ShouldThrowOnError()); 13070 Boolean::New(isolate, info.ShouldThrowOnError());
13071 CHECK(context->Global() 13071 CHECK(context->Global()
13072 ->Set(isolate->GetCurrentContext(), v8_str("should_throw_setter"), 13072 ->Set(isolate->GetCurrentContext(), v8_str("should_throw_setter"),
13073 should_throw_on_error_value) 13073 should_throw_on_error_value)
13074 .FromJust()); 13074 .FromJust());
13075 } 13075 }
13076 13076
13077 13077
13078 THREADED_TEST(AccessorShouldThrowOnError) { 13078 THREADED_TEST(AccessorShouldThrowOnError) {
13079 i::FLAG_strong_mode = true;
13080 LocalContext context; 13079 LocalContext context;
13081 v8::Isolate* isolate = context->GetIsolate(); 13080 v8::Isolate* isolate = context->GetIsolate();
13082 v8::HandleScope scope(isolate); 13081 v8::HandleScope scope(isolate);
13083 Local<Object> global = context->Global(); 13082 Local<Object> global = context->Global();
13084 13083
13085 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); 13084 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
13086 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); 13085 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate();
13087 instance_templ->SetAccessor(v8_str("f"), ShouldThrowOnErrorGetter, 13086 instance_templ->SetAccessor(v8_str("f"), ShouldThrowOnErrorGetter,
13088 ShouldThrowOnErrorSetter<void>); 13087 ShouldThrowOnErrorSetter<void>);
13089 13088
(...skipping 12 matching lines...) Expand all
13102 .ToLocalChecked(); 13101 .ToLocalChecked();
13103 CHECK(value->IsFalse()); 13102 CHECK(value->IsFalse());
13104 13103
13105 // STRICT mode 13104 // STRICT mode
13106 value = v8_compile("'use strict';o.f")->Run(context.local()).ToLocalChecked(); 13105 value = v8_compile("'use strict';o.f")->Run(context.local()).ToLocalChecked();
13107 CHECK(value->IsFalse()); 13106 CHECK(value->IsFalse());
13108 v8_compile("'use strict'; o.f = 153")->Run(context.local()).ToLocalChecked(); 13107 v8_compile("'use strict'; o.f = 153")->Run(context.local()).ToLocalChecked();
13109 value = global->Get(context.local(), v8_str("should_throw_setter")) 13108 value = global->Get(context.local(), v8_str("should_throw_setter"))
13110 .ToLocalChecked(); 13109 .ToLocalChecked();
13111 CHECK(value->IsTrue()); 13110 CHECK(value->IsTrue());
13112
13113 // STRONG mode
13114 value = v8_compile("'use strong';o.f")->Run(context.local()).ToLocalChecked();
13115 CHECK(value->IsFalse());
13116 v8_compile("'use strong'; o.f = 153")->Run(context.local()).ToLocalChecked();
13117 value = global->Get(context.local(), v8_str("should_throw_setter"))
13118 .ToLocalChecked();
13119 CHECK(value->IsTrue());
13120 } 13111 }
13121 13112
13122 13113
13123 static void ShouldThrowOnErrorQuery( 13114 static void ShouldThrowOnErrorQuery(
13124 Local<Name> name, const v8::PropertyCallbackInfo<v8::Integer>& info) { 13115 Local<Name> name, const v8::PropertyCallbackInfo<v8::Integer>& info) {
13125 ApiTestFuzzer::Fuzz(); 13116 ApiTestFuzzer::Fuzz();
13126 v8::Isolate* isolate = info.GetIsolate(); 13117 v8::Isolate* isolate = info.GetIsolate();
13127 info.GetReturnValue().Set(v8::None); 13118 info.GetReturnValue().Set(v8::None);
13128 13119
13129 auto context = isolate->GetCurrentContext(); 13120 auto context = isolate->GetCurrentContext();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
13165 Boolean::New(isolate, info.ShouldThrowOnError()); 13156 Boolean::New(isolate, info.ShouldThrowOnError());
13166 CHECK(context->Global() 13157 CHECK(context->Global()
13167 ->Set(isolate->GetCurrentContext(), 13158 ->Set(isolate->GetCurrentContext(),
13168 v8_str("should_throw_enumerator"), 13159 v8_str("should_throw_enumerator"),
13169 should_throw_on_error_value) 13160 should_throw_on_error_value)
13170 .FromJust()); 13161 .FromJust());
13171 } 13162 }
13172 13163
13173 13164
13174 THREADED_TEST(InterceptorShouldThrowOnError) { 13165 THREADED_TEST(InterceptorShouldThrowOnError) {
13175 i::FLAG_strong_mode = true;
13176 LocalContext context; 13166 LocalContext context;
13177 v8::Isolate* isolate = context->GetIsolate(); 13167 v8::Isolate* isolate = context->GetIsolate();
13178 v8::HandleScope scope(isolate); 13168 v8::HandleScope scope(isolate);
13179 Local<Object> global = context->Global(); 13169 Local<Object> global = context->Global();
13180 13170
13181 auto interceptor_templ = v8::ObjectTemplate::New(isolate); 13171 auto interceptor_templ = v8::ObjectTemplate::New(isolate);
13182 v8::NamedPropertyHandlerConfiguration handler( 13172 v8::NamedPropertyHandlerConfiguration handler(
13183 ShouldThrowOnErrorGetter, ShouldThrowOnErrorSetter<Value>, 13173 ShouldThrowOnErrorGetter, ShouldThrowOnErrorSetter<Value>,
13184 ShouldThrowOnErrorQuery, ShouldThrowOnErrorDeleter, 13174 ShouldThrowOnErrorQuery, ShouldThrowOnErrorDeleter,
13185 ShouldThrowOnErrorPropertyEnumerator); 13175 ShouldThrowOnErrorPropertyEnumerator);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
13222 value = global->Get(context.local(), v8_str("should_throw_deleter")) 13212 value = global->Get(context.local(), v8_str("should_throw_deleter"))
13223 .ToLocalChecked(); 13213 .ToLocalChecked();
13224 CHECK(value->IsTrue()); 13214 CHECK(value->IsTrue());
13225 13215
13226 v8_compile("'use strict'; Object.getOwnPropertyNames(o)") 13216 v8_compile("'use strict'; Object.getOwnPropertyNames(o)")
13227 ->Run(context.local()) 13217 ->Run(context.local())
13228 .ToLocalChecked(); 13218 .ToLocalChecked();
13229 value = global->Get(context.local(), v8_str("should_throw_enumerator")) 13219 value = global->Get(context.local(), v8_str("should_throw_enumerator"))
13230 .ToLocalChecked(); 13220 .ToLocalChecked();
13231 CHECK(value->IsFalse()); 13221 CHECK(value->IsFalse());
13232
13233 // STRONG mode
13234 value = v8_compile("'use strong';o.f")->Run(context.local()).ToLocalChecked();
13235 CHECK(value->IsFalse());
13236 v8_compile("'use strong'; o.f = 153")->Run(context.local()).ToLocalChecked();
13237 value = global->Get(context.local(), v8_str("should_throw_setter"))
13238 .ToLocalChecked();
13239 CHECK(value->IsTrue());
13240
13241 v8_compile("'use strong'; Object.getOwnPropertyNames(o)")
13242 ->Run(context.local())
13243 .ToLocalChecked();
13244 value = global->Get(context.local(), v8_str("should_throw_enumerator"))
13245 .ToLocalChecked();
13246 CHECK(value->IsFalse());
13247 } 13222 }
13248 13223
13249 13224
13250 static void IsConstructHandler( 13225 static void IsConstructHandler(
13251 const v8::FunctionCallbackInfo<v8::Value>& args) { 13226 const v8::FunctionCallbackInfo<v8::Value>& args) {
13252 ApiTestFuzzer::Fuzz(); 13227 ApiTestFuzzer::Fuzz();
13253 args.GetReturnValue().Set(args.IsConstructCall()); 13228 args.GetReturnValue().Set(args.IsConstructCall());
13254 } 13229 }
13255 13230
13256 13231
(...skipping 11096 matching lines...) Expand 10 before | Expand all | Expand 10 after
24353 v8::HandleScope handle_scope(isolate); 24328 v8::HandleScope handle_scope(isolate);
24354 24329
24355 // Should work 24330 // Should work
24356 v8::Local<v8::Object> obj = v8::Object::New(isolate); 24331 v8::Local<v8::Object> obj = v8::Object::New(isolate);
24357 24332
24358 USE(obj); 24333 USE(obj);
24359 } 24334 }
24360 } 24335 }
24361 24336
24362 24337
24363 static bool access_was_called = false;
24364
24365 static bool AccessAlwaysAllowedWithFlag(Local<v8::Context> accessing_context,
24366 Local<v8::Object> accessed_object,
24367 Local<v8::Value> data) {
24368 access_was_called = true;
24369 return true;
24370 }
24371
24372 static bool AccessAlwaysBlockedWithFlag(Local<v8::Context> accessing_context,
24373 Local<v8::Object> accessed_object,
24374 Local<v8::Value> data) {
24375 access_was_called = true;
24376 return false;
24377 }
24378
24379
24380 TEST(StrongModeAccessCheckAllowed) {
24381 i::FLAG_strong_mode = true;
24382 v8::Isolate* isolate = CcTest::isolate();
24383 v8::HandleScope handle_scope(isolate);
24384 v8::Local<Value> value;
24385 access_was_called = false;
24386
24387 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate);
24388
24389 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42));
24390 obj_template->SetAccessCheckCallback(AccessAlwaysAllowedWithFlag);
24391
24392 // Create an environment
24393 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
24394 context0->Enter();
24395 v8::Local<v8::Object> global0 = context0->Global();
24396 global0->Set(context0, v8_str("object"),
24397 obj_template->NewInstance(context0).ToLocalChecked())
24398 .FromJust();
24399 {
24400 v8::TryCatch try_catch(isolate);
24401 value = CompileRun("'use strong'; object.x");
24402 CHECK(!try_catch.HasCaught());
24403 CHECK(!access_was_called);
24404 CHECK_EQ(42, value->Int32Value(context0).FromJust());
24405 }
24406 {
24407 v8::TryCatch try_catch(isolate);
24408 value = CompileRun("'use strong'; object.foo");
24409 CHECK(try_catch.HasCaught());
24410 CHECK(!access_was_called);
24411 }
24412 {
24413 v8::TryCatch try_catch(isolate);
24414 value = CompileRun("'use strong'; object[10]");
24415 CHECK(try_catch.HasCaught());
24416 CHECK(!access_was_called);
24417 }
24418
24419 // Create an environment
24420 v8::Local<Context> context1 = Context::New(isolate);
24421 context1->Enter();
24422 v8::Local<v8::Object> global1 = context1->Global();
24423 global1->Set(context1, v8_str("object"),
24424 obj_template->NewInstance(context1).ToLocalChecked())
24425 .FromJust();
24426 {
24427 v8::TryCatch try_catch(isolate);
24428 value = CompileRun("'use strong'; object.x");
24429 CHECK(!try_catch.HasCaught());
24430 CHECK(access_was_called);
24431 CHECK_EQ(42, value->Int32Value(context1).FromJust());
24432 }
24433 access_was_called = false;
24434 {
24435 v8::TryCatch try_catch(isolate);
24436 value = CompileRun("'use strong'; object.foo");
24437 CHECK(try_catch.HasCaught());
24438 CHECK(access_was_called);
24439 }
24440 access_was_called = false;
24441 {
24442 v8::TryCatch try_catch(isolate);
24443 value = CompileRun("'use strong'; object[10]");
24444 CHECK(try_catch.HasCaught());
24445 CHECK(access_was_called);
24446 }
24447
24448 context1->Exit();
24449 context0->Exit();
24450 }
24451
24452
24453 TEST(StrongModeAccessCheckBlocked) {
24454 i::FLAG_strong_mode = true;
24455 v8::Isolate* isolate = CcTest::isolate();
24456 v8::HandleScope handle_scope(isolate);
24457 v8::Local<Value> value;
24458 access_was_called = false;
24459
24460 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate);
24461
24462 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42));
24463 obj_template->SetAccessCheckCallback(AccessAlwaysBlockedWithFlag);
24464
24465 // Create an environment
24466 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
24467 context0->Enter();
24468 v8::Local<v8::Object> global0 = context0->Global();
24469 global0->Set(context0, v8_str("object"),
24470 obj_template->NewInstance(context0).ToLocalChecked())
24471 .FromJust();
24472 {
24473 v8::TryCatch try_catch(isolate);
24474 value = CompileRun("'use strong'; object.x");
24475 CHECK(!try_catch.HasCaught());
24476 CHECK(!access_was_called);
24477 CHECK_EQ(42, value->Int32Value(context0).FromJust());
24478 }
24479 {
24480 v8::TryCatch try_catch(isolate);
24481 value = CompileRun("'use strong'; object.foo");
24482 CHECK(try_catch.HasCaught());
24483 CHECK(!access_was_called);
24484 }
24485 {
24486 v8::TryCatch try_catch(isolate);
24487 value = CompileRun("'use strong'; object[10]");
24488 CHECK(try_catch.HasCaught());
24489 CHECK(!access_was_called);
24490 }
24491
24492 // Create an environment
24493 v8::Local<Context> context1 = Context::New(isolate);
24494 context1->Enter();
24495 v8::Local<v8::Object> global1 = context1->Global();
24496 global1->Set(context1, v8_str("object"),
24497 obj_template->NewInstance(context1).ToLocalChecked())
24498 .FromJust();
24499 {
24500 v8::TryCatch try_catch(isolate);
24501 value = CompileRun("'use strong'; object.x");
24502 CHECK(try_catch.HasCaught());
24503 CHECK(access_was_called);
24504 }
24505 access_was_called = false;
24506 {
24507 v8::TryCatch try_catch(isolate);
24508 value = CompileRun("'use strong'; object.foo");
24509 CHECK(try_catch.HasCaught());
24510 CHECK(access_was_called);
24511 }
24512 access_was_called = false;
24513 {
24514 v8::TryCatch try_catch(isolate);
24515 value = CompileRun("'use strong'; object[10]");
24516 CHECK(try_catch.HasCaught());
24517 CHECK(access_was_called);
24518 }
24519
24520 context1->Exit();
24521 context0->Exit();
24522 }
24523
24524
24525 TEST(StrongModeArityCallFromApi) {
24526 i::FLAG_strong_mode = true;
24527 LocalContext env;
24528 v8::Isolate* isolate = env->GetIsolate();
24529 v8::HandleScope scope(isolate);
24530 Local<Function> fun;
24531 {
24532 v8::TryCatch try_catch(isolate);
24533 fun = Local<Function>::Cast(CompileRun(
24534 "function f(x) { 'use strong'; }"
24535 "f"));
24536
24537 CHECK(!try_catch.HasCaught());
24538 }
24539
24540 {
24541 v8::TryCatch try_catch(isolate);
24542 CHECK(fun->Call(env.local(), v8::Undefined(isolate), 0, nullptr).IsEmpty());
24543 CHECK(try_catch.HasCaught());
24544 }
24545
24546 {
24547 v8::TryCatch try_catch(isolate);
24548 v8::Local<Value> args[] = {v8_num(42)};
24549 fun->Call(env.local(), v8::Undefined(isolate), arraysize(args), args)
24550 .ToLocalChecked();
24551 CHECK(!try_catch.HasCaught());
24552 }
24553
24554 {
24555 v8::TryCatch try_catch(isolate);
24556 v8::Local<Value> args[] = {v8_num(42), v8_num(555)};
24557 fun->Call(env.local(), v8::Undefined(isolate), arraysize(args), args)
24558 .ToLocalChecked();
24559 CHECK(!try_catch.HasCaught());
24560 }
24561 }
24562
24563
24564 TEST(StrongModeArityCallFromApi2) {
24565 i::FLAG_strong_mode = true;
24566 LocalContext env;
24567 v8::Isolate* isolate = env->GetIsolate();
24568 v8::HandleScope scope(isolate);
24569 Local<Function> fun;
24570 {
24571 v8::TryCatch try_catch(isolate);
24572 fun = Local<Function>::Cast(CompileRun(
24573 "'use strong';"
24574 "function f(x) {}"
24575 "f"));
24576
24577 CHECK(!try_catch.HasCaught());
24578 }
24579
24580 {
24581 v8::TryCatch try_catch(isolate);
24582 CHECK(fun->Call(env.local(), v8::Undefined(isolate), 0, nullptr).IsEmpty());
24583 CHECK(try_catch.HasCaught());
24584 }
24585
24586 {
24587 v8::TryCatch try_catch(isolate);
24588 v8::Local<Value> args[] = {v8_num(42)};
24589 fun->Call(env.local(), v8::Undefined(isolate), arraysize(args), args)
24590 .ToLocalChecked();
24591 CHECK(!try_catch.HasCaught());
24592 }
24593
24594 {
24595 v8::TryCatch try_catch(isolate);
24596 v8::Local<Value> args[] = {v8_num(42), v8_num(555)};
24597 fun->Call(env.local(), v8::Undefined(isolate), arraysize(args), args)
24598 .ToLocalChecked();
24599 CHECK(!try_catch.HasCaught());
24600 }
24601 }
24602
24603
24604 static void ExtrasBindingTestRuntimeFunction( 24338 static void ExtrasBindingTestRuntimeFunction(
24605 const v8::FunctionCallbackInfo<v8::Value>& args) { 24339 const v8::FunctionCallbackInfo<v8::Value>& args) {
24606 CHECK_EQ( 24340 CHECK_EQ(
24607 3, 24341 3,
24608 args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust()); 24342 args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust());
24609 args.GetReturnValue().Set(v8_num(7)); 24343 args.GetReturnValue().Set(v8_num(7));
24610 } 24344 }
24611 24345
24612 TEST(ExtrasFunctionSource) { 24346 TEST(ExtrasFunctionSource) {
24613 v8::Isolate* isolate = CcTest::isolate(); 24347 v8::Isolate* isolate = CcTest::isolate();
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
25119 CHECK(proxy->GetTarget()->SameValue(target)); 24853 CHECK(proxy->GetTarget()->SameValue(target));
25120 CHECK(proxy->GetHandler()->SameValue(handler)); 24854 CHECK(proxy->GetHandler()->SameValue(handler));
25121 24855
25122 proxy->Revoke(); 24856 proxy->Revoke();
25123 CHECK(proxy->IsProxy()); 24857 CHECK(proxy->IsProxy());
25124 CHECK(!target->IsProxy()); 24858 CHECK(!target->IsProxy());
25125 CHECK(proxy->IsRevoked()); 24859 CHECK(proxy->IsRevoked());
25126 CHECK(proxy->GetTarget()->SameValue(target)); 24860 CHECK(proxy->GetTarget()->SameValue(target));
25127 CHECK(proxy->GetHandler()->IsNull()); 24861 CHECK(proxy->GetHandler()->IsNull());
25128 } 24862 }
OLDNEW
« no previous file with comments | « test/cctest/heap/test-heap.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698