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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "testing/js_embedder_test.h" | 6 #include "testing/js_embedder_test.h" |
7 | 7 |
8 namespace { | 8 namespace { |
9 | 9 |
10 const double kExpected0 = 6.0; | 10 const double kExpected0 = 6.0; |
11 const double kExpected1 = 7.0; | 11 const double kExpected1 = 7.0; |
12 const double kExpected2 = 8.0; | 12 const double kExpected2 = 8.0; |
13 | 13 |
14 const wchar_t kScript0[] = L"fred = 6"; | 14 const wchar_t kScript0[] = L"fred = 6"; |
15 const wchar_t kScript1[] = L"fred = 7"; | 15 const wchar_t kScript1[] = L"fred = 7"; |
16 const wchar_t kScript2[] = L"fred = 8"; | 16 const wchar_t kScript2[] = L"fred = 8"; |
17 | 17 |
18 } // namespace | 18 } // namespace |
19 | 19 |
20 class FXJSV8EmbedderTest : public JSEmbedderTest { | 20 class FXJSV8EmbedderTest : public JSEmbedderTest { |
21 public: | 21 public: |
22 void ExecuteInCurrentContext(const wchar_t* script) { | 22 void ExecuteInCurrentContext(const wchar_t* script) { |
23 FXJSErr error; | 23 FXJSErr error; |
24 int sts = FXJS_Execute(isolate(), nullptr, script, &error); | 24 int sts = FXJS_Execute(isolate(), script, &error); |
25 EXPECT_EQ(0, sts); | 25 EXPECT_EQ(0, sts); |
26 } | 26 } |
27 void CheckAssignmentInCurrentContext(double expected) { | 27 void CheckAssignmentInCurrentContext(double expected) { |
28 v8::Local<v8::Object> This = FXJS_GetThisObj(isolate()); | 28 v8::Local<v8::Object> This = FXJS_GetThisObj(isolate()); |
29 v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred"); | 29 v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred"); |
30 EXPECT_TRUE(fred->IsNumber()); | 30 EXPECT_TRUE(fred->IsNumber()); |
31 EXPECT_EQ(expected, fred->ToNumber(isolate()->GetCurrentContext()) | 31 EXPECT_EQ(expected, fred->ToNumber(isolate()->GetCurrentContext()) |
32 .ToLocalChecked() | 32 .ToLocalChecked() |
33 ->Value()); | 33 ->Value()); |
34 } | 34 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 v8::Local<v8::Context> context2 = | 80 v8::Local<v8::Context> context2 = |
81 v8::Local<v8::Context>::New(isolate(), global_context2); | 81 v8::Local<v8::Context>::New(isolate(), global_context2); |
82 v8::Context::Scope context_scope(context2); | 82 v8::Context::Scope context_scope(context2); |
83 ExecuteInCurrentContext(kScript2); | 83 ExecuteInCurrentContext(kScript2); |
84 CheckAssignmentInCurrentContext(kExpected2); | 84 CheckAssignmentInCurrentContext(kExpected2); |
85 } | 85 } |
86 FXJS_ReleaseRuntime(isolate(), &global_context2, &static_objects2); | 86 FXJS_ReleaseRuntime(isolate(), &global_context2, &static_objects2); |
87 | 87 |
88 CheckAssignmentInCurrentContext(kExpected0); | 88 CheckAssignmentInCurrentContext(kExpected0); |
89 } | 89 } |
OLD | NEW |