LibJS: Add StringPrototype and make it the prototype of StringObject

This patch adds String.prototype.charAt() to demonstrate that prototype
property lookup works, and that you can call a prototype function on an
object, and it will do what you expect. :^)
This commit is contained in:
Andreas Kling 2020-03-15 15:02:49 +01:00
parent f7c15d00c9
commit 2c5b9fb8f9
Notes: sideshowbarker 2024-07-19 08:17:58 +09:00
6 changed files with 109 additions and 0 deletions

View file

@ -24,8 +24,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <LibJS/Heap.h>
#include <LibJS/PrimitiveString.h>
#include <LibJS/StringObject.h>
#include <LibJS/StringPrototype.h>
#include <LibJS/Value.h>
namespace JS {
@ -33,6 +35,7 @@ namespace JS {
StringObject::StringObject(PrimitiveString* string)
: m_string(string)
{
set_prototype(heap().allocate<StringPrototype>());
put("length", Value(static_cast<i32>(m_string->string().length())));
}