Skip to content

Commit 99c6719

Browse files
authored
Fix invalid exception for class method with name "get"
Ref: bellard/quickjs#258
1 parent 5ca3c50 commit 99c6719

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

quickjs.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -20810,7 +20810,8 @@ static int __exception js_parse_property_name(JSParseState *s,
2081020810
if (next_token(s))
2081120811
goto fail1;
2081220812
if (s->token.val == ':' || s->token.val == ',' ||
20813-
s->token.val == '}' || s->token.val == '(') {
20813+
s->token.val == '}' || s->token.val == '(' ||
20814+
s->token.val == '=' ) {
2081420815
is_non_reserved_ident = TRUE;
2081520816
goto ident_found;
2081620817
}

tests/test_language.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ function test_class()
336336
assert(S.x === 42);
337337
assert(S.y === 42);
338338
assert(S.z === 42);
339+
class P {
340+
get = () => "123"
341+
}
342+
assert(new P().get() === "123");
339343
};
340344

341345
function test_template()
@@ -363,8 +367,9 @@ function test_template_skip()
363367
function test_object_literal()
364368
{
365369
var x = 0, get = 1, set = 2; async = 3;
366-
a = { get: 2, set: 3, async: 4 };
367-
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);
368373

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

0 commit comments

Comments
 (0)