summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/Value.cpp
diff options
context:
space:
mode:
authorMatthew Olsson <matthewcolsson@gmail.com>2020-05-21 11:14:23 -0700
committerAndreas Kling <kling@serenityos.org>2020-05-21 22:56:18 +0200
commit45dfa094e9ab88c4af833674e85a93b704c79988 (patch)
tree8ec3962e3336559a099ed18559cc6eb1efbd1755 /Libraries/LibJS/Runtime/Value.cpp
parenta4d04cc74831e83775b2c4542c270a324b6cb24c (diff)
downloadserenity-45dfa094e9ab88c4af833674e85a93b704c79988.zip
LibJS: Add getter/setter support
This patch adds a GetterSetterPair object. Values can now store pointers to objects of this type. These objects are created when using Object.defineProperty and providing an accessor descriptor.
Diffstat (limited to 'Libraries/LibJS/Runtime/Value.cpp')
-rw-r--r--Libraries/LibJS/Runtime/Value.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp
index 7c19e5529b..dc45ea589b 100644
--- a/Libraries/LibJS/Runtime/Value.cpp
+++ b/Libraries/LibJS/Runtime/Value.cpp
@@ -29,6 +29,7 @@
#include <AK/StringBuilder.h>
#include <LibJS/Heap/Heap.h>
#include <LibJS/Interpreter.h>
+#include <LibJS/Runtime/Accessor.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/BooleanObject.h>
#include <LibJS/Runtime/Error.h>
@@ -63,6 +64,12 @@ Function& Value::as_function()
return static_cast<Function&>(as_object());
}
+Accessor& Value::as_accessor()
+{
+ ASSERT(is_accessor());
+ return static_cast<Accessor&>(*m_value.as_accessor);
+}
+
String Value::to_string_without_side_effects() const
{
if (is_boolean())
@@ -92,6 +99,9 @@ String Value::to_string_without_side_effects() const
if (is_symbol())
return as_symbol().to_string();
+ if (is_accessor())
+ return "<accessor>";
+
ASSERT(is_object());
return String::format("[object %s]", as_object().class_name());
}
@@ -205,6 +215,7 @@ Value Value::to_number(Interpreter& interpreter) const
{
switch (m_type) {
case Type::Empty:
+ case Type::Accessor:
ASSERT_NOT_REACHED();
return {};
case Type::Undefined: