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

Side by Side Diff: fpdfsdk/jsapi/fxjs_v8_embeddertest.cpp

Issue 1826223002: Revert "Preserve m_pDynamicObjsMap until FXJS_PerIsolateData is destroyed." (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « fpdfsdk/jsapi/fxjs_v8.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 PDFium Authors. All rights reserved. 1 // Copyright 2015 PDFium 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "testing/js_embedder_test.h" 6 #include "testing/js_embedder_test.h"
7 7
8 namespace { 8 namespace {
9 9
10 const double kExpected0 = 6.0; 10 const wchar_t kScript[] = L"fred = 7";
11 const double kExpected1 = 7.0;
12 const double kExpected2 = 8.0;
13
14 const wchar_t kScript0[] = L"fred = 6";
15 const wchar_t kScript1[] = L"fred = 7";
16 const wchar_t kScript2[] = L"fred = 8";
17 11
18 } // namespace 12 } // namespace
19 13
20 class FXJSV8EmbedderTest : public JSEmbedderTest { 14 class FXJSV8EmbedderTest : public JSEmbedderTest {};
21 public:
22 void ExecuteInCurrentContext(const wchar_t* script) {
23 FXJSErr error;
24 int sts = FXJS_Execute(isolate(), nullptr, script, &error);
25 EXPECT_EQ(0, sts);
26 }
27 void CheckAssignmentInCurrentContext(double expected) {
28 v8::Local<v8::Object> This = FXJS_GetThisObj(isolate());
29 v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred");
30 EXPECT_TRUE(fred->IsNumber());
31 EXPECT_EQ(expected, fred->ToNumber(isolate()->GetCurrentContext())
32 .ToLocalChecked()
33 ->Value());
34 }
35 };
36 15
37 TEST_F(FXJSV8EmbedderTest, Getters) { 16 TEST_F(FXJSV8EmbedderTest, Getters) {
38 v8::Isolate::Scope isolate_scope(isolate()); 17 v8::Isolate::Scope isolate_scope(isolate());
39 #ifdef PDF_ENABLE_XFA 18 #ifdef PDF_ENABLE_XFA
40 v8::Locker locker(isolate()); 19 v8::Locker locker(isolate());
41 #endif // PDF_ENABLE_XFA 20 #endif // PDF_ENABLE_XFA
42 v8::HandleScope handle_scope(isolate()); 21 v8::HandleScope handle_scope(isolate());
43 v8::Context::Scope context_scope(GetV8Context()); 22 v8::Context::Scope context_scope(GetV8Context());
44 23
45 ExecuteInCurrentContext(kScript1); 24 FXJSErr error;
46 CheckAssignmentInCurrentContext(kExpected1); 25 int sts = FXJS_Execute(isolate(), nullptr, kScript, &error);
26 EXPECT_EQ(0, sts);
27
28 v8::Local<v8::Object> This = FXJS_GetThisObj(isolate());
29 v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred");
30 EXPECT_TRUE(fred->IsNumber());
47 } 31 }
48
49 TEST_F(FXJSV8EmbedderTest, MultipleRutimes) {
50 v8::Isolate::Scope isolate_scope(isolate());
51 #ifdef PDF_ENABLE_XFA
52 v8::Locker locker(isolate());
53 #endif // PDF_ENABLE_XFA
54 v8::HandleScope handle_scope(isolate());
55
56 v8::Global<v8::Context> global_context1;
57 std::vector<v8::Global<v8::Object>*> static_objects1;
58 FXJS_InitializeRuntime(isolate(), nullptr, &global_context1,
59 &static_objects1);
60
61 v8::Global<v8::Context> global_context2;
62 std::vector<v8::Global<v8::Object>*> static_objects2;
63 FXJS_InitializeRuntime(isolate(), nullptr, &global_context2,
64 &static_objects2);
65
66 v8::Context::Scope context_scope(GetV8Context());
67 ExecuteInCurrentContext(kScript0);
68 CheckAssignmentInCurrentContext(kExpected0);
69
70 {
71 v8::Local<v8::Context> context1 =
72 v8::Local<v8::Context>::New(isolate(), global_context1);
73 v8::Context::Scope context_scope(context1);
74 ExecuteInCurrentContext(kScript1);
75 CheckAssignmentInCurrentContext(kExpected1);
76 }
77 FXJS_ReleaseRuntime(isolate(), &global_context1, &static_objects1);
78
79 {
80 v8::Local<v8::Context> context2 =
81 v8::Local<v8::Context>::New(isolate(), global_context2);
82 v8::Context::Scope context_scope(context2);
83 ExecuteInCurrentContext(kScript2);
84 CheckAssignmentInCurrentContext(kExpected2);
85 }
86 FXJS_ReleaseRuntime(isolate(), &global_context2, &static_objects2);
87
88 CheckAssignmentInCurrentContext(kExpected0);
89 }
OLDNEW
« no previous file with comments | « fpdfsdk/jsapi/fxjs_v8.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698