Skip to content

Commit d9c699f

Browse files
richardddricharddavison
andauthoredMay 5, 2024
fix class method with name get (bellard#258)
Co-authored-by: Richard Davison <ridaviso@amazon.com>
1 parent 7a2c6f4 commit d9c699f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed
 

‎quickjs.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -22380,7 +22380,8 @@ static int __exception js_parse_property_name(JSParseState *s,
2238022380
if (next_token(s))
2238122381
goto fail1;
2238222382
if (s->token.val == ':' || s->token.val == ',' ||
22383-
s->token.val == '}' || s->token.val == '(') {
22383+
s->token.val == '}' || s->token.val == '(' ||
22384+
s->token.val == '=' ) {
2238422385
is_non_reserved_ident = TRUE;
2238522386
goto ident_found;
2238622387
}

‎tests/test_language.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ function test_class()
335335
assert(S.x === 42);
336336
assert(S.y === 42);
337337
assert(S.z === 42);
338+
339+
class P {
340+
get = () => "123"
341+
}
342+
assert(new P().get() === "123");
338343
};
339344

340345
function test_template()
@@ -362,8 +367,9 @@ function test_template_skip()
362367
function test_object_literal()
363368
{
364369
var x = 0, get = 1, set = 2; async = 3;
365-
a = { get: 2, set: 3, async: 4 };
366-
assert(JSON.stringify(a), '{"get":2,"set":3,"async":4}');
370+
a = { get: 2, set: 3, async: 4, get a(){ return this.get} };
371+
assert(JSON.stringify(a), '{"get":2,"set":3,"async":4,"a":2}');
372+
assert(a.a === 2);
367373

368374
a = { x, get, set, async };
369375
assert(JSON.stringify(a), '{"x":0,"get":1,"set":2,"async":3}');

0 commit comments

Comments
 (0)