mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:07:46 +00:00
LibWeb+WebContent: Store Realm instead of Interpreter in ConsoleClient
This commit is contained in:
parent
905eb8cb4d
commit
2d72abc3d4
5 changed files with 20 additions and 19 deletions
|
@ -1058,14 +1058,14 @@ JS::Interpreter& Document::interpreter()
|
||||||
JS::Value Document::run_javascript(StringView source, StringView filename)
|
JS::Value Document::run_javascript(StringView source, StringView filename)
|
||||||
{
|
{
|
||||||
// FIXME: The only user of this function now is javascript: URLs. Refactor them to follow the spec: https://html.spec.whatwg.org/multipage/browsing-the-web.html#javascript-protocol
|
// FIXME: The only user of this function now is javascript: URLs. Refactor them to follow the spec: https://html.spec.whatwg.org/multipage/browsing-the-web.html#javascript-protocol
|
||||||
auto& interpreter = document().interpreter();
|
auto interpreter = JS::Interpreter::create_with_existing_realm(realm());
|
||||||
auto script_or_error = JS::Script::parse(source, interpreter.realm(), filename);
|
auto script_or_error = JS::Script::parse(source, realm(), filename);
|
||||||
if (script_or_error.is_error()) {
|
if (script_or_error.is_error()) {
|
||||||
// FIXME: Add error logging back.
|
// FIXME: Add error logging back.
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = interpreter.run(script_or_error.value());
|
auto result = interpreter->run(script_or_error.value());
|
||||||
|
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
// FIXME: I'm sure the spec could tell us something about error propagation here!
|
// FIXME: I'm sure the spec could tell us something about error propagation here!
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include <LibGfx/SystemTheme.h>
|
#include <LibGfx/SystemTheme.h>
|
||||||
#include <LibJS/Console.h>
|
#include <LibJS/Console.h>
|
||||||
#include <LibJS/Heap/Heap.h>
|
#include <LibJS/Heap/Heap.h>
|
||||||
#include <LibJS/Interpreter.h>
|
|
||||||
#include <LibJS/Parser.h>
|
#include <LibJS/Parser.h>
|
||||||
#include <LibJS/Runtime/ConsoleObject.h>
|
#include <LibJS/Runtime/ConsoleObject.h>
|
||||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||||
|
@ -386,13 +385,13 @@ Messages::WebContentServer::GetHoveredNodeIdResponse ConnectionFromClient::get_h
|
||||||
void ConnectionFromClient::initialize_js_console(Badge<PageHost>)
|
void ConnectionFromClient::initialize_js_console(Badge<PageHost>)
|
||||||
{
|
{
|
||||||
auto* document = page().top_level_browsing_context().active_document();
|
auto* document = page().top_level_browsing_context().active_document();
|
||||||
auto interpreter = document->interpreter().make_weak_ptr();
|
auto realm = document->realm().make_weak_ptr();
|
||||||
if (m_interpreter.ptr() == interpreter.ptr())
|
if (m_realm.ptr() == realm.ptr())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto& console_object = *interpreter->realm().intrinsics().console_object();
|
auto& console_object = *realm->intrinsics().console_object();
|
||||||
m_interpreter = interpreter;
|
m_realm = realm;
|
||||||
m_console_client = make<WebContentConsoleClient>(console_object.console(), interpreter, *this);
|
m_console_client = make<WebContentConsoleClient>(console_object.console(), *m_realm, *this);
|
||||||
console_object.console().set_client(*m_console_client.ptr());
|
console_object.console().set_client(*m_console_client.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ private:
|
||||||
|
|
||||||
HashMap<i32, NonnullRefPtr<Gfx::Bitmap>> m_backing_stores;
|
HashMap<i32, NonnullRefPtr<Gfx::Bitmap>> m_backing_stores;
|
||||||
|
|
||||||
WeakPtr<JS::Interpreter> m_interpreter;
|
WeakPtr<JS::Realm> m_realm;
|
||||||
OwnPtr<WebContentConsoleClient> m_console_client;
|
OwnPtr<WebContentConsoleClient> m_console_client;
|
||||||
JS::Handle<JS::GlobalObject> m_console_global_object;
|
JS::Handle<JS::GlobalObject> m_console_global_object;
|
||||||
|
|
||||||
|
|
|
@ -16,18 +16,17 @@
|
||||||
|
|
||||||
namespace WebContent {
|
namespace WebContent {
|
||||||
|
|
||||||
WebContentConsoleClient::WebContentConsoleClient(JS::Console& console, WeakPtr<JS::Interpreter> interpreter, ConnectionFromClient& client)
|
WebContentConsoleClient::WebContentConsoleClient(JS::Console& console, JS::Realm& realm, ConnectionFromClient& client)
|
||||||
: ConsoleClient(console)
|
: ConsoleClient(console)
|
||||||
, m_client(client)
|
, m_client(client)
|
||||||
, m_interpreter(interpreter)
|
, m_realm(realm)
|
||||||
{
|
{
|
||||||
JS::DeferGC defer_gc(m_interpreter->heap());
|
JS::DeferGC defer_gc(realm.heap());
|
||||||
|
|
||||||
auto& vm = m_interpreter->vm();
|
auto& vm = realm.vm();
|
||||||
auto& realm = m_interpreter->realm();
|
|
||||||
auto& window = static_cast<Web::HTML::Window&>(realm.global_object());
|
auto& window = static_cast<Web::HTML::Window&>(realm.global_object());
|
||||||
|
|
||||||
auto console_global_object = m_interpreter->heap().allocate_without_realm<ConsoleGlobalObject>(realm, window);
|
auto console_global_object = realm.heap().allocate_without_realm<ConsoleGlobalObject>(realm, window);
|
||||||
|
|
||||||
// NOTE: We need to push an execution context here for NativeFunction::create() to succeed during global object initialization.
|
// NOTE: We need to push an execution context here for NativeFunction::create() to succeed during global object initialization.
|
||||||
// It gets removed immediately after creating the interpreter in Document::interpreter().
|
// It gets removed immediately after creating the interpreter in Document::interpreter().
|
||||||
|
@ -41,7 +40,10 @@ WebContentConsoleClient::WebContentConsoleClient(JS::Console& console, WeakPtr<J
|
||||||
|
|
||||||
void WebContentConsoleClient::handle_input(String const& js_source)
|
void WebContentConsoleClient::handle_input(String const& js_source)
|
||||||
{
|
{
|
||||||
auto& settings = verify_cast<Web::HTML::EnvironmentSettingsObject>(*m_interpreter->realm().host_defined());
|
if (!m_realm)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto& settings = verify_cast<Web::HTML::EnvironmentSettingsObject>(*m_realm->host_defined());
|
||||||
auto script = Web::HTML::ClassicScript::create("(console)", js_source, settings, settings.api_base_url());
|
auto script = Web::HTML::ClassicScript::create("(console)", js_source, settings, settings.api_base_url());
|
||||||
|
|
||||||
// FIXME: Add parse error printouts back once ClassicScript can report parse errors.
|
// FIXME: Add parse error printouts back once ClassicScript can report parse errors.
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace WebContent {
|
||||||
|
|
||||||
class WebContentConsoleClient final : public JS::ConsoleClient {
|
class WebContentConsoleClient final : public JS::ConsoleClient {
|
||||||
public:
|
public:
|
||||||
WebContentConsoleClient(JS::Console&, WeakPtr<JS::Interpreter>, ConnectionFromClient&);
|
WebContentConsoleClient(JS::Console&, JS::Realm&, ConnectionFromClient&);
|
||||||
|
|
||||||
void handle_input(String const& js_source);
|
void handle_input(String const& js_source);
|
||||||
void send_messages(i32 start_index);
|
void send_messages(i32 start_index);
|
||||||
|
@ -28,7 +28,7 @@ private:
|
||||||
virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, PrinterArguments) override;
|
virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, PrinterArguments) override;
|
||||||
|
|
||||||
ConnectionFromClient& m_client;
|
ConnectionFromClient& m_client;
|
||||||
WeakPtr<JS::Interpreter> m_interpreter;
|
WeakPtr<JS::Realm> m_realm;
|
||||||
JS::Handle<ConsoleGlobalObject> m_console_global_object;
|
JS::Handle<ConsoleGlobalObject> m_console_global_object;
|
||||||
|
|
||||||
void clear_output();
|
void clear_output();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue