| 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 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 { | 536 { |
| 537 if (ScriptForbiddenScope::isScriptForbidden()) { | 537 if (ScriptForbiddenScope::isScriptForbidden()) { |
| 538 throwScriptForbiddenException(isolate); | 538 throwScriptForbiddenException(isolate); |
| 539 return v8::MaybeLocal<v8::Value>(); | 539 return v8::MaybeLocal<v8::Value>(); |
| 540 } | 540 } |
| 541 v8::MicrotasksScope microtasksScope(isolate, | 541 v8::MicrotasksScope microtasksScope(isolate, |
| 542 v8::MicrotasksScope::kRunMicrotasks); | 542 v8::MicrotasksScope::kRunMicrotasks); |
| 543 probe::ExecuteScript probe(context); | 543 probe::ExecuteScript probe(context); |
| 544 ThreadDebugger::willExecuteScript(isolate, | 544 ThreadDebugger::willExecuteScript(isolate, |
| 545 script->GetUnboundScript()->GetId()); | 545 script->GetUnboundScript()->GetId()); |
| 546 V8PerIsolateData::EntryRealmScope entryRealmScope( |
| 547 V8PerIsolateData::from(isolate), isolate->GetCurrentContext()); |
| 546 result = script->Run(isolate->GetCurrentContext()); | 548 result = script->Run(isolate->GetCurrentContext()); |
| 547 ThreadDebugger::didExecuteScript(isolate); | 549 ThreadDebugger::didExecuteScript(isolate); |
| 548 } | 550 } |
| 549 | 551 |
| 550 CHECK(!isolate->IsDead()); | 552 CHECK(!isolate->IsDead()); |
| 551 return result; | 553 return result; |
| 552 } | 554 } |
| 553 | 555 |
| 554 v8::MaybeLocal<v8::Value> V8ScriptRunner::compileAndRunInternalScript( | 556 v8::MaybeLocal<v8::Value> V8ScriptRunner::compileAndRunInternalScript( |
| 555 v8::Local<v8::String> source, | 557 v8::Local<v8::String> source, |
| 556 v8::Isolate* isolate, | 558 v8::Isolate* isolate, |
| 557 const String& fileName, | 559 const String& fileName, |
| 558 const TextPosition& scriptStartPosition) { | 560 const TextPosition& scriptStartPosition) { |
| 559 v8::Local<v8::Script> script; | 561 v8::Local<v8::Script> script; |
| 560 if (!V8ScriptRunner::compileScript( | 562 if (!V8ScriptRunner::compileScript( |
| 561 source, fileName, String(), scriptStartPosition, isolate, nullptr, | 563 source, fileName, String(), scriptStartPosition, isolate, nullptr, |
| 562 nullptr, nullptr, SharableCrossOrigin, V8CacheOptionsDefault) | 564 nullptr, nullptr, SharableCrossOrigin, V8CacheOptionsDefault) |
| 563 .ToLocal(&script)) | 565 .ToLocal(&script)) |
| 564 return v8::MaybeLocal<v8::Value>(); | 566 return v8::MaybeLocal<v8::Value>(); |
| 565 | 567 |
| 566 TRACE_EVENT0("v8", "v8.run"); | 568 TRACE_EVENT0("v8", "v8.run"); |
| 567 v8::MicrotasksScope microtasksScope(isolate, | 569 v8::MicrotasksScope microtasksScope(isolate, |
| 568 v8::MicrotasksScope::kDoNotRunMicrotasks); | 570 v8::MicrotasksScope::kDoNotRunMicrotasks); |
| 571 V8PerIsolateData::EntryRealmScope entryRealmScope( |
| 572 V8PerIsolateData::from(isolate), isolate->GetCurrentContext()); |
| 569 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()); | 573 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()); |
| 570 CHECK(!isolate->IsDead()); | 574 CHECK(!isolate->IsDead()); |
| 571 return result; | 575 return result; |
| 572 } | 576 } |
| 573 | 577 |
| 574 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledInternalScript( | 578 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledInternalScript( |
| 575 v8::Isolate* isolate, | 579 v8::Isolate* isolate, |
| 576 v8::Local<v8::Script> script) { | 580 v8::Local<v8::Script> script) { |
| 577 TRACE_EVENT0("v8", "v8.run"); | 581 TRACE_EVENT0("v8", "v8.run"); |
| 578 v8::MicrotasksScope microtasksScope(isolate, | 582 v8::MicrotasksScope microtasksScope(isolate, |
| 579 v8::MicrotasksScope::kDoNotRunMicrotasks); | 583 v8::MicrotasksScope::kDoNotRunMicrotasks); |
| 584 V8PerIsolateData::EntryRealmScope entryRealmScope( |
| 585 V8PerIsolateData::from(isolate), isolate->GetCurrentContext()); |
| 580 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()); | 586 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()); |
| 581 CHECK(!isolate->IsDead()); | 587 CHECK(!isolate->IsDead()); |
| 582 return result; | 588 return result; |
| 583 } | 589 } |
| 584 | 590 |
| 585 v8::MaybeLocal<v8::Value> V8ScriptRunner::callAsConstructor( | 591 v8::MaybeLocal<v8::Value> V8ScriptRunner::callAsConstructor( |
| 586 v8::Isolate* isolate, | 592 v8::Isolate* isolate, |
| 587 v8::Local<v8::Object> constructor, | 593 v8::Local<v8::Object> constructor, |
| 588 ExecutionContext* context, | 594 ExecutionContext* context, |
| 589 int argc, | 595 int argc, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 606 // invocation, change this to use v8::Object instead of | 612 // invocation, change this to use v8::Object instead of |
| 607 // v8::Function. All callers use functions because | 613 // v8::Function. All callers use functions because |
| 608 // CustomElementRegistry#define's IDL signature is Function. | 614 // CustomElementRegistry#define's IDL signature is Function. |
| 609 CHECK(constructor->IsFunction()); | 615 CHECK(constructor->IsFunction()); |
| 610 v8::Local<v8::Function> function = constructor.As<v8::Function>(); | 616 v8::Local<v8::Function> function = constructor.As<v8::Function>(); |
| 611 | 617 |
| 612 v8::MicrotasksScope microtasksScope(isolate, | 618 v8::MicrotasksScope microtasksScope(isolate, |
| 613 v8::MicrotasksScope::kRunMicrotasks); | 619 v8::MicrotasksScope::kRunMicrotasks); |
| 614 probe::CallFunction probe(context, function, depth); | 620 probe::CallFunction probe(context, function, depth); |
| 615 ThreadDebugger::willExecuteScript(isolate, function->ScriptId()); | 621 ThreadDebugger::willExecuteScript(isolate, function->ScriptId()); |
| 622 V8PerIsolateData::EntryRealmScope entryRealmScope( |
| 623 V8PerIsolateData::from(isolate), isolate->GetCurrentContext()); |
| 616 v8::MaybeLocal<v8::Value> result = | 624 v8::MaybeLocal<v8::Value> result = |
| 617 constructor->CallAsConstructor(isolate->GetCurrentContext(), argc, argv); | 625 constructor->CallAsConstructor(isolate->GetCurrentContext(), argc, argv); |
| 618 CHECK(!isolate->IsDead()); | 626 CHECK(!isolate->IsDead()); |
| 619 ThreadDebugger::didExecuteScript(isolate); | 627 ThreadDebugger::didExecuteScript(isolate); |
| 620 return result; | 628 return result; |
| 621 } | 629 } |
| 622 | 630 |
| 623 v8::MaybeLocal<v8::Value> V8ScriptRunner::callFunction( | 631 v8::MaybeLocal<v8::Value> V8ScriptRunner::callFunction( |
| 624 v8::Local<v8::Function> function, | 632 v8::Local<v8::Function> function, |
| 625 ExecutionContext* context, | 633 ExecutionContext* context, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 645 } | 653 } |
| 646 | 654 |
| 647 DCHECK(!frame || BindingSecurity::shouldAllowAccessToFrame( | 655 DCHECK(!frame || BindingSecurity::shouldAllowAccessToFrame( |
| 648 toLocalDOMWindow(function->CreationContext()), frame, | 656 toLocalDOMWindow(function->CreationContext()), frame, |
| 649 BindingSecurity::ErrorReportOption::DoNotReport)); | 657 BindingSecurity::ErrorReportOption::DoNotReport)); |
| 650 CHECK(!ThreadState::current()->isWrapperTracingForbidden()); | 658 CHECK(!ThreadState::current()->isWrapperTracingForbidden()); |
| 651 v8::MicrotasksScope microtasksScope(isolate, | 659 v8::MicrotasksScope microtasksScope(isolate, |
| 652 v8::MicrotasksScope::kRunMicrotasks); | 660 v8::MicrotasksScope::kRunMicrotasks); |
| 653 probe::CallFunction probe(context, function, depth); | 661 probe::CallFunction probe(context, function, depth); |
| 654 ThreadDebugger::willExecuteScript(isolate, function->ScriptId()); | 662 ThreadDebugger::willExecuteScript(isolate, function->ScriptId()); |
| 663 V8PerIsolateData::EntryRealmScope entryRealmScope( |
| 664 V8PerIsolateData::from(isolate), isolate->GetCurrentContext()); |
| 655 v8::MaybeLocal<v8::Value> result = | 665 v8::MaybeLocal<v8::Value> result = |
| 656 function->Call(isolate->GetCurrentContext(), receiver, argc, args); | 666 function->Call(isolate->GetCurrentContext(), receiver, argc, args); |
| 657 CHECK(!isolate->IsDead()); | 667 CHECK(!isolate->IsDead()); |
| 658 ThreadDebugger::didExecuteScript(isolate); | 668 ThreadDebugger::didExecuteScript(isolate); |
| 659 | 669 |
| 660 return result; | 670 return result; |
| 661 } | 671 } |
| 662 | 672 |
| 663 v8::MaybeLocal<v8::Value> V8ScriptRunner::callInternalFunction( | 673 v8::MaybeLocal<v8::Value> V8ScriptRunner::callInternalFunction( |
| 664 v8::Local<v8::Function> function, | 674 v8::Local<v8::Function> function, |
| 665 v8::Local<v8::Value> receiver, | 675 v8::Local<v8::Value> receiver, |
| 666 int argc, | 676 int argc, |
| 667 v8::Local<v8::Value> args[], | 677 v8::Local<v8::Value> args[], |
| 668 v8::Isolate* isolate) { | 678 v8::Isolate* isolate) { |
| 669 TRACE_EVENT0("v8", "v8.callFunction"); | 679 TRACE_EVENT0("v8", "v8.callFunction"); |
| 670 CHECK(!ThreadState::current()->isWrapperTracingForbidden()); | 680 CHECK(!ThreadState::current()->isWrapperTracingForbidden()); |
| 671 v8::MicrotasksScope microtasksScope(isolate, | 681 v8::MicrotasksScope microtasksScope(isolate, |
| 672 v8::MicrotasksScope::kDoNotRunMicrotasks); | 682 v8::MicrotasksScope::kDoNotRunMicrotasks); |
| 683 V8PerIsolateData::EntryRealmScope entryRealmScope( |
| 684 V8PerIsolateData::from(isolate), isolate->GetCurrentContext()); |
| 673 v8::MaybeLocal<v8::Value> result = | 685 v8::MaybeLocal<v8::Value> result = |
| 674 function->Call(isolate->GetCurrentContext(), receiver, argc, args); | 686 function->Call(isolate->GetCurrentContext(), receiver, argc, args); |
| 675 CHECK(!isolate->IsDead()); | 687 CHECK(!isolate->IsDead()); |
| 676 return result; | 688 return result; |
| 677 } | 689 } |
| 678 | 690 |
| 679 v8::MaybeLocal<v8::Value> V8ScriptRunner::evaluateModule( | 691 v8::MaybeLocal<v8::Value> V8ScriptRunner::evaluateModule( |
| 680 v8::Local<v8::Module> module, | 692 v8::Local<v8::Module> module, |
| 681 v8::Local<v8::Context> context, | 693 v8::Local<v8::Context> context, |
| 682 v8::Isolate* isolate) { | 694 v8::Isolate* isolate) { |
| 683 TRACE_EVENT0("v8", "v8.evaluateModule"); | 695 TRACE_EVENT0("v8", "v8.evaluateModule"); |
| 684 v8::MicrotasksScope microtasksScope(isolate, | 696 v8::MicrotasksScope microtasksScope(isolate, |
| 685 v8::MicrotasksScope::kRunMicrotasks); | 697 v8::MicrotasksScope::kRunMicrotasks); |
| 698 V8PerIsolateData::EntryRealmScope entryRealmScope( |
| 699 V8PerIsolateData::from(isolate), context); |
| 686 return module->Evaluate(context); | 700 return module->Evaluate(context); |
| 687 } | 701 } |
| 688 | 702 |
| 689 uint32_t V8ScriptRunner::tagForParserCache( | 703 uint32_t V8ScriptRunner::tagForParserCache( |
| 690 CachedMetadataHandler* cacheHandler) { | 704 CachedMetadataHandler* cacheHandler) { |
| 691 return cacheTag(CacheTagParser, cacheHandler); | 705 return cacheTag(CacheTagParser, cacheHandler); |
| 692 } | 706 } |
| 693 | 707 |
| 694 uint32_t V8ScriptRunner::tagForCodeCache(CachedMetadataHandler* cacheHandler) { | 708 uint32_t V8ScriptRunner::tagForCodeCache(CachedMetadataHandler* cacheHandler) { |
| 695 return cacheTag(CacheTagCode, cacheHandler); | 709 return cacheTag(CacheTagCode, cacheHandler); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 724 v8AtomicString(isolate, "((e) => { throw e; })"), origin) | 738 v8AtomicString(isolate, "((e) => { throw e; })"), origin) |
| 725 .ToLocalChecked(); | 739 .ToLocalChecked(); |
| 726 v8::Local<v8::Function> thrower = runCompiledInternalScript(isolate, script) | 740 v8::Local<v8::Function> thrower = runCompiledInternalScript(isolate, script) |
| 727 .ToLocalChecked() | 741 .ToLocalChecked() |
| 728 .As<v8::Function>(); | 742 .As<v8::Function>(); |
| 729 v8::Local<v8::Value> args[] = {exception}; | 743 v8::Local<v8::Value> args[] = {exception}; |
| 730 callInternalFunction(thrower, thrower, WTF_ARRAY_LENGTH(args), args, isolate); | 744 callInternalFunction(thrower, thrower, WTF_ARRAY_LENGTH(args), args, isolate); |
| 731 } | 745 } |
| 732 | 746 |
| 733 } // namespace blink | 747 } // namespace blink |
| OLD | NEW |