Skip Menu |
 

This queue is for tickets about the JavaScript CPAN distribution.

Report information
The Basics
Id: 8079
Status: resolved
Priority: 0/
Queue: JavaScript

People
Owner: CLAESJAC [...] cpan.org
Requestors: SREZIC [...] cpan.org
Cc:
AdminCc:

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



Subject: [PATCH] Unicode support
Download (untitled) / with headers
text/plain 374b
It seems that JavaScript.pm cannot handle javascript unicode strings. The attached patch adds unicode/utf-8 support to the .xs portion of the module. I also added a simple script for the test suite. The patch needs some polishment i.e. it should check if the current perl has unicode support built-in and should fallback to the old behaviour otherwise. Regards, Slaven
--- ./t/t80unicode.t.orig 2004-10-21 12:49:53.000000000 +0200 +++ ./t/t80unicode.t 2004-10-21 12:49:37.000000000 +0200 @@ -0,0 +1,12 @@ +use strict; +use Test; +use JavaScript; + +plan tests => 1; + +my $runtime = new JavaScript::Runtime(); +my $context = $runtime->create_context(); + +my $output = 'a="ab\u20accd";'; +my $perlstring = $context->eval($output); +ok($perlstring, "ab\x{20ac}cd"); --- ./JavaScript.xs.orig 2001-08-08 22:13:37.000000000 +0200 +++ ./JavaScript.xs 2004-10-21 12:44:36.000000000 +0200 @@ -877,7 +877,27 @@ JSVALToSV(JSContext *cx, JSObject *obj, } else if(JSVAL_IS_DOUBLE(v)){ sv_setnv(*sv, *JSVAL_TO_DOUBLE(v)); } else if(JSVAL_IS_STRING(v)){ - sv_setpv(*sv, JS_GetStringBytes(JSVAL_TO_STRING(v))); + int unilen, i; + char *p, *utf8s; + jschar *uni = JS_GetStringChars(JSVAL_TO_STRING(v)); + unilen = 0; + for(i = 0; i < JS_GetStringLength(JSVAL_TO_STRING(v)); i++) { + unilen += UNISKIP((UV)(uni[i])); + } + if(unilen == JS_GetStringLength(JSVAL_TO_STRING(v))){ + sv_setpv(*sv, JS_GetStringBytes(JSVAL_TO_STRING(v))); + } else { + Newz(1211, utf8s, unilen+1, char); + p = utf8s; + /* check p! XXX */ + for(i = 0; i < JS_GetStringLength(JSVAL_TO_STRING(v)); i++) { + p = uvchr_to_utf8(p, (UV)(uni[i])); + } + *p = 0; + sv_setpv(*sv, utf8s); + Safefree(utf8s); + SvUTF8_on(*sv); + } } else { warn("Unknown primitive type");
Download (untitled) / with headers
text/plain 428b
Hi, JavaScript.pm 1.00 and later supports UTF-8 strings from JavaScript if the SpiderMonkey that it links against has support for it. I think support for UTF-8 was added to SpiderMonkey 1.7 which is shipped in FireFox 2.0. We now use SM official UTF8 API if available and thus I never integrated your patch. If you still have interest in JavaScript.pm you'll find lots of new goodies in the latest version. Thanks /Claes


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.