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

Unified Diff: test/cctest/test-api.cc

Side-by-side diff isn't available for this file because of its large size.
Issue 2862483003: Do not enter contexts implicitly (Closed)
Patch Set: Use correct NewInstance() overload Created 3 years, 7 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:
Download patch
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index c1d7670f999f833e9146fdec07a1b7b2e965fa79..c3d45cc4b1c0b78c165ecbd1b0e69db1fa0ac577 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -26601,3 +26601,69 @@ UNINITIALIZED_TEST(AllowAtomicsWait) {
}
isolate->Dispose();
}
+
+enum ContextId { EnteredContext, CurrentContext };
+
+void CheckContexts(v8::Isolate* isolate) {
+ CHECK_EQ(CurrentContext, isolate->GetCurrentContext()
+ ->GetEmbedderData(1)
+ .As<v8::Integer>()
+ ->Value());
+ CHECK_EQ(EnteredContext, isolate->GetEnteredContext()
+ ->GetEmbedderData(1)
+ .As<v8::Integer>()
+ ->Value());
+}
+
+void ContextCheckGetter(Local<String> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ CheckContexts(info.GetIsolate());
+ info.GetReturnValue().Set(true);
+}
+
+void ContextCheckSetter(Local<String> name, Local<Value>,
+ const v8::PropertyCallbackInfo<void>& info) {
+ CheckContexts(info.GetIsolate());
+}
+
+void ContextCheckToString(const v8::FunctionCallbackInfo<v8::Value>& info) {
+ CheckContexts(info.GetIsolate());
+ info.GetReturnValue().Set(v8_str("foo"));
+}
+
+TEST(CorrectEnteredContext) {
+ v8::HandleScope scope(CcTest::isolate());
+
+ LocalContext currentContext;
+ currentContext->SetEmbedderData(
+ 1, v8::Integer::New(currentContext->GetIsolate(), CurrentContext));
+ LocalContext enteredContext;
+ enteredContext->SetEmbedderData(
+ 1, v8::Integer::New(enteredContext->GetIsolate(), EnteredContext));
+
+ v8::Context::Scope contextScope(enteredContext.local());
+
+ v8::Local<v8::ObjectTemplate> object_template =
+ ObjectTemplate::New(currentContext->GetIsolate());
+ object_template->SetAccessor(v8_str("p"), &ContextCheckGetter,
+ &ContextCheckSetter);
+
+ v8::Local<v8::Object> object =
+ object_template->NewInstance(currentContext.local()).ToLocalChecked();
+
+ object->Get(currentContext.local(), v8_str("p")).ToLocalChecked();
+ object->Set(currentContext.local(), v8_str("p"), v8_int(0)).FromJust();
+
+ v8::Local<v8::Function> to_string =
+ v8::Function::New(currentContext.local(), ContextCheckToString)
+ .ToLocalChecked();
+
+ to_string->Call(currentContext.local(), object, 0, nullptr).ToLocalChecked();
+
+ object
+ ->CreateDataProperty(currentContext.local(), v8_str("toString"),
+ to_string)
+ .FromJust();
+
+ object->ToString(currentContext.local()).ToLocalChecked();
+}
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698