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

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

Issue 1769273004: Remove V8RecrusionScope, cleanup call sites. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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 11 matching lines...) Expand all
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE. 23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "bindings/core/v8/V8ScriptRunner.h" 26 #include "bindings/core/v8/V8ScriptRunner.h"
27 27
28 #include "bindings/core/v8/ScriptSourceCode.h" 28 #include "bindings/core/v8/ScriptSourceCode.h"
29 #include "bindings/core/v8/ScriptStreamer.h" 29 #include "bindings/core/v8/ScriptStreamer.h"
30 #include "bindings/core/v8/V8Binding.h" 30 #include "bindings/core/v8/V8Binding.h"
31 #include "bindings/core/v8/V8GCController.h" 31 #include "bindings/core/v8/V8GCController.h"
32 #include "bindings/core/v8/V8RecursionScope.h"
33 #include "bindings/core/v8/V8ThrowException.h" 32 #include "bindings/core/v8/V8ThrowException.h"
34 #include "core/dom/ExecutionContext.h" 33 #include "core/dom/ExecutionContext.h"
35 #include "core/fetch/CachedMetadata.h" 34 #include "core/fetch/CachedMetadata.h"
36 #include "core/fetch/ScriptResource.h" 35 #include "core/fetch/ScriptResource.h"
37 #include "core/inspector/InspectorInstrumentation.h" 36 #include "core/inspector/InspectorInstrumentation.h"
38 #include "core/inspector/InspectorTraceEvents.h" 37 #include "core/inspector/InspectorTraceEvents.h"
39 #include "platform/Histogram.h" 38 #include "platform/Histogram.h"
40 #include "platform/ScriptForbiddenScope.h" 39 #include "platform/ScriptForbiddenScope.h"
41 #include "platform/TraceEvent.h" 40 #include "platform/TraceEvent.h"
42 #include "public/platform/Platform.h" 41 #include "public/platform/Platform.h"
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 392
394 return (*compileFn)(isolate, code, origin); 393 return (*compileFn)(isolate, code, origin);
395 } 394 }
396 395
397 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledScript(v8::Isolate* isolate , v8::Local<v8::Script> script, ExecutionContext* context) 396 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledScript(v8::Isolate* isolate , v8::Local<v8::Script> script, ExecutionContext* context)
398 { 397 {
399 ASSERT(!script.IsEmpty()); 398 ASSERT(!script.IsEmpty());
400 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 399 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
401 TRACE_EVENT1("v8", "v8.run", "fileName", TRACE_STR_COPY(*v8::String::Utf8Val ue(script->GetUnboundScript()->GetScriptName()))); 400 TRACE_EVENT1("v8", "v8.run", "fileName", TRACE_STR_COPY(*v8::String::Utf8Val ue(script->GetUnboundScript()->GetScriptName())));
402 401
403 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) 402 if (v8::MicrotasksScope::GetCurrentDepth(isolate) >= kMaxRecursionDepth)
404 return throwStackOverflowExceptionIfNeeded(isolate); 403 return throwStackOverflowExceptionIfNeeded(isolate);
405 404
406 RELEASE_ASSERT(!context->isIteratingOverObservers()); 405 RELEASE_ASSERT(!context->isIteratingOverObservers());
407 406
408 // Run the script and keep track of the current recursion depth. 407 // Run the script and keep track of the current recursion depth.
409 v8::MaybeLocal<v8::Value> result; 408 v8::MaybeLocal<v8::Value> result;
410 { 409 {
411 if (ScriptForbiddenScope::isScriptForbidden()) { 410 if (ScriptForbiddenScope::isScriptForbidden()) {
412 throwScriptForbiddenException(isolate); 411 throwScriptForbiddenException(isolate);
413 return v8::MaybeLocal<v8::Value>(); 412 return v8::MaybeLocal<v8::Value>();
414 } 413 }
415 V8RecursionScope recursionScope(isolate); 414 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kRunMi crotasks);
416 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEx ecuteScript(context, script->GetUnboundScript()->GetId()); 415 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEx ecuteScript(context, script->GetUnboundScript()->GetId());
417 result = script->Run(isolate->GetCurrentContext()); 416 result = script->Run(isolate->GetCurrentContext());
418 InspectorInstrumentation::didExecuteScript(cookie); 417 InspectorInstrumentation::didExecuteScript(cookie);
419 } 418 }
420 419
421 crashIfIsolateIsDead(isolate); 420 crashIfIsolateIsDead(isolate);
422 return result; 421 return result;
423 } 422 }
424 423
425 v8::MaybeLocal<v8::Value> V8ScriptRunner::compileAndRunInternalScript(v8::Local< v8::String> source, v8::Isolate* isolate, const String& fileName, const TextPosi tion& scriptStartPosition) 424 v8::MaybeLocal<v8::Value> V8ScriptRunner::compileAndRunInternalScript(v8::Local< v8::String> source, v8::Isolate* isolate, const String& fileName, const TextPosi tion& scriptStartPosition)
426 { 425 {
427 v8::Local<v8::Script> script; 426 v8::Local<v8::Script> script;
428 if (!V8ScriptRunner::compileScript(source, fileName, String(), scriptStartPo sition, isolate, nullptr, nullptr, nullptr, SharableCrossOrigin, V8CacheOptionsD efault, true).ToLocal(&script)) 427 if (!V8ScriptRunner::compileScript(source, fileName, String(), scriptStartPo sition, isolate, nullptr, nullptr, nullptr, SharableCrossOrigin, V8CacheOptionsD efault, true).ToLocal(&script))
429 return v8::MaybeLocal<v8::Value>(); 428 return v8::MaybeLocal<v8::Value>();
430 429
431 TRACE_EVENT0("v8", "v8.run"); 430 TRACE_EVENT0("v8", "v8.run");
432 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 431 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
433 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); 432 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
434 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()) ; 433 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()) ;
435 crashIfIsolateIsDead(isolate); 434 crashIfIsolateIsDead(isolate);
436 return result; 435 return result;
437 } 436 }
438 437
439 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledInternalScript(v8::Isolate* isolate, v8::Local<v8::Script> script) 438 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledInternalScript(v8::Isolate* isolate, v8::Local<v8::Script> script)
440 { 439 {
441 TRACE_EVENT0("v8", "v8.run"); 440 TRACE_EVENT0("v8", "v8.run");
442 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 441 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
443 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); 442 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
444 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()) ; 443 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()) ;
445 crashIfIsolateIsDead(isolate); 444 crashIfIsolateIsDead(isolate);
446 return result; 445 return result;
447 } 446 }
448 447
449 v8::MaybeLocal<v8::Value> V8ScriptRunner::callFunction(v8::Local<v8::Function> f unction, ExecutionContext* context, v8::Local<v8::Value> receiver, int argc, v8: :Local<v8::Value> args[], v8::Isolate* isolate) 448 v8::MaybeLocal<v8::Value> V8ScriptRunner::callFunction(v8::Local<v8::Function> f unction, ExecutionContext* context, v8::Local<v8::Value> receiver, int argc, v8: :Local<v8::Value> args[], v8::Isolate* isolate)
450 { 449 {
451 TRACE_EVENT1("devtools.timeline,v8", "FunctionCall", "data", devToolsTraceEv entData(isolate, context, function)); 450 TRACE_EVENT1("devtools.timeline,v8", "FunctionCall", "data", devToolsTraceEv entData(isolate, context, function));
452 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 451 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
453 452
454 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) 453 if (v8::MicrotasksScope::GetCurrentDepth(isolate) >= kMaxRecursionDepth)
455 return v8::MaybeLocal<v8::Value>(throwStackOverflowExceptionIfNeeded(iso late)); 454 return v8::MaybeLocal<v8::Value>(throwStackOverflowExceptionIfNeeded(iso late));
456 455
457 RELEASE_ASSERT(!context->isIteratingOverObservers()); 456 RELEASE_ASSERT(!context->isIteratingOverObservers());
458 457
459 if (ScriptForbiddenScope::isScriptForbidden()) { 458 if (ScriptForbiddenScope::isScriptForbidden()) {
460 throwScriptForbiddenException(isolate); 459 throwScriptForbiddenException(isolate);
461 return v8::MaybeLocal<v8::Value>(); 460 return v8::MaybeLocal<v8::Value>();
462 } 461 }
463 V8RecursionScope recursionScope(isolate); 462 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kRunMicrot asks);
464 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willExecut eScript(context, function->ScriptId()); 463 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willExecut eScript(context, function->ScriptId());
465 v8::MaybeLocal<v8::Value> result = function->Call(isolate->GetCurrentContext (), receiver, argc, args); 464 v8::MaybeLocal<v8::Value> result = function->Call(isolate->GetCurrentContext (), receiver, argc, args);
466 crashIfIsolateIsDead(isolate); 465 crashIfIsolateIsDead(isolate);
467 InspectorInstrumentation::didExecuteScript(cookie); 466 InspectorInstrumentation::didExecuteScript(cookie);
468 return result; 467 return result;
469 } 468 }
470 469
471 v8::MaybeLocal<v8::Value> V8ScriptRunner::callInternalFunction(v8::Local<v8::Fun ction> function, v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> a rgs[], v8::Isolate* isolate) 470 v8::MaybeLocal<v8::Value> V8ScriptRunner::callInternalFunction(v8::Local<v8::Fun ction> function, v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> a rgs[], v8::Isolate* isolate)
472 { 471 {
473 TRACE_EVENT0("v8", "v8.callFunction"); 472 TRACE_EVENT0("v8", "v8.callFunction");
474 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 473 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
475 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); 474 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
476 v8::MaybeLocal<v8::Value> result = function->Call(isolate->GetCurrentContext (), receiver, argc, args); 475 v8::MaybeLocal<v8::Value> result = function->Call(isolate->GetCurrentContext (), receiver, argc, args);
477 crashIfIsolateIsDead(isolate); 476 crashIfIsolateIsDead(isolate);
478 return result; 477 return result;
479 } 478 }
480 479
481 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObject(v8::Isolate* isolat e, v8::Local<v8::ObjectTemplate> objectTemplate) 480 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObject(v8::Isolate* isolat e, v8::Local<v8::ObjectTemplate> objectTemplate)
482 { 481 {
483 TRACE_EVENT0("v8", "v8.newInstance"); 482 TRACE_EVENT0("v8", "v8.newInstance");
484 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 483 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
485 484
486 V8RecursionScope::MicrotaskSuppression scope(isolate); 485 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
487 v8::MaybeLocal<v8::Object> result = objectTemplate->NewInstance(isolate->Get CurrentContext()); 486 v8::MaybeLocal<v8::Object> result = objectTemplate->NewInstance(isolate->Get CurrentContext());
488 crashIfIsolateIsDead(isolate); 487 crashIfIsolateIsDead(isolate);
489 return result; 488 return result;
490 } 489 }
491 490
492 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObject(v8::Isolate* isolat e, v8::Local<v8::Function> function, int argc, v8::Local<v8::Value> argv[]) 491 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObject(v8::Isolate* isolat e, v8::Local<v8::Function> function, int argc, v8::Local<v8::Value> argv[])
493 { 492 {
494 TRACE_EVENT0("v8", "v8.newInstance"); 493 TRACE_EVENT0("v8", "v8.newInstance");
495 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 494 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
496 495
497 V8RecursionScope::MicrotaskSuppression scope(isolate); 496 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
498 v8::MaybeLocal<v8::Object> result = function->NewInstance(isolate->GetCurren tContext(), argc, argv); 497 v8::MaybeLocal<v8::Object> result = function->NewInstance(isolate->GetCurren tContext(), argc, argv);
499 crashIfIsolateIsDead(isolate); 498 crashIfIsolateIsDead(isolate);
500 return result; 499 return result;
501 } 500 }
502 501
503 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObjectInDocument(v8::Isola te* isolate, v8::Local<v8::Function> function, ExecutionContext* context, int ar gc, v8::Local<v8::Value> argv[]) 502 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObjectInDocument(v8::Isola te* isolate, v8::Local<v8::Function> function, ExecutionContext* context, int ar gc, v8::Local<v8::Value> argv[])
504 { 503 {
505 TRACE_EVENT0("v8", "v8.newInstance"); 504 TRACE_EVENT0("v8", "v8.newInstance");
506 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 505 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
507 if (ScriptForbiddenScope::isScriptForbidden()) { 506 if (ScriptForbiddenScope::isScriptForbidden()) {
508 throwScriptForbiddenException(isolate); 507 throwScriptForbiddenException(isolate);
509 return v8::MaybeLocal<v8::Object>(); 508 return v8::MaybeLocal<v8::Object>();
510 } 509 }
511 V8RecursionScope scope(isolate); 510 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kRunMicrot asks);
512 v8::MaybeLocal<v8::Object> result = function->NewInstance(isolate->GetCurren tContext(), argc, argv); 511 v8::MaybeLocal<v8::Object> result = function->NewInstance(isolate->GetCurren tContext(), argc, argv);
513 crashIfIsolateIsDead(isolate); 512 crashIfIsolateIsDead(isolate);
514 return result; 513 return result;
515 } 514 }
516 515
517 unsigned V8ScriptRunner::tagForParserCache(CachedMetadataHandler* cacheHandler) 516 unsigned V8ScriptRunner::tagForParserCache(CachedMetadataHandler* cacheHandler)
518 { 517 {
519 return cacheTag(CacheTagParser, cacheHandler); 518 return cacheTag(CacheTagParser, cacheHandler);
520 } 519 }
521 520
522 unsigned V8ScriptRunner::tagForCodeCache(CachedMetadataHandler* cacheHandler) 521 unsigned V8ScriptRunner::tagForCodeCache(CachedMetadataHandler* cacheHandler)
523 { 522 {
524 return cacheTag(CacheTagCode, cacheHandler); 523 return cacheTag(CacheTagCode, cacheHandler);
525 } 524 }
526 525
527 } // namespace blink 526 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698