Skip Menu |
 

This queue is for tickets about the JavaScript-V8 CPAN distribution.

Report information
The Basics
Id: 103943
Status: open
Priority: 0/
Queue: JavaScript-V8

People
Owner: Nobody in particular
Requestors: tildedave [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



MIME-Version: 1.0
X-Spam-Status: No, score=-2.699 tagged_above=-99.9 required=10 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=ham
X-Spam-Flag: NO
content-type: text/plain; charset="utf-8"
Message-ID: <CAF3xSCZkBWD11cZ0_DT_=_JcVaQQXRcBLB4v_9u2==Y0wKjkbg [...] mail.gmail.com>
X-Received: by 10.112.142.232 with SMTP id rz8mr7203457lbb.74.1429890463591; Fri, 24 Apr 2015 08:47:43 -0700 (PDT)
X-Virus-Scanned: Debian amavisd-new at bestpractical.com
X-Spam-Score: -2.699
Received: from localhost (localhost [127.0.0.1]) by hipster.bestpractical.com (Postfix) with ESMTP id AF827240411 for <cpan-bug+JavaScript-V8 [...] hipster.bestpractical.com>; Fri, 24 Apr 2015 11:47:58 -0400 (EDT)
Received: from hipster.bestpractical.com ([127.0.0.1]) by localhost (hipster.bestpractical.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gce3PIrD5akI for <cpan-bug+JavaScript-V8 [...] hipster.bestpractical.com>; Fri, 24 Apr 2015 11:47:57 -0400 (EDT)
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by hipster.bestpractical.com (Postfix) with SMTP id 6EC182400D8 for <bug-JavaScript-V8 [...] rt.cpan.org>; Fri, 24 Apr 2015 11:47:57 -0400 (EDT)
Received: (qmail 11951 invoked by alias); 24 Apr 2015 15:47:53 -0000
Received: from mail-la0-f51.google.com (HELO mail-la0-f51.google.com) (209.85.215.51) by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Fri, 24 Apr 2015 08:47:48 -0700
Received: by layy10 with SMTP id y10so38377633lay.0 for <bug-JavaScript-V8 [...] rt.cpan.org>; Fri, 24 Apr 2015 08:47:43 -0700 (PDT)
Received: by 10.114.29.36 with HTTP; Fri, 24 Apr 2015 08:47:43 -0700 (PDT)
Authentication-Results: hipster.bestpractical.com (amavisd-new); dkim=pass header.i= [...] gmail.com
Delivered-To: cpan-bug+JavaScript-V8 [...] hipster.bestpractical.com
Subject: JSON::true / JSON::false converted to empty JavaScript object
Return-Path: <tildedave [...] gmail.com>
X-RT-Mail-Extension: javascript-v8
X-Original-To: cpan-bug+JavaScript-V8 [...] hipster.bestpractical.com
X-Spam-Check-BY: la.mx.develooper.com
Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=zjGjsR9mcT1FNEYVDDSXjcQXXoKDpKfSPrqbgwDBM/U=; b=Sn/b/9W1Ywhd7JkdS6FStkHDb/L3VI4ryR3NTLpY06gG7vh2nP+3/uyEEo8Ha9LAUr js+Ylhsg66ZnYp5PvltdnyI92NB1LOUjt7PIGNMIocS1S7qUE6H1rdLwB3Pk/EVR6wIl Ud23aKJ4RN+O4IuxqZ3R/Q2do+s6RepePWjFld0kak32EkjZeqntkUF8x2m6kbsjyjCY oCyl6FE/533Ab1aBT/8hU8Que5DzRtkBJ26aHKAJ6Z3iTolbeSzgN0iQMcM5WtKZq4i/ ARwitg3GauO2VDN2angqu2uGUdnSZNUT+YhGvTZjqX+VTNr9MkBDm9v1VbjumAZvbYNt oTUA==
Date: Fri, 24 Apr 2015 08:47:43 -0700
X-Spam-Level:
To: bug-JavaScript-V8 [...] rt.cpan.org
From: Dave King <tildedave [...] gmail.com>
X-RT-Original-Encoding: utf-8
X-RT-Interface: Email
Content-Length: 912
Download (untitled) / with headers
text/plain 912b
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
MIME-Version: 1.0
In-Reply-To: <CAF3xSCZkBWD11cZ0_DT_=_JcVaQQXRcBLB4v_9u2==Y0wKjkbg [...] mail.gmail.com>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <CAF3xSCZkBWD11cZ0_DT_=_JcVaQQXRcBLB4v_9u2==Y0wKjkbg [...] mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-14249-1450133655-521.103943-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 1266
Download (untitled) / with headers
text/plain 1.2k
On Fri Apr 24 11:47:59 2015, tildedave@gmail.com wrote: Show quoted text
> 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' >
I've forked DGL's GitHub fork of this code and submitted a pull request[1] that adds Perl JSON::PP::Boolean object -> Javascript boolean primitive handling. It also adds test cases for JSON and JSON::XS. Cheers Brad [1] https://github.com/dgl/javascript-v8/pull/17


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.