Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: test/unittests/api/v8-object-unittest.cc

Issue 2770003002: Set the current context to the function's context when entering to LAP. (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/x64/code-stubs-x64.cc ('K') | « src/x64/macro-assembler-x64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« src/x64/code-stubs-x64.cc ('K') | « src/x64/macro-assembler-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698