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 "../../../testing/embedder_test.h" | 6 #include "../../../testing/embedder_test.h" |
7 #include "../../../testing/embedder_test_shared_isolate_delegate.h" | |
7 #include "../../include/fsdk_mgr.h" | 8 #include "../../include/fsdk_mgr.h" |
8 #include "../../include/javascript/JS_Runtime.h" | 9 #include "../../include/javascript/JS_Runtime.h" |
9 #include "../../include/jsapi/fxjs_v8.h" | 10 #include "../../include/jsapi/fxjs_v8.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 const wchar_t kScript[] = L"fred = 7"; | 15 const wchar_t kScript[] = L"fred = 7"; |
15 | 16 |
16 } // namespace | 17 } // namespace |
17 | 18 |
18 class FXJSV8Embeddertest : public EmbedderTest { | 19 class FXJSV8Embeddertest : public EmbedderTest { |
19 public: | 20 public: |
20 FXJSV8Embeddertest() : m_pIsolate(nullptr) {} | 21 FXJSV8Embeddertest() : m_pDelegate(new EmbedderTestSharedIsolateDelegate) {} |
21 ~FXJSV8Embeddertest() override {} | 22 ~FXJSV8Embeddertest() override {} |
22 | 23 |
23 void SetUp() override { | 24 void SetUp() override { |
25 EmbedderTest::SetDelegate(m_pDelegate.get()); | |
Tom Sepez
2015/10/05 20:17:51
Question: Is this worth adding to the delegate, o
| |
24 EmbedderTest::SetUp(); | 26 EmbedderTest::SetUp(); |
25 m_pAllocator.reset(new FXJS_ArrayBufferAllocator()); | |
26 | 27 |
27 v8::Isolate::CreateParams params; | 28 v8::Isolate* pIsolate = GetIsolate(); |
28 params.array_buffer_allocator = m_pAllocator.get(); | 29 v8::Isolate::Scope isolate_scope(pIsolate); |
29 m_pIsolate = v8::Isolate::New(params); | 30 v8::HandleScope handle_scope(pIsolate); |
30 | 31 FXJS_PerIsolateData::SetUp(pIsolate); |
31 v8::Isolate::Scope isolate_scope(m_pIsolate); | 32 FXJS_InitializeRuntime(pIsolate, nullptr, nullptr, m_pPersistentContext); |
32 v8::HandleScope handle_scope(m_pIsolate); | |
33 FXJS_Initialize(0, nullptr); | |
34 FXJS_PerIsolateData::SetUp(m_pIsolate); | |
35 FXJS_InitializeRuntime(m_pIsolate, nullptr, nullptr, m_pPersistentContext); | |
36 } | 33 } |
37 | 34 |
38 void TearDown() override { | 35 void TearDown() override { |
39 FXJS_ReleaseRuntime(m_pIsolate, m_pPersistentContext); | 36 FXJS_ReleaseRuntime(GetIsolate(), m_pPersistentContext); |
37 m_pPersistentContext.Reset(); | |
40 FXJS_Release(); | 38 FXJS_Release(); |
41 EmbedderTest::TearDown(); | 39 EmbedderTest::TearDown(); |
42 } | 40 } |
43 | 41 |
44 v8::Isolate* isolate() const { return m_pIsolate; } | 42 v8::Isolate* GetIsolate() const { return m_pDelegate->GetSharedIsolate(); } |
45 v8::Local<v8::Context> GetV8Context() { | 43 v8::Local<v8::Context> GetV8Context() { |
46 return v8::Local<v8::Context>::New(m_pIsolate, m_pPersistentContext); | 44 return v8::Local<v8::Context>::New(GetIsolate(), m_pPersistentContext); |
47 } | 45 } |
48 | 46 |
49 private: | 47 private: |
50 v8::Isolate* m_pIsolate; | |
51 v8::Global<v8::Context> m_pPersistentContext; | 48 v8::Global<v8::Context> m_pPersistentContext; |
52 nonstd::unique_ptr<v8::ArrayBuffer::Allocator> m_pAllocator; | 49 nonstd::unique_ptr<EmbedderTestSharedIsolateDelegate> m_pDelegate; |
53 }; | 50 }; |
54 | 51 |
55 TEST_F(FXJSV8Embeddertest, Getters) { | 52 TEST_F(FXJSV8Embeddertest, Getters) { |
56 v8::Isolate::Scope isolate_scope(isolate()); | 53 v8::Isolate* pIsolate = GetIsolate(); |
57 v8::HandleScope handle_scope(isolate()); | 54 v8::Isolate::Scope isolate_scope(pIsolate); |
55 v8::HandleScope handle_scope(pIsolate); | |
58 v8::Context::Scope context_scope(GetV8Context()); | 56 v8::Context::Scope context_scope(GetV8Context()); |
59 | 57 |
60 FXJSErr error; | 58 FXJSErr error; |
61 CFX_WideString wsInfo; | 59 CFX_WideString wsInfo; |
62 CFX_WideString wsScript(kScript); | 60 CFX_WideString wsScript(kScript); |
63 int sts = FXJS_Execute(isolate(), nullptr, kScript, wcslen(kScript), &error); | 61 int sts = FXJS_Execute(pIsolate, nullptr, kScript, wcslen(kScript), &error); |
64 EXPECT_EQ(0, sts); | 62 EXPECT_EQ(0, sts); |
65 | 63 |
66 v8::Local<v8::Object> This = FXJS_GetThisObj(isolate()); | 64 v8::Local<v8::Object> This = FXJS_GetThisObj(pIsolate); |
67 v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred"); | 65 v8::Local<v8::Value> fred = FXJS_GetObjectElement(pIsolate, This, L"fred"); |
68 EXPECT_TRUE(fred->IsNumber()); | 66 EXPECT_TRUE(fred->IsNumber()); |
69 } | 67 } |
OLD | NEW |