summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-14 17:31:07 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-14 17:31:07 +0200
commitbbe2d4a2d97ce7968b0985e4f99cdfc01fe5823e (patch)
treeee26f6da1865c600da92c961982f3f06794e45ee /Libraries
parentc5127389caeab57f1f90d722350f691b0365a5fc (diff)
downloadserenity-bbe2d4a2d97ce7968b0985e4f99cdfc01fe5823e.zip
LibJS+LibWeb: Clear exceptions after call'ing JavaScript functions
Decorated Interpreter::call() with [[nodiscard]] to provoke thinking about the returned value at each call site. This is definitely not perfect and we should really start thinking about slimming down the public-facing LibJS interpreter API. Fixes #3136.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibJS/Interpreter.h2
-rw-r--r--Libraries/LibJS/Runtime/Accessor.h3
-rw-r--r--Libraries/LibJS/Runtime/Object.cpp2
-rw-r--r--Libraries/LibWeb/DOM/Node.cpp5
-rw-r--r--Libraries/LibWeb/DOM/Window.cpp8
-rw-r--r--Libraries/LibWeb/DOM/XMLHttpRequest.cpp5
6 files changed, 18 insertions, 7 deletions
diff --git a/Libraries/LibJS/Interpreter.h b/Libraries/LibJS/Interpreter.h
index 99b011e213..b18c490a79 100644
--- a/Libraries/LibJS/Interpreter.h
+++ b/Libraries/LibJS/Interpreter.h
@@ -118,7 +118,7 @@ public:
void enter_scope(const ScopeNode&, ArgumentVector, ScopeType, GlobalObject&);
void exit_scope(const ScopeNode&);
- Value call(Function&, Value this_value, Optional<MarkedValueList> arguments = {});
+ [[nodiscard]] Value call(Function&, Value this_value, Optional<MarkedValueList> arguments = {});
Value construct(Function&, Function& new_target, Optional<MarkedValueList> arguments, GlobalObject&);
CallFrame& push_call_frame()
diff --git a/Libraries/LibJS/Runtime/Accessor.h b/Libraries/LibJS/Runtime/Accessor.h
index 115a405ffa..612472e27e 100644
--- a/Libraries/LibJS/Runtime/Accessor.h
+++ b/Libraries/LibJS/Runtime/Accessor.h
@@ -65,7 +65,8 @@ public:
return;
MarkedValueList arguments(interpreter().heap());
arguments.append(setter_value);
- interpreter().call(*m_setter, this_value, move(arguments));
+ // FIXME: It might be nice if we had a way to communicate to our caller if an exception happened after this.
+ (void)interpreter().call(*m_setter, this_value, move(arguments));
}
void visit_children(Cell::Visitor& visitor) override
diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cpp
index b026dff3be..d5797deec4 100644
--- a/Libraries/LibJS/Runtime/Object.cpp
+++ b/Libraries/LibJS/Runtime/Object.cpp
@@ -737,7 +737,7 @@ bool Object::put(const PropertyName& property_name, Value value, Value receiver)
}
object = object->prototype();
if (interpreter().exception())
- return {};
+ return false;
}
return put_own_property(*this, string_or_symbol, value, default_attributes, PutOwnPropertyMode::Put);
}
diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp
index b6a51ddfe2..0b8cc49b4d 100644
--- a/Libraries/LibWeb/DOM/Node.cpp
+++ b/Libraries/LibWeb/DOM/Node.cpp
@@ -127,7 +127,10 @@ void Node::dispatch_event(NonnullRefPtr<Event> event)
auto* event_wrapper = wrap(global_object, *event);
JS::MarkedValueList arguments(global_object.heap());
arguments.append(event_wrapper);
- document().interpreter().call(function, this_value, move(arguments));
+ auto& interpreter = document().interpreter();
+ (void)interpreter.call(function, this_value, move(arguments));
+ if (interpreter.exception())
+ interpreter.clear_exception();
}
}
diff --git a/Libraries/LibWeb/DOM/Window.cpp b/Libraries/LibWeb/DOM/Window.cpp
index 965812574e..4314432c09 100644
--- a/Libraries/LibWeb/DOM/Window.cpp
+++ b/Libraries/LibWeb/DOM/Window.cpp
@@ -94,7 +94,9 @@ void Window::timer_did_fire(Badge<Timer>, Timer& timer)
}
auto& interpreter = wrapper()->interpreter();
- interpreter.call(timer.callback(), wrapper());
+ (void)interpreter.call(timer.callback(), wrapper());
+ if (interpreter.exception())
+ interpreter.clear_exception();
}
i32 Window::allocate_timer_id(Badge<Timer>)
@@ -123,7 +125,9 @@ i32 Window::request_animation_frame(JS::Function& callback)
JS::MarkedValueList arguments(interpreter.heap());
arguments.append(JS::Value(fake_timestamp));
fake_timestamp += 10;
- interpreter.call(function, {}, move(arguments));
+ (void)interpreter.call(function, {}, move(arguments));
+ if (interpreter.exception())
+ interpreter.clear_exception();
GUI::DisplayLink::unregister_callback(link_id);
});
diff --git a/Libraries/LibWeb/DOM/XMLHttpRequest.cpp b/Libraries/LibWeb/DOM/XMLHttpRequest.cpp
index 6dcf43dde7..b75d272701 100644
--- a/Libraries/LibWeb/DOM/XMLHttpRequest.cpp
+++ b/Libraries/LibWeb/DOM/XMLHttpRequest.cpp
@@ -98,7 +98,10 @@ void XMLHttpRequest::dispatch_event(NonnullRefPtr<DOM::Event> event)
auto* this_value = wrap(global_object, *this);
JS::MarkedValueList arguments(global_object.heap());
arguments.append(wrap(global_object, *event));
- function.interpreter().call(function, this_value, move(arguments));
+ auto& interpreter = function.interpreter();
+ (void)interpreter.call(function, this_value, move(arguments));
+ if (interpreter.exception())
+ interpreter.clear_exception();
}
}
}