Subject: | JSON::true / JSON::false converted to empty JavaScript object |
Date: | Fri, 24 Apr 2015 08:47:43 -0700 |
To: | bug-JavaScript-V8 [...] rt.cpan.org |
From: | Dave King <tildedave [...] gmail.com> |
It seems that the JSON::true and JSON::false objects are embedded into
JavaScript as empty objects. I understand why this happens - the V8
embedding sees these as objects (because they are), but this behavior
seems counterintuitive enough and not the right thing.
Could the library override the conversions for these special objects,
or barring that, provide some way to do custom conversions so that
clients could override conversions for their own objects?
Here's a snippet that demonstrates the non-intuitive behavior:
use JavaScript::V8;
use JSON;
my $v8context = JavaScript::V8::Context->new();
$v8context->bind(f => JSON::false);
my $res = $v8context->eval('(function() { return (f ? 1 : 0) })()');
print "$res\n";
# returns 1, because JSON::false is bound to the empty object and so truthy
my $res = $v8context->eval('typeof f');
print "$res\n";
# prints 'object', not 'boolean'
--
Regards,
Dave