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

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: rebased 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 V8ThrowException::throwGeneralError(isolate, "Script execution is forbidden. "); 112 V8ThrowException::throwGeneralError(isolate, "Script execution is forbidden. ");
114 } 113 }
115 114
116 v8::Local<v8::Value> throwStackOverflowExceptionIfNeeded(v8::Isolate* isolate) 115 v8::Local<v8::Value> throwStackOverflowExceptionIfNeeded(v8::Isolate* isolate)
117 { 116 {
118 if (V8PerIsolateData::from(isolate)->isHandlingRecursionLevelError()) { 117 if (V8PerIsolateData::from(isolate)->isHandlingRecursionLevelError()) {
119 // If we are already handling a recursion level error, we should 118 // If we are already handling a recursion level error, we should
120 // not invoke v8::Function::Call. 119 // not invoke v8::Function::Call.
121 return v8::Undefined(isolate); 120 return v8::Undefined(isolate);
122 } 121 }
122 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
123 V8PerIsolateData::from(isolate)->setIsHandlingRecursionLevelError(true); 123 V8PerIsolateData::from(isolate)->setIsHandlingRecursionLevelError(true);
124 v8::Local<v8::Value> result = v8::Function::New(isolate, throwStackOverflowE xception)->Call(v8::Undefined(isolate), 0, 0); 124 v8::Local<v8::Value> result = v8::Function::New(isolate, throwStackOverflowE xception)->Call(v8::Undefined(isolate), 0, 0);
125 V8PerIsolateData::from(isolate)->setIsHandlingRecursionLevelError(false); 125 V8PerIsolateData::from(isolate)->setIsHandlingRecursionLevelError(false);
126 return result; 126 return result;
127 } 127 }
128 128
129 // Compile a script without any caching or compile options. 129 // Compile a script without any caching or compile options.
130 v8::MaybeLocal<v8::Script> compileWithoutOptions(V8CompileHistogram::Cacheabilit y cacheability, v8::Isolate* isolate, v8::Local<v8::String> code, v8::ScriptOrig in origin) 130 v8::MaybeLocal<v8::Script> compileWithoutOptions(V8CompileHistogram::Cacheabilit y cacheability, v8::Isolate* isolate, v8::Local<v8::String> code, v8::ScriptOrig in origin)
131 { 131 {
132 V8CompileHistogram histogramScope(cacheability); 132 V8CompileHistogram histogramScope(cacheability);
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 393
394 return (*compileFn)(isolate, code, origin); 394 return (*compileFn)(isolate, code, origin);
395 } 395 }
396 396
397 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledScript(v8::Isolate* isolate , v8::Local<v8::Script> script, ExecutionContext* context) 397 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledScript(v8::Isolate* isolate , v8::Local<v8::Script> script, ExecutionContext* context)
398 { 398 {
399 ASSERT(!script.IsEmpty()); 399 ASSERT(!script.IsEmpty());
400 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 400 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
401 TRACE_EVENT1("v8", "v8.run", "fileName", TRACE_STR_COPY(*v8::String::Utf8Val ue(script->GetUnboundScript()->GetScriptName()))); 401 TRACE_EVENT1("v8", "v8.run", "fileName", TRACE_STR_COPY(*v8::String::Utf8Val ue(script->GetUnboundScript()->GetScriptName())));
402 402
403 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) 403 if (v8::MicrotasksScope::GetCurrentDepth(isolate) >= kMaxRecursionDepth)
404 return throwStackOverflowExceptionIfNeeded(isolate); 404 return throwStackOverflowExceptionIfNeeded(isolate);
405 405
406 RELEASE_ASSERT(!context->isIteratingOverObservers()); 406 RELEASE_ASSERT(!context->isIteratingOverObservers());
407 407
408 // Run the script and keep track of the current recursion depth. 408 // Run the script and keep track of the current recursion depth.
409 v8::MaybeLocal<v8::Value> result; 409 v8::MaybeLocal<v8::Value> result;
410 { 410 {
411 if (ScriptForbiddenScope::isScriptForbidden()) { 411 if (ScriptForbiddenScope::isScriptForbidden()) {
412 throwScriptForbiddenException(isolate); 412 throwScriptForbiddenException(isolate);
413 return v8::MaybeLocal<v8::Value>(); 413 return v8::MaybeLocal<v8::Value>();
414 } 414 }
415 V8RecursionScope recursionScope(isolate); 415 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kRunMi crotasks);
416 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEx ecuteScript(context, script->GetUnboundScript()->GetId()); 416 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEx ecuteScript(context, script->GetUnboundScript()->GetId());
417 result = script->Run(isolate->GetCurrentContext()); 417 result = script->Run(isolate->GetCurrentContext());
418 InspectorInstrumentation::didExecuteScript(cookie); 418 InspectorInstrumentation::didExecuteScript(cookie);
419 } 419 }
420 420
421 crashIfIsolateIsDead(isolate); 421 crashIfIsolateIsDead(isolate);
422 return result; 422 return result;
423 } 423 }
424 424
425 v8::MaybeLocal<v8::Value> V8ScriptRunner::compileAndRunInternalScript(v8::Local< v8::String> source, v8::Isolate* isolate, const String& fileName, const TextPosi tion& scriptStartPosition) 425 v8::MaybeLocal<v8::Value> V8ScriptRunner::compileAndRunInternalScript(v8::Local< v8::String> source, v8::Isolate* isolate, const String& fileName, const TextPosi tion& scriptStartPosition)
426 { 426 {
427 v8::Local<v8::Script> script; 427 v8::Local<v8::Script> script;
428 if (!V8ScriptRunner::compileScript(source, fileName, String(), scriptStartPo sition, isolate, nullptr, nullptr, nullptr, SharableCrossOrigin, V8CacheOptionsD efault, true).ToLocal(&script)) 428 if (!V8ScriptRunner::compileScript(source, fileName, String(), scriptStartPo sition, isolate, nullptr, nullptr, nullptr, SharableCrossOrigin, V8CacheOptionsD efault, true).ToLocal(&script))
429 return v8::MaybeLocal<v8::Value>(); 429 return v8::MaybeLocal<v8::Value>();
430 430
431 TRACE_EVENT0("v8", "v8.run"); 431 TRACE_EVENT0("v8", "v8.run");
432 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 432 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
433 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); 433 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
434 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()) ; 434 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()) ;
435 crashIfIsolateIsDead(isolate); 435 crashIfIsolateIsDead(isolate);
436 return result; 436 return result;
437 } 437 }
438 438
439 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledInternalScript(v8::Isolate* isolate, v8::Local<v8::Script> script) 439 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledInternalScript(v8::Isolate* isolate, v8::Local<v8::Script> script)
440 { 440 {
441 TRACE_EVENT0("v8", "v8.run"); 441 TRACE_EVENT0("v8", "v8.run");
442 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 442 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
443 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); 443 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
444 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()) ; 444 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()) ;
445 crashIfIsolateIsDead(isolate); 445 crashIfIsolateIsDead(isolate);
446 return result; 446 return result;
447 } 447 }
448 448
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) 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)
450 { 450 {
451 TRACE_EVENT1("devtools.timeline,v8", "FunctionCall", "data", devToolsTraceEv entData(isolate, context, function)); 451 TRACE_EVENT1("devtools.timeline,v8", "FunctionCall", "data", devToolsTraceEv entData(isolate, context, function));
452 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 452 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
453 453
454 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) 454 if (v8::MicrotasksScope::GetCurrentDepth(isolate) >= kMaxRecursionDepth)
455 return v8::MaybeLocal<v8::Value>(throwStackOverflowExceptionIfNeeded(iso late)); 455 return v8::MaybeLocal<v8::Value>(throwStackOverflowExceptionIfNeeded(iso late));
456 456
457 RELEASE_ASSERT(!context->isIteratingOverObservers()); 457 RELEASE_ASSERT(!context->isIteratingOverObservers());
458 458
459 if (ScriptForbiddenScope::isScriptForbidden()) { 459 if (ScriptForbiddenScope::isScriptForbidden()) {
460 throwScriptForbiddenException(isolate); 460 throwScriptForbiddenException(isolate);
461 return v8::MaybeLocal<v8::Value>(); 461 return v8::MaybeLocal<v8::Value>();
462 } 462 }
463 V8RecursionScope recursionScope(isolate); 463 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kRunMicrot asks);
464 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willExecut eScript(context, function->ScriptId()); 464 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willExecut eScript(context, function->ScriptId());
465 v8::MaybeLocal<v8::Value> result = function->Call(isolate->GetCurrentContext (), receiver, argc, args); 465 v8::MaybeLocal<v8::Value> result = function->Call(isolate->GetCurrentContext (), receiver, argc, args);
466 crashIfIsolateIsDead(isolate); 466 crashIfIsolateIsDead(isolate);
467 InspectorInstrumentation::didExecuteScript(cookie); 467 InspectorInstrumentation::didExecuteScript(cookie);
468 return result; 468 return result;
469 } 469 }
470 470
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) 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)
472 { 472 {
473 TRACE_EVENT0("v8", "v8.callFunction"); 473 TRACE_EVENT0("v8", "v8.callFunction");
474 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 474 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
475 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); 475 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
476 v8::MaybeLocal<v8::Value> result = function->Call(isolate->GetCurrentContext (), receiver, argc, args); 476 v8::MaybeLocal<v8::Value> result = function->Call(isolate->GetCurrentContext (), receiver, argc, args);
477 crashIfIsolateIsDead(isolate); 477 crashIfIsolateIsDead(isolate);
478 return result; 478 return result;
479 } 479 }
480 480
481 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObject(v8::Isolate* isolat e, v8::Local<v8::ObjectTemplate> objectTemplate) 481 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObject(v8::Isolate* isolat e, v8::Local<v8::ObjectTemplate> objectTemplate)
482 { 482 {
483 TRACE_EVENT0("v8", "v8.newInstance"); 483 TRACE_EVENT0("v8", "v8.newInstance");
484 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 484 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
485 485
486 V8RecursionScope::MicrotaskSuppression scope(isolate); 486 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
487 v8::MaybeLocal<v8::Object> result = objectTemplate->NewInstance(isolate->Get CurrentContext()); 487 v8::MaybeLocal<v8::Object> result = objectTemplate->NewInstance(isolate->Get CurrentContext());
488 crashIfIsolateIsDead(isolate); 488 crashIfIsolateIsDead(isolate);
489 return result; 489 return result;
490 } 490 }
491 491
492 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObject(v8::Isolate* isolat e, v8::Local<v8::Function> function, int argc, v8::Local<v8::Value> argv[]) 492 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObject(v8::Isolate* isolat e, v8::Local<v8::Function> function, int argc, v8::Local<v8::Value> argv[])
493 { 493 {
494 TRACE_EVENT0("v8", "v8.newInstance"); 494 TRACE_EVENT0("v8", "v8.newInstance");
495 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 495 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
496 496
497 V8RecursionScope::MicrotaskSuppression scope(isolate); 497 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
498 v8::MaybeLocal<v8::Object> result = function->NewInstance(isolate->GetCurren tContext(), argc, argv); 498 v8::MaybeLocal<v8::Object> result = function->NewInstance(isolate->GetCurren tContext(), argc, argv);
499 crashIfIsolateIsDead(isolate); 499 crashIfIsolateIsDead(isolate);
500 return result; 500 return result;
501 } 501 }
502 502
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[]) 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[])
504 { 504 {
505 TRACE_EVENT0("v8", "v8.newInstance"); 505 TRACE_EVENT0("v8", "v8.newInstance");
506 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 506 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
507 if (ScriptForbiddenScope::isScriptForbidden()) { 507 if (ScriptForbiddenScope::isScriptForbidden()) {
508 throwScriptForbiddenException(isolate); 508 throwScriptForbiddenException(isolate);
509 return v8::MaybeLocal<v8::Object>(); 509 return v8::MaybeLocal<v8::Object>();
510 } 510 }
511 V8RecursionScope scope(isolate); 511 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kRunMicrot asks);
512 v8::MaybeLocal<v8::Object> result = function->NewInstance(isolate->GetCurren tContext(), argc, argv); 512 v8::MaybeLocal<v8::Object> result = function->NewInstance(isolate->GetCurren tContext(), argc, argv);
513 crashIfIsolateIsDead(isolate); 513 crashIfIsolateIsDead(isolate);
514 return result; 514 return result;
515 } 515 }
516 516
517 unsigned V8ScriptRunner::tagForParserCache(CachedMetadataHandler* cacheHandler) 517 unsigned V8ScriptRunner::tagForParserCache(CachedMetadataHandler* cacheHandler)
518 { 518 {
519 return cacheTag(CacheTagParser, cacheHandler); 519 return cacheTag(CacheTagParser, cacheHandler);
520 } 520 }
521 521
522 unsigned V8ScriptRunner::tagForCodeCache(CachedMetadataHandler* cacheHandler) 522 unsigned V8ScriptRunner::tagForCodeCache(CachedMetadataHandler* cacheHandler)
523 { 523 {
524 return cacheTag(CacheTagCode, cacheHandler); 524 return cacheTag(CacheTagCode, cacheHandler);
525 } 525 }
526 526
527 } // namespace blink 527 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698