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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 CHECK_EQ(44, v8::Script::Compile(ctx, code) | 569 CHECK_EQ(44, v8::Script::Compile(ctx, code) |
570 .ToLocalChecked() | 570 .ToLocalChecked() |
571 ->Run(ctx) | 571 ->Run(ctx) |
572 .ToLocalChecked() | 572 .ToLocalChecked() |
573 ->Int32Value(ctx) | 573 ->Int32Value(ctx) |
574 .FromJust()); | 574 .FromJust()); |
575 CHECK_EQ(3, set_was_called_counter); | 575 CHECK_EQ(3, set_was_called_counter); |
576 } | 576 } |
577 | 577 |
578 namespace { | 578 namespace { |
| 579 int descriptor_was_called; |
| 580 |
| 581 void PropertyDescriptorCallback( |
| 582 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 583 // Intercept the callback by setting a different descriptor. |
| 584 descriptor_was_called++; |
| 585 const char* code = |
| 586 "var desc = {value: 5};" |
| 587 "desc;"; |
| 588 Local<Value> descriptor = v8_compile(code) |
| 589 ->Run(info.GetIsolate()->GetCurrentContext()) |
| 590 .ToLocalChecked(); |
| 591 info.GetReturnValue().Set(descriptor); |
| 592 } |
| 593 } // namespace |
| 594 |
| 595 // Check that the descriptor callback is called on the global object. |
| 596 THREADED_TEST(DescriptorCallbackOnGlobalObject) { |
| 597 v8::HandleScope scope(CcTest::isolate()); |
| 598 LocalContext env; |
| 599 v8::Local<v8::FunctionTemplate> templ = |
| 600 v8::FunctionTemplate::New(CcTest::isolate()); |
| 601 |
| 602 v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate(); |
| 603 object_template->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 604 nullptr, nullptr, PropertyDescriptorCallback, nullptr, nullptr, nullptr)); |
| 605 v8::Local<v8::Context> ctx = |
| 606 v8::Context::New(CcTest::isolate(), nullptr, object_template); |
| 607 |
| 608 descriptor_was_called = 0; |
| 609 |
| 610 // Declare function. |
| 611 v8::Local<v8::String> code = v8_str( |
| 612 "var x = 42; var desc = Object.getOwnPropertyDescriptor(this, 'x'); " |
| 613 "desc.value;"); |
| 614 CHECK_EQ(5, v8::Script::Compile(ctx, code) |
| 615 .ToLocalChecked() |
| 616 ->Run(ctx) |
| 617 .ToLocalChecked() |
| 618 ->Int32Value(ctx) |
| 619 .FromJust()); |
| 620 CHECK_EQ(1, descriptor_was_called); |
| 621 } |
| 622 |
| 623 namespace { |
579 void QueryCallbackSetDontDelete( | 624 void QueryCallbackSetDontDelete( |
580 Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { | 625 Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { |
581 info.GetReturnValue().Set(v8::PropertyAttribute::DontDelete); | 626 info.GetReturnValue().Set(v8::PropertyAttribute::DontDelete); |
582 } | 627 } |
583 | 628 |
584 } // namespace | 629 } // namespace |
585 | 630 |
586 // Regression for a Node.js test that fails in debug mode. | 631 // Regression for a Node.js test that fails in debug mode. |
587 THREADED_TEST(InterceptorFunctionRedeclareWithQueryCallback) { | 632 THREADED_TEST(InterceptorFunctionRedeclareWithQueryCallback) { |
588 v8::HandleScope scope(CcTest::isolate()); | 633 v8::HandleScope scope(CcTest::isolate()); |
(...skipping 4381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4970 ->Set(env.local(), v8_str("Fun"), | 5015 ->Set(env.local(), v8_str("Fun"), |
4971 fun_templ->GetFunction(env.local()).ToLocalChecked()) | 5016 fun_templ->GetFunction(env.local()).ToLocalChecked()) |
4972 .FromJust()); | 5017 .FromJust()); |
4973 | 5018 |
4974 CompileRun( | 5019 CompileRun( |
4975 "var f = new Fun();" | 5020 "var f = new Fun();" |
4976 "Number.prototype.__proto__ = f;" | 5021 "Number.prototype.__proto__ = f;" |
4977 "var a = 42;" | 5022 "var a = 42;" |
4978 "for (var i = 0; i<3; i++) { a.foo; }"); | 5023 "for (var i = 0; i<3; i++) { a.foo; }"); |
4979 } | 5024 } |
OLD | NEW |