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

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

Issue 2677133002: [test] Cleanup CHECK_EQ order. (Closed)
Patch Set: Reparent to master. Created 3 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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 v8::FunctionTemplate::New(CcTest::isolate()); 397 v8::FunctionTemplate::New(CcTest::isolate());
398 templ->InstanceTemplate()->SetHandler( 398 templ->InstanceTemplate()->SetHandler(
399 v8::NamedPropertyHandlerConfiguration(0, 0, QueryCallback)); 399 v8::NamedPropertyHandlerConfiguration(0, 0, QueryCallback));
400 LocalContext env; 400 LocalContext env;
401 env->Global() 401 env->Global()
402 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) 402 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
403 .ToLocalChecked() 403 .ToLocalChecked()
404 ->NewInstance(env.local()) 404 ->NewInstance(env.local())
405 .ToLocalChecked()) 405 .ToLocalChecked())
406 .FromJust(); 406 .FromJust();
407 CHECK_EQ(query_counter_int, 0); 407 CHECK_EQ(0, query_counter_int);
408 v8::Local<Value> result = 408 v8::Local<Value> result =
409 v8_compile("Object.getOwnPropertyDescriptor(obj, 'x');") 409 v8_compile("Object.getOwnPropertyDescriptor(obj, 'x');")
410 ->Run(env.local()) 410 ->Run(env.local())
411 .ToLocalChecked(); 411 .ToLocalChecked();
412 CHECK_EQ(query_counter_int, 1); 412 CHECK_EQ(1, query_counter_int);
413 CHECK_EQ(v8::PropertyAttribute::None, 413 CHECK_EQ(v8::PropertyAttribute::None,
414 static_cast<v8::PropertyAttribute>( 414 static_cast<v8::PropertyAttribute>(
415 result->Int32Value(env.local()).FromJust())); 415 result->Int32Value(env.local()).FromJust()));
416 416
417 v8_compile("Object.defineProperty(obj, 'not_enum', {value: 17});") 417 v8_compile("Object.defineProperty(obj, 'not_enum', {value: 17});")
418 ->Run(env.local()) 418 ->Run(env.local())
419 .ToLocalChecked(); 419 .ToLocalChecked();
420 CHECK_EQ(query_counter_int, 2); 420 CHECK_EQ(2, query_counter_int);
421 421
422 v8_compile( 422 v8_compile(
423 "Object.defineProperty(obj, 'enum', {value: 17, enumerable: true, " 423 "Object.defineProperty(obj, 'enum', {value: 17, enumerable: true, "
424 "writable: true});") 424 "writable: true});")
425 ->Run(env.local()) 425 ->Run(env.local())
426 .ToLocalChecked(); 426 .ToLocalChecked();
427 CHECK_EQ(query_counter_int, 3); 427 CHECK_EQ(3, query_counter_int);
428 428
429 CHECK(v8_compile("obj.propertyIsEnumerable('enum');") 429 CHECK(v8_compile("obj.propertyIsEnumerable('enum');")
430 ->Run(env.local()) 430 ->Run(env.local())
431 .ToLocalChecked() 431 .ToLocalChecked()
432 ->BooleanValue(env.local()) 432 ->BooleanValue(env.local())
433 .FromJust()); 433 .FromJust());
434 CHECK_EQ(query_counter_int, 4); 434 CHECK_EQ(4, query_counter_int);
435 435
436 CHECK(!v8_compile("obj.propertyIsEnumerable('not_enum');") 436 CHECK(!v8_compile("obj.propertyIsEnumerable('not_enum');")
437 ->Run(env.local()) 437 ->Run(env.local())
438 .ToLocalChecked() 438 .ToLocalChecked()
439 ->BooleanValue(env.local()) 439 ->BooleanValue(env.local())
440 .FromJust()); 440 .FromJust());
441 CHECK_EQ(query_counter_int, 5); 441 CHECK_EQ(5, query_counter_int);
442 442
443 CHECK(v8_compile("obj.hasOwnProperty('enum');") 443 CHECK(v8_compile("obj.hasOwnProperty('enum');")
444 ->Run(env.local()) 444 ->Run(env.local())
445 .ToLocalChecked() 445 .ToLocalChecked()
446 ->BooleanValue(env.local()) 446 ->BooleanValue(env.local())
447 .FromJust()); 447 .FromJust());
448 CHECK_EQ(query_counter_int, 5); 448 CHECK_EQ(5, query_counter_int);
449 449
450 CHECK(v8_compile("obj.hasOwnProperty('not_enum');") 450 CHECK(v8_compile("obj.hasOwnProperty('not_enum');")
451 ->Run(env.local()) 451 ->Run(env.local())
452 .ToLocalChecked() 452 .ToLocalChecked()
453 ->BooleanValue(env.local()) 453 ->BooleanValue(env.local())
454 .FromJust()); 454 .FromJust());
455 CHECK_EQ(query_counter_int, 5); 455 CHECK_EQ(5, query_counter_int);
456 456
457 CHECK(!v8_compile("obj.hasOwnProperty('x');") 457 CHECK(!v8_compile("obj.hasOwnProperty('x');")
458 ->Run(env.local()) 458 ->Run(env.local())
459 .ToLocalChecked() 459 .ToLocalChecked()
460 ->BooleanValue(env.local()) 460 ->BooleanValue(env.local())
461 .FromJust()); 461 .FromJust());
462 CHECK_EQ(query_counter_int, 6); 462 CHECK_EQ(6, query_counter_int);
463 463
464 CHECK(!v8_compile("obj.propertyIsEnumerable('undef');") 464 CHECK(!v8_compile("obj.propertyIsEnumerable('undef');")
465 ->Run(env.local()) 465 ->Run(env.local())
466 .ToLocalChecked() 466 .ToLocalChecked()
467 ->BooleanValue(env.local()) 467 ->BooleanValue(env.local())
468 .FromJust()); 468 .FromJust());
469 CHECK_EQ(query_counter_int, 7); 469 CHECK_EQ(7, query_counter_int);
470 470
471 v8_compile("Object.defineProperty(obj, 'enum', {value: 42});") 471 v8_compile("Object.defineProperty(obj, 'enum', {value: 42});")
472 ->Run(env.local()) 472 ->Run(env.local())
473 .ToLocalChecked(); 473 .ToLocalChecked();
474 CHECK_EQ(query_counter_int, 8); 474 CHECK_EQ(8, query_counter_int);
475 475
476 v8_compile("Object.isFrozen('obj.x');")->Run(env.local()).ToLocalChecked(); 476 v8_compile("Object.isFrozen('obj.x');")->Run(env.local()).ToLocalChecked();
477 CHECK_EQ(query_counter_int, 8); 477 CHECK_EQ(8, query_counter_int);
478 } 478 }
479 479
480 namespace { 480 namespace {
481 481
482 bool get_was_called = false; 482 bool get_was_called = false;
483 bool set_was_called = false; 483 bool set_was_called = false;
484 484
485 int set_was_called_counter = 0; 485 int set_was_called_counter = 0;
486 486
487 void GetterCallback(Local<Name> property, 487 void GetterCallback(Local<Name> property,
(...skipping 23 matching lines...) Expand all
511 ->NewInstance(env.local()) 511 ->NewInstance(env.local())
512 .ToLocalChecked()) 512 .ToLocalChecked())
513 .FromJust(); 513 .FromJust();
514 514
515 get_was_called = false; 515 get_was_called = false;
516 set_was_called = false; 516 set_was_called = false;
517 517
518 v8_compile("Object.defineProperty(obj, 'x', {set: function() {return 17;}});") 518 v8_compile("Object.defineProperty(obj, 'x', {set: function() {return 17;}});")
519 ->Run(env.local()) 519 ->Run(env.local())
520 .ToLocalChecked(); 520 .ToLocalChecked();
521 CHECK_EQ(get_was_called, true); 521 CHECK(get_was_called);
522 CHECK_EQ(set_was_called, false); 522 CHECK(!set_was_called);
523 } 523 }
524 524
525 // Check that set callback is called for function declarations. 525 // Check that set callback is called for function declarations.
526 THREADED_TEST(SetterCallbackFunctionDeclarationInterceptor) { 526 THREADED_TEST(SetterCallbackFunctionDeclarationInterceptor) {
527 v8::HandleScope scope(CcTest::isolate()); 527 v8::HandleScope scope(CcTest::isolate());
528 LocalContext env; 528 LocalContext env;
529 v8::Local<v8::FunctionTemplate> templ = 529 v8::Local<v8::FunctionTemplate> templ =
530 v8::FunctionTemplate::New(CcTest::isolate()); 530 v8::FunctionTemplate::New(CcTest::isolate());
531 531
532 v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate(); 532 v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate();
533 object_template->SetHandler( 533 object_template->SetHandler(
534 v8::NamedPropertyHandlerConfiguration(nullptr, SetterCallback)); 534 v8::NamedPropertyHandlerConfiguration(nullptr, SetterCallback));
535 v8::Local<v8::Context> ctx = 535 v8::Local<v8::Context> ctx =
536 v8::Context::New(CcTest::isolate(), nullptr, object_template); 536 v8::Context::New(CcTest::isolate(), nullptr, object_template);
537 537
538 set_was_called_counter = 0; 538 set_was_called_counter = 0;
539 539
540 // Declare function. 540 // Declare function.
541 v8::Local<v8::String> code = v8_str("function x() {return 42;}; x();"); 541 v8::Local<v8::String> code = v8_str("function x() {return 42;}; x();");
542 CHECK_EQ(42, v8::Script::Compile(ctx, code) 542 CHECK_EQ(42, v8::Script::Compile(ctx, code)
543 .ToLocalChecked() 543 .ToLocalChecked()
544 ->Run(ctx) 544 ->Run(ctx)
545 .ToLocalChecked() 545 .ToLocalChecked()
546 ->Int32Value(ctx) 546 ->Int32Value(ctx)
547 .FromJust()); 547 .FromJust());
548 CHECK_EQ(set_was_called_counter, 1); 548 CHECK_EQ(1, set_was_called_counter);
549 549
550 // Redeclare function. 550 // Redeclare function.
551 code = v8_str("function x() {return 43;}; x();"); 551 code = v8_str("function x() {return 43;}; x();");
552 CHECK_EQ(43, v8::Script::Compile(ctx, code) 552 CHECK_EQ(43, v8::Script::Compile(ctx, code)
553 .ToLocalChecked() 553 .ToLocalChecked()
554 ->Run(ctx) 554 ->Run(ctx)
555 .ToLocalChecked() 555 .ToLocalChecked()
556 ->Int32Value(ctx) 556 ->Int32Value(ctx)
557 .FromJust()); 557 .FromJust());
558 CHECK_EQ(set_was_called_counter, 2); 558 CHECK_EQ(2, set_was_called_counter);
559 559
560 // Redefine function. 560 // Redefine function.
561 code = v8_str("x = function() {return 44;}; x();"); 561 code = v8_str("x = function() {return 44;}; x();");
562 CHECK_EQ(44, v8::Script::Compile(ctx, code) 562 CHECK_EQ(44, v8::Script::Compile(ctx, code)
563 .ToLocalChecked() 563 .ToLocalChecked()
564 ->Run(ctx) 564 ->Run(ctx)
565 .ToLocalChecked() 565 .ToLocalChecked()
566 ->Int32Value(ctx) 566 ->Int32Value(ctx)
567 .FromJust()); 567 .FromJust());
568 CHECK_EQ(set_was_called_counter, 3); 568 CHECK_EQ(3, set_was_called_counter);
569 } 569 }
570 570
571 namespace { 571 namespace {
572 void QueryCallbackSetDontDelete( 572 void QueryCallbackSetDontDelete(
573 Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { 573 Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) {
574 info.GetReturnValue().Set(v8::PropertyAttribute::DontDelete); 574 info.GetReturnValue().Set(v8::PropertyAttribute::DontDelete);
575 } 575 }
576 576
577 } // namespace 577 } // namespace
578 578
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 "configurable: false, " 617 "configurable: false, "
618 "writable: false});" 618 "writable: false});"
619 "x();"); 619 "x();");
620 CHECK_EQ(42, v8::Script::Compile(ctx, code) 620 CHECK_EQ(42, v8::Script::Compile(ctx, code)
621 .ToLocalChecked() 621 .ToLocalChecked()
622 ->Run(ctx) 622 ->Run(ctx)
623 .ToLocalChecked() 623 .ToLocalChecked()
624 ->Int32Value(ctx) 624 ->Int32Value(ctx)
625 .FromJust()); 625 .FromJust());
626 626
627 CHECK_EQ(set_was_called, true); 627 CHECK(set_was_called);
628 628
629 v8::TryCatch try_catch(CcTest::isolate()); 629 v8::TryCatch try_catch(CcTest::isolate());
630 set_was_called = false; 630 set_was_called = false;
631 631
632 // Redeclare function that is read-only. 632 // Redeclare function that is read-only.
633 code = v8_str("function x() {return 43;};"); 633 code = v8_str("function x() {return 43;};");
634 CHECK(v8::Script::Compile(ctx, code).ToLocalChecked()->Run(ctx).IsEmpty()); 634 CHECK(v8::Script::Compile(ctx, code).ToLocalChecked()->Run(ctx).IsEmpty());
635 CHECK(try_catch.HasCaught()); 635 CHECK(try_catch.HasCaught());
636 636
637 CHECK_EQ(set_was_called, false); 637 CHECK(!set_was_called);
638 } 638 }
639 639
640 640
641 namespace { 641 namespace {
642 642
643 bool get_was_called_in_order = false; 643 bool get_was_called_in_order = false;
644 bool define_was_called_in_order = false; 644 bool define_was_called_in_order = false;
645 645
646 void GetterCallbackOrder(Local<Name> property, 646 void GetterCallbackOrder(Local<Name> property,
647 const v8::PropertyCallbackInfo<v8::Value>& info) { 647 const v8::PropertyCallbackInfo<v8::Value>& info) {
648 get_was_called_in_order = true; 648 get_was_called_in_order = true;
649 CHECK_EQ(define_was_called_in_order, true); 649 CHECK(define_was_called_in_order);
650 info.GetReturnValue().Set(property); 650 info.GetReturnValue().Set(property);
651 } 651 }
652 652
653 void DefinerCallbackOrder(Local<Name> property, 653 void DefinerCallbackOrder(Local<Name> property,
654 const v8::PropertyDescriptor& desc, 654 const v8::PropertyDescriptor& desc,
655 const v8::PropertyCallbackInfo<v8::Value>& info) { 655 const v8::PropertyCallbackInfo<v8::Value>& info) {
656 CHECK_EQ(get_was_called_in_order, false); // Define called before get. 656 CHECK(!get_was_called_in_order); // Define called before get.
657 define_was_called_in_order = true; 657 define_was_called_in_order = true;
658 } 658 }
659 659
660 } // namespace 660 } // namespace
661 661
662 // Check that definer callback is called before getter callback. 662 // Check that definer callback is called before getter callback.
663 THREADED_TEST(DefinerCallbackGetAndDefine) { 663 THREADED_TEST(DefinerCallbackGetAndDefine) {
664 v8::HandleScope scope(CcTest::isolate()); 664 v8::HandleScope scope(CcTest::isolate());
665 v8::Local<v8::FunctionTemplate> templ = 665 v8::Local<v8::FunctionTemplate> templ =
666 v8::FunctionTemplate::New(CcTest::isolate()); 666 v8::FunctionTemplate::New(CcTest::isolate());
667 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( 667 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration(
668 GetterCallbackOrder, SetterCallback, 0, 0, 0, DefinerCallbackOrder)); 668 GetterCallbackOrder, SetterCallback, 0, 0, 0, DefinerCallbackOrder));
669 LocalContext env; 669 LocalContext env;
670 env->Global() 670 env->Global()
671 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) 671 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
672 .ToLocalChecked() 672 .ToLocalChecked()
673 ->NewInstance(env.local()) 673 ->NewInstance(env.local())
674 .ToLocalChecked()) 674 .ToLocalChecked())
675 .FromJust(); 675 .FromJust();
676 676
677 CHECK_EQ(get_was_called_in_order, false); 677 CHECK(!get_was_called_in_order);
678 CHECK_EQ(define_was_called_in_order, false); 678 CHECK(!define_was_called_in_order);
679 679
680 v8_compile("Object.defineProperty(obj, 'x', {set: function() {return 17;}});") 680 v8_compile("Object.defineProperty(obj, 'x', {set: function() {return 17;}});")
681 ->Run(env.local()) 681 ->Run(env.local())
682 .ToLocalChecked(); 682 .ToLocalChecked();
683 CHECK_EQ(get_was_called_in_order, true); 683 CHECK(get_was_called_in_order);
684 CHECK_EQ(define_was_called_in_order, true); 684 CHECK(define_was_called_in_order);
685 } 685 }
686 686
687 namespace { // namespace for InObjectLiteralDefinitionWithInterceptor 687 namespace { // namespace for InObjectLiteralDefinitionWithInterceptor
688 688
689 // Workaround for no-snapshot builds: only intercept once Context::New() is 689 // Workaround for no-snapshot builds: only intercept once Context::New() is
690 // done, otherwise we'll intercept 690 // done, otherwise we'll intercept
691 // bootstrapping like defining array on the global object. 691 // bootstrapping like defining array on the global object.
692 bool context_is_done = false; 692 bool context_is_done = false;
693 bool getter_callback_was_called = false; 693 bool getter_callback_was_called = false;
694 694
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 instance_templ->SetHandler( 755 instance_templ->SetHandler(
756 v8::NamedPropertyHandlerConfiguration(InterceptorHasOwnPropertyGetter)); 756 v8::NamedPropertyHandlerConfiguration(InterceptorHasOwnPropertyGetter));
757 Local<Function> function = 757 Local<Function> function =
758 fun_templ->GetFunction(context.local()).ToLocalChecked(); 758 fun_templ->GetFunction(context.local()).ToLocalChecked();
759 context->Global() 759 context->Global()
760 ->Set(context.local(), v8_str("constructor"), function) 760 ->Set(context.local(), v8_str("constructor"), function)
761 .FromJust(); 761 .FromJust();
762 v8::Local<Value> value = CompileRun( 762 v8::Local<Value> value = CompileRun(
763 "var o = new constructor();" 763 "var o = new constructor();"
764 "o.hasOwnProperty('ostehaps');"); 764 "o.hasOwnProperty('ostehaps');");
765 CHECK_EQ(false, value->BooleanValue(context.local()).FromJust()); 765 CHECK(!value->BooleanValue(context.local()).FromJust());
766 value = CompileRun( 766 value = CompileRun(
767 "o.ostehaps = 42;" 767 "o.ostehaps = 42;"
768 "o.hasOwnProperty('ostehaps');"); 768 "o.hasOwnProperty('ostehaps');");
769 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust()); 769 CHECK(value->BooleanValue(context.local()).FromJust());
770 value = CompileRun( 770 value = CompileRun(
771 "var p = new constructor();" 771 "var p = new constructor();"
772 "p.hasOwnProperty('ostehaps');"); 772 "p.hasOwnProperty('ostehaps');");
773 CHECK_EQ(false, value->BooleanValue(context.local()).FromJust()); 773 CHECK(!value->BooleanValue(context.local()).FromJust());
774 } 774 }
775 775
776 776
777 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) { 777 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) {
778 LocalContext context; 778 LocalContext context;
779 v8::Isolate* isolate = context->GetIsolate(); 779 v8::Isolate* isolate = context->GetIsolate();
780 v8::HandleScope scope(isolate); 780 v8::HandleScope scope(isolate);
781 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); 781 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate);
782 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 782 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
783 instance_templ->SetHandler( 783 instance_templ->SetHandler(
(...skipping 13 matching lines...) Expand all
797 " }" 797 " }"
798 " return makestr(size >> 1) + makestr((size + 1) >> 1);" 798 " return makestr(size >> 1) + makestr((size + 1) >> 1);"
799 "}" 799 "}"
800 "var x = makestr(12345);" 800 "var x = makestr(12345);"
801 "x = makestr(31415);" 801 "x = makestr(31415);"
802 "x = makestr(23456);"); 802 "x = makestr(23456);");
803 v8::Local<Value> value = CompileRun( 803 v8::Local<Value> value = CompileRun(
804 "var o = new constructor();" 804 "var o = new constructor();"
805 "o.__proto__ = new String(x);" 805 "o.__proto__ = new String(x);"
806 "o.hasOwnProperty('ostehaps');"); 806 "o.hasOwnProperty('ostehaps');");
807 CHECK_EQ(false, value->BooleanValue(context.local()).FromJust()); 807 CHECK(!value->BooleanValue(context.local()).FromJust());
808 } 808 }
809 809
810 810
811 static void CheckInterceptorLoadIC( 811 static void CheckInterceptorLoadIC(
812 v8::GenericNamedPropertyGetterCallback getter, const char* source, 812 v8::GenericNamedPropertyGetterCallback getter, const char* source,
813 int expected) { 813 int expected) {
814 v8::Isolate* isolate = CcTest::isolate(); 814 v8::Isolate* isolate = CcTest::isolate();
815 v8::HandleScope scope(isolate); 815 v8::HandleScope scope(isolate);
816 v8::Local<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); 816 v8::Local<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
817 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(getter, 0, 0, 0, 0, 817 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(getter, 0, 0, 0, 0,
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 " try {" 1273 " try {"
1274 " x1;" 1274 " x1;"
1275 " } catch(e) {" 1275 " } catch(e) {"
1276 " }" 1276 " }"
1277 " return typeof x1 === 'undefined';" 1277 " return typeof x1 === 'undefined';"
1278 "};" 1278 "};"
1279 "for (var i = 0; i < 10; i++) {" 1279 "for (var i = 0; i < 10; i++) {"
1280 " f();" 1280 " f();"
1281 "};" 1281 "};"
1282 "f();"); 1282 "f();");
1283 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust()); 1283 CHECK(value->BooleanValue(context.local()).FromJust());
1284 1284
1285 value = CompileRun( 1285 value = CompileRun(
1286 "var f = function() { " 1286 "var f = function() { "
1287 " try {" 1287 " try {"
1288 " x2;" 1288 " x2;"
1289 " return false;" 1289 " return false;"
1290 " } catch(e) {" 1290 " } catch(e) {"
1291 " return true;" 1291 " return true;"
1292 " }" 1292 " }"
1293 "};" 1293 "};"
1294 "for (var i = 0; i < 10; i++) {" 1294 "for (var i = 0; i < 10; i++) {"
1295 " f();" 1295 " f();"
1296 "};" 1296 "};"
1297 "f();"); 1297 "f();");
1298 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust()); 1298 CHECK(value->BooleanValue(context.local()).FromJust());
1299 1299
1300 value = CompileRun( 1300 value = CompileRun(
1301 "var f = function() { " 1301 "var f = function() { "
1302 " try {" 1302 " try {"
1303 " typeof(x3);" 1303 " typeof(x3);"
1304 " return true;" 1304 " return true;"
1305 " } catch(e) {" 1305 " } catch(e) {"
1306 " return false;" 1306 " return false;"
1307 " }" 1307 " }"
1308 "};" 1308 "};"
1309 "for (var i = 0; i < 10; i++) {" 1309 "for (var i = 0; i < 10; i++) {"
1310 " f();" 1310 " f();"
1311 "};" 1311 "};"
1312 "f();"); 1312 "f();");
1313 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust()); 1313 CHECK(value->BooleanValue(context.local()).FromJust());
1314 } 1314 }
1315 1315
1316 static void InterceptorLoadICGetter0( 1316 static void InterceptorLoadICGetter0(
1317 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { 1317 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
1318 ApiTestFuzzer::Fuzz(); 1318 ApiTestFuzzer::Fuzz();
1319 CHECK(v8_str("x") 1319 CHECK(v8_str("x")
1320 ->Equals(info.GetIsolate()->GetCurrentContext(), name) 1320 ->Equals(info.GetIsolate()->GetCurrentContext(), name)
1321 .FromJust()); 1321 .FromJust());
1322 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 0)); 1322 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 0));
1323 } 1323 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 v8::FunctionTemplate::New(CcTest::isolate()); 1470 v8::FunctionTemplate::New(CcTest::isolate());
1471 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( 1471 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration(
1472 EchoNamedProperty, 0, 0, 0, 0, v8_str("data"))); 1472 EchoNamedProperty, 0, 0, 0, 0, v8_str("data")));
1473 LocalContext env; 1473 LocalContext env;
1474 env->Global() 1474 env->Global()
1475 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) 1475 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
1476 .ToLocalChecked() 1476 .ToLocalChecked()
1477 ->NewInstance(env.local()) 1477 ->NewInstance(env.local())
1478 .ToLocalChecked()) 1478 .ToLocalChecked())
1479 .FromJust(); 1479 .FromJust();
1480 CHECK_EQ(echo_named_call_count, 0); 1480 CHECK_EQ(0, echo_named_call_count);
1481 v8_compile("obj.x")->Run(env.local()).ToLocalChecked(); 1481 v8_compile("obj.x")->Run(env.local()).ToLocalChecked();
1482 CHECK_EQ(echo_named_call_count, 1); 1482 CHECK_EQ(1, echo_named_call_count);
1483 const char* code = "var str = 'oddle'; obj[str] + obj.poddle;"; 1483 const char* code = "var str = 'oddle'; obj[str] + obj.poddle;";
1484 v8::Local<Value> str = CompileRun(code); 1484 v8::Local<Value> str = CompileRun(code);
1485 String::Utf8Value value(str); 1485 String::Utf8Value value(str);
1486 CHECK_EQ(0, strcmp(*value, "oddlepoddle")); 1486 CHECK_EQ(0, strcmp(*value, "oddlepoddle"));
1487 // Check default behavior 1487 // Check default behavior
1488 CHECK_EQ(10, v8_compile("obj.flob = 10;") 1488 CHECK_EQ(10, v8_compile("obj.flob = 10;")
1489 ->Run(env.local()) 1489 ->Run(env.local())
1490 .ToLocalChecked() 1490 .ToLocalChecked()
1491 ->Int32Value(env.local()) 1491 ->Int32Value(env.local())
1492 .FromJust()); 1492 .FromJust());
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 templ->InstanceTemplate()->SetHandler(v8::IndexedPropertyHandlerConfiguration( 2022 templ->InstanceTemplate()->SetHandler(v8::IndexedPropertyHandlerConfiguration(
2023 EchoIndexedProperty, 0, 0, 0, 0, v8_num(637))); 2023 EchoIndexedProperty, 0, 0, 0, 0, v8_num(637)));
2024 LocalContext env; 2024 LocalContext env;
2025 env->Global() 2025 env->Global()
2026 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) 2026 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
2027 .ToLocalChecked() 2027 .ToLocalChecked()
2028 ->NewInstance(env.local()) 2028 ->NewInstance(env.local())
2029 .ToLocalChecked()) 2029 .ToLocalChecked())
2030 .FromJust(); 2030 .FromJust();
2031 Local<Script> script = v8_compile("obj[900]"); 2031 Local<Script> script = v8_compile("obj[900]");
2032 CHECK_EQ(script->Run(env.local()) 2032 CHECK_EQ(900, script->Run(env.local())
2033 .ToLocalChecked() 2033 .ToLocalChecked()
2034 ->Int32Value(env.local()) 2034 ->Int32Value(env.local())
2035 .FromJust(), 2035 .FromJust());
2036 900);
2037 } 2036 }
2038 2037
2039 2038
2040 THREADED_TEST(PropertyHandlerInPrototype) { 2039 THREADED_TEST(PropertyHandlerInPrototype) {
2041 LocalContext env; 2040 LocalContext env;
2042 v8::Isolate* isolate = env->GetIsolate(); 2041 v8::Isolate* isolate = env->GetIsolate();
2043 v8::HandleScope scope(isolate); 2042 v8::HandleScope scope(isolate);
2044 2043
2045 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); 2044 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
2046 templ->InstanceTemplate()->SetHandler(v8::IndexedPropertyHandlerConfiguration( 2045 templ->InstanceTemplate()->SetHandler(v8::IndexedPropertyHandlerConfiguration(
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
2652 v8::NamedPropertyHandlerConfiguration(SetXOnPrototypeGetter)); 2651 v8::NamedPropertyHandlerConfiguration(SetXOnPrototypeGetter));
2653 LocalContext context; 2652 LocalContext context;
2654 context->Global() 2653 context->Global()
2655 ->Set(context.local(), v8_str("F"), 2654 ->Set(context.local(), v8_str("F"),
2656 function_template->GetFunction(context.local()).ToLocalChecked()) 2655 function_template->GetFunction(context.local()).ToLocalChecked())
2657 .FromJust(); 2656 .FromJust();
2658 // Create an instance of F and introduce a map transition for x. 2657 // Create an instance of F and introduce a map transition for x.
2659 CompileRun("var o = new F(); o.x = 23;"); 2658 CompileRun("var o = new F(); o.x = 23;");
2660 // Create an instance of F and invoke the getter. The result should be 23. 2659 // Create an instance of F and invoke the getter. The result should be 23.
2661 Local<Value> result = CompileRun("o = new F(); o.x"); 2660 Local<Value> result = CompileRun("o = new F(); o.x");
2662 CHECK_EQ(result->Int32Value(context.local()).FromJust(), 23); 2661 CHECK_EQ(23, result->Int32Value(context.local()).FromJust());
2663 } 2662 }
2664 2663
2665 2664
2666 static void IndexedPropertyGetter( 2665 static void IndexedPropertyGetter(
2667 uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) { 2666 uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) {
2668 ApiTestFuzzer::Fuzz(); 2667 ApiTestFuzzer::Fuzz();
2669 if (index == 37) { 2668 if (index == 37) {
2670 info.GetReturnValue().Set(v8_num(625)); 2669 info.GetReturnValue().Set(v8_num(625));
2671 } 2670 }
2672 } 2671 }
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after
3956 ->Run(context.local()) 3955 ->Run(context.local())
3957 .ToLocalChecked(); 3956 .ToLocalChecked();
3958 v8::Local<Value> value = CompileRun( 3957 v8::Local<Value> value = CompileRun(
3959 "function f() {" 3958 "function f() {"
3960 " for (var i = 0; i < 1000; i++) {" 3959 " for (var i = 0; i < 1000; i++) {"
3961 " try { x; } catch(e) { return true; }" 3960 " try { x; } catch(e) { return true; }"
3962 " }" 3961 " }"
3963 " return false;" 3962 " return false;"
3964 "};" 3963 "};"
3965 "f();"); 3964 "f();");
3966 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust()); 3965 CHECK(value->BooleanValue(context.local()).FromJust());
3967 interceptor_call_count = 0; 3966 interceptor_call_count = 0;
3968 value = CompileRun( 3967 value = CompileRun(
3969 "function g() {" 3968 "function g() {"
3970 " for (var i = 0; i < 1000; i++) {" 3969 " for (var i = 0; i < 1000; i++) {"
3971 " try { x(42); } catch(e) { return true; }" 3970 " try { x(42); } catch(e) { return true; }"
3972 " }" 3971 " }"
3973 " return false;" 3972 " return false;"
3974 "};" 3973 "};"
3975 "g();"); 3974 "g();");
3976 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust()); 3975 CHECK(value->BooleanValue(context.local()).FromJust());
3977 } 3976 }
3978 3977
3979 3978
3980 static int interceptor_ic_exception_get_count = 0; 3979 static int interceptor_ic_exception_get_count = 0;
3981 3980
3982 static void InterceptorICExceptionGetter( 3981 static void InterceptorICExceptionGetter(
3983 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { 3982 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
3984 ApiTestFuzzer::Fuzz(); 3983 ApiTestFuzzer::Fuzz();
3985 if (is_bootstrapping) return; 3984 if (is_bootstrapping) return;
3986 if (v8_str("x") 3985 if (v8_str("x")
(...skipping 25 matching lines...) Expand all
4012 ->Run(context.local()) 4011 ->Run(context.local())
4013 .ToLocalChecked(); 4012 .ToLocalChecked();
4014 v8::Local<Value> value = CompileRun( 4013 v8::Local<Value> value = CompileRun(
4015 "function f() {" 4014 "function f() {"
4016 " for (var i = 0; i < 100; i++) {" 4015 " for (var i = 0; i < 100; i++) {"
4017 " try { x; } catch(e) { return true; }" 4016 " try { x; } catch(e) { return true; }"
4018 " }" 4017 " }"
4019 " return false;" 4018 " return false;"
4020 "};" 4019 "};"
4021 "f();"); 4020 "f();");
4022 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust()); 4021 CHECK(value->BooleanValue(context.local()).FromJust());
4023 interceptor_ic_exception_get_count = 0; 4022 interceptor_ic_exception_get_count = 0;
4024 value = CompileRun( 4023 value = CompileRun(
4025 "function f() {" 4024 "function f() {"
4026 " for (var i = 0; i < 100; i++) {" 4025 " for (var i = 0; i < 100; i++) {"
4027 " try { x(42); } catch(e) { return true; }" 4026 " try { x(42); } catch(e) { return true; }"
4028 " }" 4027 " }"
4029 " return false;" 4028 " return false;"
4030 "};" 4029 "};"
4031 "f();"); 4030 "f();");
4032 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust()); 4031 CHECK(value->BooleanValue(context.local()).FromJust());
4033 } 4032 }
4034 4033
4035 4034
4036 static int interceptor_ic_exception_set_count = 0; 4035 static int interceptor_ic_exception_set_count = 0;
4037 4036
4038 static void InterceptorICExceptionSetter( 4037 static void InterceptorICExceptionSetter(
4039 Local<Name> key, Local<Value> value, 4038 Local<Name> key, Local<Value> value,
4040 const v8::PropertyCallbackInfo<v8::Value>& info) { 4039 const v8::PropertyCallbackInfo<v8::Value>& info) {
4041 ApiTestFuzzer::Fuzz(); 4040 ApiTestFuzzer::Fuzz();
4042 if (++interceptor_ic_exception_set_count > 20) { 4041 if (++interceptor_ic_exception_set_count > 20) {
(...skipping 13 matching lines...) Expand all
4056 v8::NamedPropertyHandlerConfiguration(0, InterceptorICExceptionSetter)); 4055 v8::NamedPropertyHandlerConfiguration(0, InterceptorICExceptionSetter));
4057 LocalContext context(0, templ, v8::Local<Value>()); 4056 LocalContext context(0, templ, v8::Local<Value>());
4058 v8::Local<Value> value = CompileRun( 4057 v8::Local<Value> value = CompileRun(
4059 "function f() {" 4058 "function f() {"
4060 " for (var i = 0; i < 100; i++) {" 4059 " for (var i = 0; i < 100; i++) {"
4061 " try { x = 42; } catch(e) { return true; }" 4060 " try { x = 42; } catch(e) { return true; }"
4062 " }" 4061 " }"
4063 " return false;" 4062 " return false;"
4064 "};" 4063 "};"
4065 "f();"); 4064 "f();");
4066 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust()); 4065 CHECK(value->BooleanValue(context.local()).FromJust());
4067 } 4066 }
4068 4067
4069 4068
4070 // Test that we ignore null interceptors. 4069 // Test that we ignore null interceptors.
4071 THREADED_TEST(NullNamedInterceptor) { 4070 THREADED_TEST(NullNamedInterceptor) {
4072 v8::Isolate* isolate = CcTest::isolate(); 4071 v8::Isolate* isolate = CcTest::isolate();
4073 v8::HandleScope scope(isolate); 4072 v8::HandleScope scope(isolate);
4074 v8::Local<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); 4073 v8::Local<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
4075 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( 4074 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
4076 static_cast<v8::GenericNamedPropertyGetterCallback>(0))); 4075 static_cast<v8::GenericNamedPropertyGetterCallback>(0)));
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
4945 ->Set(env.local(), v8_str("Fun"), 4944 ->Set(env.local(), v8_str("Fun"),
4946 fun_templ->GetFunction(env.local()).ToLocalChecked()) 4945 fun_templ->GetFunction(env.local()).ToLocalChecked())
4947 .FromJust()); 4946 .FromJust());
4948 4947
4949 CompileRun( 4948 CompileRun(
4950 "var f = new Fun();" 4949 "var f = new Fun();"
4951 "Number.prototype.__proto__ = f;" 4950 "Number.prototype.__proto__ = f;"
4952 "var a = 42;" 4951 "var a = 42;"
4953 "for (var i = 0; i<3; i++) { a.foo; }"); 4952 "for (var i = 0; i<3; i++) { a.foo; }");
4954 } 4953 }
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