Index: fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp |
diff --git a/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp b/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp |
index 1c660397d1914aa3f0c12ce843f3522e87476433..bb556cba936fa6f39c55a99319fe76e4f669c8a2 100644 |
--- a/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp |
+++ b/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp |
@@ -4,6 +4,7 @@ |
#include "../../../core/include/fpdfapi/fpdf_parser.h" |
#include "../../../testing/embedder_test.h" |
+#include "../../../testing/embedder_test_shared_isolate_delegate.h" |
#include "../../include/fsdk_mgr.h" |
#include "../../include/javascript/JS_Runtime.h" |
#include "../../include/jsapi/fxjs_v8.h" |
@@ -17,53 +18,50 @@ const wchar_t kScript[] = L"fred = 7"; |
class FXJSV8Embeddertest : public EmbedderTest { |
public: |
- FXJSV8Embeddertest() : m_pIsolate(nullptr) {} |
+ FXJSV8Embeddertest() : m_pDelegate(new EmbedderTestSharedIsolateDelegate) {} |
~FXJSV8Embeddertest() override {} |
void SetUp() override { |
+ EmbedderTest::SetDelegate(m_pDelegate.get()); |
Tom Sepez
2015/10/05 20:17:51
Question: Is this worth adding to the delegate, o
|
EmbedderTest::SetUp(); |
- m_pAllocator.reset(new FXJS_ArrayBufferAllocator()); |
- v8::Isolate::CreateParams params; |
- params.array_buffer_allocator = m_pAllocator.get(); |
- m_pIsolate = v8::Isolate::New(params); |
- |
- v8::Isolate::Scope isolate_scope(m_pIsolate); |
- v8::HandleScope handle_scope(m_pIsolate); |
- FXJS_Initialize(0, nullptr); |
- FXJS_PerIsolateData::SetUp(m_pIsolate); |
- FXJS_InitializeRuntime(m_pIsolate, nullptr, nullptr, m_pPersistentContext); |
+ v8::Isolate* pIsolate = GetIsolate(); |
+ v8::Isolate::Scope isolate_scope(pIsolate); |
+ v8::HandleScope handle_scope(pIsolate); |
+ FXJS_PerIsolateData::SetUp(pIsolate); |
+ FXJS_InitializeRuntime(pIsolate, nullptr, nullptr, m_pPersistentContext); |
} |
void TearDown() override { |
- FXJS_ReleaseRuntime(m_pIsolate, m_pPersistentContext); |
+ FXJS_ReleaseRuntime(GetIsolate(), m_pPersistentContext); |
+ m_pPersistentContext.Reset(); |
FXJS_Release(); |
EmbedderTest::TearDown(); |
} |
- v8::Isolate* isolate() const { return m_pIsolate; } |
+ v8::Isolate* GetIsolate() const { return m_pDelegate->GetSharedIsolate(); } |
v8::Local<v8::Context> GetV8Context() { |
- return v8::Local<v8::Context>::New(m_pIsolate, m_pPersistentContext); |
+ return v8::Local<v8::Context>::New(GetIsolate(), m_pPersistentContext); |
} |
private: |
- v8::Isolate* m_pIsolate; |
v8::Global<v8::Context> m_pPersistentContext; |
- nonstd::unique_ptr<v8::ArrayBuffer::Allocator> m_pAllocator; |
+ nonstd::unique_ptr<EmbedderTestSharedIsolateDelegate> m_pDelegate; |
}; |
TEST_F(FXJSV8Embeddertest, Getters) { |
- v8::Isolate::Scope isolate_scope(isolate()); |
- v8::HandleScope handle_scope(isolate()); |
+ v8::Isolate* pIsolate = GetIsolate(); |
+ v8::Isolate::Scope isolate_scope(pIsolate); |
+ v8::HandleScope handle_scope(pIsolate); |
v8::Context::Scope context_scope(GetV8Context()); |
FXJSErr error; |
CFX_WideString wsInfo; |
CFX_WideString wsScript(kScript); |
- int sts = FXJS_Execute(isolate(), nullptr, kScript, wcslen(kScript), &error); |
+ int sts = FXJS_Execute(pIsolate, nullptr, kScript, wcslen(kScript), &error); |
EXPECT_EQ(0, sts); |
- v8::Local<v8::Object> This = FXJS_GetThisObj(isolate()); |
- v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred"); |
+ v8::Local<v8::Object> This = FXJS_GetThisObj(pIsolate); |
+ v8::Local<v8::Value> fred = FXJS_GetObjectElement(pIsolate, This, L"fred"); |
EXPECT_TRUE(fred->IsNumber()); |
} |