mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-29 15:58:47 +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:
parent
f7c15d00c9
commit
2c5b9fb8f9
Notes:
sideshowbarker
2024-07-19 08:17:58 +09:00
Author: https://github.com/awesomekling
Commit: 2c5b9fb8f9
6 changed files with 109 additions and 0 deletions
|
@ -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())));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue