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

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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // not invoke v8::Function::Call. 95 // not invoke v8::Function::Call.
96 return v8::Undefined(isolate); 96 return v8::Undefined(isolate);
97 } 97 }
98 V8PerIsolateData::from(isolate)->setIsHandlingRecursionLevelError(true); 98 V8PerIsolateData::from(isolate)->setIsHandlingRecursionLevelError(true);
99 v8::Local<v8::Value> result = v8::Function::New(isolate, throwStackOverflowE xception)->Call(v8::Undefined(isolate), 0, 0); 99 v8::Local<v8::Value> result = v8::Function::New(isolate, throwStackOverflowE xception)->Call(v8::Undefined(isolate), 0, 0);
100 V8PerIsolateData::from(isolate)->setIsHandlingRecursionLevelError(false); 100 V8PerIsolateData::from(isolate)->setIsHandlingRecursionLevelError(false);
101 return result; 101 return result;
102 } 102 }
103 103
104 // Compile a script without any caching or compile options. 104 // 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) 105 v8::MaybeLocal<v8::Script> compileWithoutOptions(V8CompileHistogram::Cacheabilit y cacheability, v8::Isolate* isolate, v8::Handle<v8::String> code, v8::ScriptOri gin origin)
haraken 2015/03/13 04:31:16 oh... we cannot avoid introducing MaybeLocal in th
bashi 2015/03/13 05:15:20 Unfortunately, yeah.. IMHO, these methods should
106 { 106 {
107 V8CompileHistogram histogramScope(cacheability); 107 V8CompileHistogram histogramScope(cacheability);
108 v8::ScriptCompiler::Source source(code, origin); 108 v8::ScriptCompiler::Source source(code, origin);
109 return v8::ScriptCompiler::Compile(isolate, &source, v8::ScriptCompiler::kNo CompileOptions); 109 return v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &source, v8 ::ScriptCompiler::kNoCompileOptions);
110 } 110 }
111 111
112 // Compile a script, and consume a V8 cache that was generated previously. 112 // 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) 113 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 { 114 {
115 V8CompileHistogram histogramScope(V8CompileHistogram::Cacheable); 115 V8CompileHistogram histogramScope(V8CompileHistogram::Cacheable);
116 CachedMetadata* cachedMetadata = cacheHandler->cachedMetadata(tag); 116 CachedMetadata* cachedMetadata = cacheHandler->cachedMetadata(tag);
117 const char* data = cachedMetadata->data(); 117 const char* data = cachedMetadata->data();
118 int length = cachedMetadata->size(); 118 int length = cachedMetadata->size();
119 std::string uncompressedOutput; 119 std::string uncompressedOutput;
120 bool invalidCache = false; 120 bool invalidCache = false;
121 if (compressed) { 121 if (compressed) {
122 if (snappy::Uncompress(data, length, &uncompressedOutput)) { 122 if (snappy::Uncompress(data, length, &uncompressedOutput)) {
123 data = uncompressedOutput.data(); 123 data = uncompressedOutput.data();
124 length = uncompressedOutput.length(); 124 length = uncompressedOutput.length();
125 } else { 125 } else {
126 invalidCache = true; 126 invalidCache = true;
127 } 127 }
128 } 128 }
129 v8::Local<v8::Script> script; 129 v8::MaybeLocal<v8::Script> script;
130 if (invalidCache) { 130 if (invalidCache) {
131 v8::ScriptCompiler::Source source(code, origin); 131 v8::ScriptCompiler::Source source(code, origin);
132 script = v8::ScriptCompiler::Compile(isolate, &source, v8::ScriptCompile r::kNoCompileOptions); 132 script = v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &sour ce, v8::ScriptCompiler::kNoCompileOptions);
133 } else { 133 } else {
134 v8::ScriptCompiler::CachedData* cachedData = new v8::ScriptCompiler::Cac hedData( 134 v8::ScriptCompiler::CachedData* cachedData = new v8::ScriptCompiler::Cac hedData(
135 reinterpret_cast<const uint8_t*>(data), length, v8::ScriptCompiler:: CachedData::BufferNotOwned); 135 reinterpret_cast<const uint8_t*>(data), length, v8::ScriptCompiler:: CachedData::BufferNotOwned);
136 v8::ScriptCompiler::Source source(code, origin, cachedData); 136 v8::ScriptCompiler::Source source(code, origin, cachedData);
137 script = v8::ScriptCompiler::Compile(isolate, &source, compileOptions); 137 script = v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &sour ce, compileOptions);
138 invalidCache = cachedData->rejected; 138 invalidCache = cachedData->rejected;
139 } 139 }
140 if (invalidCache) 140 if (invalidCache)
141 cacheHandler->clearCachedMetadata(CachedMetadataHandler::SendToPlatform) ; 141 cacheHandler->clearCachedMetadata(CachedMetadataHandler::SendToPlatform) ;
142 return script; 142 return script;
143 } 143 }
144 144
145 // Compile a script, and produce a V8 cache for future use. 145 // 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) 146 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 { 147 {
148 V8CompileHistogram histogramScope(V8CompileHistogram::Cacheable); 148 V8CompileHistogram histogramScope(V8CompileHistogram::Cacheable);
149 v8::ScriptCompiler::Source source(code, origin); 149 v8::ScriptCompiler::Source source(code, origin);
150 v8::Local<v8::Script> script = v8::ScriptCompiler::Compile(isolate, &source, compileOptions); 150 v8::MaybeLocal<v8::Script> script = v8::ScriptCompiler::Compile(isolate->Get CurrentContext(), &source, compileOptions);
151 const v8::ScriptCompiler::CachedData* cachedData = source.GetCachedData(); 151 const v8::ScriptCompiler::CachedData* cachedData = source.GetCachedData();
152 if (cachedData) { 152 if (cachedData) {
153 const char* data = reinterpret_cast<const char*>(cachedData->data); 153 const char* data = reinterpret_cast<const char*>(cachedData->data);
154 int length = cachedData->length; 154 int length = cachedData->length;
155 std::string compressedOutput; 155 std::string compressedOutput;
156 if (compressed) { 156 if (compressed) {
157 snappy::Compress(data, length, &compressedOutput); 157 snappy::Compress(data, length, &compressedOutput);
158 data = compressedOutput.data(); 158 data = compressedOutput.data();
159 length = compressedOutput.length(); 159 length = compressedOutput.length();
160 } 160 }
161 if (length > 1024) { 161 if (length > 1024) {
162 // Omit histogram samples for small cache data to avoid outliers. 162 // Omit histogram samples for small cache data to avoid outliers.
163 int cacheSizeRatio = static_cast<int>(100.0 * length / code->Length( )); 163 int cacheSizeRatio = static_cast<int>(100.0 * length / code->Length( ));
164 blink::Platform::current()->histogramCustomCounts("V8.CodeCacheSizeR atio", cacheSizeRatio, 0, 10000, 50); 164 blink::Platform::current()->histogramCustomCounts("V8.CodeCacheSizeR atio", cacheSizeRatio, 0, 10000, 50);
165 } 165 }
166 cacheHandler->clearCachedMetadata(CachedMetadataHandler::CacheLocally); 166 cacheHandler->clearCachedMetadata(CachedMetadataHandler::CacheLocally);
167 cacheHandler->setCachedMetadata(tag, data, length, cacheType); 167 cacheHandler->setCachedMetadata(tag, data, length, cacheType);
168 } 168 }
169 return script; 169 return script;
170 } 170 }
171 171
172 // Compile a script, and consume or produce a V8 Cache, depending on whether the 172 // Compile a script, and consume or produce a V8 Cache, depending on whether the
173 // given resource already has cached data available. 173 // 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) 174 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 { 175 {
176 return cacheHandler->cachedMetadata(tag) 176 return cacheHandler->cachedMetadata(tag)
177 ? compileAndConsumeCache(cacheHandler, tag, consumeOptions, compressed, isolate, code, origin) 177 ? compileAndConsumeCache(cacheHandler, tag, consumeOptions, compressed, isolate, code, origin)
178 : compileAndProduceCache(cacheHandler, tag, produceOptions, compressed, cacheType, isolate, code, origin); 178 : compileAndProduceCache(cacheHandler, tag, produceOptions, compressed, cacheType, isolate, code, origin);
179 } 179 }
180 180
181 enum CacheTagKind { 181 enum CacheTagKind {
182 CacheTagParser = 0, 182 CacheTagParser = 0,
183 CacheTagCode = 1, 183 CacheTagCode = 1,
184 CacheTagCodeCompressed = 2, 184 CacheTagCodeCompressed = 2,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 return false; 220 return false;
221 double timeStamp; 221 double timeStamp;
222 const int size = sizeof(timeStamp); 222 const int size = sizeof(timeStamp);
223 ASSERT(cachedMetadata->size() == size); 223 ASSERT(cachedMetadata->size() == size);
224 memcpy(&timeStamp, cachedMetadata->data(), size); 224 memcpy(&timeStamp, cachedMetadata->data(), size);
225 return (WTF::currentTime() - timeStamp) < kCacheWithinSeconds; 225 return (WTF::currentTime() - timeStamp) < kCacheWithinSeconds;
226 } 226 }
227 227
228 // Final compile call for a streamed compilation. Most decisions have already 228 // Final compile call for a streamed compilation. Most decisions have already
229 // been made, but we need to write back data into the cache. 229 // 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) 230 v8::MaybeLocal<v8::Script> postStreamCompile(CachedMetadataHandler* cacheHandler , ScriptStreamer* streamer, v8::Isolate* isolate, v8::Handle<v8::String> code, v 8::ScriptOrigin origin)
231 { 231 {
232 V8CompileHistogram histogramScope(V8CompileHistogram::Noncacheable); 232 V8CompileHistogram histogramScope(V8CompileHistogram::Noncacheable);
233 v8::Local<v8::Script> script = v8::ScriptCompiler::Compile(isolate, streamer ->source(), code, origin); 233 v8::MaybeLocal<v8::Script> script = v8::ScriptCompiler::Compile(isolate->Get CurrentContext(), streamer->source(), code, origin);
234 234
235 if (!cacheHandler) 235 if (!cacheHandler)
236 return script; 236 return script;
237 237
238 // Whether to produce the cached data or not is decided when the 238 // 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. 239 // streamer is started. Here we only need to get the data out.
240 const v8::ScriptCompiler::CachedData* newCachedData = streamer->source()->Ge tCachedData(); 240 const v8::ScriptCompiler::CachedData* newCachedData = streamer->source()->Ge tCachedData();
241 if (newCachedData) { 241 if (newCachedData) {
242 cacheHandler->clearCachedMetadata(CachedMetadataHandler::CacheLocally); 242 cacheHandler->clearCachedMetadata(CachedMetadataHandler::CacheLocally);
243 v8::ScriptCompiler::CompileOptions options = streamer->compileOptions(); 243 v8::ScriptCompiler::CompileOptions options = streamer->compileOptions();
244 switch (options) { 244 switch (options) {
245 case v8::ScriptCompiler::kProduceParserCache: 245 case v8::ScriptCompiler::kProduceParserCache:
246 cacheHandler->setCachedMetadata(cacheTag(CacheTagParser, cacheHandle r), reinterpret_cast<const char*>(newCachedData->data), newCachedData->length, C achedMetadataHandler::CacheLocally); 246 cacheHandler->setCachedMetadata(cacheTag(CacheTagParser, cacheHandle r), reinterpret_cast<const char*>(newCachedData->data), newCachedData->length, C achedMetadataHandler::CacheLocally);
247 break; 247 break;
248 case v8::ScriptCompiler::kProduceCodeCache: 248 case v8::ScriptCompiler::kProduceCodeCache:
249 cacheHandler->setCachedMetadata(cacheTag(CacheTagCode, cacheHandler) , reinterpret_cast<const char*>(newCachedData->data), newCachedData->length, Cac hedMetadataHandler::SendToPlatform); 249 cacheHandler->setCachedMetadata(cacheTag(CacheTagCode, cacheHandler) , reinterpret_cast<const char*>(newCachedData->data), newCachedData->length, Cac hedMetadataHandler::SendToPlatform);
250 break; 250 break;
251 default: 251 default:
252 break; 252 break;
253 } 253 }
254 } 254 }
255 255
256 return script; 256 return script;
257 } 257 }
258 258
259 typedef Function<v8::Local<v8::Script>(v8::Isolate*, v8::Handle<v8::String>, v8: :ScriptOrigin)> CompileFn; 259 typedef Function<v8::MaybeLocal<v8::Script>(v8::Isolate*, v8::Handle<v8::String> , v8::ScriptOrigin)> CompileFn;
260 260
261 // A notation convenience: WTF::bind<...> needs to be given the right argument 261 // 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 262 // 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 263 // this local bind lets WTF::bind to all the work, but 'knows' the right
264 // parameter types. 264 // parameter types.
265 // This version isn't quite as smart as the real WTF::bind, though, so you 265 // This version isn't quite as smart as the real WTF::bind, though, so you
266 // sometimes may still have to call the original. 266 // sometimes may still have to call the original.
267 template<typename... A> 267 template<typename... A>
268 PassOwnPtr<CompileFn> bind(const A&... args) 268 PassOwnPtr<CompileFn> bind(const A&... args)
269 { 269 {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // We don't stream scripts which don't have a Resource. 353 // We don't stream scripts which don't have a Resource.
354 ASSERT(resource); 354 ASSERT(resource);
355 // Failed resources should never get this far. 355 // Failed resources should never get this far.
356 ASSERT(!resource->errorOccurred()); 356 ASSERT(!resource->errorOccurred());
357 ASSERT(streamer->isFinished()); 357 ASSERT(streamer->isFinished());
358 ASSERT(!streamer->streamingSuppressed()); 358 ASSERT(!streamer->streamingSuppressed());
359 return WTF::bind<v8::Isolate*, v8::Handle<v8::String>, v8::ScriptOrigin>(pos tStreamCompile, resource->cacheHandler(), streamer); 359 return WTF::bind<v8::Isolate*, v8::Handle<v8::String>, v8::ScriptOrigin>(pos tStreamCompile, resource->cacheHandler(), streamer);
360 } 360 }
361 } // namespace 361 } // namespace
362 362
363 v8::Local<v8::Script> V8ScriptRunner::compileScript(const ScriptSourceCode& sour ce, v8::Isolate* isolate, AccessControlStatus corsStatus, V8CacheOptions cacheOp tions) 363 v8::MaybeLocal<v8::Script> V8ScriptRunner::compileScript(const ScriptSourceCode& source, v8::Isolate* isolate, AccessControlStatus corsStatus, V8CacheOptions ca cheOptions)
364 { 364 {
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); 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);
366 } 366 }
367 367
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) 368 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 { 369 {
370 TRACE_EVENT1("v8", "v8.compile", "fileName", fileName.utf8()); 370 TRACE_EVENT1("v8", "v8.compile", "fileName", fileName.utf8());
371 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Compile"); 371 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Compile");
372 372
373 ASSERT(!streamer || resource); 373 ASSERT(!streamer || resource);
374 ASSERT(!resource || resource->cacheHandler() == cacheHandler); 374 ASSERT(!resource || resource->cacheHandler() == cacheHandler);
375 375
376 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at 376 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at
377 // 1, whereas v8 starts at 0. 377 // 1, whereas v8 starts at 0.
378 v8::ScriptOrigin origin( 378 v8::ScriptOrigin origin(
379 v8String(isolate, fileName), 379 v8String(isolate, fileName),
380 v8::Integer::New(isolate, scriptStartPosition.m_line.zeroBasedInt()), 380 v8::Integer::New(isolate, scriptStartPosition.m_line.zeroBasedInt()),
381 v8::Integer::New(isolate, scriptStartPosition.m_column.zeroBasedInt()), 381 v8::Integer::New(isolate, scriptStartPosition.m_column.zeroBasedInt()),
382 v8Boolean(corsStatus == SharableCrossOrigin, isolate), 382 v8Boolean(corsStatus == SharableCrossOrigin, isolate),
383 v8::Handle<v8::Integer>(), 383 v8::Handle<v8::Integer>(),
384 v8Boolean(isInternalScript, isolate), 384 v8Boolean(isInternalScript, isolate),
385 v8String(isolate, sourceMapUrl)); 385 v8String(isolate, sourceMapUrl));
386 386
387 OwnPtr<CompileFn> compileFn = streamer 387 OwnPtr<CompileFn> compileFn = streamer
388 ? selectCompileFunction(resource, streamer) 388 ? selectCompileFunction(resource, streamer)
389 : selectCompileFunction(cacheOptions, cacheHandler, code); 389 : selectCompileFunction(cacheOptions, cacheHandler, code);
390 390
391 return (*compileFn)(isolate, code, origin); 391 return (*compileFn)(isolate, code, origin);
392 } 392 }
393 393
394 v8::Local<v8::Value> V8ScriptRunner::runCompiledScript(v8::Isolate* isolate, v8: :Handle<v8::Script> script, ExecutionContext* context) 394 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledScript(v8::Isolate* isolate , v8::Local<v8::Script> script, ExecutionContext* context)
395 { 395 {
396 if (script.IsEmpty()) 396 if (script.IsEmpty())
397 return v8::Local<v8::Value>(); 397 return v8::MaybeLocal<v8::Value>();
398 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 398 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
399 TRACE_EVENT1("v8", "v8.run", "fileName", TRACE_STR_COPY(*v8::String::Utf8Val ue(script->GetUnboundScript()->GetScriptName()))); 399 TRACE_EVENT1("v8", "v8.run", "fileName", TRACE_STR_COPY(*v8::String::Utf8Val ue(script->GetUnboundScript()->GetScriptName())));
400 400
401 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) 401 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth)
402 return throwStackOverflowExceptionIfNeeded(isolate); 402 return throwStackOverflowExceptionIfNeeded(isolate);
403 403
404 RELEASE_ASSERT(!context->isIteratingOverObservers()); 404 RELEASE_ASSERT(!context->isIteratingOverObservers());
405 405
406 // Run the script and keep track of the current recursion depth. 406 // Run the script and keep track of the current recursion depth.
407 v8::Local<v8::Value> result; 407 v8::MaybeLocal<v8::Value> result;
408 { 408 {
409 if (ScriptForbiddenScope::isScriptForbidden()) 409 if (ScriptForbiddenScope::isScriptForbidden())
410 return v8::Local<v8::Value>(); 410 return v8::Local<v8::Value>();
411 V8RecursionScope recursionScope(isolate); 411 V8RecursionScope recursionScope(isolate);
412 result = script->Run(); 412 result = script->Run(isolate->GetCurrentContext());
413 } 413 }
414 414
415 if (result.IsEmpty())
416 return v8::Local<v8::Value>();
417
418 crashIfV8IsDead(); 415 crashIfV8IsDead();
419 return result; 416 return result;
420 } 417 }
421 418
422 v8::Local<v8::Value> V8ScriptRunner::compileAndRunInternalScript(v8::Handle<v8:: String> source, v8::Isolate* isolate, const String& fileName, const TextPosition & scriptStartPosition) 419 v8::MaybeLocal<v8::Value> V8ScriptRunner::compileAndRunInternalScript(v8::Handle <v8::String> source, v8::Isolate* isolate, const String& fileName, const TextPos ition& scriptStartPosition)
423 { 420 {
424 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(source, fileNa me, String(), scriptStartPosition, isolate, nullptr, nullptr, nullptr, SharableC rossOrigin, V8CacheOptionsDefault, true); 421 v8::Local<v8::Script> script;
425 if (script.IsEmpty()) 422 if (!V8ScriptRunner::compileScript(source, fileName, String(), scriptStartPo sition, isolate, nullptr, nullptr, nullptr, SharableCrossOrigin, V8CacheOptionsD efault, true).ToLocal(&script))
426 return v8::Local<v8::Value>(); 423 return v8::MaybeLocal<v8::Value>();
427 424
428 TRACE_EVENT0("v8", "v8.run"); 425 TRACE_EVENT0("v8", "v8.run");
429 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 426 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
430 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); 427 V8RecursionScope::MicrotaskSuppression recursionScope(isolate);
431 v8::Local<v8::Value> result = script->Run(); 428 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()) ;
432 crashIfV8IsDead(); 429 crashIfV8IsDead();
433 return result; 430 return result;
434 } 431 }
435 432
436 v8::Local<v8::Value> V8ScriptRunner::runCompiledInternalScript(v8::Isolate* isol ate, v8::Handle<v8::Script> script) 433 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledInternalScript(v8::Isolate* isolate, v8::Local<v8::Script> script)
437 { 434 {
438 TRACE_EVENT0("v8", "v8.run"); 435 TRACE_EVENT0("v8", "v8.run");
439 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 436 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
440 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); 437 V8RecursionScope::MicrotaskSuppression recursionScope(isolate);
441 v8::Local<v8::Value> result = script->Run(); 438 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()) ;
442 crashIfV8IsDead(); 439 crashIfV8IsDead();
443 return result; 440 return result;
444 } 441 }
445 442
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) 443 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 { 444 {
448 TRACE_EVENT0("v8", "v8.callFunction"); 445 TRACE_EVENT0("v8", "v8.callFunction");
449 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 446 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
450 447
451 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) 448 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 { 506 {
510 return cacheTag(CacheTagParser, cacheHandler); 507 return cacheTag(CacheTagParser, cacheHandler);
511 } 508 }
512 509
513 unsigned V8ScriptRunner::tagForCodeCache(CachedMetadataHandler* cacheHandler) 510 unsigned V8ScriptRunner::tagForCodeCache(CachedMetadataHandler* cacheHandler)
514 { 511 {
515 return cacheTag(CacheTagCode, cacheHandler); 512 return cacheTag(CacheTagCode, cacheHandler);
516 } 513 }
517 514
518 } // namespace blink 515 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698