Skip to content

Commit a185d00

Browse files
committed
Perlito5 - js3 - use exists() method
1 parent e8d1c6d commit a185d00

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

perlito5.pl

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

src5/lib/Perlito5/Javascript3/Emitter.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,13 +1844,13 @@ package Perlito5::AST::Apply;
18441844
)
18451845
{
18461846
$v = Perlito5::AST::Var->new( sigil => '%', namespace => $v->namespace, name => $v->name );
1847-
return '(' . $v->emit_javascript3() . ').hasOwnProperty(' . Perlito5::Javascript3::autoquote($arg->{index_exp}, $level) . ')';
1847+
return '(' . $v->emit_javascript3() . ').exists(' . Perlito5::Javascript3::autoquote($arg->{index_exp}, $level) . ')';
18481848
}
1849-
return '(' . $v->emit_javascript3() . ').hderef().hasOwnProperty(' . Perlito5::Javascript3::autoquote($arg->{index_exp}, $level) . ')';
1849+
return '(' . $v->emit_javascript3() . ').hderef().exists(' . Perlito5::Javascript3::autoquote($arg->{index_exp}, $level) . ')';
18501850
}
18511851
if ($arg->isa( 'Perlito5::AST::Call' )) {
18521852
if ( $arg->method eq 'postcircumfix:<{ }>' ) {
1853-
return '(' . $arg->invocant->emit_javascript3() . ').hderef().hasOwnProperty(' . Perlito5::Javascript3::autoquote($arg->{arguments}, $level) . ')';
1853+
return '(' . $arg->invocant->emit_javascript3() . ').hderef().exists(' . Perlito5::Javascript3::autoquote($arg->{arguments}, $level) . ')';
18541854
}
18551855
}
18561856
},

src5/lib/Perlito5/Javascript3/Runtime.pm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ function p5Hash(o) {
465465
}
466466
return out;
467467
};
468+
this.exists = function(i) {
469+
return this._hash_.hasOwnProperty(i);
470+
};
468471
this.hset = function(i, v) {
469472
if (this._hash_[i] instanceof p5Scalar) {
470473
this._hash_[i].assign(v);

0 commit comments

Comments
 (0)