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

Side by Side Diff: Source/bindings/core/v8/V8ScriptRunner.cpp

Issue 1003043002: bindings: Use Maybe APIs in V8ScriptRunner (part 1) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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.
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
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
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 v8::Handle<v8::String> sourceAsV8String(v8String(isolate, source.source())); 370 v8::Handle<v8::String> sourceAsV8String(v8String(isolate, source.source()));
366 if (sourceAsV8String.IsEmpty()) { 371 if (sourceAsV8String.IsEmpty()) {
367 V8ThrowException::throwGeneralError(isolate, "Source file too large."); 372 V8ThrowException::throwGeneralError(isolate, "Source file too large.");
368 return v8::Local<v8::Script>(); 373 return v8::Local<v8::Script>();
369 } 374 }
370 return compileScript(sourceAsV8String, source.url(), source.sourceMapUrl(), source.startPosition(), isolate, source.resource(), source.streamer(), source.re source() ? source.resource()->cacheHandler() : nullptr, corsStatus, cacheOptions ); 375 return compileScript(sourceAsV8String, source.url(), source.sourceMapUrl(), source.startPosition(), isolate, source.resource(), source.streamer(), source.re source() ? source.resource()->cacheHandler() : nullptr, corsStatus, cacheOptions );
371 } 376 }
372 377
373 v8::Local<v8::Script> V8ScriptRunner::compileScript(const String& code, const St ring& fileName, const String& sourceMapUrl, const TextPosition& textPosition, v8 ::Isolate* isolate, CachedMetadataHandler* cacheMetadataHandler, AccessControlSt atus accessControlStatus, V8CacheOptions v8CacheOptions) 378 v8::MaybeLocal<v8::Script> V8ScriptRunner::compileScript(const String& code, con st String& fileName, const String& sourceMapUrl, const TextPosition& textPositio n, v8::Isolate* isolate, CachedMetadataHandler* cacheMetadataHandler, AccessCont rolStatus accessControlStatus, V8CacheOptions v8CacheOptions)
374 { 379 {
375 v8::Handle<v8::String> codeAsV8String(v8String(isolate, code)); 380 v8::Handle<v8::String> codeAsV8String(v8String(isolate, code));
376 if (codeAsV8String.IsEmpty()) { 381 if (codeAsV8String.IsEmpty()) {
377 V8ThrowException::throwGeneralError(isolate, "Source file too large."); 382 V8ThrowException::throwGeneralError(isolate, "Source file too large.");
378 return v8::Local<v8::Script>(); 383 return v8::Local<v8::Script>();
379 } 384 }
380 return compileScript(codeAsV8String, fileName, sourceMapUrl, textPosition, i solate, nullptr, nullptr, cacheMetadataHandler, accessControlStatus, v8CacheOpti ons); 385 return compileScript(codeAsV8String, fileName, sourceMapUrl, textPosition, i solate, nullptr, nullptr, cacheMetadataHandler, accessControlStatus, v8CacheOpti ons);
381 } 386 }
382 387
383 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) 388 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)
384 { 389 {
385 TRACE_EVENT1("v8", "v8.compile", "fileName", fileName.utf8()); 390 TRACE_EVENT1("v8", "v8.compile", "fileName", fileName.utf8());
386 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Compile"); 391 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Compile");
387 392
388 ASSERT(!streamer || resource); 393 ASSERT(!streamer || resource);
389 ASSERT(!resource || resource->cacheHandler() == cacheHandler); 394 ASSERT(!resource || resource->cacheHandler() == cacheHandler);
390 395
391 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at 396 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at
392 // 1, whereas v8 starts at 0. 397 // 1, whereas v8 starts at 0.
393 v8::ScriptOrigin origin( 398 v8::ScriptOrigin origin(
394 v8String(isolate, fileName), 399 v8String(isolate, fileName),
395 v8::Integer::New(isolate, scriptStartPosition.m_line.zeroBasedInt()), 400 v8::Integer::New(isolate, scriptStartPosition.m_line.zeroBasedInt()),
396 v8::Integer::New(isolate, scriptStartPosition.m_column.zeroBasedInt()), 401 v8::Integer::New(isolate, scriptStartPosition.m_column.zeroBasedInt()),
397 v8Boolean(corsStatus == SharableCrossOrigin, isolate), 402 v8Boolean(corsStatus == SharableCrossOrigin, isolate),
398 v8::Handle<v8::Integer>(), 403 v8::Handle<v8::Integer>(),
399 v8Boolean(isInternalScript, isolate), 404 v8Boolean(isInternalScript, isolate),
400 v8String(isolate, sourceMapUrl)); 405 v8String(isolate, sourceMapUrl));
401 406
402 OwnPtr<CompileFn> compileFn = streamer 407 OwnPtr<CompileFn> compileFn = streamer
403 ? selectCompileFunction(resource, streamer) 408 ? selectCompileFunction(resource, streamer)
404 : selectCompileFunction(cacheOptions, cacheHandler, code); 409 : selectCompileFunction(cacheOptions, cacheHandler, code);
405 410
406 return (*compileFn)(isolate, code, origin); 411 return (*compileFn)(isolate, code, origin);
407 } 412 }
408 413
409 v8::Local<v8::Value> V8ScriptRunner::runCompiledScript(v8::Isolate* isolate, v8: :Handle<v8::Script> script, ExecutionContext* context) 414 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledScript(v8::Isolate* isolate , v8::Local<v8::Script> script, ExecutionContext* context)
410 { 415 {
411 if (script.IsEmpty()) 416 ASSERT(!script.IsEmpty());
412 return v8::Local<v8::Value>();
413 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 417 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
414 TRACE_EVENT1("v8", "v8.run", "fileName", TRACE_STR_COPY(*v8::String::Utf8Val ue(script->GetUnboundScript()->GetScriptName()))); 418 TRACE_EVENT1("v8", "v8.run", "fileName", TRACE_STR_COPY(*v8::String::Utf8Val ue(script->GetUnboundScript()->GetScriptName())));
415 419
416 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) 420 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth)
417 return throwStackOverflowExceptionIfNeeded(isolate); 421 return throwStackOverflowExceptionIfNeeded(isolate);
418 422
419 RELEASE_ASSERT(!context->isIteratingOverObservers()); 423 RELEASE_ASSERT(!context->isIteratingOverObservers());
420 424
421 // Run the script and keep track of the current recursion depth. 425 // Run the script and keep track of the current recursion depth.
422 v8::Local<v8::Value> result; 426 v8::MaybeLocal<v8::Value> result;
423 { 427 {
424 if (ScriptForbiddenScope::isScriptForbidden()) 428 if (ScriptForbiddenScope::isScriptForbidden()) {
425 return v8::Local<v8::Value>(); 429 throwScriptForbiddenException(isolate);
haraken 2015/03/20 01:38:56 Just to confirm: If we forget to throw this except
430 return v8::MaybeLocal<v8::Value>();
431 }
426 V8RecursionScope recursionScope(isolate); 432 V8RecursionScope recursionScope(isolate);
427 result = script->Run(); 433 result = script->Run(isolate->GetCurrentContext());
428 } 434 }
429 435
430 if (result.IsEmpty())
431 return v8::Local<v8::Value>();
432
433 crashIfV8IsDead(); 436 crashIfV8IsDead();
434 return result; 437 return result;
435 } 438 }
436 439
437 v8::Local<v8::Value> V8ScriptRunner::compileAndRunInternalScript(v8::Handle<v8:: String> source, v8::Isolate* isolate, const String& fileName, const TextPosition & scriptStartPosition) 440 v8::MaybeLocal<v8::Value> V8ScriptRunner::compileAndRunInternalScript(v8::Handle <v8::String> source, v8::Isolate* isolate, const String& fileName, const TextPos ition& scriptStartPosition)
438 { 441 {
439 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(source, fileNa me, String(), scriptStartPosition, isolate, nullptr, nullptr, nullptr, SharableC rossOrigin, V8CacheOptionsDefault, true); 442 v8::Local<v8::Script> script;
440 if (script.IsEmpty()) 443 if (!V8ScriptRunner::compileScript(source, fileName, String(), scriptStartPo sition, isolate, nullptr, nullptr, nullptr, SharableCrossOrigin, V8CacheOptionsD efault, true).ToLocal(&script))
441 return v8::Local<v8::Value>(); 444 return v8::MaybeLocal<v8::Value>();
442 445
443 TRACE_EVENT0("v8", "v8.run"); 446 TRACE_EVENT0("v8", "v8.run");
444 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 447 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
445 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); 448 V8RecursionScope::MicrotaskSuppression recursionScope(isolate);
446 v8::Local<v8::Value> result = script->Run(); 449 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()) ;
447 crashIfV8IsDead(); 450 crashIfV8IsDead();
448 return result; 451 return result;
449 } 452 }
450 453
451 v8::Local<v8::Value> V8ScriptRunner::runCompiledInternalScript(v8::Isolate* isol ate, v8::Handle<v8::Script> script) 454 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledInternalScript(v8::Isolate* isolate, v8::Local<v8::Script> script)
452 { 455 {
453 TRACE_EVENT0("v8", "v8.run"); 456 TRACE_EVENT0("v8", "v8.run");
454 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 457 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
455 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); 458 V8RecursionScope::MicrotaskSuppression recursionScope(isolate);
456 v8::Local<v8::Value> result = script->Run(); 459 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()) ;
457 crashIfV8IsDead(); 460 crashIfV8IsDead();
458 return result; 461 return result;
459 } 462 }
460 463
461 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) 464 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)
462 { 465 {
463 TRACE_EVENT0("v8", "v8.callFunction"); 466 TRACE_EVENT0("v8", "v8.callFunction");
464 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 467 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
465 468
466 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) 469 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth)
467 return throwStackOverflowExceptionIfNeeded(isolate); 470 return throwStackOverflowExceptionIfNeeded(isolate);
468 471
469 RELEASE_ASSERT(!context->isIteratingOverObservers()); 472 RELEASE_ASSERT(!context->isIteratingOverObservers());
470 473
471 if (ScriptForbiddenScope::isScriptForbidden()) 474 if (ScriptForbiddenScope::isScriptForbidden()) {
475 throwScriptForbiddenException(isolate);
472 return v8::Local<v8::Value>(); 476 return v8::Local<v8::Value>();
477 }
473 V8RecursionScope recursionScope(isolate); 478 V8RecursionScope recursionScope(isolate);
474 v8::Local<v8::Value> result = function->Call(receiver, argc, args); 479 v8::Local<v8::Value> result = function->Call(receiver, argc, args);
475 crashIfV8IsDead(); 480 crashIfV8IsDead();
476 return result; 481 return result;
477 } 482 }
478 483
479 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) 484 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)
480 { 485 {
481 TRACE_EVENT0("v8", "v8.callFunction"); 486 TRACE_EVENT0("v8", "v8.callFunction");
482 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 487 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 { 529 {
525 return cacheTag(CacheTagParser, cacheHandler); 530 return cacheTag(CacheTagParser, cacheHandler);
526 } 531 }
527 532
528 unsigned V8ScriptRunner::tagForCodeCache(CachedMetadataHandler* cacheHandler) 533 unsigned V8ScriptRunner::tagForCodeCache(CachedMetadataHandler* cacheHandler)
529 { 534 {
530 return cacheTag(CacheTagCode, cacheHandler); 535 return cacheTag(CacheTagCode, cacheHandler);
531 } 536 }
532 537
533 } // namespace blink 538 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/V8ScriptRunner.h ('k') | Source/bindings/core/v8/WorkerScriptController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698