Age | Commit message (Collapse) | Author |
|
types: fix potential use after free on adding keys during iteration
|
|
When keys are added to the object currently being iterated by a for loop,
the insert operation might cause a hashtable resize with a subsequent
memory reallocation and a different table base pointer, clobbering the
entry pointers held by iterators pointing to the containing object of the
resized table.
In order to address this issue while keeping the iteration overhead low,
extend the object key insert logic to check whether the insertion will
trigger a reallocation and backup and restore the iterator pointers when
needed.
This slightly increases the size of the iterator states but the overhead
for this should be neglectible as there'll only be a low amount of
concurrently active iterations at any time.
Fixes: #230
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
When converting numeric strings into numbers, ensure that only optional
trailing whitespace follows and no other characters.
Fixes: #231
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Ensure that unquoted property names following spread expressions in object
declaration literals are not treated as keywords.
Prior to this fix, an expression such as `{ ...someobj, default: 1 }` would
result in a compile time syntax error.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
|
|
When removing locals from all scopes, upvalues need to be considered like
in uc_compiler_leave_scope(). Closing them is required to avoid leaving
lingering references to stack values that went out of scope, which would
lead to invalid memory accesses in subsequent code when such upvalues are
used by closures.
Fixes: #187
Signed-off-by: Felix Fietkau <nbd@nbd.name>
[add testcase, reword commit message]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
ECMAScript allows using `as` and `from` as identifiers so follow suit
and don't treat them specially while parsing. Extend the compiler logic
instead to check for TK_LABEL tokens with the expected value to properly
parse import and export statements.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
The `%g` printf format used for serializing double values into strings
will not include any decimal place if the value happens to be integral,
leading to an unwanted double to integer conversion when serializing
and subsequently deserializing an integral double value as JSON.
Solve this issue by checking the serialized string result for a decimal
point or exponential notation and appending `.0` if neither is found.
Ref: #173
Suggested-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
The existing `ucv_compare()` implementation utilized `strcmp()` to compare
two ucode string values, which may lead to incorrect results for strings
containing null bytes as the comparison prematurely aborts when encountering
the first null.
Rework the string comparison logic to use `memcmp()` for comparing both ucv
strings with each other in order to ensure that expressions such as
`"" == "\u0000"` lead to the expected `false` result.
Ref: https://github.com/openwrt/luci/issues/6530
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
- When skipping the interpreter line, don't count it's newline twice
- Fix reporting byte offsets beyond the end of line
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Track last emitted statement type in compiled code and only generate final
`return null` opcodes if there is no preceeding `return` statement.
Also use this statement tracking to avoid emitting invalid return opcodes
for arrow function bodies with trailing empty statements.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
This commit introduces syntax level support for ES6 style module import
and export statements. Imports are resolved at compile time and the
corresponding module code is compiled into the main program.
Also add testcases to cover import and export statement semantics.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|