| Index: test/unittests/api/v8-object-unittest.cc
|
| diff --git a/test/unittests/api/v8-object-unittest.cc b/test/unittests/api/v8-object-unittest.cc
|
| index 2e7ab350ea38c5283a8574275457642284201f6e..8dfefbc11440db23f0eebe529f455d5516ce197f 100644
|
| --- a/test/unittests/api/v8-object-unittest.cc
|
| +++ b/test/unittests/api/v8-object-unittest.cc
|
| @@ -3,6 +3,8 @@
|
| // found in the LICENSE file.
|
|
|
| #include "include/v8.h"
|
| +#include "src/api.h"
|
| +#include "src/objects-inl.h"
|
| #include "test/unittests/test-utils.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -33,5 +35,34 @@ TEST_F(ObjectTest, SetAccessorWhenUnconfigurablePropAlreadyDefined) {
|
| ASSERT_FALSE(try_catch.HasCaught());
|
| }
|
|
|
| +using LapContextTest = TestWithIsolate;
|
| +
|
| +TEST_F(LapContextTest, CurrentContextMustBeFunctionContext) {
|
| + // Objects and functions will be created in |context1|, and accessed from
|
| + // |context2|. The current context in the accessor functions must be
|
| + // |context1|.
|
| + Local<Context> context1 = Context::New(isolate());
|
| + Local<Context> context2 = Context::New(isolate());
|
| +
|
| + Local<FunctionTemplate> function_template = FunctionTemplate::New(isolate());
|
| + Local<String> property_key =
|
| + String::NewFromUtf8(isolate(), "property_key", NewStringType::kNormal)
|
| + .ToLocalChecked();
|
| + Local<FunctionTemplate> get_or_set = FunctionTemplate::New(
|
| + isolate(), [](const FunctionCallbackInfo<Value>& info) {
|
| + EXPECT_EQ(info.Holder()->CreationContext(),
|
| + info.GetIsolate()->GetCurrentContext());
|
| + });
|
| + function_template->PrototypeTemplate()->SetAccessorProperty(
|
| + property_key, get_or_set, get_or_set);
|
| +
|
| + Local<Function> interface =
|
| + function_template->GetFunction(context1).ToLocalChecked();
|
| + Local<Object> object = interface->NewInstance(context1).ToLocalChecked();
|
| +
|
| + object->Get(context2, property_key).ToLocalChecked();
|
| + object->Set(context2, property_key, Null(isolate())).ToChecked();
|
| +}
|
| +
|
| } // namespace
|
| } // namespace v8
|
|
|