r24594 - in /branches/upstream/libjavascript-perl/current: Changes JavaScript.xs MANIFEST META.yml lib/JavaScript.pm lib/JavaScript/Context.pm t/34-options.t

gregoa at users.alioth.debian.org gregoa at users.alioth.debian.org
Mon Aug 25 03:02:18 UTC 2008


Author: gregoa
Date: Mon Aug 25 03:02:02 2008
New Revision: 24594

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=24594
Log:
[svn-upgrade] Integrating new upstream version, libjavascript-perl (1.11)

Added:
    branches/upstream/libjavascript-perl/current/t/34-options.t
Modified:
    branches/upstream/libjavascript-perl/current/Changes
    branches/upstream/libjavascript-perl/current/JavaScript.xs
    branches/upstream/libjavascript-perl/current/MANIFEST
    branches/upstream/libjavascript-perl/current/META.yml
    branches/upstream/libjavascript-perl/current/lib/JavaScript.pm
    branches/upstream/libjavascript-perl/current/lib/JavaScript/Context.pm

Modified: branches/upstream/libjavascript-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-perl/current/Changes?rev=24594&op=diff
==============================================================================
--- branches/upstream/libjavascript-perl/current/Changes (original)
+++ branches/upstream/libjavascript-perl/current/Changes Mon Aug 25 03:02:02 2008
@@ -1,5 +1,9 @@
 Revision history for Perl extension JavaScript.
 
+1.11  2008-08-23
+    - Added get_options, has_options and toggle_options so one can enable stuff like strict mode and JIT compilation
+      if the underlying SpiderMonkey supports it (TraceMonkey ftw!).
+      
 1.10  2008-08-11
     - Warn user that JS_THREADSAFE is not what's recommended.
     - Added a native PerlHash type that encapsulates a Perl hash reference in JavaScript.

Modified: branches/upstream/libjavascript-perl/current/JavaScript.xs
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-perl/current/JavaScript.xs?rev=24594&op=diff
==============================================================================
--- branches/upstream/libjavascript-perl/current/JavaScript.xs (original)
+++ branches/upstream/libjavascript-perl/current/JavaScript.xs Mon Aug 25 03:02:02 2008
@@ -426,7 +426,21 @@
     OUTPUT:
         RETVAL
 
-
+U32
+jsc_get_options(cx)
+    PJS_Context *cx;
+    CODE:
+        RETVAL = JS_GetOptions(cx->cx);
+    OUTPUT:
+        RETVAL
+    
+void
+jsc_toggle_options(cx, options)
+    PJS_Context *cx;
+    U32         options;
+    CODE:
+        JS_ToggleOptions(cx->cx, options);
+    
 MODULE = JavaScript     PACKAGE = JavaScript::Script
 
 jsval

Modified: branches/upstream/libjavascript-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-perl/current/MANIFEST?rev=24594&op=diff
==============================================================================
--- branches/upstream/libjavascript-perl/current/MANIFEST (original)
+++ branches/upstream/libjavascript-perl/current/MANIFEST Mon Aug 25 03:02:02 2008
@@ -84,6 +84,7 @@
 t/31-version.t
 t/32-perlarray.t
 t/33-perlhash.t
+t/34-options.t
 t/99-bottles-of-beer.t
 t/lib/DummyClass.pm
 t/pod-coverage.t

Modified: branches/upstream/libjavascript-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-perl/current/META.yml?rev=24594&op=diff
==============================================================================
--- branches/upstream/libjavascript-perl/current/META.yml (original)
+++ branches/upstream/libjavascript-perl/current/META.yml Mon Aug 25 03:02:02 2008
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:                JavaScript
-version:             1.10
+version:             1.11
 abstract:            Perl extension for executing embedded JavaScript
 license:             perl
 author:              

Modified: branches/upstream/libjavascript-perl/current/lib/JavaScript.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-perl/current/lib/JavaScript.pm?rev=24594&op=diff
==============================================================================
--- branches/upstream/libjavascript-perl/current/lib/JavaScript.pm (original)
+++ branches/upstream/libjavascript-perl/current/lib/JavaScript.pm Mon Aug 25 03:02:02 2008
@@ -23,7 +23,7 @@
 
 our %EXPORT_TAGS = ( all => [@EXPORT_OK] );
 
-our $VERSION = "1.10";
+our $VERSION = "1.11";
 
 our $MAXBYTES = 1024 ** 2;
 

Modified: branches/upstream/libjavascript-perl/current/lib/JavaScript/Context.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-perl/current/lib/JavaScript/Context.pm?rev=24594&op=diff
==============================================================================
--- branches/upstream/libjavascript-perl/current/lib/JavaScript/Context.pm (original)
+++ branches/upstream/libjavascript-perl/current/lib/JavaScript/Context.pm Mon Aug 25 03:02:02 2008
@@ -319,6 +319,44 @@
     1;
 }
 
+
+{
+    my %options_by_tag = (
+        strict  => 1,
+        xml     => 1 << 6,
+        jit     => 1 << 11,
+    );
+
+    sub get_options {
+        my ($self) = @_;
+        my $options = jsc_get_options($self->{_impl});
+        return grep { $options & $options_by_tag{$_} } keys %options_by_tag;
+    }
+    
+    sub has_options {
+        my $self = shift;
+    
+        my %options = map { $_ => 1 } $self->get_options;
+        
+        !exists $options{$_} && return 0 for @_;
+
+        return 1;
+    }
+    
+    sub toggle_options {
+        my $self = shift;
+        
+        my $options = 0;
+        for (@_) {
+            $options |= 1 if exists $options_by_tag{lc $_};
+        }
+        
+        jsc_toggle_options($self->{_impl}, $options);
+        
+        1;
+    }
+}
+
 sub _destroy {
     my $self = shift;
     return unless $self->{'_impl'};
@@ -519,8 +557,42 @@
 A list of these can be found at L<http://developer.mozilla.org/en/docs/JSVersion> but may vary 
 depending on the version of your runtime.
 
+=item get_options ( )
+
+Returns a list of the options currently enabled on the context.
+
+=item has_options ( OPTION, ... )
+
+Tests if the options are eneabled on the context.
+
+=item toggle_options ( OPTION, ... )
+
+Toggles the options on the context.
+
 =back
 
+=head2 OPTIONS
+
+A number of options can be set on contexts. The following are understood (case-insensitive):
+
+=over 4
+
+=item strict
+
+Warn on dubious practice.
+
+=item xml
+
+ECMAScript for XML (E4X) support: parse E<lt>!-- --E<gt> as a token, not backward compatible with the comment-hiding hack used in HTML script tags.
+
+=item jit
+
+Enable JIT compilation. Requires a SpiderMonkey with TraceMonkey.
+
+=back
+
+(Descriptions copied from jsapi.h and thus copyrighted under its license)
+
 =begin PRIVATE
 
 =head1 PRIVATE INTERFACE
@@ -587,6 +659,14 @@
 
 Set the version of the context to the one specified in version.
 
+=item jsc_get_options ( PJS_Context *context )
+
+Returns the options set on the undelying JSContext
+
+=item jsc_toggle_options ( PJS_Context *context, U32 options )
+
+Toggle the options on the underlying JSContext
+
 =back
 
 =end PRIVATE

Added: branches/upstream/libjavascript-perl/current/t/34-options.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-perl/current/t/34-options.t?rev=24594&op=file
==============================================================================
--- branches/upstream/libjavascript-perl/current/t/34-options.t (added)
+++ branches/upstream/libjavascript-perl/current/t/34-options.t Mon Aug 25 03:02:02 2008
@@ -1,0 +1,18 @@
+#!perl
+
+use Test::More tests => 4;
+
+use strict;
+use warnings;
+
+use JavaScript;
+
+my $rt = JavaScript::Runtime->new();
+my $cx = $rt->create_context();
+
+is_deeply([$cx->get_options], []);
+
+is($cx->has_options("strict"), 0);
+$cx->toggle_options("strict");
+is_deeply([$cx->get_options], [qw(strict)]);
+is($cx->has_options("strict"), 1);




More information about the Pkg-perl-cvs-commits mailing list