forked from gonzus/JavaScript-Duktape-XS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle missing elements in a returned array.
Issue gonzus#30: Missing JS array items cause Duktape’s duk_get_prop_index() to return false. In that case pl_duk_to_perl_impl() was neglecting to duk_pop(ctx), which caused the next read on the array to be an attempt to read index 1 from undefined, which triggered an abort(). This fixes that by ensuring that we always duk_pop(ctx) in the relevant piece of code and return Perl undef to represent missing array items.
- Loading branch information
Showing
2 changed files
with
57 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
|
||
use blib; | ||
|
||
use JavaScript::Duktape::XS; | ||
|
||
my $js = JavaScript::Duktape::XS->new(); | ||
|
||
my $got = $js->eval('var foo = []; foo[1] = 123; foo'); | ||
|
||
is_deeply( | ||
$got, | ||
[undef, 123], | ||
'[(empty), 123]', | ||
) or diag explain $got; | ||
|
||
$got = $js->eval('var foo = []; foo[1] = undefined; foo'); | ||
|
||
is_deeply( | ||
$got, | ||
[undef, undef], | ||
'[(empty), undefined]', | ||
) or diag explain $got; | ||
|
||
$got = $js->eval('[undefined, undefined]'); | ||
|
||
is_deeply( | ||
$got, | ||
[undef, undef], | ||
'[undefined, undefined]', | ||
) or diag explain $got; | ||
|
||
done_testing; |