OLD | NEW |
---|---|
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 "core/include/fpdfapi/fpdf_parser.h" | 5 #include "core/include/fpdfapi/fpdf_parser.h" |
6 #include "fpdfsdk/include/jsapi/fxjs_v8.h" | 6 #include "fpdfsdk/include/jsapi/fxjs_v8.h" |
7 #include "testing/embedder_test.h" | 7 #include "testing/embedder_test.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "third_party/base/nonstd_unique_ptr.h" | 9 #include "third_party/base/nonstd_unique_ptr.h" |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... | |
23 m_pIsolate = v8::Isolate::New(params); | 23 m_pIsolate = v8::Isolate::New(params); |
24 } | 24 } |
25 | 25 |
26 ~FXJSV8Embeddertest() override { m_pIsolate->Dispose(); } | 26 ~FXJSV8Embeddertest() override { m_pIsolate->Dispose(); } |
27 | 27 |
28 void SetUp() override { | 28 void SetUp() override { |
29 EmbedderTest::SetExternalIsolate(m_pIsolate); | 29 EmbedderTest::SetExternalIsolate(m_pIsolate); |
30 EmbedderTest::SetUp(); | 30 EmbedderTest::SetUp(); |
31 | 31 |
32 v8::Isolate::Scope isolate_scope(m_pIsolate); | 32 v8::Isolate::Scope isolate_scope(m_pIsolate); |
33 #ifdef PDF_ENABLE_XFA | |
33 v8::Locker locker(m_pIsolate); | 34 v8::Locker locker(m_pIsolate); |
Lei Zhang
2015/11/25 00:34:31
Do you know if these are needed on master too? Dit
Tom Sepez
2015/11/25 21:45:30
They are probably not needed anywhere. If you loo
| |
35 #endif | |
34 v8::HandleScope handle_scope(m_pIsolate); | 36 v8::HandleScope handle_scope(m_pIsolate); |
35 FXJS_PerIsolateData::SetUp(m_pIsolate); | 37 FXJS_PerIsolateData::SetUp(m_pIsolate); |
36 FXJS_InitializeRuntime(m_pIsolate, nullptr, &m_pPersistentContext, | 38 FXJS_InitializeRuntime(m_pIsolate, nullptr, &m_pPersistentContext, |
37 &m_StaticObjects); | 39 &m_StaticObjects); |
38 } | 40 } |
39 | 41 |
40 void TearDown() override { | 42 void TearDown() override { |
41 FXJS_ReleaseRuntime(m_pIsolate, &m_pPersistentContext, &m_StaticObjects); | 43 FXJS_ReleaseRuntime(m_pIsolate, &m_pPersistentContext, &m_StaticObjects); |
42 m_pPersistentContext.Reset(); | 44 m_pPersistentContext.Reset(); |
43 FXJS_Release(); | 45 FXJS_Release(); |
44 EmbedderTest::TearDown(); | 46 EmbedderTest::TearDown(); |
45 } | 47 } |
46 | 48 |
47 v8::Isolate* isolate() { return m_pIsolate; } | 49 v8::Isolate* isolate() { return m_pIsolate; } |
48 v8::Local<v8::Context> GetV8Context() { | 50 v8::Local<v8::Context> GetV8Context() { |
49 return m_pPersistentContext.Get(m_pIsolate); | 51 return m_pPersistentContext.Get(m_pIsolate); |
50 } | 52 } |
51 | 53 |
52 private: | 54 private: |
53 nonstd::unique_ptr<FXJS_ArrayBufferAllocator> m_pArrayBufferAllocator; | 55 nonstd::unique_ptr<FXJS_ArrayBufferAllocator> m_pArrayBufferAllocator; |
54 v8::Isolate* m_pIsolate; | 56 v8::Isolate* m_pIsolate; |
55 v8::Global<v8::Context> m_pPersistentContext; | 57 v8::Global<v8::Context> m_pPersistentContext; |
56 std::vector<v8::Global<v8::Object>*> m_StaticObjects; | 58 std::vector<v8::Global<v8::Object>*> m_StaticObjects; |
57 }; | 59 }; |
58 | 60 |
59 TEST_F(FXJSV8Embeddertest, Getters) { | 61 TEST_F(FXJSV8Embeddertest, Getters) { |
60 v8::Isolate::Scope isolate_scope(isolate()); | 62 v8::Isolate::Scope isolate_scope(isolate()); |
63 #ifdef PDF_ENABLE_XFA | |
61 v8::Locker locker(isolate()); | 64 v8::Locker locker(isolate()); |
65 #endif | |
62 v8::HandleScope handle_scope(isolate()); | 66 v8::HandleScope handle_scope(isolate()); |
63 v8::Context::Scope context_scope(GetV8Context()); | 67 v8::Context::Scope context_scope(GetV8Context()); |
64 | 68 |
65 FXJSErr error; | 69 FXJSErr error; |
66 int sts = FXJS_Execute(isolate(), nullptr, kScript, &error); | 70 int sts = FXJS_Execute(isolate(), nullptr, kScript, &error); |
67 EXPECT_EQ(0, sts); | 71 EXPECT_EQ(0, sts); |
68 | 72 |
69 v8::Local<v8::Object> This = FXJS_GetThisObj(isolate()); | 73 v8::Local<v8::Object> This = FXJS_GetThisObj(isolate()); |
70 v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred"); | 74 v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred"); |
71 EXPECT_TRUE(fred->IsNumber()); | 75 EXPECT_TRUE(fred->IsNumber()); |
72 } | 76 } |
OLD | NEW |