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 "../../../third_party/base/nonstd_unique_ptr.h" | 5 #include "../../../third_party/base/nonstd_unique_ptr.h" |
6 #include "../../../core/include/fpdfapi/fpdf_parser.h" | 6 #include "../../../core/include/fpdfapi/fpdf_parser.h" |
7 #include "../../../testing/embedder_test.h" | 7 #include "../../../testing/embedder_test.h" |
8 #include "../../include/jsapi/fxjs_v8.h" | 8 #include "../../include/jsapi/fxjs_v8.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
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 v8::Locker locker(m_pIsolate); | 33 v8::Locker locker(m_pIsolate); |
34 v8::HandleScope handle_scope(m_pIsolate); | 34 v8::HandleScope handle_scope(m_pIsolate); |
35 FXJS_PerIsolateData::SetUp(m_pIsolate); | 35 FXJS_PerIsolateData::SetUp(m_pIsolate); |
36 FXJS_InitializeRuntime(m_pIsolate, nullptr, nullptr, m_pPersistentContext); | 36 FXJS_InitializeRuntime(m_pIsolate, nullptr, m_pPersistentContext); |
37 } | 37 } |
38 | 38 |
39 void TearDown() override { | 39 void TearDown() override { |
40 FXJS_ReleaseRuntime(m_pIsolate, m_pPersistentContext); | 40 FXJS_ReleaseRuntime(m_pIsolate, m_pPersistentContext); |
41 m_pPersistentContext.Reset(); | 41 m_pPersistentContext.Reset(); |
42 FXJS_Release(); | 42 FXJS_Release(); |
43 EmbedderTest::TearDown(); | 43 EmbedderTest::TearDown(); |
44 } | 44 } |
45 | 45 |
46 v8::Isolate* isolate() { return m_pIsolate; } | 46 v8::Isolate* isolate() { return m_pIsolate; } |
47 v8::Local<v8::Context> GetV8Context() { | 47 v8::Local<v8::Context> GetV8Context() { |
48 return m_pPersistentContext.Get(m_pIsolate); | 48 return m_pPersistentContext.Get(m_pIsolate); |
49 } | 49 } |
50 | 50 |
51 private: | 51 private: |
52 nonstd::unique_ptr<FXJS_ArrayBufferAllocator> m_pArrayBufferAllocator; | 52 nonstd::unique_ptr<FXJS_ArrayBufferAllocator> m_pArrayBufferAllocator; |
53 v8::Isolate* m_pIsolate; | 53 v8::Isolate* m_pIsolate; |
54 v8::Global<v8::Context> m_pPersistentContext; | 54 v8::Global<v8::Context> m_pPersistentContext; |
55 }; | 55 }; |
56 | 56 |
57 TEST_F(FXJSV8Embeddertest, Getters) { | 57 TEST_F(FXJSV8Embeddertest, Getters) { |
58 v8::Isolate::Scope isolate_scope(isolate()); | 58 v8::Isolate::Scope isolate_scope(isolate()); |
59 v8::Locker locker(isolate()); | 59 v8::Locker locker(isolate()); |
60 v8::HandleScope handle_scope(isolate()); | 60 v8::HandleScope handle_scope(isolate()); |
61 v8::Context::Scope context_scope(GetV8Context()); | 61 v8::Context::Scope context_scope(GetV8Context()); |
62 | 62 |
63 FXJSErr error; | 63 FXJSErr error; |
64 CFX_WideString wsInfo; | 64 CFX_WideString wsInfo; |
65 CFX_WideString wsScript(kScript); | 65 CFX_WideString wsScript(kScript); |
66 int sts = FXJS_Execute(isolate(), nullptr, kScript, wcslen(kScript), &error); | 66 int sts = FXJS_Execute(isolate(), nullptr, kScript, &error); |
67 EXPECT_EQ(0, sts); | 67 EXPECT_EQ(0, sts); |
68 | 68 |
69 v8::Local<v8::Object> This = FXJS_GetThisObj(isolate()); | 69 v8::Local<v8::Object> This = FXJS_GetThisObj(isolate()); |
70 v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred"); | 70 v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred"); |
71 EXPECT_TRUE(fred->IsNumber()); | 71 EXPECT_TRUE(fred->IsNumber()); |
72 } | 72 } |
OLD | NEW |