OLD | NEW |
1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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 "include/v8.h" | 5 #include "include/v8.h" |
| 6 #include "src/api.h" |
| 7 #include "src/objects-inl.h" |
6 #include "test/unittests/test-utils.h" | 8 #include "test/unittests/test-utils.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
8 | 10 |
9 namespace v8 { | 11 namespace v8 { |
10 namespace { | 12 namespace { |
11 | 13 |
12 using ObjectTest = TestWithContext; | 14 using ObjectTest = TestWithContext; |
13 | 15 |
14 void accessor_name_getter_callback(Local<Name>, | 16 void accessor_name_getter_callback(Local<Name>, |
15 const PropertyCallbackInfo<Value>&) {} | 17 const PropertyCallbackInfo<Value>&) {} |
(...skipping 10 matching lines...) Expand all Loading... |
26 prop_desc.set_configurable(false); | 28 prop_desc.set_configurable(false); |
27 global->DefineProperty(context(), property_name, prop_desc).ToChecked(); | 29 global->DefineProperty(context(), property_name, prop_desc).ToChecked(); |
28 | 30 |
29 Maybe<bool> result = global->SetAccessor(context(), property_name, | 31 Maybe<bool> result = global->SetAccessor(context(), property_name, |
30 accessor_name_getter_callback); | 32 accessor_name_getter_callback); |
31 ASSERT_TRUE(result.IsJust()); | 33 ASSERT_TRUE(result.IsJust()); |
32 ASSERT_FALSE(result.FromJust()); | 34 ASSERT_FALSE(result.FromJust()); |
33 ASSERT_FALSE(try_catch.HasCaught()); | 35 ASSERT_FALSE(try_catch.HasCaught()); |
34 } | 36 } |
35 | 37 |
| 38 using LapContextTest = TestWithIsolate; |
| 39 |
| 40 TEST_F(LapContextTest, CurrentContextMustBeFunctionContext) { |
| 41 // Objects and functions will be created in |context1|, and accessed from |
| 42 // |context2|. The current context in the accessor functions must be |
| 43 // |context1|. |
| 44 Local<Context> context1 = Context::New(isolate()); |
| 45 Local<Context> context2 = Context::New(isolate()); |
| 46 |
| 47 Local<FunctionTemplate> function_template = FunctionTemplate::New(isolate()); |
| 48 Local<String> property_key = |
| 49 String::NewFromUtf8(isolate(), "property_key", NewStringType::kNormal) |
| 50 .ToLocalChecked(); |
| 51 Local<FunctionTemplate> get_or_set = FunctionTemplate::New( |
| 52 isolate(), [](const FunctionCallbackInfo<Value>& info) { |
| 53 EXPECT_EQ(info.Holder()->CreationContext(), |
| 54 info.GetIsolate()->GetCurrentContext()); |
| 55 }); |
| 56 function_template->PrototypeTemplate()->SetAccessorProperty( |
| 57 property_key, get_or_set, get_or_set); |
| 58 |
| 59 Local<Function> interface = |
| 60 function_template->GetFunction(context1).ToLocalChecked(); |
| 61 Local<Object> object = interface->NewInstance(context1).ToLocalChecked(); |
| 62 |
| 63 object->Get(context2, property_key).ToLocalChecked(); |
| 64 object->Set(context2, property_key, Null(isolate())).ToChecked(); |
| 65 } |
| 66 |
36 } // namespace | 67 } // namespace |
37 } // namespace v8 | 68 } // namespace v8 |
OLD | NEW |