mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 17:58:12 +00:00
LibJS: Rework how native functions are called to improve |this| value
Native functions now only get the Interpreter& as an argument. They can then extract |this| along with any indexed arguments it wants from it. This forces functions that want |this| to actually deal with calling interpreter.this_value().to_object(), and dealing with the possibility of a non-object |this|. This is still not great but let's keep massaging it forward.
This commit is contained in:
parent
c209ea1985
commit
7c4e53f31e
25 changed files with 145 additions and 102 deletions
|
@ -24,8 +24,9 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/Function.h>
|
||||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/Runtime/PrimitiveString.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibWeb/Bindings/CanvasRenderingContext2DWrapper.h>
|
||||
|
@ -50,7 +51,8 @@ CanvasRenderingContext2DWrapper::CanvasRenderingContext2DWrapper(CanvasRendering
|
|||
[this](JS::Object*, JS::Value value) {
|
||||
m_impl->set_fill_style(value.to_string());
|
||||
});
|
||||
put_native_function("fillRect", [this](JS::Object*, const Vector<JS::Value>& arguments) {
|
||||
put_native_function("fillRect", [this](JS::Interpreter& interpreter) {
|
||||
auto& arguments = interpreter.call_frame().arguments;
|
||||
if (arguments.size() >= 4) {
|
||||
m_impl->fill_rect(arguments[0].to_i32(), arguments[1].to_i32(), arguments[2].to_i32(), arguments[3].to_i32());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue