JE/Object/Error.pm

filter: Statementstmt 97.7% 44 / 45 Branchbran 100% 2 / 2 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 90.0% 9 / 10 Podpod 100% 3 / 3 totaltotal 84.0% 63 / 75 CC 5 SCAR 7.6
CC
5
Cov
89%
new
4.2
_new_subclass_constructor
2.0
value
2.0
CRAP 2.1
« JE/Object/Boolean.pm ↑ Summary JavaScript/Engine.pm »
1 package JE::Object::Error;
2  
3 101 our $VERSION = '0.066';
4  
5  
6 101 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 101 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 101 our @ISA = 'JE::Object';
10  
11 101 require JE::Object;
12 101 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<SEE ALSO>, below.)
38  
39 =head1 METHODS
40  
41 See L<JE::Types> for descriptions of most of the methods. Only what
42 is specific to JE::Object::Error is explained here.
43  
44 The C<value> 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 337 ▶sub new {
Subroutine new: called CC=4 SCAR=14.3
Pod documented
52 337 my($class, $global, $val) = @_;
53 337 my($js_class) = $class->name;
54 337 ▶ my $self = $class->SUPER::new($global, {
Condition33%1/3
$global->prototype_for($js_class) || $global->prop($js_class)->prop('prototype')
l!l&&r!l&&!r
33700
MC/DC0%0/2
$global->prototype_for($js_class) || $global->prop($js_class)->prop('prototype')
$global->prototype_for($js_class) $global->prop($js_class)->prop('prototype')
Truth table33%1/3
A || B
A= $global->prototype_for($js_class)B= $global->prop($js_class)->prop('prototype')
ABresult
1X1
011
000
55 prototype => $global->prototype_for($js_class) ||
56 $global->prop($js_class)->prop('prototype')
57 });
58  
59 337 ▶ $self->prop({
Branch: 1 branch
BranchTrueFalseTotal
if defined $val and ref $val ne "JE::Undefined" 315 22 337
Condition66%2/3
defined $val and ref $val ne "JE::Undefined"
!ll&&!rl&&r
220315
MC/DC50%1/2
defined $val and ref $val ne "JE::Undefined"
defined $val ref $val ne "JE::Undefined"
Truth table66%2/3
A and B
A= defined $valB= ref $val ne "JE::Undefined"
ABresult
0X0
100
111
60 dontenum => 1,
61 name => 'message',
62 value => JE::String->_new($global, $val),
63 }) if defined $val and ref $val ne 'JE::Undefined';
64 337 $self;
65 }
66  
67 0 ▶sub value { $_[0]->method('toString')->value }
Subroutine value: not called CC=1 SCAR=6.9
Pod documented
68  
69 45 ▶sub class { 'Error' }
Subroutine class: called CC=1 SCAR=0.0
Pod documented
70 101 *name = *class;
71  
72 36 ▶sub _new_constructor {
Subroutine _new_constructor: called CC=1 SCAR=0.0
73 36 my $global = shift;
74 8 ▶ my $con = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
75 8 __PACKAGE__->new(@_);
76 36 };
77 36 my $args = ['scope','args'];
78 36 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 36 my $proto = bless $f->prop({
89 name => 'prototype', dontenum => 1, readonly => 1
90 });
91
92 36 $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 31 ▶ function => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
101 31 my $self = shift;
102 JE::String->_new(
103 $$$self{global},
104 31 $self->prop(
105 'name'
106 ) .
107 ': ' .
108 $self->prop(
109 'message' )
110 );
111 }
112 36 }),
113 dontenum => 1,
114 });
115 36 $proto->prop({
116 name => 'name',
117 value => JE::String->_new($global, 'Error'),
118 dontenum => 1,
119 });
120 36 $proto->prop({
121 name => 'message',
122 value => JE::String->_new($global,
123 'Unknown error'),
124 dontenum => 1,
125 });
126  
127 36 weaken $global;
128 36 $f
129 }
130  
131 44 ▶sub _new_subclass_constructor {
Subroutine _new_subclass_constructor: called CC=2 SCAR=7.0
132 44 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 ▶ function =>(sub { $package->new(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
139 44 function_args => ['scope','args'],
140 constructor => # "
141 constructor_args => # "
142 )[ 0..3,0,4,2 ],
143 });
144  
145 44 my $proto = $f->prop({
146 name => 'prototype',
147 dontenum => 1,
148 readonly => 1,
149 });
150 44 $global->prototype_for($name=>$proto);
151 44 bless $proto, $package;
152 44 ▶ $proto->prototype(
Condition33%1/3
$global->prototype_for('Error') || $global->prop('Error')->prop('prototype')
l!l&&r!l&&!r
4400
MC/DC0%0/2
$global->prototype_for('Error') || $global->prop('Error')->prop('prototype')
$global->prototype_for('Error') $global->prop('Error')->prop('prototype')
Truth table33%1/3
A || B
A= $global->prototype_for('Error')B= $global->prop('Error')->prop('prototype')
ABresult
1X1
011
000
153 $global->prototype_for('Error')
154 || $global->prop('Error')->prop('prototype')
155 );
156 44 $proto->prop({
157 name => 'name',
158 value => JE::String->_new($global, $name),
159 dontenum => 1,
160 });
161 44 (my $msg = $name) =~ s/(?!^)([A-Z])(?![A-Z])/ \l$1/g;
162 44 $proto->prop({
163 name => 'message',
164 value => JE::String->_new($global, $msg),
165 dontenum => 1,
166 });
167  
168 44 weaken $global;
169 44 $f;
170 }
171  
172  
173 101 return "a true value";
174  
175 =head1 SEE ALSO
176  
177 =over 4
178  
179 =item L<JE>
180  
181 =item L<JE::Object>
182  
183 =item L<JE::Object::Error::RangeError>
184  
185 =item L<JE::Object::Error::SyntaxError>
186  
187 =item L<JE::Object::Error::TypeError>
188  
189 =item L<JE::Object::Error::URIError>
190  
191 =item L<JE::Object::Error::ReferenceError>
192  
193 =back
194  
195 =cut
196  
197  
198  
199  
« JE/Object/Boolean.pm ↑ Summary JavaScript/Engine.pm »