| 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 "testing/js_embedder_test.h" |
| 6 #include "fpdfsdk/include/jsapi/fxjs_v8.h" | |
| 7 #include "testing/embedder_test.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/base/nonstd_unique_ptr.h" | |
| 10 | 7 |
| 11 namespace { | 8 namespace { |
| 12 | 9 |
| 13 const wchar_t kScript[] = L"fred = 7"; | 10 const wchar_t kScript[] = L"fred = 7"; |
| 14 | 11 |
| 15 } // namespace | 12 } // namespace |
| 16 | 13 |
| 17 class FXJSV8Embeddertest : public EmbedderTest { | 14 class FXJSV8EmbedderTest : public JSEmbedderTest {}; |
| 18 public: | |
| 19 FXJSV8Embeddertest() | |
| 20 : m_pArrayBufferAllocator(new FXJS_ArrayBufferAllocator) { | |
| 21 v8::Isolate::CreateParams params; | |
| 22 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); | |
| 23 m_pIsolate = v8::Isolate::New(params); | |
| 24 } | |
| 25 | 15 |
| 26 ~FXJSV8Embeddertest() override { m_pIsolate->Dispose(); } | 16 TEST_F(FXJSV8EmbedderTest, Getters) { |
| 27 | |
| 28 void SetUp() override { | |
| 29 EmbedderTest::SetExternalIsolate(m_pIsolate); | |
| 30 EmbedderTest::SetUp(); | |
| 31 | |
| 32 v8::Isolate::Scope isolate_scope(m_pIsolate); | |
| 33 #ifdef PDF_ENABLE_XFA | |
| 34 v8::Locker locker(m_pIsolate); | |
| 35 #endif // PDF_ENABLE_XFA | |
| 36 v8::HandleScope handle_scope(m_pIsolate); | |
| 37 FXJS_PerIsolateData::SetUp(m_pIsolate); | |
| 38 FXJS_InitializeRuntime(m_pIsolate, nullptr, &m_pPersistentContext, | |
| 39 &m_StaticObjects); | |
| 40 } | |
| 41 | |
| 42 void TearDown() override { | |
| 43 FXJS_ReleaseRuntime(m_pIsolate, &m_pPersistentContext, &m_StaticObjects); | |
| 44 m_pPersistentContext.Reset(); | |
| 45 FXJS_Release(); | |
| 46 EmbedderTest::TearDown(); | |
| 47 } | |
| 48 | |
| 49 v8::Isolate* isolate() { return m_pIsolate; } | |
| 50 v8::Local<v8::Context> GetV8Context() { | |
| 51 return m_pPersistentContext.Get(m_pIsolate); | |
| 52 } | |
| 53 | |
| 54 private: | |
| 55 nonstd::unique_ptr<FXJS_ArrayBufferAllocator> m_pArrayBufferAllocator; | |
| 56 v8::Isolate* m_pIsolate; | |
| 57 v8::Global<v8::Context> m_pPersistentContext; | |
| 58 std::vector<v8::Global<v8::Object>*> m_StaticObjects; | |
| 59 }; | |
| 60 | |
| 61 TEST_F(FXJSV8Embeddertest, Getters) { | |
| 62 v8::Isolate::Scope isolate_scope(isolate()); | 17 v8::Isolate::Scope isolate_scope(isolate()); |
| 63 #ifdef PDF_ENABLE_XFA | 18 #ifdef PDF_ENABLE_XFA |
| 64 v8::Locker locker(isolate()); | 19 v8::Locker locker(isolate()); |
| 65 #endif // PDF_ENABLE_XFA | 20 #endif // PDF_ENABLE_XFA |
| 66 v8::HandleScope handle_scope(isolate()); | 21 v8::HandleScope handle_scope(isolate()); |
| 67 v8::Context::Scope context_scope(GetV8Context()); | 22 v8::Context::Scope context_scope(GetV8Context()); |
| 68 | 23 |
| 69 FXJSErr error; | 24 FXJSErr error; |
| 70 int sts = FXJS_Execute(isolate(), nullptr, kScript, &error); | 25 int sts = FXJS_Execute(isolate(), nullptr, kScript, &error); |
| 71 EXPECT_EQ(0, sts); | 26 EXPECT_EQ(0, sts); |
| 72 | 27 |
| 73 v8::Local<v8::Object> This = FXJS_GetThisObj(isolate()); | 28 v8::Local<v8::Object> This = FXJS_GetThisObj(isolate()); |
| 74 v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred"); | 29 v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred"); |
| 75 EXPECT_TRUE(fred->IsNumber()); | 30 EXPECT_TRUE(fred->IsNumber()); |
| 76 } | 31 } |
| OLD | NEW |