OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/inspector/v8-console.h" | 5 #include "src/inspector/v8-console.h" |
6 | 6 |
7 #include "src/base/macros.h" | 7 #include "src/base/macros.h" |
8 #include "src/inspector/injected-script.h" | 8 #include "src/inspector/injected-script.h" |
9 #include "src/inspector/inspected-context.h" | 9 #include "src/inspector/inspected-context.h" |
10 #include "src/inspector/string-util.h" | 10 #include "src/inspector/string-util.h" |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 V8InspectorSession::Inspectable* object = session->inspectedObject(num); | 550 V8InspectorSession::Inspectable* object = session->inspectedObject(num); |
551 v8::Isolate* isolate = info.GetIsolate(); | 551 v8::Isolate* isolate = info.GetIsolate(); |
552 if (object) | 552 if (object) |
553 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext())); | 553 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext())); |
554 else | 554 else |
555 info.GetReturnValue().Set(v8::Undefined(isolate)); | 555 info.GetReturnValue().Set(v8::Undefined(isolate)); |
556 } | 556 } |
557 } | 557 } |
558 | 558 |
559 v8::Local<v8::Object> V8Console::createConsole( | 559 v8::Local<v8::Object> V8Console::createConsole( |
560 InspectedContext* inspectedContext, bool hasMemoryAttribute) { | 560 InspectedContext* inspectedContext) { |
561 v8::Local<v8::Context> context = inspectedContext->context(); | 561 v8::Local<v8::Context> context = inspectedContext->context(); |
562 v8::Context::Scope contextScope(context); | 562 v8::Context::Scope contextScope(context); |
563 v8::Isolate* isolate = context->GetIsolate(); | 563 v8::Isolate* isolate = context->GetIsolate(); |
564 v8::MicrotasksScope microtasksScope(isolate, | 564 v8::MicrotasksScope microtasksScope(isolate, |
565 v8::MicrotasksScope::kDoNotRunMicrotasks); | 565 v8::MicrotasksScope::kDoNotRunMicrotasks); |
566 | 566 |
567 v8::Local<v8::Object> console = v8::Object::New(isolate); | 567 v8::Local<v8::Object> console = v8::Object::New(isolate); |
568 bool success = | 568 bool success = |
569 console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false); | 569 console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false); |
570 DCHECK(success); | 570 DCHECK(success); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 createBoundFunctionProperty(context, console, data, "timeline", | 611 createBoundFunctionProperty(context, console, data, "timeline", |
612 V8Console::timelineCallback); | 612 V8Console::timelineCallback); |
613 createBoundFunctionProperty(context, console, data, "timelineEnd", | 613 createBoundFunctionProperty(context, console, data, "timelineEnd", |
614 V8Console::timelineEndCallback); | 614 V8Console::timelineEndCallback); |
615 createBoundFunctionProperty(context, console, data, "time", | 615 createBoundFunctionProperty(context, console, data, "time", |
616 V8Console::timeCallback); | 616 V8Console::timeCallback); |
617 createBoundFunctionProperty(context, console, data, "timeEnd", | 617 createBoundFunctionProperty(context, console, data, "timeEnd", |
618 V8Console::timeEndCallback); | 618 V8Console::timeEndCallback); |
619 createBoundFunctionProperty(context, console, data, "timeStamp", | 619 createBoundFunctionProperty(context, console, data, "timeStamp", |
620 V8Console::timeStampCallback); | 620 V8Console::timeStampCallback); |
| 621 return console; |
| 622 } |
621 | 623 |
622 const char* jsConsoleAssert = | 624 void V8Console::installMemoryGetter(V8InspectorImpl* inspector, |
623 "(function(){\n" | 625 v8::Local<v8::Context> context, |
624 " var originAssert = this.assert;\n" | 626 v8::Local<v8::Object> console) { |
625 " originAssert.apply = Function.prototype.apply;\n" | 627 v8::Local<v8::External> data = |
626 " this.assert = assertWrapper;\n" | 628 v8::External::New(inspector->isolate(), inspector); |
627 " assertWrapper.toString = () => originAssert.toString();\n" | 629 console->SetAccessorProperty( |
628 " function assertWrapper(){\n" | 630 toV8StringInternalized(inspector->isolate(), "memory"), |
629 " if (!!arguments[0]) return;\n" | 631 v8::Function::New(context, V8Console::memoryGetterCallback, data, 0, |
630 " originAssert.apply(null, arguments);\n" | 632 v8::ConstructorBehavior::kThrow) |
631 " }\n" | 633 .ToLocalChecked(), |
632 "})"; | 634 v8::Function::New(context, V8Console::memorySetterCallback, data, 0, |
633 | 635 v8::ConstructorBehavior::kThrow) |
634 v8::Local<v8::String> assertSource = toV8String(isolate, jsConsoleAssert); | 636 .ToLocalChecked(), |
635 V8InspectorImpl* inspector = inspectedContext->inspector(); | 637 static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT); |
636 v8::Local<v8::Value> setupFunction; | |
637 if (inspector->compileAndRunInternalScript(context, assertSource) | |
638 .ToLocal(&setupFunction) && | |
639 setupFunction->IsFunction()) { | |
640 v8::MicrotasksScope microtasksScope( | |
641 isolate, v8::MicrotasksScope::kDoNotRunMicrotasks); | |
642 v8::MaybeLocal<v8::Value> result; | |
643 result = v8::Local<v8::Function>::Cast(setupFunction) | |
644 ->Call(context, console, 0, nullptr); | |
645 } | |
646 | |
647 if (hasMemoryAttribute) { | |
648 console->SetAccessorProperty( | |
649 toV8StringInternalized(isolate, "memory"), | |
650 v8::Function::New(context, V8Console::memoryGetterCallback, data, 0, | |
651 v8::ConstructorBehavior::kThrow) | |
652 .ToLocalChecked(), | |
653 v8::Function::New(context, V8Console::memorySetterCallback, data, 0, | |
654 v8::ConstructorBehavior::kThrow) | |
655 .ToLocalChecked(), | |
656 static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT); | |
657 } | |
658 | |
659 return console; | |
660 } | 638 } |
661 | 639 |
662 v8::Local<v8::Object> V8Console::createCommandLineAPI( | 640 v8::Local<v8::Object> V8Console::createCommandLineAPI( |
663 InspectedContext* inspectedContext) { | 641 InspectedContext* inspectedContext) { |
664 v8::Local<v8::Context> context = inspectedContext->context(); | 642 v8::Local<v8::Context> context = inspectedContext->context(); |
665 v8::Isolate* isolate = context->GetIsolate(); | 643 v8::Isolate* isolate = context->GetIsolate(); |
666 v8::MicrotasksScope microtasksScope(isolate, | 644 v8::MicrotasksScope microtasksScope(isolate, |
667 v8::MicrotasksScope::kDoNotRunMicrotasks); | 645 v8::MicrotasksScope::kDoNotRunMicrotasks); |
668 | 646 |
669 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); | 647 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 ->GetOwnPropertyDescriptor( | 813 ->GetOwnPropertyDescriptor( |
836 m_context, v8::Local<v8::String>::Cast(name)) | 814 m_context, v8::Local<v8::String>::Cast(name)) |
837 .ToLocal(&descriptor); | 815 .ToLocal(&descriptor); |
838 DCHECK(success); | 816 DCHECK(success); |
839 USE(success); | 817 USE(success); |
840 } | 818 } |
841 } | 819 } |
842 } | 820 } |
843 | 821 |
844 } // namespace v8_inspector | 822 } // namespace v8_inspector |
OLD | NEW |