Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp

Issue 1338073002: Refactor fxjs_v8 and add embeddertests for it. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Working, expose new API to condition the isolate Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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()
21 : m_pContext(nullptr), m_pRuntime(nullptr), m_pIsolate(nullptr) {}
22 ~FXJSV8Embeddertest() override {}
23
24 void SetUp() override {
25 EmbedderTest::SetUp();
26 m_pAllocator.reset(new JS_ArrayBufferAllocator());
27
28 v8::Isolate::CreateParams params;
29 params.array_buffer_allocator = m_pAllocator.get();
30 m_pIsolate = v8::Isolate::New(params);
31
32 v8::Isolate::Scope isolate_scope(m_pIsolate);
33 v8::HandleScope handle_scope(m_pIsolate);
34 JS_Initial(0);
35 JS_PrepareIsolate(m_pIsolate);
Tom Sepez 2015/09/14 23:42:52 note: this is the important step, since PrepareIso
36 JS_InitialRuntime(m_pIsolate, m_pRuntime, m_pContext, m_pPersistentContext);
37 }
38
39 void TearDown() override {
40 JS_ReleaseRuntime(m_pIsolate, m_pPersistentContext);
41 JS_ResetIsolate(m_pIsolate);
42 JS_Release();
43 EmbedderTest::TearDown();
44 }
45
46 IFXJS_Context* context() const { return m_pContext; }
47 IFXJS_Runtime* runtime() const { return m_pRuntime; }
48 v8::Isolate* isolate() const { return m_pIsolate; }
49 v8::Local<v8::Context> GetV8Context() {
50 return v8::Local<v8::Context>::New(m_pIsolate, m_pPersistentContext);
51 }
52
53 private:
54 IFXJS_Context* m_pContext;
Lei Zhang 2015/09/15 01:59:55 (Just staring the at the code) Does the runtime/co
Tom Sepez 2015/09/15 15:56:42 Not yet. In the future, mock objects will need to
55 IFXJS_Runtime* m_pRuntime;
56 v8::Isolate* m_pIsolate;
57 v8::Global<v8::Context> m_pPersistentContext;
58 nonstd::unique_ptr<v8::ArrayBuffer::Allocator> m_pAllocator;
59 };
60
61 TEST_F(FXJSV8Embeddertest, Getters) {
62 v8::Isolate::Scope isolate_scope(isolate());
63 v8::HandleScope handle_scope(isolate());
64 v8::Context::Scope context_scope(GetV8Context());
65
66 FXJSErr error;
67 CFX_WideString wsInfo;
68 CFX_WideString wsScript(kScript);
69 int sts = JS_Execute(isolate(), context(), kScript, wcslen(kScript), &error);
70 EXPECT_EQ(0, sts);
71
72 v8::Local<v8::Object> This = JS_GetThisObj(isolate());
73 v8::Local<v8::Value> fred = JS_GetObjectElement(isolate(), This, L"fred");
74 EXPECT_TRUE(fred->IsNumber());
75 }
OLDNEW
« fpdfsdk/src/jsapi/fxjs_v8.cpp ('K') | « fpdfsdk/src/jsapi/fxjs_v8.cpp ('k') | pdfium.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698