From 10569fcd4a3a9fb0140aa641372bcd462c6aa2f3 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 7 Jun 2018 00:42:46 +0000 Subject: Simplify cfxjs_engine_embeddertest.cpp In a world without context slots, we don't need to test getting an engine from a content slot. Change-Id: If572c364d663d1f20af659392bda3b96348fd4d4 Reviewed-on: https://pdfium-review.googlesource.com/34270 Commit-Queue: dsinclair Reviewed-by: dsinclair --- fxjs/cfxjs_engine_embeddertest.cpp | 89 ++++++++++++-------------------------- 1 file changed, 27 insertions(+), 62 deletions(-) diff --git a/fxjs/cfxjs_engine_embeddertest.cpp b/fxjs/cfxjs_engine_embeddertest.cpp index 75f07982aa..ff866d3ee0 100644 --- a/fxjs/cfxjs_engine_embeddertest.cpp +++ b/fxjs/cfxjs_engine_embeddertest.cpp @@ -19,35 +19,25 @@ const wchar_t kScript2[] = L"fred = 8"; } // namespace -class CFXJSEngineEmbedderTest : public JSEmbedderTest { - public: - Optional ExecuteInCurrentContext( - const WideString& script) { - auto* current_engine = - CFXJS_Engine::EngineFromIsolateCurrentContext(isolate()); - return current_engine->Execute(script); - } - - void CheckAssignmentInCurrentContext(double expected) { - auto* current_engine = - CFXJS_Engine::EngineFromIsolateCurrentContext(isolate()); - v8::Local This = current_engine->GetThisObj(); - v8::Local fred = - current_engine->GetObjectProperty(This, L"fred"); - EXPECT_TRUE(fred->IsNumber()); - EXPECT_EQ(expected, current_engine->ToDouble(fred)); - } -}; +using CFXJSEngineEmbedderTest = JSEmbedderTest; + +void CheckAssignmentInEngineContext(CFXJS_Engine* current_engine, + double expected) { + v8::Context::Scope context_scope(current_engine->GetV8Context()); + v8::Local This = current_engine->GetThisObj(); + v8::Local fred = current_engine->GetObjectProperty(This, L"fred"); + EXPECT_TRUE(fred->IsNumber()); + EXPECT_EQ(expected, current_engine->ToDouble(fred)); +} TEST_F(CFXJSEngineEmbedderTest, Getters) { v8::Isolate::Scope isolate_scope(isolate()); v8::HandleScope handle_scope(isolate()); v8::Context::Scope context_scope(GetV8Context()); - Optional err = - ExecuteInCurrentContext(WideString(kScript1)); + Optional err = engine()->Execute(WideString(kScript1)); EXPECT_FALSE(err); - CheckAssignmentInCurrentContext(kExpected1); + CheckAssignmentInEngineContext(engine(), kExpected1); } TEST_F(CFXJSEngineEmbedderTest, MultipleEngines) { @@ -60,53 +50,28 @@ TEST_F(CFXJSEngineEmbedderTest, MultipleEngines) { CFXJS_Engine engine2(isolate()); engine2.InitializeEngine(); - v8::Local context1 = engine1.GetV8Context(); - v8::Local context2 = engine2.GetV8Context(); - v8::Context::Scope context_scope(GetV8Context()); - Optional err = - ExecuteInCurrentContext(WideString(kScript0)); + Optional err = engine()->Execute(WideString(kScript0)); EXPECT_FALSE(err); - CheckAssignmentInCurrentContext(kExpected0); + CheckAssignmentInEngineContext(engine(), kExpected0); { - v8::Context::Scope context_scope1(context1); - Optional err = - ExecuteInCurrentContext(WideString(kScript1)); + // engine1 executing in engine1's context doesn't affect main. + v8::Context::Scope context_scope1(engine1.GetV8Context()); + Optional err = engine1.Execute(WideString(kScript1)); EXPECT_FALSE(err); - CheckAssignmentInCurrentContext(kExpected1); + CheckAssignmentInEngineContext(engine(), kExpected0); + CheckAssignmentInEngineContext(&engine1, kExpected1); } { - v8::Context::Scope context_scope2(context2); - Optional err = - ExecuteInCurrentContext(WideString(kScript2)); + // engine1 executing in engine2's context doesn't affect engine1. + v8::Context::Scope context_scope2(engine2.GetV8Context()); + Optional err = engine1.Execute(WideString(kScript2)); EXPECT_FALSE(err); - CheckAssignmentInCurrentContext(kExpected2); + CheckAssignmentInEngineContext(engine(), kExpected0); + CheckAssignmentInEngineContext(&engine1, kExpected1); + CheckAssignmentInEngineContext(&engine2, kExpected2); } - - CheckAssignmentInCurrentContext(kExpected0); - - { - v8::Context::Scope context_scope1(context1); - CheckAssignmentInCurrentContext(kExpected1); - { - v8::Context::Scope context_scope2(context2); - CheckAssignmentInCurrentContext(kExpected2); - } - CheckAssignmentInCurrentContext(kExpected1); - } - { - v8::Context::Scope context_scope2(context2); - CheckAssignmentInCurrentContext(kExpected2); - { - v8::Context::Scope context_scope1(context1); - CheckAssignmentInCurrentContext(kExpected1); - } - CheckAssignmentInCurrentContext(kExpected2); - } - - CheckAssignmentInCurrentContext(kExpected0); - engine1.ReleaseEngine(); engine2.ReleaseEngine(); } @@ -117,7 +82,7 @@ TEST_F(CFXJSEngineEmbedderTest, JSCompileError) { v8::Context::Scope context_scope(GetV8Context()); Optional err = - ExecuteInCurrentContext(L"functoon(x) { return x+1; }"); + engine()->Execute(L"functoon(x) { return x+1; }"); EXPECT_TRUE(err); EXPECT_EQ(L"SyntaxError: Unexpected token {", err->exception); EXPECT_EQ(1, err->line); @@ -130,7 +95,7 @@ TEST_F(CFXJSEngineEmbedderTest, JSRuntimeError) { v8::Context::Scope context_scope(GetV8Context()); Optional err = - ExecuteInCurrentContext(L"let a = 3;\nundefined.colour"); + engine()->Execute(L"let a = 3;\nundefined.colour"); EXPECT_TRUE(err); EXPECT_EQ(L"TypeError: Cannot read property 'colour' of undefined", err->exception); -- cgit v1.2.3