| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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" |
| 32 #include "bindings/core/v8/V8ThrowException.h" | 33 #include "bindings/core/v8/V8ThrowException.h" |
| 33 #include "core/dom/ExecutionContext.h" | 34 #include "core/dom/ExecutionContext.h" |
| 34 #include "core/fetch/CachedMetadata.h" | 35 #include "core/fetch/CachedMetadata.h" |
| 35 #include "core/fetch/ScriptResource.h" | 36 #include "core/fetch/ScriptResource.h" |
| 36 #include "core/inspector/InspectorInstrumentation.h" | 37 #include "core/inspector/InspectorInstrumentation.h" |
| 37 #include "core/inspector/InspectorTraceEvents.h" | 38 #include "core/inspector/InspectorTraceEvents.h" |
| 38 #include "platform/Histogram.h" | 39 #include "platform/Histogram.h" |
| 39 #include "platform/ScriptForbiddenScope.h" | 40 #include "platform/ScriptForbiddenScope.h" |
| 40 #include "platform/TraceEvent.h" | 41 #include "platform/TraceEvent.h" |
| 41 #include "public/platform/Platform.h" | 42 #include "public/platform/Platform.h" |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 | 393 |
| 393 return (*compileFn)(isolate, code, origin); | 394 return (*compileFn)(isolate, code, origin); |
| 394 } | 395 } |
| 395 | 396 |
| 396 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) |
| 397 { | 398 { |
| 398 ASSERT(!script.IsEmpty()); | 399 ASSERT(!script.IsEmpty()); |
| 399 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 400 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| 400 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()))); |
| 401 | 402 |
| 402 if (v8::MicrotasksScope::GetCurrentDepth(isolate) >= kMaxRecursionDepth) | 403 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) |
| 403 return throwStackOverflowExceptionIfNeeded(isolate); | 404 return throwStackOverflowExceptionIfNeeded(isolate); |
| 404 | 405 |
| 405 RELEASE_ASSERT(!context->isIteratingOverObservers()); | 406 RELEASE_ASSERT(!context->isIteratingOverObservers()); |
| 406 | 407 |
| 407 // Run the script and keep track of the current recursion depth. | 408 // Run the script and keep track of the current recursion depth. |
| 408 v8::MaybeLocal<v8::Value> result; | 409 v8::MaybeLocal<v8::Value> result; |
| 409 { | 410 { |
| 410 if (ScriptForbiddenScope::isScriptForbidden()) { | 411 if (ScriptForbiddenScope::isScriptForbidden()) { |
| 411 throwScriptForbiddenException(isolate); | 412 throwScriptForbiddenException(isolate); |
| 412 return v8::MaybeLocal<v8::Value>(); | 413 return v8::MaybeLocal<v8::Value>(); |
| 413 } | 414 } |
| 414 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kRunMi
crotasks); | 415 V8RecursionScope recursionScope(isolate); |
| 415 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEx
ecuteScript(context, script->GetUnboundScript()->GetId()); | 416 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEx
ecuteScript(context, script->GetUnboundScript()->GetId()); |
| 416 result = script->Run(isolate->GetCurrentContext()); | 417 result = script->Run(isolate->GetCurrentContext()); |
| 417 InspectorInstrumentation::didExecuteScript(cookie); | 418 InspectorInstrumentation::didExecuteScript(cookie); |
| 418 } | 419 } |
| 419 | 420 |
| 420 crashIfIsolateIsDead(isolate); | 421 crashIfIsolateIsDead(isolate); |
| 421 return result; | 422 return result; |
| 422 } | 423 } |
| 423 | 424 |
| 424 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) |
| 425 { | 426 { |
| 426 v8::Local<v8::Script> script; | 427 v8::Local<v8::Script> script; |
| 427 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)) |
| 428 return v8::MaybeLocal<v8::Value>(); | 429 return v8::MaybeLocal<v8::Value>(); |
| 429 | 430 |
| 430 TRACE_EVENT0("v8", "v8.run"); | 431 TRACE_EVENT0("v8", "v8.run"); |
| 431 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 432 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| 432 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM
icrotasks); | 433 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); |
| 433 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext())
; | 434 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext())
; |
| 434 crashIfIsolateIsDead(isolate); | 435 crashIfIsolateIsDead(isolate); |
| 435 return result; | 436 return result; |
| 436 } | 437 } |
| 437 | 438 |
| 438 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) |
| 439 { | 440 { |
| 440 TRACE_EVENT0("v8", "v8.run"); | 441 TRACE_EVENT0("v8", "v8.run"); |
| 441 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 442 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| 442 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM
icrotasks); | 443 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); |
| 443 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext())
; | 444 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext())
; |
| 444 crashIfIsolateIsDead(isolate); | 445 crashIfIsolateIsDead(isolate); |
| 445 return result; | 446 return result; |
| 446 } | 447 } |
| 447 | 448 |
| 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) | 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 { | 450 { |
| 450 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)); |
| 451 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 452 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| 452 | 453 |
| 453 if (v8::MicrotasksScope::GetCurrentDepth(isolate) >= kMaxRecursionDepth) | 454 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) |
| 454 return v8::MaybeLocal<v8::Value>(throwStackOverflowExceptionIfNeeded(iso
late)); | 455 return v8::MaybeLocal<v8::Value>(throwStackOverflowExceptionIfNeeded(iso
late)); |
| 455 | 456 |
| 456 RELEASE_ASSERT(!context->isIteratingOverObservers()); | 457 RELEASE_ASSERT(!context->isIteratingOverObservers()); |
| 457 | 458 |
| 458 if (ScriptForbiddenScope::isScriptForbidden()) { | 459 if (ScriptForbiddenScope::isScriptForbidden()) { |
| 459 throwScriptForbiddenException(isolate); | 460 throwScriptForbiddenException(isolate); |
| 460 return v8::MaybeLocal<v8::Value>(); | 461 return v8::MaybeLocal<v8::Value>(); |
| 461 } | 462 } |
| 462 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kRunMicrot
asks); | 463 V8RecursionScope recursionScope(isolate); |
| 463 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willExecut
eScript(context, function->ScriptId()); | 464 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willExecut
eScript(context, function->ScriptId()); |
| 464 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); |
| 465 crashIfIsolateIsDead(isolate); | 466 crashIfIsolateIsDead(isolate); |
| 466 InspectorInstrumentation::didExecuteScript(cookie); | 467 InspectorInstrumentation::didExecuteScript(cookie); |
| 467 return result; | 468 return result; |
| 468 } | 469 } |
| 469 | 470 |
| 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) | 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 { | 472 { |
| 472 TRACE_EVENT0("v8", "v8.callFunction"); | 473 TRACE_EVENT0("v8", "v8.callFunction"); |
| 473 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 474 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| 474 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM
icrotasks); | 475 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); |
| 475 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); |
| 476 crashIfIsolateIsDead(isolate); | 477 crashIfIsolateIsDead(isolate); |
| 477 return result; | 478 return result; |
| 478 } | 479 } |
| 479 | 480 |
| 480 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) |
| 481 { | 482 { |
| 482 TRACE_EVENT0("v8", "v8.newInstance"); | 483 TRACE_EVENT0("v8", "v8.newInstance"); |
| 483 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 484 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| 484 | 485 |
| 485 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM
icrotasks); | 486 V8RecursionScope::MicrotaskSuppression scope(isolate); |
| 486 v8::MaybeLocal<v8::Object> result = objectTemplate->NewInstance(isolate->Get
CurrentContext()); | 487 v8::MaybeLocal<v8::Object> result = objectTemplate->NewInstance(isolate->Get
CurrentContext()); |
| 487 crashIfIsolateIsDead(isolate); | 488 crashIfIsolateIsDead(isolate); |
| 488 return result; | 489 return result; |
| 489 } | 490 } |
| 490 | 491 |
| 491 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[]) |
| 492 { | 493 { |
| 493 TRACE_EVENT0("v8", "v8.newInstance"); | 494 TRACE_EVENT0("v8", "v8.newInstance"); |
| 494 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 495 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| 495 | 496 |
| 496 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM
icrotasks); | 497 V8RecursionScope::MicrotaskSuppression scope(isolate); |
| 497 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); |
| 498 crashIfIsolateIsDead(isolate); | 499 crashIfIsolateIsDead(isolate); |
| 499 return result; | 500 return result; |
| 500 } | 501 } |
| 501 | 502 |
| 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[]) | 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 { | 504 { |
| 504 TRACE_EVENT0("v8", "v8.newInstance"); | 505 TRACE_EVENT0("v8", "v8.newInstance"); |
| 505 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 506 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| 506 if (ScriptForbiddenScope::isScriptForbidden()) { | 507 if (ScriptForbiddenScope::isScriptForbidden()) { |
| 507 throwScriptForbiddenException(isolate); | 508 throwScriptForbiddenException(isolate); |
| 508 return v8::MaybeLocal<v8::Object>(); | 509 return v8::MaybeLocal<v8::Object>(); |
| 509 } | 510 } |
| 510 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kRunMicrot
asks); | 511 V8RecursionScope scope(isolate); |
| 511 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); |
| 512 crashIfIsolateIsDead(isolate); | 513 crashIfIsolateIsDead(isolate); |
| 513 return result; | 514 return result; |
| 514 } | 515 } |
| 515 | 516 |
| 516 unsigned V8ScriptRunner::tagForParserCache(CachedMetadataHandler* cacheHandler) | 517 unsigned V8ScriptRunner::tagForParserCache(CachedMetadataHandler* cacheHandler) |
| 517 { | 518 { |
| 518 return cacheTag(CacheTagParser, cacheHandler); | 519 return cacheTag(CacheTagParser, cacheHandler); |
| 519 } | 520 } |
| 520 | 521 |
| 521 unsigned V8ScriptRunner::tagForCodeCache(CachedMetadataHandler* cacheHandler) | 522 unsigned V8ScriptRunner::tagForCodeCache(CachedMetadataHandler* cacheHandler) |
| 522 { | 523 { |
| 523 return cacheTag(CacheTagCode, cacheHandler); | 524 return cacheTag(CacheTagCode, cacheHandler); |
| 524 } | 525 } |
| 525 | 526 |
| 526 } // namespace blink | 527 } // namespace blink |
| OLD | NEW |