/usr/share/perl5/JE/Object/Error.pm is in libje-perl 0.066-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | package JE::Object::Error;
our $VERSION = '0.066';
use strict;
use warnings;
our @ISA = 'JE::Object';
require JE::Object;
require JE::String;
# ~~~ Need to add support for line number, script name, etc., or perhaps
# just a reference to the corresponding JE::Code object.
=head1 NAME
JE::Object::Error - JavaScript Error object class
=head1 SYNOPSIS
use JE::Object::Error;
# Somewhere in code called by an eval{}
die new JE::Object::Error $global, "(Error message here)";
# Later:
$@->prop('message'); # error message
$@->prop('name'); # 'Error'
"$@"; # 'Error: ' plus the error message
=head1 DESCRIPTION
This class implements JavaScript Error objects for JE. This is the base
class for all JavaScript's native error objects. (See L<SEE ALSO>, below.)
=head1 METHODS
See L<JE::Types> for descriptions of most of the methods. Only what
is specific to JE::Object::Error is explained here.
The C<value> method returns the string S<'Error: '> followed by the error
message. 'Error' will be replaced with the class name (the result of
calling
C<< ->class >>) for subclasses.
=cut
sub new {
my($class, $global, $val) = @_;
my($js_class) = $class->name;
my $self = $class->SUPER::new($global, {
prototype => $global->prototype_for($js_class) ||
$global->prop($js_class)->prop('prototype')
});
$self->prop({
dontenum => 1,
name => 'message',
value => JE::String->_new($global, $val),
}) if defined $val and ref $val ne 'JE::Undefined';
$self;
}
sub value { $_[0]->method('toString')->value }
sub class { 'Error' }
*name = *class;
sub _new_constructor {
my $global = shift;
my $con = sub {
__PACKAGE__->new(@_);
};
my $args = ['scope','args'];
my $f = JE'Object'Function->new({
name => 'Error',
scope => $global,
argnames => ['message'],
function => $con,
function_args => $args,
constructor => $con,
constructor_args => $args,
});
my $proto = bless $f->prop({
name => 'prototype', dontenum => 1, readonly => 1
});
$global->prototype_for('Error',$proto);
$proto->prop({
name => 'toString',
value => JE::Object::Function->new({
scope => $global,
name => 'toString',
length => 0,
function_args => ['this'],
function => sub {
my $self = shift;
JE::String->_new(
$$$self{global},
$self->prop(
'name'
) .
': ' .
$self->prop(
'message' )
);
}
}),
dontenum => 1,
});
$proto->prop({
name => 'name',
value => JE::String->_new($global, 'Error'),
dontenum => 1,
});
$proto->prop({
name => 'message',
value => JE::String->_new($global,
'Unknown error'),
dontenum => 1,
});
weaken $global;
$f
}
sub _new_subclass_constructor {
my($package,$global) = @_;
my $f = JE::Object::Function->new({
name => my $name = $package->name,
scope => $global,
argnames => ['message'],
function =>(sub { $package->new(@_) },
function_args => ['scope','args'],
constructor => # "
constructor_args => # "
)[ 0..3,0,4,2 ],
});
my $proto = $f->prop({
name => 'prototype',
dontenum => 1,
readonly => 1,
});
$global->prototype_for($name=>$proto);
bless $proto, $package;
$proto->prototype(
$global->prototype_for('Error')
|| $global->prop('Error')->prop('prototype')
);
$proto->prop({
name => 'name',
value => JE::String->_new($global, $name),
dontenum => 1,
});
(my $msg = $name) =~ s/(?!^)([A-Z])(?![A-Z])/ \l$1/g;
$proto->prop({
name => 'message',
value => JE::String->_new($global, $msg),
dontenum => 1,
});
weaken $global;
$f;
}
return "a true value";
=head1 SEE ALSO
=over 4
=item L<JE>
=item L<JE::Object>
=item L<JE::Object::Error::RangeError>
=item L<JE::Object::Error::SyntaxError>
=item L<JE::Object::Error::TypeError>
=item L<JE::Object::Error::URIError>
=item L<JE::Object::Error::ReferenceError>
=back
=cut
|