Skip to content

Commit 0ace21c

Browse files
committed
indentation
unify all indentations in files to 4 speces
1 parent 15cbee3 commit 0ace21c

28 files changed

+965
-965
lines changed

examples/advanced-array.pl

Lines changed: 130 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -13,134 +13,134 @@
1313
## from perl
1414

1515
{
16-
## set some javascript objects
17-
$js->eval(q{
18-
function Users (name, age, isAdmin){
19-
this.name = name;
20-
this.age = age;
21-
this.role = isAdmin;
22-
}
23-
24-
function Roles (role){
25-
this.admin = role.admin;
26-
this.developer = role.developer;
27-
}
28-
});
29-
30-
## getting both Users & Roles objects from
31-
## javascript land as perl objects
32-
my $users = $js->get_object('Users');
33-
my $role = $js->get_object('Roles');
34-
35-
## add userList javascript array
36-
## but this time from perl
37-
$js->set('usersList', [
38-
$users->new('Joe The Admin', 36, $role->new({ admin => true, developer => false })),
39-
$users->new('Doe The Developer', 28, $role->new({ admin => false, developer => true }))
40-
]);
41-
42-
## did we get this right ?
43-
$js->eval(q{
44-
print(usersList[0].name); // => Joe
45-
print(usersList[1].age); // => 28
46-
});
47-
48-
## get userList from perl again!!
49-
## not sure if you ever need to do this :)
50-
my $usersList = $js->get_object('usersList');
51-
52-
## set a map function, we are going to use it
53-
## from javascript to map our userList
54-
## and set admins
55-
$duk->push_perl_function( sub {
56-
57-
# javascript array map prototype pass
58-
# three arguments, (current element, element index, whole array)
59-
# so getting argument at index 0 for each array element
60-
61-
# we need to extract it as javascript object
62-
# because we need to do some stuff with it
63-
# so instead of using to_perl method
64-
# we use to_perl_object
65-
my $user = $duk->to_perl_object(0);
66-
67-
# if his role is admin add isAdmin prop
68-
if ($user->role->admin){
69-
$duk->push_perl($user);
70-
$duk->push_true();
71-
$duk->put_prop_string(-2, "isAdmin");
72-
$duk->pop();
73-
}
74-
75-
# return array element
76-
$duk->push_perl($user);
77-
78-
# tell duktape stack that we are pushing/return something
79-
return 1;
80-
});
81-
82-
## push the above created function to duktape stack
83-
## as a global function with "maps" name
84-
$duk->put_global_string('maps');
85-
86-
## use our maps function from javascript
87-
my $admins = $duk->eval_string(q{ usersList.map(maps); });
88-
89-
## get
90-
$admins = $duk->to_perl_object(-1);
91-
92-
## don't forget to pop eval results
93-
## we already have it mapped to perl
94-
$duk->pop();
95-
96-
## admins should be a javascript array object
97-
## let's check if forEach works
98-
$admins->forEach( sub {
99-
my $user = $duk->to_perl_object(0);
100-
if ($user->isAdmin) {
101-
print "==================================\n";
102-
print "found an admin\n";
103-
print "his name is : ";
104-
print $user->name, "\n";
105-
print "==================================\n";
106-
}
107-
});
108-
109-
## $admin is a javascript array prototype
110-
## so instead of using map from javascript we can
111-
## also use it from perl land too, and we will
112-
## assign new created array to $dev array
113-
my $dev = $admins->map( sub {
114-
my $user = $duk->to_perl_object(0);
115-
if (!$user->isAdmin){
116-
return $user;
117-
}
118-
return false;
119-
});
120-
121-
## again since javascript map function
122-
## creates new Array, $dev is an object to
123-
## javascript Array
124-
$dev->forEach( sub {
125-
my $user = shift;
126-
if ($user == false){
127-
print "** only devs allowed\n";
128-
} else {
129-
print "welcome home ", $user->{name}, "\n";
130-
}
131-
});
132-
133-
print "==================================\n";
134-
## now back to perl again, let's check who's admin
135-
## we can also get list as a perl array
136-
## eval function will not convert results as objects
137-
## it will return as perl data so ..
138-
$admins = $js->eval(q{ usersList.map(maps); });
139-
for (@{$admins}){
140-
if (!$_->{isAdmin}) {
141-
print "found a Developer\n";
142-
print "his name is : ";
143-
print $_->{name}, "\n";
144-
}
145-
}
16+
## set some javascript objects
17+
$js->eval(q{
18+
function Users (name, age, isAdmin){
19+
this.name = name;
20+
this.age = age;
21+
this.role = isAdmin;
22+
}
23+
24+
function Roles (role){
25+
this.admin = role.admin;
26+
this.developer = role.developer;
27+
}
28+
});
29+
30+
## getting both Users & Roles objects from
31+
## javascript land as perl objects
32+
my $users = $js->get_object('Users');
33+
my $role = $js->get_object('Roles');
34+
35+
## add userList javascript array
36+
## but this time from perl
37+
$js->set('usersList', [
38+
$users->new('Joe The Admin', 36, $role->new({ admin => true, developer => false })),
39+
$users->new('Doe The Developer', 28, $role->new({ admin => false, developer => true }))
40+
]);
41+
42+
## did we get this right ?
43+
$js->eval(q{
44+
print(usersList[0].name); // => Joe
45+
print(usersList[1].age); // => 28
46+
});
47+
48+
## get userList from perl again!!
49+
## not sure if you ever need to do this :)
50+
my $usersList = $js->get_object('usersList');
51+
52+
## set a map function, we are going to use it
53+
## from javascript to map our userList
54+
## and set admins
55+
$duk->push_perl_function( sub {
56+
57+
# javascript array map prototype pass
58+
# three arguments, (current element, element index, whole array)
59+
# so getting argument at index 0 for each array element
60+
61+
# we need to extract it as javascript object
62+
# because we need to do some stuff with it
63+
# so instead of using to_perl method
64+
# we use to_perl_object
65+
my $user = $duk->to_perl_object(0);
66+
67+
# if his role is admin add isAdmin prop
68+
if ($user->role->admin){
69+
$duk->push_perl($user);
70+
$duk->push_true();
71+
$duk->put_prop_string(-2, "isAdmin");
72+
$duk->pop();
73+
}
74+
75+
# return array element
76+
$duk->push_perl($user);
77+
78+
# tell duktape stack that we are pushing/return something
79+
return 1;
80+
});
81+
82+
## push the above created function to duktape stack
83+
## as a global function with "maps" name
84+
$duk->put_global_string('maps');
85+
86+
## use our maps function from javascript
87+
my $admins = $duk->eval_string(q{ usersList.map(maps); });
88+
89+
## get
90+
$admins = $duk->to_perl_object(-1);
91+
92+
## don't forget to pop eval results
93+
## we already have it mapped to perl
94+
$duk->pop();
95+
96+
## admins should be a javascript array object
97+
## let's check if forEach works
98+
$admins->forEach( sub {
99+
my $user = $duk->to_perl_object(0);
100+
if ($user->isAdmin) {
101+
print "==================================\n";
102+
print "found an admin\n";
103+
print "his name is : ";
104+
print $user->name, "\n";
105+
print "==================================\n";
106+
}
107+
});
108+
109+
## $admin is a javascript array prototype
110+
## so instead of using map from javascript we can
111+
## also use it from perl land too, and we will
112+
## assign new created array to $dev array
113+
my $dev = $admins->map( sub {
114+
my $user = $duk->to_perl_object(0);
115+
if (!$user->isAdmin){
116+
return $user;
117+
}
118+
return false;
119+
});
120+
121+
## again since javascript map function
122+
## creates new Array, $dev is an object to
123+
## javascript Array
124+
$dev->forEach( sub {
125+
my $user = shift;
126+
if ($user == false){
127+
print "** only devs allowed\n";
128+
} else {
129+
print "welcome home ", $user->{name}, "\n";
130+
}
131+
});
132+
133+
print "==================================\n";
134+
## now back to perl again, let's check who's admin
135+
## we can also get list as a perl array
136+
## eval function will not convert results as objects
137+
## it will return as perl data so ..
138+
$admins = $js->eval(q{ usersList.map(maps); });
139+
for (@{$admins}){
140+
if (!$_->{isAdmin}) {
141+
print "found a Developer\n";
142+
print "his name is : ";
143+
print $_->{name}, "\n";
144+
}
145+
}
146146
}

examples/array.pl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
# check if it's really set in JavaScript
1616
$js->eval(q{
17-
print(numbers[0]); // => 1
18-
print(numbers[4]); // => 5
17+
print(numbers[0]); // => 1
18+
print(numbers[4]); // => 5
1919
});
2020

2121

@@ -34,8 +34,8 @@
3434
# 1 => 3
3535
# 2 => 4
3636
$numbers->forEach(sub {
37-
my ($value, $index, $ar) = @_;
38-
print $index, " => ", $value, "\n";
37+
my ($value, $index, $ar) = @_;
38+
print $index, " => ", $value, "\n";
3939
});
4040

4141
print "We ar now reversed \n";
@@ -46,6 +46,6 @@
4646
# 1 => 3
4747
# 2 => 2
4848
$reversed->forEach(sub {
49-
my ($value, $index, $ar) = @_;
50-
print $index, " => ", $value, "\n";
49+
my ($value, $index, $ar) = @_;
50+
print $index, " => ", $value, "\n";
5151
});

examples/date.pl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
my $duk = $js->duk;
99

1010
$js->eval(q{
11-
var today = new Date();
12-
print(today.getMinutes());
13-
var unixTimestamp = Date.now();
14-
print(unixTimestamp);
11+
var today = new Date();
12+
print(today.getMinutes());
13+
var unixTimestamp = Date.now();
14+
print(unixTimestamp);
1515
});
1616

1717
my $date = $js->get_object('Date');

examples/this.pl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
my $duk = $js->duk;
99

1010
$js->eval(q{
11-
function Person (fname, lname) {
12-
this.firstName = fname;
13-
this.lastName = lname;
14-
this.getName = getName;
15-
}
11+
function Person (fname, lname) {
12+
this.firstName = fname;
13+
this.lastName = lname;
14+
this.getName = getName;
15+
}
1616
});
1717

1818
$js->set('getName', sub {
19-
return this->firstName . ' ' . this->lastName;
19+
return this->firstName . ' ' . this->lastName;
2020
});
2121

2222

t/api/c-constructor.t

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ my $duk = $js->duk;
1212
SET_PRINT_METHOD($duk);
1313

1414
sub my_constructor {
15-
return 0;
15+
return 0;
1616
}
1717

1818
sub test1 {
19-
$duk->push_global_object();
20-
$duk->push_function(\&my_constructor, 0); # constructor (function) */
21-
$duk->push_object(); # prototype object -> [ global cons proto ] */
22-
$duk->push_string("inherited value");
23-
$duk->put_prop_string(-2, "inherited"); # set proto.inherited = "inherited value" */
24-
$duk->put_prop_string(-2, "prototype"); # set cons.prototype = proto; stack -> [ global cons ] */
25-
$duk->put_prop_string(-2, "MyConstructor"); # set global.MyConstructor = cons; stack -> [ global ] */
26-
$duk->pop();
27-
28-
$duk->eval_string("var obj = new MyConstructor(); print(obj.inherited);");
29-
# $duk->dump();
30-
$duk->pop();
31-
32-
printf("top at end: %ld\n", $duk->get_top());
33-
return 0;
19+
$duk->push_global_object();
20+
$duk->push_function(\&my_constructor, 0); # constructor (function) */
21+
$duk->push_object(); # prototype object -> [ global cons proto ] */
22+
$duk->push_string("inherited value");
23+
$duk->put_prop_string(-2, "inherited"); # set proto.inherited = "inherited value" */
24+
$duk->put_prop_string(-2, "prototype"); # set cons.prototype = proto; stack -> [ global cons ] */
25+
$duk->put_prop_string(-2, "MyConstructor"); # set global.MyConstructor = cons; stack -> [ global ] */
26+
$duk->pop();
27+
28+
$duk->eval_string("var obj = new MyConstructor(); print(obj.inherited);");
29+
# $duk->dump();
30+
$duk->pop();
31+
32+
printf("top at end: %ld\n", $duk->get_top());
33+
return 0;
3434
}
3535

3636
TEST_SAFE_CALL($duk, \&test1, 'test1');

t/api/check-type.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ my $i = 0;
2828

2929
my $n = $duk->get_top();
3030
for ($i = 0; $i < $n + 1; $i++) { # end on invalid index on purpose
31-
printf("stack[%ld] --> DUK_TYPE_NUMBER=%ld DUK_TYPE_NONE=%ld\n",
32-
$i, $duk->check_type($i, DUK_TYPE_NUMBER),
33-
$duk->check_type($i, DUK_TYPE_NONE));
31+
printf("stack[%ld] --> DUK_TYPE_NUMBER=%ld DUK_TYPE_NONE=%ld\n",
32+
$i, $duk->check_type($i, DUK_TYPE_NUMBER),
33+
$duk->check_type($i, DUK_TYPE_NONE));
3434
}
3535

3636
test_stdout();

0 commit comments

Comments
 (0)