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