OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "../../../core/include/fpdfapi/fpdf_parser.h" |
| 6 #include "../../../testing/embedder_test.h" |
| 7 #include "../../include/fsdk_mgr.h" |
| 8 #include "../../include/javascript/JS_Runtime.h" |
| 9 #include "../../include/jsapi/fxjs_v8.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 const wchar_t kScript[] = L"fred = 7"; |
| 15 |
| 16 } // namespace |
| 17 |
| 18 class FXJSV8Embeddertest : public EmbedderTest { |
| 19 public: |
| 20 FXJSV8Embeddertest() : m_pIsolate(nullptr) {} |
| 21 ~FXJSV8Embeddertest() override {} |
| 22 |
| 23 void SetUp() override { |
| 24 EmbedderTest::SetUp(); |
| 25 m_pAllocator.reset(new JS_ArrayBufferAllocator()); |
| 26 |
| 27 v8::Isolate::CreateParams params; |
| 28 params.array_buffer_allocator = m_pAllocator.get(); |
| 29 m_pIsolate = v8::Isolate::New(params); |
| 30 |
| 31 v8::Isolate::Scope isolate_scope(m_pIsolate); |
| 32 v8::Locker locker(m_pIsolate); |
| 33 v8::HandleScope handle_scope(m_pIsolate); |
| 34 JS_Initialize(0); |
| 35 JS_PrepareIsolate(m_pIsolate); |
| 36 JS_InitializeRuntime(m_pIsolate, nullptr, nullptr, m_pPersistentContext); |
| 37 } |
| 38 |
| 39 void TearDown() override { |
| 40 JS_ReleaseRuntime(m_pIsolate, m_pPersistentContext); |
| 41 JS_Release(); |
| 42 EmbedderTest::TearDown(); |
| 43 } |
| 44 |
| 45 v8::Isolate* isolate() const { return m_pIsolate; } |
| 46 v8::Local<v8::Context> GetV8Context() { |
| 47 return v8::Local<v8::Context>::New(m_pIsolate, m_pPersistentContext); |
| 48 } |
| 49 |
| 50 private: |
| 51 v8::Isolate* m_pIsolate; |
| 52 v8::Global<v8::Context> m_pPersistentContext; |
| 53 nonstd::unique_ptr<v8::ArrayBuffer::Allocator> m_pAllocator; |
| 54 }; |
| 55 |
| 56 TEST_F(FXJSV8Embeddertest, Getters) { |
| 57 v8::Isolate::Scope isolate_scope(isolate()); |
| 58 v8::Locker locker(isolate()); |
| 59 v8::HandleScope handle_scope(isolate()); |
| 60 v8::Context::Scope context_scope(GetV8Context()); |
| 61 |
| 62 FXJSErr error; |
| 63 CFX_WideString wsInfo; |
| 64 CFX_WideString wsScript(kScript); |
| 65 int sts = JS_Execute(isolate(), nullptr, kScript, wcslen(kScript), &error); |
| 66 EXPECT_EQ(0, sts); |
| 67 |
| 68 v8::Local<v8::Object> This = JS_GetThisObj(isolate()); |
| 69 v8::Local<v8::Value> fred = JS_GetObjectElement(isolate(), This, L"fred"); |
| 70 EXPECT_TRUE(fred->IsNumber()); |
| 71 } |
OLD | NEW |