mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-02 06:09:08 +00:00
LibJS: Loosen type system
This commits makes effort towards tolerating some of javascript's quirks when it comes to its type system, note that the interpreter's way of handling type coercion is still not mature at all, for example, we still have to implement NaN instead of just crashing when trying to parse a string and failing.
This commit is contained in:
parent
419d57e492
commit
4d22a142f7
Notes:
sideshowbarker
2024-07-19 08:16:48 +09:00
Author: https://github.com/0xtechnobabble
Commit: 4d22a142f7
Pull-request: https://github.com/SerenityOS/serenity/pull/1470
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/oriko1010
9 changed files with 109 additions and 55 deletions
|
@ -27,9 +27,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibJS/Cell.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Cell.h>
|
||||
#include <LibJS/PrimitiveString.h>
|
||||
#include <LibJS/Value.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
|
@ -57,6 +59,15 @@ public:
|
|||
void set_prototype(Object* prototype) { m_prototype = prototype; }
|
||||
|
||||
bool has_own_property(const String& property_name) const;
|
||||
enum class PreferredType {
|
||||
Default,
|
||||
String,
|
||||
Number,
|
||||
};
|
||||
|
||||
virtual Value value_of() const { return Value(const_cast<Object*>(this)); }
|
||||
virtual Value to_primitive(PreferredType preferred_type = PreferredType::Default) const;
|
||||
virtual Value to_string() const;
|
||||
|
||||
private:
|
||||
HashMap<String, Value> m_properties;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue