Skip to content

Commit

Permalink
parser: allow numeric literals as object keys
Browse files Browse the repository at this point in the history
Refs: https://github.com/metarhia/jstp/issues/152
PR-URL: metarhia/jstp#223
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: Alexey Orlenko <[email protected]>
Reviewed-By: Dmytro Nechai <[email protected]>
  • Loading branch information
belochub committed Jul 21, 2018
1 parent 1561100 commit bdff719
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/jsrs_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ MaybeLocal<Value> ParseObject(Isolate* isolate,
bool key_mode = true;
*size = end - begin;
MaybeLocal<String> current_key;
MaybeLocal<Value> current_numeric_key;
MaybeLocal<Value> current_value;
size_t current_length = 0;
auto result = Object::New(isolate);
Expand All @@ -734,10 +735,16 @@ MaybeLocal<Value> ParseObject(Isolate* isolate,
has_ended = true;
break;
}
current_key = ParseKeyInObject(isolate,
begin + i,
end,
&current_length);
if (!isdigit(begin[i])) {
current_key = ParseKeyInObject(isolate, begin + i, end,
&current_length);
} else {
current_numeric_key = ParseNumber(isolate, begin + i, end,
&current_length);
current_key = current_numeric_key.IsEmpty() ? MaybeLocal<String>() :
current_numeric_key.ToLocalChecked()->ToString(
isolate->GetCurrentContext());
}
if (current_key.IsEmpty()) {
return MaybeLocal<Value>();
}
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/json5/objects/numeric-literal-key.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
42: true
}

0 comments on commit bdff719

Please sign in to comment.