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

Unified Diff: Source/bindings/core/v8/V8ScriptRunnerTest.cpp

Issue 549533002: Follow-on to "Restore in-memory parser cache for V8 compile" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/core/v8/V8ScriptRunner.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/v8/V8ScriptRunnerTest.cpp
diff --git a/Source/bindings/core/v8/V8ScriptRunnerTest.cpp b/Source/bindings/core/v8/V8ScriptRunnerTest.cpp
index 3fde4cf7aae259b025cc6ce0c93b684338bacb57..0f12f1cd3312f8d1bee4e9e77191bd3bbb7d1ebe 100644
--- a/Source/bindings/core/v8/V8ScriptRunnerTest.cpp
+++ b/Source/bindings/core/v8/V8ScriptRunnerTest.cpp
@@ -5,6 +5,7 @@
#include "config.h"
#include "bindings/core/v8/V8ScriptRunner.h"
+#include "bindings/core/v8/V8Binding.h"
#include "core/fetch/ScriptResource.h"
#include "platform/heap/Handle.h"
#include <gtest/gtest.h>
@@ -16,15 +17,9 @@ namespace {
class V8ScriptRunnerTest : public ::testing::Test {
public:
- V8ScriptRunnerTest() { }
+ V8ScriptRunnerTest() : m_scope(v8::Isolate::GetCurrent()) { }
virtual ~V8ScriptRunnerTest() { }
- static void SetUpTestCase()
- {
- cacheTagParser = StringHash::hash(v8::V8::GetVersion()) * 2;
- cacheTagCode = cacheTagParser + 1;
- }
-
virtual void SetUp() OVERRIDE
{
// To trick various layers of caching, increment a counter for each
@@ -38,43 +33,39 @@ public:
m_resource.clear();
}
- v8::Isolate* isolate()
+ v8::Isolate* isolate() const
{
- return v8::Isolate::GetCurrent();
+ return m_scope.isolate();
}
- v8::Local<v8::String> v8String(const char* value)
- {
- return v8::String::NewFromOneByte(
- isolate(), reinterpret_cast<const uint8_t*>(value));
- }
- v8::Local<v8::String> v8String(const WTF::String& value)
- {
- return v8String(value.ascii().data());
- }
- WTF::String code()
+ WTF::String code() const
{
// Simple function for testing. Note:
// - Add counter to trick V8 code cache.
// - Pad counter to 1000 digits, to trick minimal cacheability threshold.
return WTF::String::format("a = function() { 1 + 1; } // %01000d\n", counter);
}
- WTF::String filename()
+ WTF::String filename() const
{
return WTF::String::format("whatever%d.js", counter);
}
- WTF::String url()
+ WTF::String url() const
{
return WTF::String::format("http://bla.com/bla%d", counter);
}
+ unsigned tagForParserCache() const
+ {
+ return StringHash::hash(v8::V8::GetVersion()) * 2;
+ }
+ unsigned tagForCodeCache() const
+ {
+ return tagForParserCache() + 1;
+ }
bool compileScript(V8CacheOptions cacheOptions)
{
- v8::HandleScope handleScope(isolate());
- v8::Local<v8::Context> context = v8::Context::New(isolate());
- v8::Context::Scope contextScope(context);
return !V8ScriptRunner::compileScript(
- v8String(code()), filename(), WTF::TextPosition(), m_resource.get(),
- isolate(), NotSharableCrossOrigin, cacheOptions)
+ v8String(isolate(), code()), filename(), WTF::TextPosition(),
+ m_resource.get(), isolate(), NotSharableCrossOrigin, cacheOptions)
.IsEmpty();
}
@@ -93,14 +84,11 @@ public:
protected:
WTF::OwnPtr<ResourceRequest> m_resourceRequest;
OwnPtrWillBePersistent<ScriptResource> m_resource;
+ V8TestingScope m_scope;
- static unsigned cacheTagParser;
- static unsigned cacheTagCode;
static int counter;
};
-unsigned V8ScriptRunnerTest::cacheTagParser = 0;
-unsigned V8ScriptRunnerTest::cacheTagCode = 0;
int V8ScriptRunnerTest::counter = 0;
TEST_F(V8ScriptRunnerTest, resourcelessShouldPass)
@@ -114,43 +102,43 @@ TEST_F(V8ScriptRunnerTest, emptyResourceDoesNothing)
{
setEmptyResource();
EXPECT_TRUE(compileScript(V8CacheOptionsOff));
- EXPECT_FALSE(m_resource->cachedMetadata(cacheTagParser));
- EXPECT_FALSE(m_resource->cachedMetadata(cacheTagCode));
+ EXPECT_FALSE(m_resource->cachedMetadata(tagForParserCache()));
+ EXPECT_FALSE(m_resource->cachedMetadata(tagForCodeCache()));
EXPECT_TRUE(compileScript(V8CacheOptionsParse));
- EXPECT_FALSE(m_resource->cachedMetadata(cacheTagParser));
- EXPECT_FALSE(m_resource->cachedMetadata(cacheTagCode));
+ EXPECT_FALSE(m_resource->cachedMetadata(tagForParserCache()));
+ EXPECT_FALSE(m_resource->cachedMetadata(tagForCodeCache()));
EXPECT_TRUE(compileScript(V8CacheOptionsCode));
- EXPECT_FALSE(m_resource->cachedMetadata(cacheTagParser));
- EXPECT_FALSE(m_resource->cachedMetadata(cacheTagCode));
+ EXPECT_FALSE(m_resource->cachedMetadata(tagForParserCache()));
+ EXPECT_FALSE(m_resource->cachedMetadata(tagForCodeCache()));
}
TEST_F(V8ScriptRunnerTest, defaultOptions)
{
setResource();
EXPECT_TRUE(compileScript(V8CacheOptionsOff));
- EXPECT_TRUE(m_resource->cachedMetadata(cacheTagParser));
- EXPECT_FALSE(m_resource->cachedMetadata(cacheTagCode));
+ EXPECT_TRUE(m_resource->cachedMetadata(tagForParserCache()));
+ EXPECT_FALSE(m_resource->cachedMetadata(tagForCodeCache()));
}
TEST_F(V8ScriptRunnerTest, parseOptions)
{
setResource();
EXPECT_TRUE(compileScript(V8CacheOptionsParse));
- EXPECT_TRUE(m_resource->cachedMetadata(cacheTagParser));
- EXPECT_FALSE(m_resource->cachedMetadata(cacheTagCode));
+ EXPECT_TRUE(m_resource->cachedMetadata(tagForParserCache()));
+ EXPECT_FALSE(m_resource->cachedMetadata(tagForCodeCache()));
}
TEST_F(V8ScriptRunnerTest, codeOptions)
{
setResource();
EXPECT_TRUE(compileScript(V8CacheOptionsCode));
- EXPECT_FALSE(m_resource->cachedMetadata(cacheTagParser));
+ EXPECT_FALSE(m_resource->cachedMetadata(tagForParserCache()));
- // TODO(vogelheim): Code caching is presently still disabled.
- // Enable EXPECT when code caching lands.
- // EXPECT_TRUE(m_resource->cachedMetadata(cacheTagCode));
+ // FIXME: Code caching is presently still disabled.
+ // Enable EXPECT when code caching lands.
+ // EXPECT_TRUE(m_resource->cachedMetadata(tagForCodeCache()));
}
} // namespace
« no previous file with comments | « Source/bindings/core/v8/V8ScriptRunner.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698