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 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 const TextPosition& scriptStartPosition, | 454 const TextPosition& scriptStartPosition, |
455 v8::Isolate* isolate, | 455 v8::Isolate* isolate, |
456 ScriptResource* resource, | 456 ScriptResource* resource, |
457 ScriptStreamer* streamer, | 457 ScriptStreamer* streamer, |
458 CachedMetadataHandler* cacheHandler, | 458 CachedMetadataHandler* cacheHandler, |
459 AccessControlStatus accessControlStatus, | 459 AccessControlStatus accessControlStatus, |
460 V8CacheOptions cacheOptions) { | 460 V8CacheOptions cacheOptions) { |
461 TRACE_EVENT2( | 461 TRACE_EVENT2( |
462 "v8,devtools.timeline", "v8.compile", "fileName", fileName.utf8(), "data", | 462 "v8,devtools.timeline", "v8.compile", "fileName", fileName.utf8(), "data", |
463 InspectorCompileScriptEvent::data(fileName, scriptStartPosition)); | 463 InspectorCompileScriptEvent::data(fileName, scriptStartPosition)); |
464 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Compile"); | |
465 | 464 |
466 ASSERT(!streamer || resource); | 465 ASSERT(!streamer || resource); |
467 ASSERT(!resource || resource->cacheHandler() == cacheHandler); | 466 ASSERT(!resource || resource->cacheHandler() == cacheHandler); |
468 | 467 |
469 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at | 468 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at |
470 // 1, whereas v8 starts at 0. | 469 // 1, whereas v8 starts at 0. |
471 v8::ScriptOrigin origin( | 470 v8::ScriptOrigin origin( |
472 v8String(isolate, fileName), | 471 v8String(isolate, fileName), |
473 v8::Integer::New(isolate, scriptStartPosition.m_line.zeroBasedInt()), | 472 v8::Integer::New(isolate, scriptStartPosition.m_line.zeroBasedInt()), |
474 v8::Integer::New(isolate, scriptStartPosition.m_column.zeroBasedInt()), | 473 v8::Integer::New(isolate, scriptStartPosition.m_column.zeroBasedInt()), |
(...skipping 20 matching lines...) Expand all Loading... |
495 return (*compileFn)(isolate, code, origin); | 494 return (*compileFn)(isolate, code, origin); |
496 } | 495 } |
497 | 496 |
498 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledScript( | 497 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledScript( |
499 v8::Isolate* isolate, | 498 v8::Isolate* isolate, |
500 v8::Local<v8::Script> script, | 499 v8::Local<v8::Script> script, |
501 ExecutionContext* context) { | 500 ExecutionContext* context) { |
502 ASSERT(!script.IsEmpty()); | 501 ASSERT(!script.IsEmpty()); |
503 ScopedFrameBlamer frameBlamer( | 502 ScopedFrameBlamer frameBlamer( |
504 context->isDocument() ? toDocument(context)->frame() : nullptr); | 503 context->isDocument() ? toDocument(context)->frame() : nullptr); |
505 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | |
506 TRACE_EVENT1("v8", "v8.run", "fileName", | 504 TRACE_EVENT1("v8", "v8.run", "fileName", |
507 TRACE_STR_COPY(*v8::String::Utf8Value( | 505 TRACE_STR_COPY(*v8::String::Utf8Value( |
508 script->GetUnboundScript()->GetScriptName()))); | 506 script->GetUnboundScript()->GetScriptName()))); |
509 | 507 |
510 if (v8::MicrotasksScope::GetCurrentDepth(isolate) >= kMaxRecursionDepth) | 508 if (v8::MicrotasksScope::GetCurrentDepth(isolate) >= kMaxRecursionDepth) |
511 return throwStackOverflowExceptionIfNeeded(isolate); | 509 return throwStackOverflowExceptionIfNeeded(isolate); |
512 | 510 |
513 RELEASE_ASSERT(!context->isIteratingOverObservers()); | 511 RELEASE_ASSERT(!context->isIteratingOverObservers()); |
514 | 512 |
515 // Run the script and keep track of the current recursion depth. | 513 // Run the script and keep track of the current recursion depth. |
(...skipping 23 matching lines...) Expand all Loading... |
539 const String& fileName, | 537 const String& fileName, |
540 const TextPosition& scriptStartPosition) { | 538 const TextPosition& scriptStartPosition) { |
541 v8::Local<v8::Script> script; | 539 v8::Local<v8::Script> script; |
542 if (!V8ScriptRunner::compileScript( | 540 if (!V8ScriptRunner::compileScript( |
543 source, fileName, String(), scriptStartPosition, isolate, nullptr, | 541 source, fileName, String(), scriptStartPosition, isolate, nullptr, |
544 nullptr, nullptr, SharableCrossOrigin, V8CacheOptionsDefault) | 542 nullptr, nullptr, SharableCrossOrigin, V8CacheOptionsDefault) |
545 .ToLocal(&script)) | 543 .ToLocal(&script)) |
546 return v8::MaybeLocal<v8::Value>(); | 544 return v8::MaybeLocal<v8::Value>(); |
547 | 545 |
548 TRACE_EVENT0("v8", "v8.run"); | 546 TRACE_EVENT0("v8", "v8.run"); |
549 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | |
550 v8::MicrotasksScope microtasksScope(isolate, | 547 v8::MicrotasksScope microtasksScope(isolate, |
551 v8::MicrotasksScope::kDoNotRunMicrotasks); | 548 v8::MicrotasksScope::kDoNotRunMicrotasks); |
552 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()); | 549 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()); |
553 crashIfIsolateIsDead(isolate); | 550 crashIfIsolateIsDead(isolate); |
554 return result; | 551 return result; |
555 } | 552 } |
556 | 553 |
557 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledInternalScript( | 554 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledInternalScript( |
558 v8::Isolate* isolate, | 555 v8::Isolate* isolate, |
559 v8::Local<v8::Script> script) { | 556 v8::Local<v8::Script> script) { |
560 TRACE_EVENT0("v8", "v8.run"); | 557 TRACE_EVENT0("v8", "v8.run"); |
561 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | |
562 v8::MicrotasksScope microtasksScope(isolate, | 558 v8::MicrotasksScope microtasksScope(isolate, |
563 v8::MicrotasksScope::kDoNotRunMicrotasks); | 559 v8::MicrotasksScope::kDoNotRunMicrotasks); |
564 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()); | 560 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()); |
565 crashIfIsolateIsDead(isolate); | 561 crashIfIsolateIsDead(isolate); |
566 return result; | 562 return result; |
567 } | 563 } |
568 | 564 |
569 v8::MaybeLocal<v8::Value> V8ScriptRunner::callAsConstructor( | 565 v8::MaybeLocal<v8::Value> V8ScriptRunner::callAsConstructor( |
570 v8::Isolate* isolate, | 566 v8::Isolate* isolate, |
571 v8::Local<v8::Object> constructor, | 567 v8::Local<v8::Object> constructor, |
572 ExecutionContext* context, | 568 ExecutionContext* context, |
573 int argc, | 569 int argc, |
574 v8::Local<v8::Value> argv[]) { | 570 v8::Local<v8::Value> argv[]) { |
575 TRACE_EVENT0("v8", "v8.callAsConstructor"); | 571 TRACE_EVENT0("v8", "v8.callAsConstructor"); |
576 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | |
577 | 572 |
578 int depth = v8::MicrotasksScope::GetCurrentDepth(isolate); | 573 int depth = v8::MicrotasksScope::GetCurrentDepth(isolate); |
579 if (depth >= kMaxRecursionDepth) | 574 if (depth >= kMaxRecursionDepth) |
580 return v8::MaybeLocal<v8::Value>( | 575 return v8::MaybeLocal<v8::Value>( |
581 throwStackOverflowExceptionIfNeeded(isolate)); | 576 throwStackOverflowExceptionIfNeeded(isolate)); |
582 | 577 |
583 CHECK(!context->isIteratingOverObservers()); | 578 CHECK(!context->isIteratingOverObservers()); |
584 | 579 |
585 if (ScriptForbiddenScope::isScriptForbidden()) { | 580 if (ScriptForbiddenScope::isScriptForbidden()) { |
586 throwScriptForbiddenException(isolate); | 581 throwScriptForbiddenException(isolate); |
(...skipping 25 matching lines...) Expand all Loading... |
612 v8::MaybeLocal<v8::Value> V8ScriptRunner::callFunction( | 607 v8::MaybeLocal<v8::Value> V8ScriptRunner::callFunction( |
613 v8::Local<v8::Function> function, | 608 v8::Local<v8::Function> function, |
614 ExecutionContext* context, | 609 ExecutionContext* context, |
615 v8::Local<v8::Value> receiver, | 610 v8::Local<v8::Value> receiver, |
616 int argc, | 611 int argc, |
617 v8::Local<v8::Value> args[], | 612 v8::Local<v8::Value> args[], |
618 v8::Isolate* isolate) { | 613 v8::Isolate* isolate) { |
619 ScopedFrameBlamer frameBlamer( | 614 ScopedFrameBlamer frameBlamer( |
620 context->isDocument() ? toDocument(context)->frame() : nullptr); | 615 context->isDocument() ? toDocument(context)->frame() : nullptr); |
621 TRACE_EVENT0("v8", "v8.callFunction"); | 616 TRACE_EVENT0("v8", "v8.callFunction"); |
622 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | |
623 | 617 |
624 int depth = v8::MicrotasksScope::GetCurrentDepth(isolate); | 618 int depth = v8::MicrotasksScope::GetCurrentDepth(isolate); |
625 if (depth >= kMaxRecursionDepth) | 619 if (depth >= kMaxRecursionDepth) |
626 return v8::MaybeLocal<v8::Value>( | 620 return v8::MaybeLocal<v8::Value>( |
627 throwStackOverflowExceptionIfNeeded(isolate)); | 621 throwStackOverflowExceptionIfNeeded(isolate)); |
628 | 622 |
629 RELEASE_ASSERT(!context->isIteratingOverObservers()); | 623 RELEASE_ASSERT(!context->isIteratingOverObservers()); |
630 | 624 |
631 if (ScriptForbiddenScope::isScriptForbidden()) { | 625 if (ScriptForbiddenScope::isScriptForbidden()) { |
632 throwScriptForbiddenException(isolate); | 626 throwScriptForbiddenException(isolate); |
(...skipping 17 matching lines...) Expand all Loading... |
650 return result; | 644 return result; |
651 } | 645 } |
652 | 646 |
653 v8::MaybeLocal<v8::Value> V8ScriptRunner::callInternalFunction( | 647 v8::MaybeLocal<v8::Value> V8ScriptRunner::callInternalFunction( |
654 v8::Local<v8::Function> function, | 648 v8::Local<v8::Function> function, |
655 v8::Local<v8::Value> receiver, | 649 v8::Local<v8::Value> receiver, |
656 int argc, | 650 int argc, |
657 v8::Local<v8::Value> args[], | 651 v8::Local<v8::Value> args[], |
658 v8::Isolate* isolate) { | 652 v8::Isolate* isolate) { |
659 TRACE_EVENT0("v8", "v8.callFunction"); | 653 TRACE_EVENT0("v8", "v8.callFunction"); |
660 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | |
661 v8::MicrotasksScope microtasksScope(isolate, | 654 v8::MicrotasksScope microtasksScope(isolate, |
662 v8::MicrotasksScope::kDoNotRunMicrotasks); | 655 v8::MicrotasksScope::kDoNotRunMicrotasks); |
663 v8::MaybeLocal<v8::Value> result = | 656 v8::MaybeLocal<v8::Value> result = |
664 function->Call(isolate->GetCurrentContext(), receiver, argc, args); | 657 function->Call(isolate->GetCurrentContext(), receiver, argc, args); |
665 crashIfIsolateIsDead(isolate); | 658 crashIfIsolateIsDead(isolate); |
666 return result; | 659 return result; |
667 } | 660 } |
668 | 661 |
669 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObject( | 662 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObject( |
670 v8::Isolate* isolate, | 663 v8::Isolate* isolate, |
671 v8::Local<v8::ObjectTemplate> objectTemplate) { | 664 v8::Local<v8::ObjectTemplate> objectTemplate) { |
672 TRACE_EVENT0("v8", "v8.newInstance"); | 665 TRACE_EVENT0("v8", "v8.newInstance"); |
673 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | |
674 | 666 |
675 v8::MicrotasksScope microtasksScope(isolate, | 667 v8::MicrotasksScope microtasksScope(isolate, |
676 v8::MicrotasksScope::kDoNotRunMicrotasks); | 668 v8::MicrotasksScope::kDoNotRunMicrotasks); |
677 v8::MaybeLocal<v8::Object> result = | 669 v8::MaybeLocal<v8::Object> result = |
678 objectTemplate->NewInstance(isolate->GetCurrentContext()); | 670 objectTemplate->NewInstance(isolate->GetCurrentContext()); |
679 crashIfIsolateIsDead(isolate); | 671 crashIfIsolateIsDead(isolate); |
680 return result; | 672 return result; |
681 } | 673 } |
682 | 674 |
683 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObject( | 675 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObject( |
684 v8::Isolate* isolate, | 676 v8::Isolate* isolate, |
685 v8::Local<v8::Function> function, | 677 v8::Local<v8::Function> function, |
686 int argc, | 678 int argc, |
687 v8::Local<v8::Value> argv[]) { | 679 v8::Local<v8::Value> argv[]) { |
688 TRACE_EVENT0("v8", "v8.newInstance"); | 680 TRACE_EVENT0("v8", "v8.newInstance"); |
689 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | |
690 | 681 |
691 v8::MicrotasksScope microtasksScope(isolate, | 682 v8::MicrotasksScope microtasksScope(isolate, |
692 v8::MicrotasksScope::kDoNotRunMicrotasks); | 683 v8::MicrotasksScope::kDoNotRunMicrotasks); |
693 v8::MaybeLocal<v8::Object> result = | 684 v8::MaybeLocal<v8::Object> result = |
694 function->NewInstance(isolate->GetCurrentContext(), argc, argv); | 685 function->NewInstance(isolate->GetCurrentContext(), argc, argv); |
695 crashIfIsolateIsDead(isolate); | 686 crashIfIsolateIsDead(isolate); |
696 return result; | 687 return result; |
697 } | 688 } |
698 | 689 |
699 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObjectInDocument( | 690 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObjectInDocument( |
700 v8::Isolate* isolate, | 691 v8::Isolate* isolate, |
701 v8::Local<v8::Function> function, | 692 v8::Local<v8::Function> function, |
702 ExecutionContext* context, | 693 ExecutionContext* context, |
703 int argc, | 694 int argc, |
704 v8::Local<v8::Value> argv[]) { | 695 v8::Local<v8::Value> argv[]) { |
705 TRACE_EVENT0("v8", "v8.newInstance"); | 696 TRACE_EVENT0("v8", "v8.newInstance"); |
706 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | |
707 if (ScriptForbiddenScope::isScriptForbidden()) { | 697 if (ScriptForbiddenScope::isScriptForbidden()) { |
708 throwScriptForbiddenException(isolate); | 698 throwScriptForbiddenException(isolate); |
709 return v8::MaybeLocal<v8::Object>(); | 699 return v8::MaybeLocal<v8::Object>(); |
710 } | 700 } |
711 v8::MicrotasksScope microtasksScope(isolate, | 701 v8::MicrotasksScope microtasksScope(isolate, |
712 v8::MicrotasksScope::kRunMicrotasks); | 702 v8::MicrotasksScope::kRunMicrotasks); |
713 v8::MaybeLocal<v8::Object> result = | 703 v8::MaybeLocal<v8::Object> result = |
714 function->NewInstance(isolate->GetCurrentContext(), argc, argv); | 704 function->NewInstance(isolate->GetCurrentContext(), argc, argv); |
715 crashIfIsolateIsDead(isolate); | 705 crashIfIsolateIsDead(isolate); |
716 return result; | 706 return result; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 v8AtomicString(isolate, "((e) => { throw e; })"), origin) | 744 v8AtomicString(isolate, "((e) => { throw e; })"), origin) |
755 .ToLocalChecked(); | 745 .ToLocalChecked(); |
756 v8::Local<v8::Function> thrower = runCompiledInternalScript(isolate, script) | 746 v8::Local<v8::Function> thrower = runCompiledInternalScript(isolate, script) |
757 .ToLocalChecked() | 747 .ToLocalChecked() |
758 .As<v8::Function>(); | 748 .As<v8::Function>(); |
759 v8::Local<v8::Value> args[] = {exception}; | 749 v8::Local<v8::Value> args[] = {exception}; |
760 callInternalFunction(thrower, thrower, WTF_ARRAY_LENGTH(args), args, isolate); | 750 callInternalFunction(thrower, thrower, WTF_ARRAY_LENGTH(args), args, isolate); |
761 } | 751 } |
762 | 752 |
763 } // namespace blink | 753 } // namespace blink |
OLD | NEW |