Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 } | 73 } |
| 74 | 74 |
| 75 V8CompileHistogram::~V8CompileHistogram() | 75 V8CompileHistogram::~V8CompileHistogram() |
| 76 { | 76 { |
| 77 int64_t elapsedMicroSeconds = static_cast<int64_t>((WTF::currentTime() - m_t imeStamp) * 1000000); | 77 int64_t elapsedMicroSeconds = static_cast<int64_t>((WTF::currentTime() - m_t imeStamp) * 1000000); |
| 78 const char* name = (m_cacheability == Cacheable) ? "V8.CompileCacheableMicro Seconds" : "V8.CompileNoncacheableMicroSeconds"; | 78 const char* name = (m_cacheability == Cacheable) ? "V8.CompileCacheableMicro Seconds" : "V8.CompileNoncacheableMicroSeconds"; |
| 79 blink::Platform::current()->histogramCustomCounts(name, elapsedMicroSeconds, 0, 1000000, 50); | 79 blink::Platform::current()->histogramCustomCounts(name, elapsedMicroSeconds, 0, 1000000, 50); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // In order to make sure all pending messages to be processed in | 82 // In order to make sure all pending messages to be processed in |
| 83 // v8::Function::Call, we don't call handleMaxRecursionDepthExceeded | 83 // v8::Function::Call, we don't call throwStackOverflowException |
| 84 // directly. Instead, we create a v8::Function of | 84 // directly. Instead, we create a v8::Function of |
| 85 // throwStackOverflowException and call it. | 85 // throwStackOverflowException and call it. |
|
haraken
2015/03/18 01:58:51
Not related to your CL, this comment doesn't make
bashi
2015/03/18 02:33:12
I guess this comment explains what throwStackOverf
| |
| 86 void throwStackOverflowException(const v8::FunctionCallbackInfo<v8::Value>& info ) | 86 void throwStackOverflowException(const v8::FunctionCallbackInfo<v8::Value>& info ) |
| 87 { | 87 { |
| 88 V8ThrowException::throwRangeError(info.GetIsolate(), "Maximum call stack siz e exceeded."); | 88 V8ThrowException::throwRangeError(info.GetIsolate(), "Maximum call stack siz e exceeded."); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void throwScriptForbiddenException(v8::Isolate* isolate) | |
| 92 { | |
| 93 V8ThrowException::throwGeneralError(isolate, "Script execution is forbidden. "); | |
| 94 } | |
| 95 | |
| 91 v8::Local<v8::Value> throwStackOverflowExceptionIfNeeded(v8::Isolate* isolate) | 96 v8::Local<v8::Value> throwStackOverflowExceptionIfNeeded(v8::Isolate* isolate) |
| 92 { | 97 { |
| 93 if (V8PerIsolateData::from(isolate)->isHandlingRecursionLevelError()) { | 98 if (V8PerIsolateData::from(isolate)->isHandlingRecursionLevelError()) { |
| 94 // If we are already handling a recursion level error, we should | 99 // If we are already handling a recursion level error, we should |
| 95 // not invoke v8::Function::Call. | 100 // not invoke v8::Function::Call. |
| 96 return v8::Undefined(isolate); | 101 return v8::Undefined(isolate); |
| 97 } | 102 } |
| 98 V8PerIsolateData::from(isolate)->setIsHandlingRecursionLevelError(true); | 103 V8PerIsolateData::from(isolate)->setIsHandlingRecursionLevelError(true); |
| 99 v8::Local<v8::Value> result = v8::Function::New(isolate, throwStackOverflowE xception)->Call(v8::Undefined(isolate), 0, 0); | 104 v8::Local<v8::Value> result = v8::Function::New(isolate, throwStackOverflowE xception)->Call(v8::Undefined(isolate), 0, 0); |
| 100 V8PerIsolateData::from(isolate)->setIsHandlingRecursionLevelError(false); | 105 V8PerIsolateData::from(isolate)->setIsHandlingRecursionLevelError(false); |
| 101 return result; | 106 return result; |
| 102 } | 107 } |
| 103 | 108 |
| 104 // Compile a script without any caching or compile options. | 109 // Compile a script without any caching or compile options. |
| 105 v8::Local<v8::Script> compileWithoutOptions(V8CompileHistogram::Cacheability cac heability, v8::Isolate* isolate, v8::Handle<v8::String> code, v8::ScriptOrigin o rigin) | 110 v8::MaybeLocal<v8::Script> compileWithoutOptions(V8CompileHistogram::Cacheabilit y cacheability, v8::Isolate* isolate, v8::Handle<v8::String> code, v8::ScriptOri gin origin) |
| 106 { | 111 { |
| 107 V8CompileHistogram histogramScope(cacheability); | 112 V8CompileHistogram histogramScope(cacheability); |
| 108 v8::ScriptCompiler::Source source(code, origin); | 113 v8::ScriptCompiler::Source source(code, origin); |
| 109 return v8::ScriptCompiler::Compile(isolate, &source, v8::ScriptCompiler::kNo CompileOptions); | 114 return v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &source, v8 ::ScriptCompiler::kNoCompileOptions); |
| 110 } | 115 } |
| 111 | 116 |
| 112 // Compile a script, and consume a V8 cache that was generated previously. | 117 // Compile a script, and consume a V8 cache that was generated previously. |
| 113 v8::Local<v8::Script> compileAndConsumeCache(CachedMetadataHandler* cacheHandler , unsigned tag, v8::ScriptCompiler::CompileOptions compileOptions, bool compress ed, v8::Isolate* isolate, v8::Handle<v8::String> code, v8::ScriptOrigin origin) | 118 v8::MaybeLocal<v8::Script> compileAndConsumeCache(CachedMetadataHandler* cacheHa ndler, unsigned tag, v8::ScriptCompiler::CompileOptions compileOptions, bool com pressed, v8::Isolate* isolate, v8::Handle<v8::String> code, v8::ScriptOrigin ori gin) |
| 114 { | 119 { |
| 115 V8CompileHistogram histogramScope(V8CompileHistogram::Cacheable); | 120 V8CompileHistogram histogramScope(V8CompileHistogram::Cacheable); |
| 116 CachedMetadata* cachedMetadata = cacheHandler->cachedMetadata(tag); | 121 CachedMetadata* cachedMetadata = cacheHandler->cachedMetadata(tag); |
| 117 const char* data = cachedMetadata->data(); | 122 const char* data = cachedMetadata->data(); |
| 118 int length = cachedMetadata->size(); | 123 int length = cachedMetadata->size(); |
| 119 std::string uncompressedOutput; | 124 std::string uncompressedOutput; |
| 120 bool invalidCache = false; | 125 bool invalidCache = false; |
| 121 if (compressed) { | 126 if (compressed) { |
| 122 if (snappy::Uncompress(data, length, &uncompressedOutput)) { | 127 if (snappy::Uncompress(data, length, &uncompressedOutput)) { |
| 123 data = uncompressedOutput.data(); | 128 data = uncompressedOutput.data(); |
| 124 length = uncompressedOutput.length(); | 129 length = uncompressedOutput.length(); |
| 125 } else { | 130 } else { |
| 126 invalidCache = true; | 131 invalidCache = true; |
| 127 } | 132 } |
| 128 } | 133 } |
| 129 v8::Local<v8::Script> script; | 134 v8::MaybeLocal<v8::Script> script; |
| 130 if (invalidCache) { | 135 if (invalidCache) { |
| 131 v8::ScriptCompiler::Source source(code, origin); | 136 v8::ScriptCompiler::Source source(code, origin); |
| 132 script = v8::ScriptCompiler::Compile(isolate, &source, v8::ScriptCompile r::kNoCompileOptions); | 137 script = v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &sour ce, v8::ScriptCompiler::kNoCompileOptions); |
| 133 } else { | 138 } else { |
| 134 v8::ScriptCompiler::CachedData* cachedData = new v8::ScriptCompiler::Cac hedData( | 139 v8::ScriptCompiler::CachedData* cachedData = new v8::ScriptCompiler::Cac hedData( |
| 135 reinterpret_cast<const uint8_t*>(data), length, v8::ScriptCompiler:: CachedData::BufferNotOwned); | 140 reinterpret_cast<const uint8_t*>(data), length, v8::ScriptCompiler:: CachedData::BufferNotOwned); |
| 136 v8::ScriptCompiler::Source source(code, origin, cachedData); | 141 v8::ScriptCompiler::Source source(code, origin, cachedData); |
| 137 script = v8::ScriptCompiler::Compile(isolate, &source, compileOptions); | 142 script = v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &sour ce, compileOptions); |
| 138 invalidCache = cachedData->rejected; | 143 invalidCache = cachedData->rejected; |
| 139 } | 144 } |
| 140 if (invalidCache) | 145 if (invalidCache) |
| 141 cacheHandler->clearCachedMetadata(CachedMetadataHandler::SendToPlatform) ; | 146 cacheHandler->clearCachedMetadata(CachedMetadataHandler::SendToPlatform) ; |
| 142 return script; | 147 return script; |
| 143 } | 148 } |
| 144 | 149 |
| 145 // Compile a script, and produce a V8 cache for future use. | 150 // Compile a script, and produce a V8 cache for future use. |
| 146 v8::Local<v8::Script> compileAndProduceCache(CachedMetadataHandler* cacheHandler , unsigned tag, v8::ScriptCompiler::CompileOptions compileOptions, bool compress ed, CachedMetadataHandler::CacheType cacheType, v8::Isolate* isolate, v8::Handle <v8::String> code, v8::ScriptOrigin origin) | 151 v8::MaybeLocal<v8::Script> compileAndProduceCache(CachedMetadataHandler* cacheHa ndler, unsigned tag, v8::ScriptCompiler::CompileOptions compileOptions, bool com pressed, CachedMetadataHandler::CacheType cacheType, v8::Isolate* isolate, v8::H andle<v8::String> code, v8::ScriptOrigin origin) |
| 147 { | 152 { |
| 148 V8CompileHistogram histogramScope(V8CompileHistogram::Cacheable); | 153 V8CompileHistogram histogramScope(V8CompileHistogram::Cacheable); |
| 149 v8::ScriptCompiler::Source source(code, origin); | 154 v8::ScriptCompiler::Source source(code, origin); |
| 150 v8::Local<v8::Script> script = v8::ScriptCompiler::Compile(isolate, &source, compileOptions); | 155 v8::MaybeLocal<v8::Script> script = v8::ScriptCompiler::Compile(isolate->Get CurrentContext(), &source, compileOptions); |
| 151 const v8::ScriptCompiler::CachedData* cachedData = source.GetCachedData(); | 156 const v8::ScriptCompiler::CachedData* cachedData = source.GetCachedData(); |
| 152 if (cachedData) { | 157 if (cachedData) { |
| 153 const char* data = reinterpret_cast<const char*>(cachedData->data); | 158 const char* data = reinterpret_cast<const char*>(cachedData->data); |
| 154 int length = cachedData->length; | 159 int length = cachedData->length; |
| 155 std::string compressedOutput; | 160 std::string compressedOutput; |
| 156 if (compressed) { | 161 if (compressed) { |
| 157 snappy::Compress(data, length, &compressedOutput); | 162 snappy::Compress(data, length, &compressedOutput); |
| 158 data = compressedOutput.data(); | 163 data = compressedOutput.data(); |
| 159 length = compressedOutput.length(); | 164 length = compressedOutput.length(); |
| 160 } | 165 } |
| 161 if (length > 1024) { | 166 if (length > 1024) { |
| 162 // Omit histogram samples for small cache data to avoid outliers. | 167 // Omit histogram samples for small cache data to avoid outliers. |
| 163 int cacheSizeRatio = static_cast<int>(100.0 * length / code->Length( )); | 168 int cacheSizeRatio = static_cast<int>(100.0 * length / code->Length( )); |
| 164 blink::Platform::current()->histogramCustomCounts("V8.CodeCacheSizeR atio", cacheSizeRatio, 0, 10000, 50); | 169 blink::Platform::current()->histogramCustomCounts("V8.CodeCacheSizeR atio", cacheSizeRatio, 0, 10000, 50); |
| 165 } | 170 } |
| 166 cacheHandler->clearCachedMetadata(CachedMetadataHandler::CacheLocally); | 171 cacheHandler->clearCachedMetadata(CachedMetadataHandler::CacheLocally); |
| 167 cacheHandler->setCachedMetadata(tag, data, length, cacheType); | 172 cacheHandler->setCachedMetadata(tag, data, length, cacheType); |
| 168 } | 173 } |
| 169 return script; | 174 return script; |
| 170 } | 175 } |
| 171 | 176 |
| 172 // Compile a script, and consume or produce a V8 Cache, depending on whether the | 177 // Compile a script, and consume or produce a V8 Cache, depending on whether the |
| 173 // given resource already has cached data available. | 178 // given resource already has cached data available. |
| 174 v8::Local<v8::Script> compileAndConsumeOrProduce(CachedMetadataHandler* cacheHan dler, unsigned tag, v8::ScriptCompiler::CompileOptions consumeOptions, v8::Scrip tCompiler::CompileOptions produceOptions, bool compressed, CachedMetadataHandler ::CacheType cacheType, v8::Isolate* isolate, v8::Handle<v8::String> code, v8::Sc riptOrigin origin) | 179 v8::MaybeLocal<v8::Script> compileAndConsumeOrProduce(CachedMetadataHandler* cac heHandler, unsigned tag, v8::ScriptCompiler::CompileOptions consumeOptions, v8:: ScriptCompiler::CompileOptions produceOptions, bool compressed, CachedMetadataHa ndler::CacheType cacheType, v8::Isolate* isolate, v8::Handle<v8::String> code, v 8::ScriptOrigin origin) |
| 175 { | 180 { |
| 176 return cacheHandler->cachedMetadata(tag) | 181 return cacheHandler->cachedMetadata(tag) |
| 177 ? compileAndConsumeCache(cacheHandler, tag, consumeOptions, compressed, isolate, code, origin) | 182 ? compileAndConsumeCache(cacheHandler, tag, consumeOptions, compressed, isolate, code, origin) |
| 178 : compileAndProduceCache(cacheHandler, tag, produceOptions, compressed, cacheType, isolate, code, origin); | 183 : compileAndProduceCache(cacheHandler, tag, produceOptions, compressed, cacheType, isolate, code, origin); |
| 179 } | 184 } |
| 180 | 185 |
| 181 enum CacheTagKind { | 186 enum CacheTagKind { |
| 182 CacheTagParser = 0, | 187 CacheTagParser = 0, |
| 183 CacheTagCode = 1, | 188 CacheTagCode = 1, |
| 184 CacheTagCodeCompressed = 2, | 189 CacheTagCodeCompressed = 2, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 return false; | 225 return false; |
| 221 double timeStamp; | 226 double timeStamp; |
| 222 const int size = sizeof(timeStamp); | 227 const int size = sizeof(timeStamp); |
| 223 ASSERT(cachedMetadata->size() == size); | 228 ASSERT(cachedMetadata->size() == size); |
| 224 memcpy(&timeStamp, cachedMetadata->data(), size); | 229 memcpy(&timeStamp, cachedMetadata->data(), size); |
| 225 return (WTF::currentTime() - timeStamp) < kCacheWithinSeconds; | 230 return (WTF::currentTime() - timeStamp) < kCacheWithinSeconds; |
| 226 } | 231 } |
| 227 | 232 |
| 228 // Final compile call for a streamed compilation. Most decisions have already | 233 // Final compile call for a streamed compilation. Most decisions have already |
| 229 // been made, but we need to write back data into the cache. | 234 // been made, but we need to write back data into the cache. |
| 230 v8::Local<v8::Script> postStreamCompile(CachedMetadataHandler* cacheHandler, Scr iptStreamer* streamer, v8::Isolate* isolate, v8::Handle<v8::String> code, v8::Sc riptOrigin origin) | 235 v8::MaybeLocal<v8::Script> postStreamCompile(CachedMetadataHandler* cacheHandler , ScriptStreamer* streamer, v8::Isolate* isolate, v8::Handle<v8::String> code, v 8::ScriptOrigin origin) |
| 231 { | 236 { |
| 232 V8CompileHistogram histogramScope(V8CompileHistogram::Noncacheable); | 237 V8CompileHistogram histogramScope(V8CompileHistogram::Noncacheable); |
| 233 v8::Local<v8::Script> script = v8::ScriptCompiler::Compile(isolate, streamer ->source(), code, origin); | 238 v8::MaybeLocal<v8::Script> script = v8::ScriptCompiler::Compile(isolate->Get CurrentContext(), streamer->source(), code, origin); |
| 234 | 239 |
| 235 if (!cacheHandler) | 240 if (!cacheHandler) |
| 236 return script; | 241 return script; |
| 237 | 242 |
| 238 // Whether to produce the cached data or not is decided when the | 243 // Whether to produce the cached data or not is decided when the |
| 239 // streamer is started. Here we only need to get the data out. | 244 // streamer is started. Here we only need to get the data out. |
| 240 const v8::ScriptCompiler::CachedData* newCachedData = streamer->source()->Ge tCachedData(); | 245 const v8::ScriptCompiler::CachedData* newCachedData = streamer->source()->Ge tCachedData(); |
| 241 if (newCachedData) { | 246 if (newCachedData) { |
| 242 cacheHandler->clearCachedMetadata(CachedMetadataHandler::CacheLocally); | 247 cacheHandler->clearCachedMetadata(CachedMetadataHandler::CacheLocally); |
| 243 v8::ScriptCompiler::CompileOptions options = streamer->compileOptions(); | 248 v8::ScriptCompiler::CompileOptions options = streamer->compileOptions(); |
| 244 switch (options) { | 249 switch (options) { |
| 245 case v8::ScriptCompiler::kProduceParserCache: | 250 case v8::ScriptCompiler::kProduceParserCache: |
| 246 cacheHandler->setCachedMetadata(cacheTag(CacheTagParser, cacheHandle r), reinterpret_cast<const char*>(newCachedData->data), newCachedData->length, C achedMetadataHandler::CacheLocally); | 251 cacheHandler->setCachedMetadata(cacheTag(CacheTagParser, cacheHandle r), reinterpret_cast<const char*>(newCachedData->data), newCachedData->length, C achedMetadataHandler::CacheLocally); |
| 247 break; | 252 break; |
| 248 case v8::ScriptCompiler::kProduceCodeCache: | 253 case v8::ScriptCompiler::kProduceCodeCache: |
| 249 cacheHandler->setCachedMetadata(cacheTag(CacheTagCode, cacheHandler) , reinterpret_cast<const char*>(newCachedData->data), newCachedData->length, Cac hedMetadataHandler::SendToPlatform); | 254 cacheHandler->setCachedMetadata(cacheTag(CacheTagCode, cacheHandler) , reinterpret_cast<const char*>(newCachedData->data), newCachedData->length, Cac hedMetadataHandler::SendToPlatform); |
| 250 break; | 255 break; |
| 251 default: | 256 default: |
| 252 break; | 257 break; |
| 253 } | 258 } |
| 254 } | 259 } |
| 255 | 260 |
| 256 return script; | 261 return script; |
| 257 } | 262 } |
| 258 | 263 |
| 259 typedef Function<v8::Local<v8::Script>(v8::Isolate*, v8::Handle<v8::String>, v8: :ScriptOrigin)> CompileFn; | 264 typedef Function<v8::MaybeLocal<v8::Script>(v8::Isolate*, v8::Handle<v8::String> , v8::ScriptOrigin)> CompileFn; |
| 260 | 265 |
| 261 // A notation convenience: WTF::bind<...> needs to be given the right argument | 266 // A notation convenience: WTF::bind<...> needs to be given the right argument |
| 262 // types. We have an awful lot of bind calls below, all with the same types, so | 267 // types. We have an awful lot of bind calls below, all with the same types, so |
| 263 // this local bind lets WTF::bind to all the work, but 'knows' the right | 268 // this local bind lets WTF::bind to all the work, but 'knows' the right |
| 264 // parameter types. | 269 // parameter types. |
| 265 // This version isn't quite as smart as the real WTF::bind, though, so you | 270 // This version isn't quite as smart as the real WTF::bind, though, so you |
| 266 // sometimes may still have to call the original. | 271 // sometimes may still have to call the original. |
| 267 template<typename... A> | 272 template<typename... A> |
| 268 PassOwnPtr<CompileFn> bind(const A&... args) | 273 PassOwnPtr<CompileFn> bind(const A&... args) |
| 269 { | 274 { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 // We don't stream scripts which don't have a Resource. | 358 // We don't stream scripts which don't have a Resource. |
| 354 ASSERT(resource); | 359 ASSERT(resource); |
| 355 // Failed resources should never get this far. | 360 // Failed resources should never get this far. |
| 356 ASSERT(!resource->errorOccurred()); | 361 ASSERT(!resource->errorOccurred()); |
| 357 ASSERT(streamer->isFinished()); | 362 ASSERT(streamer->isFinished()); |
| 358 ASSERT(!streamer->streamingSuppressed()); | 363 ASSERT(!streamer->streamingSuppressed()); |
| 359 return WTF::bind<v8::Isolate*, v8::Handle<v8::String>, v8::ScriptOrigin>(pos tStreamCompile, resource->cacheHandler(), streamer); | 364 return WTF::bind<v8::Isolate*, v8::Handle<v8::String>, v8::ScriptOrigin>(pos tStreamCompile, resource->cacheHandler(), streamer); |
| 360 } | 365 } |
| 361 } // namespace | 366 } // namespace |
| 362 | 367 |
| 363 v8::Local<v8::Script> V8ScriptRunner::compileScript(const ScriptSourceCode& sour ce, v8::Isolate* isolate, AccessControlStatus corsStatus, V8CacheOptions cacheOp tions) | 368 v8::MaybeLocal<v8::Script> V8ScriptRunner::compileScript(const ScriptSourceCode& source, v8::Isolate* isolate, AccessControlStatus corsStatus, V8CacheOptions ca cheOptions) |
| 364 { | 369 { |
| 365 return compileScript(v8String(isolate, source.source()), source.url(), sourc e.sourceMapUrl(), source.startPosition(), isolate, source.resource(), source.str eamer(), source.resource() ? source.resource()->cacheHandler() : nullptr, corsSt atus, cacheOptions); | 370 return compileScript(v8String(isolate, source.source()), source.url(), sourc e.sourceMapUrl(), source.startPosition(), isolate, source.resource(), source.str eamer(), source.resource() ? source.resource()->cacheHandler() : nullptr, corsSt atus, cacheOptions); |
| 366 } | 371 } |
| 367 | 372 |
| 368 v8::Local<v8::Script> V8ScriptRunner::compileScript(v8::Handle<v8::String> code, const String& fileName, const String& sourceMapUrl, const TextPosition& scriptS tartPosition, v8::Isolate* isolate, ScriptResource* resource, ScriptStreamer* st reamer, CachedMetadataHandler* cacheHandler, AccessControlStatus corsStatus, V8C acheOptions cacheOptions, bool isInternalScript) | 373 v8::MaybeLocal<v8::Script> V8ScriptRunner::compileScript(v8::Handle<v8::String> code, const String& fileName, const String& sourceMapUrl, const TextPosition& sc riptStartPosition, v8::Isolate* isolate, ScriptResource* resource, ScriptStreame r* streamer, CachedMetadataHandler* cacheHandler, AccessControlStatus corsStatus , V8CacheOptions cacheOptions, bool isInternalScript) |
| 369 { | 374 { |
| 370 TRACE_EVENT1("v8", "v8.compile", "fileName", fileName.utf8()); | 375 TRACE_EVENT1("v8", "v8.compile", "fileName", fileName.utf8()); |
| 371 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Compile"); | 376 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Compile"); |
| 372 | 377 |
| 373 ASSERT(!streamer || resource); | 378 ASSERT(!streamer || resource); |
| 374 ASSERT(!resource || resource->cacheHandler() == cacheHandler); | 379 ASSERT(!resource || resource->cacheHandler() == cacheHandler); |
| 375 | 380 |
| 376 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at | 381 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at |
| 377 // 1, whereas v8 starts at 0. | 382 // 1, whereas v8 starts at 0. |
| 378 v8::ScriptOrigin origin( | 383 v8::ScriptOrigin origin( |
| 379 v8String(isolate, fileName), | 384 v8String(isolate, fileName), |
| 380 v8::Integer::New(isolate, scriptStartPosition.m_line.zeroBasedInt()), | 385 v8::Integer::New(isolate, scriptStartPosition.m_line.zeroBasedInt()), |
| 381 v8::Integer::New(isolate, scriptStartPosition.m_column.zeroBasedInt()), | 386 v8::Integer::New(isolate, scriptStartPosition.m_column.zeroBasedInt()), |
| 382 v8Boolean(corsStatus == SharableCrossOrigin, isolate), | 387 v8Boolean(corsStatus == SharableCrossOrigin, isolate), |
| 383 v8::Handle<v8::Integer>(), | 388 v8::Handle<v8::Integer>(), |
| 384 v8Boolean(isInternalScript, isolate), | 389 v8Boolean(isInternalScript, isolate), |
| 385 v8String(isolate, sourceMapUrl)); | 390 v8String(isolate, sourceMapUrl)); |
| 386 | 391 |
| 387 OwnPtr<CompileFn> compileFn = streamer | 392 OwnPtr<CompileFn> compileFn = streamer |
| 388 ? selectCompileFunction(resource, streamer) | 393 ? selectCompileFunction(resource, streamer) |
| 389 : selectCompileFunction(cacheOptions, cacheHandler, code); | 394 : selectCompileFunction(cacheOptions, cacheHandler, code); |
| 390 | 395 |
| 391 return (*compileFn)(isolate, code, origin); | 396 return (*compileFn)(isolate, code, origin); |
| 392 } | 397 } |
| 393 | 398 |
| 394 v8::Local<v8::Value> V8ScriptRunner::runCompiledScript(v8::Isolate* isolate, v8: :Handle<v8::Script> script, ExecutionContext* context) | 399 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledScript(v8::Isolate* isolate , v8::Local<v8::Script> script, ExecutionContext* context) |
| 395 { | 400 { |
| 396 if (script.IsEmpty()) | 401 ASSERT(!script.IsEmpty()); |
|
haraken
2015/03/18 01:58:51
Why can we change this to ASSERT?
bashi
2015/03/18 02:33:12
I should have mentioned about this. I changed the
| |
| 397 return v8::Local<v8::Value>(); | |
| 398 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 402 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| 399 TRACE_EVENT1("v8", "v8.run", "fileName", TRACE_STR_COPY(*v8::String::Utf8Val ue(script->GetUnboundScript()->GetScriptName()))); | 403 TRACE_EVENT1("v8", "v8.run", "fileName", TRACE_STR_COPY(*v8::String::Utf8Val ue(script->GetUnboundScript()->GetScriptName()))); |
| 400 | 404 |
| 401 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) | 405 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) |
| 402 return throwStackOverflowExceptionIfNeeded(isolate); | 406 return throwStackOverflowExceptionIfNeeded(isolate); |
| 403 | 407 |
| 404 RELEASE_ASSERT(!context->isIteratingOverObservers()); | 408 RELEASE_ASSERT(!context->isIteratingOverObservers()); |
| 405 | 409 |
| 406 // Run the script and keep track of the current recursion depth. | 410 // Run the script and keep track of the current recursion depth. |
| 407 v8::Local<v8::Value> result; | 411 v8::MaybeLocal<v8::Value> result; |
| 408 { | 412 { |
| 409 if (ScriptForbiddenScope::isScriptForbidden()) | 413 if (ScriptForbiddenScope::isScriptForbidden()) { |
| 410 return v8::Local<v8::Value>(); | 414 throwScriptForbiddenException(isolate); |
|
haraken
2015/03/18 01:58:51
Shall we make this change in a separate CL? I'm no
bashi
2015/03/18 02:33:12
This means that you want to allow methods which re
| |
| 415 return v8::MaybeLocal<v8::Value>(); | |
| 416 } | |
| 411 V8RecursionScope recursionScope(isolate); | 417 V8RecursionScope recursionScope(isolate); |
| 412 result = script->Run(); | 418 result = script->Run(isolate->GetCurrentContext()); |
| 413 } | 419 } |
| 414 | 420 |
| 415 if (result.IsEmpty()) | |
| 416 return v8::Local<v8::Value>(); | |
| 417 | |
| 418 crashIfV8IsDead(); | 421 crashIfV8IsDead(); |
| 419 return result; | 422 return result; |
| 420 } | 423 } |
| 421 | 424 |
| 422 v8::Local<v8::Value> V8ScriptRunner::compileAndRunInternalScript(v8::Handle<v8:: String> source, v8::Isolate* isolate, const String& fileName, const TextPosition & scriptStartPosition) | 425 v8::MaybeLocal<v8::Value> V8ScriptRunner::compileAndRunInternalScript(v8::Handle <v8::String> source, v8::Isolate* isolate, const String& fileName, const TextPos ition& scriptStartPosition) |
| 423 { | 426 { |
| 424 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(source, fileNa me, String(), scriptStartPosition, isolate, nullptr, nullptr, nullptr, SharableC rossOrigin, V8CacheOptionsDefault, true); | 427 v8::Local<v8::Script> script; |
| 425 if (script.IsEmpty()) | 428 if (!V8ScriptRunner::compileScript(source, fileName, String(), scriptStartPo sition, isolate, nullptr, nullptr, nullptr, SharableCrossOrigin, V8CacheOptionsD efault, true).ToLocal(&script)) |
| 426 return v8::Local<v8::Value>(); | 429 return v8::MaybeLocal<v8::Value>(); |
| 427 | 430 |
| 428 TRACE_EVENT0("v8", "v8.run"); | 431 TRACE_EVENT0("v8", "v8.run"); |
| 429 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 432 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| 430 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); | 433 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); |
| 431 v8::Local<v8::Value> result = script->Run(); | 434 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()) ; |
| 432 crashIfV8IsDead(); | 435 crashIfV8IsDead(); |
| 433 return result; | 436 return result; |
| 434 } | 437 } |
| 435 | 438 |
| 436 v8::Local<v8::Value> V8ScriptRunner::runCompiledInternalScript(v8::Isolate* isol ate, v8::Handle<v8::Script> script) | 439 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledInternalScript(v8::Isolate* isolate, v8::Local<v8::Script> script) |
| 437 { | 440 { |
| 438 TRACE_EVENT0("v8", "v8.run"); | 441 TRACE_EVENT0("v8", "v8.run"); |
| 439 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 442 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| 440 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); | 443 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); |
| 441 v8::Local<v8::Value> result = script->Run(); | 444 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()) ; |
| 442 crashIfV8IsDead(); | 445 crashIfV8IsDead(); |
| 443 return result; | 446 return result; |
| 444 } | 447 } |
| 445 | 448 |
| 446 v8::Local<v8::Value> V8ScriptRunner::callFunction(v8::Handle<v8::Function> funct ion, ExecutionContext* context, v8::Handle<v8::Value> receiver, int argc, v8::Ha ndle<v8::Value> args[], v8::Isolate* isolate) | 449 v8::Local<v8::Value> V8ScriptRunner::callFunction(v8::Handle<v8::Function> funct ion, ExecutionContext* context, v8::Handle<v8::Value> receiver, int argc, v8::Ha ndle<v8::Value> args[], v8::Isolate* isolate) |
| 447 { | 450 { |
| 448 TRACE_EVENT0("v8", "v8.callFunction"); | 451 TRACE_EVENT0("v8", "v8.callFunction"); |
| 449 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 452 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| 450 | 453 |
| 451 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) | 454 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) |
| 452 return throwStackOverflowExceptionIfNeeded(isolate); | 455 return throwStackOverflowExceptionIfNeeded(isolate); |
| 453 | 456 |
| 454 RELEASE_ASSERT(!context->isIteratingOverObservers()); | 457 RELEASE_ASSERT(!context->isIteratingOverObservers()); |
| 455 | 458 |
| 456 if (ScriptForbiddenScope::isScriptForbidden()) | 459 if (ScriptForbiddenScope::isScriptForbidden()) { |
| 460 throwScriptForbiddenException(isolate); | |
|
haraken
2015/03/18 01:58:51
Ditto.
| |
| 457 return v8::Local<v8::Value>(); | 461 return v8::Local<v8::Value>(); |
| 462 } | |
| 458 V8RecursionScope recursionScope(isolate); | 463 V8RecursionScope recursionScope(isolate); |
| 459 v8::Local<v8::Value> result = function->Call(receiver, argc, args); | 464 v8::Local<v8::Value> result = function->Call(receiver, argc, args); |
| 460 crashIfV8IsDead(); | 465 crashIfV8IsDead(); |
| 461 return result; | 466 return result; |
| 462 } | 467 } |
| 463 | 468 |
| 464 v8::Local<v8::Value> V8ScriptRunner::callInternalFunction(v8::Handle<v8::Functio n> function, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> arg s[], v8::Isolate* isolate) | 469 v8::Local<v8::Value> V8ScriptRunner::callInternalFunction(v8::Handle<v8::Functio n> function, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> arg s[], v8::Isolate* isolate) |
| 465 { | 470 { |
| 466 TRACE_EVENT0("v8", "v8.callFunction"); | 471 TRACE_EVENT0("v8", "v8.callFunction"); |
| 467 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 472 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 { | 514 { |
| 510 return cacheTag(CacheTagParser, cacheHandler); | 515 return cacheTag(CacheTagParser, cacheHandler); |
| 511 } | 516 } |
| 512 | 517 |
| 513 unsigned V8ScriptRunner::tagForCodeCache(CachedMetadataHandler* cacheHandler) | 518 unsigned V8ScriptRunner::tagForCodeCache(CachedMetadataHandler* cacheHandler) |
| 514 { | 519 { |
| 515 return cacheTag(CacheTagCode, cacheHandler); | 520 return cacheTag(CacheTagCode, cacheHandler); |
| 516 } | 521 } |
| 517 | 522 |
| 518 } // namespace blink | 523 } // namespace blink |
| OLD | NEW |