| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium 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 "config.h" | 5 #include "config.h" |
| 6 #include "bindings/core/v8/V8ScriptRunner.h" | 6 #include "bindings/core/v8/V8ScriptRunner.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/V8Binding.h" | 8 #include "bindings/core/v8/V8Binding.h" |
| 9 #include "core/fetch/ScriptResource.h" | 9 #include "core/fetch/ScriptResource.h" |
| 10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } | 58 } |
| 59 unsigned tagForCodeCache(Resource* resource) const | 59 unsigned tagForCodeCache(Resource* resource) const |
| 60 { | 60 { |
| 61 return V8ScriptRunner::tagForCodeCache(resource); | 61 return V8ScriptRunner::tagForCodeCache(resource); |
| 62 } | 62 } |
| 63 | 63 |
| 64 bool compileScript(V8CacheOptions cacheOptions) | 64 bool compileScript(V8CacheOptions cacheOptions) |
| 65 { | 65 { |
| 66 return !V8ScriptRunner::compileScript( | 66 return !V8ScriptRunner::compileScript( |
| 67 v8String(isolate(), code()), filename(), WTF::TextPosition(), | 67 v8String(isolate(), code()), filename(), WTF::TextPosition(), |
| 68 m_resource.get(), 0, isolate(), NotSharableCrossOrigin, cacheOptions
) | 68 m_resource.get(), 0, 0, isolate(), NotSharableCrossOrigin, cacheOpti
ons) |
| 69 .IsEmpty(); | 69 .IsEmpty(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void setEmptyResource() | 72 void setEmptyResource() |
| 73 { | 73 { |
| 74 m_resourceRequest = WTF::adoptPtr(new ResourceRequest); | 74 m_resourceRequest = WTF::adoptPtr(new ResourceRequest); |
| 75 m_resource = ScriptResource::create(*m_resourceRequest.get(), "UTF-8"); | 75 m_resource = ScriptResource::create(*m_resourceRequest.get(), "UTF-8"); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void setResource() | 78 void setResource() |
| (...skipping 17 matching lines...) Expand all Loading... |
| 96 EXPECT_TRUE(compileScript(V8CacheOptionsNone)); | 96 EXPECT_TRUE(compileScript(V8CacheOptionsNone)); |
| 97 EXPECT_TRUE(compileScript(V8CacheOptionsParseMemory)); | 97 EXPECT_TRUE(compileScript(V8CacheOptionsParseMemory)); |
| 98 EXPECT_TRUE(compileScript(V8CacheOptionsParse)); | 98 EXPECT_TRUE(compileScript(V8CacheOptionsParse)); |
| 99 EXPECT_TRUE(compileScript(V8CacheOptionsCode)); | 99 EXPECT_TRUE(compileScript(V8CacheOptionsCode)); |
| 100 } | 100 } |
| 101 | 101 |
| 102 TEST_F(V8ScriptRunnerTest, emptyResourceDoesNothing) | 102 TEST_F(V8ScriptRunnerTest, emptyResourceDoesNothing) |
| 103 { | 103 { |
| 104 setEmptyResource(); | 104 setEmptyResource(); |
| 105 EXPECT_TRUE(compileScript(V8CacheOptionsDefault)); | 105 EXPECT_TRUE(compileScript(V8CacheOptionsDefault)); |
| 106 EXPECT_FALSE(m_resource->cachedMetadata(tagForParserCache(m_resource.get()))
); | 106 EXPECT_FALSE(m_resource->cacheHandler()->cachedMetadata(tagForParserCache(m_
resource.get()))); |
| 107 EXPECT_FALSE(m_resource->cachedMetadata(tagForCodeCache(m_resource.get()))); | 107 EXPECT_FALSE(m_resource->cacheHandler()->cachedMetadata(tagForCodeCache(m_re
source.get()))); |
| 108 | 108 |
| 109 EXPECT_TRUE(compileScript(V8CacheOptionsParse)); | 109 EXPECT_TRUE(compileScript(V8CacheOptionsParse)); |
| 110 EXPECT_FALSE(m_resource->cachedMetadata(tagForParserCache(m_resource.get()))
); | 110 EXPECT_FALSE(m_resource->cacheHandler()->cachedMetadata(tagForParserCache(m_
resource.get()))); |
| 111 EXPECT_FALSE(m_resource->cachedMetadata(tagForCodeCache(m_resource.get()))); | 111 EXPECT_FALSE(m_resource->cacheHandler()->cachedMetadata(tagForCodeCache(m_re
source.get()))); |
| 112 | 112 |
| 113 EXPECT_TRUE(compileScript(V8CacheOptionsCode)); | 113 EXPECT_TRUE(compileScript(V8CacheOptionsCode)); |
| 114 EXPECT_FALSE(m_resource->cachedMetadata(tagForParserCache(m_resource.get()))
); | 114 EXPECT_FALSE(m_resource->cacheHandler()->cachedMetadata(tagForParserCache(m_
resource.get()))); |
| 115 EXPECT_FALSE(m_resource->cachedMetadata(tagForCodeCache(m_resource.get()))); | 115 EXPECT_FALSE(m_resource->cacheHandler()->cachedMetadata(tagForCodeCache(m_re
source.get()))); |
| 116 } | 116 } |
| 117 | 117 |
| 118 TEST_F(V8ScriptRunnerTest, parseMemoryOption) | 118 TEST_F(V8ScriptRunnerTest, parseMemoryOption) |
| 119 { | 119 { |
| 120 setResource(); | 120 setResource(); |
| 121 EXPECT_TRUE(compileScript(V8CacheOptionsParseMemory)); | 121 EXPECT_TRUE(compileScript(V8CacheOptionsParseMemory)); |
| 122 EXPECT_TRUE(m_resource->cachedMetadata(tagForParserCache(m_resource.get())))
; | 122 EXPECT_TRUE(m_resource->cacheHandler()->cachedMetadata(tagForParserCache(m_r
esource.get()))); |
| 123 EXPECT_FALSE(m_resource->cachedMetadata(tagForCodeCache(m_resource.get()))); | 123 EXPECT_FALSE(m_resource->cacheHandler()->cachedMetadata(tagForCodeCache(m_re
source.get()))); |
| 124 // The cached data is associated with the encoding. | 124 // The cached data is associated with the encoding. |
| 125 ResourceRequest request(url()); | 125 ResourceRequest request(url()); |
| 126 OwnPtrWillBeRawPtr<ScriptResource> anotherResource = ScriptResource::create(
request, "UTF-16"); | 126 OwnPtrWillBeRawPtr<ScriptResource> anotherResource = ScriptResource::create(
request, "UTF-16"); |
| 127 EXPECT_FALSE(m_resource->cachedMetadata(tagForParserCache(anotherResource.ge
t()))); | 127 EXPECT_FALSE(m_resource->cacheHandler()->cachedMetadata(tagForParserCache(an
otherResource.get()))); |
| 128 } | 128 } |
| 129 | 129 |
| 130 TEST_F(V8ScriptRunnerTest, parseOption) | 130 TEST_F(V8ScriptRunnerTest, parseOption) |
| 131 { | 131 { |
| 132 setResource(); | 132 setResource(); |
| 133 EXPECT_TRUE(compileScript(V8CacheOptionsParse)); | 133 EXPECT_TRUE(compileScript(V8CacheOptionsParse)); |
| 134 EXPECT_TRUE(m_resource->cachedMetadata(tagForParserCache(m_resource.get())))
; | 134 EXPECT_TRUE(m_resource->cacheHandler()->cachedMetadata(tagForParserCache(m_r
esource.get()))); |
| 135 EXPECT_FALSE(m_resource->cachedMetadata(tagForCodeCache(m_resource.get()))); | 135 EXPECT_FALSE(m_resource->cacheHandler()->cachedMetadata(tagForCodeCache(m_re
source.get()))); |
| 136 // The cached data is associated with the encoding. | 136 // The cached data is associated with the encoding. |
| 137 ResourceRequest request(url()); | 137 ResourceRequest request(url()); |
| 138 OwnPtrWillBeRawPtr<ScriptResource> anotherResource = ScriptResource::create(
request, "UTF-16"); | 138 OwnPtrWillBeRawPtr<ScriptResource> anotherResource = ScriptResource::create(
request, "UTF-16"); |
| 139 EXPECT_FALSE(m_resource->cachedMetadata(tagForParserCache(anotherResource.ge
t()))); | 139 EXPECT_FALSE(m_resource->cacheHandler()->cachedMetadata(tagForParserCache(an
otherResource.get()))); |
| 140 } | 140 } |
| 141 | 141 |
| 142 TEST_F(V8ScriptRunnerTest, codeOption) | 142 TEST_F(V8ScriptRunnerTest, codeOption) |
| 143 { | 143 { |
| 144 setResource(); | 144 setResource(); |
| 145 EXPECT_TRUE(compileScript(V8CacheOptionsCode)); | 145 EXPECT_TRUE(compileScript(V8CacheOptionsCode)); |
| 146 EXPECT_FALSE(m_resource->cachedMetadata(tagForParserCache(m_resource.get()))
); | 146 EXPECT_FALSE(m_resource->cacheHandler()->cachedMetadata(tagForParserCache(m_
resource.get()))); |
| 147 EXPECT_TRUE(m_resource->cachedMetadata(tagForCodeCache(m_resource.get()))); | 147 EXPECT_TRUE(m_resource->cacheHandler()->cachedMetadata(tagForCodeCache(m_res
ource.get()))); |
| 148 // The cached data is associated with the encoding. | 148 // The cached data is associated with the encoding. |
| 149 ResourceRequest request(url()); | 149 ResourceRequest request(url()); |
| 150 OwnPtrWillBeRawPtr<ScriptResource> anotherResource = ScriptResource::create(
request, "UTF-16"); | 150 OwnPtrWillBeRawPtr<ScriptResource> anotherResource = ScriptResource::create(
request, "UTF-16"); |
| 151 EXPECT_FALSE(m_resource->cachedMetadata(tagForCodeCache(anotherResource.get(
)))); | 151 EXPECT_FALSE(m_resource->cacheHandler()->cachedMetadata(tagForCodeCache(anot
herResource.get()))); |
| 152 } | 152 } |
| 153 | 153 |
| 154 TEST_F(V8ScriptRunnerTest, codeCompressedOptions) | 154 TEST_F(V8ScriptRunnerTest, codeCompressedOptions) |
| 155 { | 155 { |
| 156 setResource(); | 156 setResource(); |
| 157 EXPECT_TRUE(compileScript(V8CacheOptionsCodeCompressed)); | 157 EXPECT_TRUE(compileScript(V8CacheOptionsCodeCompressed)); |
| 158 EXPECT_FALSE(m_resource->cachedMetadata(tagForParserCache(m_resource.get()))
); | 158 EXPECT_FALSE(m_resource->cacheHandler()->cachedMetadata(tagForParserCache(m_
resource.get()))); |
| 159 EXPECT_FALSE(m_resource->cachedMetadata(tagForCodeCache(m_resource.get()))); | 159 EXPECT_FALSE(m_resource->cacheHandler()->cachedMetadata(tagForCodeCache(m_re
source.get()))); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace | 162 } // namespace |
| 163 | 163 |
| 164 } // namespace blink | 164 } // namespace blink |
| OLD | NEW |