1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:47:45 +00:00

LibJS: Add side-effect-free version of Value::to_string()

There are now two API's on Value:

- Value::to_string(Interpreter&) -- may throw.
- Value::to_string_without_side_effects() -- will never throw.

These are some pretty big sweeping changes, so it's possible that I did
some part the wrong way. We'll work it out as we go. :^)

Fixes #2123.
This commit is contained in:
Andreas Kling 2020-05-15 13:39:24 +02:00
parent d8aa2a6997
commit c6ddbd1f3e
25 changed files with 285 additions and 112 deletions

View file

@ -78,7 +78,9 @@ JS::Value DocumentWrapper::get_element_by_id(JS::Interpreter& interpreter)
auto& arguments = interpreter.call_frame().arguments;
if (arguments.is_empty())
return JS::js_null();
auto id = arguments[0].to_string();
auto id = arguments[0].to_string(interpreter);
if (interpreter.exception())
return {};
auto* element = document->get_element_by_id(id);
if (!element)
return JS::js_null();
@ -93,7 +95,9 @@ JS::Value DocumentWrapper::query_selector_all(JS::Interpreter& interpreter)
auto& arguments = interpreter.call_frame().arguments;
if (arguments.is_empty())
return JS::js_null();
auto selector = arguments[0].to_string();
auto selector = arguments[0].to_string(interpreter);
if (interpreter.exception())
return {};
auto elements = document->query_selector_all(selector);
// FIXME: This should be a static NodeList, not a plain JS::Array.
auto* node_list = JS::Array::create(interpreter.global_object());