| 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..b1df33628b0e800f2a9e8584a59f306201370750 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,61 @@ TEST_F(ObjectTest, SetAccessorWhenUnconfigurablePropAlreadyDefined) {
|
| ASSERT_FALSE(try_catch.HasCaught());
|
| }
|
|
|
| +using LapContextTest = TestWithIsolate;
|
| +
|
| +TEST_F(LapContextTest, CurrentContextMustBeFunctionContext) {
|
| + // The receiver object is created in |receiver_context|, and the property is
|
| + // accessed from |caller_context|.
|
| + Local<Context> receiver_context = Context::New(isolate());
|
| + Local<Context> caller_context = Context::New(isolate());
|
| +
|
| + Local<FunctionTemplate> function_template = FunctionTemplate::New(isolate());
|
| + Local<Signature> signature = Signature::New(isolate(), function_template);
|
| + Local<String> property_key =
|
| + String::NewFromUtf8(isolate(), "property", NewStringType::kNormal)
|
| + .ToLocalChecked();
|
| + Local<FunctionTemplate> get_or_set = FunctionTemplate::New(
|
| + isolate(),
|
| + [](const FunctionCallbackInfo<Value>& info) {
|
| + Local<Context> receiver_context = *reinterpret_cast<Local<Context>*>(
|
| + info.Data().As<External>()->Value());
|
| + EXPECT_EQ(receiver_context, info.GetIsolate()->GetCurrentContext());
|
| + },
|
| + External::New(isolate(), &receiver_context), signature);
|
| + function_template->PrototypeTemplate()->SetAccessorProperty(
|
| + property_key, get_or_set, get_or_set);
|
| +
|
| + // |object| is created in |receiver_context|, and |prototype| is created
|
| + // in |prototype_context|. And then, object.__proto__ = prototype.
|
| + Local<Function> interface =
|
| + function_template->GetFunction(receiver_context).ToLocalChecked();
|
| + Local<Object> object =
|
| + interface->NewInstance(receiver_context).ToLocalChecked();
|
| + EXPECT_EQ(receiver_context, object->CreationContext());
|
| +
|
| + object->Get(caller_context, property_key).ToLocalChecked();
|
| + object->Set(caller_context, property_key, Null(isolate())).ToChecked();
|
| +
|
| + // Test with a compiled version.
|
| + Local<String> object_key =
|
| + String::NewFromUtf8(isolate(), "object", NewStringType::kNormal)
|
| + .ToLocalChecked();
|
| + caller_context->Global()->Set(caller_context, object_key, object).ToChecked();
|
| + const char script[] =
|
| + "function f() { return object.property; } "
|
| + "f(); f(); "
|
| + "%OptimizeFunctionOnNextCall(f); "
|
| + "f();";
|
| + Context::Scope scope(caller_context);
|
| + internal::FLAG_allow_natives_syntax = true;
|
| + Script::Compile(
|
| + caller_context,
|
| + String::NewFromUtf8(isolate(), script, v8::NewStringType::kNormal)
|
| + .ToLocalChecked())
|
| + .ToLocalChecked()
|
| + ->Run(caller_context)
|
| + .ToLocalChecked();
|
| +}
|
| +
|
| } // namespace
|
| } // namespace v8
|
|
|