package MozRepl::Plugin::JSON2;
use strict;
use parent 'MozRepl::Plugin::Base';
use vars '$VERSION';
=head1 NAME
MozRepl::Plugin::JSON2 - use a 7bit safe json2.js for MozRepl/JS serialization
=head
1 SYNOPSIS
This module only exists to serve as a container for
the MozRepl::RemoteObject JSON encoding/decoding.
=cut
$VERSION = '0.40';
sub setup {
my ($self, $ctx, $args) = @_;
$ctx->ex
json2.js
This distribution contains a hacked, UTF-8 safe version of the json2.js
encoder. This is for channels that don't transfer data in an UTF-8 safe
manner. It is slower than using a native JSON
eturn bridge($self)->unjson($js);
}
=head2 C<< $obj->MozRepl::RemoteObject::Methods::transform_arguments(@args) >>
This method transforms the passed in arguments to their JSON string
representations
s a Javascript string.
=cut
sub transform_arguments {
my $self = shift;
my $json = bridge($self)->json;
map {
if (! defined) {
'null'
} elsif (/^(?:[1-9][0-
id($cb)
} elsif (ref) {
$json->encode($_);
} else {
$json->encode($_)
}
} @_
};
# Helper to centralize the reblessing
package MozRepl::RemoteObject;
use strict;
use Exporter 'import';
use JSON;
use Encode qw(decode);
use Carp qw(croak);
use Scalar::Util qw(refaddr weaken);
=head1 NAME
MozRepl::RemoteObject - treat
function() {
repl.linkedVars = {};
repl.linkedIdNext = 1;
};
repl.JSON_ok = function(val,context) {
return JSON.stringify({
"status":"ok",
"result": repl.wrapResults(val,
{
var res = eval(js);
return repl.JSON_ok(res,context);
} catch(e) {
//for (var x in e) { alert(x)};
return JSON.stringify({
"status":"error",