OLD | NEW |
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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 | 456 |
457 v8_compile("Object.defineProperty(obj, 'enum', {value: 42});") | 457 v8_compile("Object.defineProperty(obj, 'enum', {value: 42});") |
458 ->Run(env.local()) | 458 ->Run(env.local()) |
459 .ToLocalChecked(); | 459 .ToLocalChecked(); |
460 CHECK_EQ(query_counter_int, 8); | 460 CHECK_EQ(query_counter_int, 8); |
461 | 461 |
462 v8_compile("Object.isFrozen('obj.x');")->Run(env.local()).ToLocalChecked(); | 462 v8_compile("Object.isFrozen('obj.x');")->Run(env.local()).ToLocalChecked(); |
463 CHECK_EQ(query_counter_int, 8); | 463 CHECK_EQ(query_counter_int, 8); |
464 } | 464 } |
465 | 465 |
| 466 bool get_was_called = false; |
| 467 bool set_was_called = false; |
| 468 |
| 469 namespace { |
| 470 void GetterCallback(Local<Name> property, |
| 471 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 472 get_was_called = true; |
| 473 } |
| 474 |
| 475 void SetterCallback(Local<Name> property, Local<Value> value, |
| 476 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 477 set_was_called = true; |
| 478 } |
| 479 |
| 480 } // namespace |
| 481 |
| 482 // Check that get callback is called in defineProperty with accessor descriptor. |
| 483 THREADED_TEST(DefinerCallbackAccessorInterceptor) { |
| 484 v8::HandleScope scope(CcTest::isolate()); |
| 485 v8::Local<v8::FunctionTemplate> templ = |
| 486 v8::FunctionTemplate::New(CcTest::isolate()); |
| 487 templ->InstanceTemplate()->SetHandler( |
| 488 v8::NamedPropertyHandlerConfiguration(GetterCallback, SetterCallback)); |
| 489 LocalContext env; |
| 490 env->Global() |
| 491 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) |
| 492 .ToLocalChecked() |
| 493 ->NewInstance(env.local()) |
| 494 .ToLocalChecked()) |
| 495 .FromJust(); |
| 496 |
| 497 CHECK_EQ(get_was_called, false); |
| 498 CHECK_EQ(set_was_called, false); |
| 499 |
| 500 v8_compile("Object.defineProperty(obj, 'x', {set: function() {return 17;}});") |
| 501 ->Run(env.local()) |
| 502 .ToLocalChecked(); |
| 503 CHECK_EQ(get_was_called, true); |
| 504 CHECK_EQ(set_was_called, false); |
| 505 } |
| 506 |
| 507 bool get_was_called_in_order = false; |
| 508 bool define_was_called_in_order = false; |
| 509 |
| 510 namespace { |
| 511 |
| 512 void GetterCallbackOrder(Local<Name> property, |
| 513 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 514 get_was_called_in_order = true; |
| 515 CHECK_EQ(define_was_called_in_order, true); |
| 516 info.GetReturnValue().Set(property); |
| 517 } |
| 518 |
| 519 void DefinerCallbackOrder(Local<Name> property, |
| 520 const v8::PropertyDescriptor& desc, |
| 521 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 522 CHECK_EQ(get_was_called_in_order, false); // Define called before get. |
| 523 define_was_called_in_order = true; |
| 524 } |
| 525 |
| 526 } // namespace |
| 527 |
| 528 // Check that definer callback is called before getter callback. |
| 529 THREADED_TEST(DefinerCallbackGetAndDefine) { |
| 530 v8::HandleScope scope(CcTest::isolate()); |
| 531 v8::Local<v8::FunctionTemplate> templ = |
| 532 v8::FunctionTemplate::New(CcTest::isolate()); |
| 533 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 534 GetterCallbackOrder, SetterCallback, 0, 0, 0, DefinerCallbackOrder)); |
| 535 LocalContext env; |
| 536 env->Global() |
| 537 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) |
| 538 .ToLocalChecked() |
| 539 ->NewInstance(env.local()) |
| 540 .ToLocalChecked()) |
| 541 .FromJust(); |
| 542 |
| 543 CHECK_EQ(get_was_called_in_order, false); |
| 544 CHECK_EQ(define_was_called_in_order, false); |
| 545 |
| 546 v8_compile("Object.defineProperty(obj, 'x', {set: function() {return 17;}});") |
| 547 ->Run(env.local()) |
| 548 .ToLocalChecked(); |
| 549 CHECK_EQ(get_was_called_in_order, true); |
| 550 CHECK_EQ(define_was_called_in_order, true); |
| 551 } |
| 552 |
466 THREADED_TEST(InterceptorHasOwnProperty) { | 553 THREADED_TEST(InterceptorHasOwnProperty) { |
467 LocalContext context; | 554 LocalContext context; |
468 v8::Isolate* isolate = context->GetIsolate(); | 555 v8::Isolate* isolate = context->GetIsolate(); |
469 v8::HandleScope scope(isolate); | 556 v8::HandleScope scope(isolate); |
470 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); | 557 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); |
471 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); | 558 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); |
472 instance_templ->SetHandler( | 559 instance_templ->SetHandler( |
473 v8::NamedPropertyHandlerConfiguration(InterceptorHasOwnPropertyGetter)); | 560 v8::NamedPropertyHandlerConfiguration(InterceptorHasOwnPropertyGetter)); |
474 Local<Function> function = | 561 Local<Function> function = |
475 fun_templ->GetFunction(context.local()).ToLocalChecked(); | 562 fun_templ->GetFunction(context.local()).ToLocalChecked(); |
(...skipping 4058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4534 ->Set(env.local(), v8_str("Fun"), | 4621 ->Set(env.local(), v8_str("Fun"), |
4535 fun_templ->GetFunction(env.local()).ToLocalChecked()) | 4622 fun_templ->GetFunction(env.local()).ToLocalChecked()) |
4536 .FromJust()); | 4623 .FromJust()); |
4537 | 4624 |
4538 CompileRun( | 4625 CompileRun( |
4539 "var f = new Fun();" | 4626 "var f = new Fun();" |
4540 "Number.prototype.__proto__ = f;" | 4627 "Number.prototype.__proto__ = f;" |
4541 "var a = 42;" | 4628 "var a = 42;" |
4542 "for (var i = 0; i<3; i++) { a.foo; }"); | 4629 "for (var i = 0; i<3; i++) { a.foo; }"); |
4543 } | 4630 } |
OLD | NEW |