mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-03-03 03:54:23 +00:00
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:
@@ -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())));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user