From 0ace21c403ee55996cdd3d77064d1d625d3d4f4e Mon Sep 17 00:00:00 2001 From: mamod Date: Tue, 24 Jan 2017 20:50:16 +0300 Subject: [PATCH] indentation unify all indentations in files to 4 speces --- examples/advanced-array.pl | 260 +++++++++++++++---------------- examples/array.pl | 12 +- examples/date.pl | 8 +- examples/this.pl | 12 +- t/api/c-constructor.t | 32 ++-- t/api/check-type.t | 6 +- t/api/compile.t | 92 +++++------ t/api/dev-cfunc-name.t | 66 ++++---- t/api/dup.t | 66 ++++---- t/api/eval-string.t | 118 +++++++------- t/api/get.pl | 2 +- t/api/hex.t | 60 +++---- t/api/internal-key-access.t | 12 +- t/api/internal-property-basics.t | 48 +++--- t/api/pcall-perl-function.t | 6 +- t/api/pcall-prop.t | 216 ++++++++++++------------- t/api/push_this.t | 2 +- t/api/pushers.pl | 22 +-- t/api/require-lstring.t | 82 +++++----- t/api/safe-call.t | 98 ++++++------ t/api/safe-to-string.t | 100 ++++++------ t/eval-function.t | 52 +++---- t/helper.pl | 84 +++++----- t/perl-data.t | 82 +++++----- t/prop.t | 10 +- t/safe-call.t | 76 ++++----- t/trycatch.t | 140 ++++++++--------- t/uncaught.t | 166 ++++++++++---------- 28 files changed, 965 insertions(+), 965 deletions(-) diff --git a/examples/advanced-array.pl b/examples/advanced-array.pl index 722fba9..cea6d4c 100644 --- a/examples/advanced-array.pl +++ b/examples/advanced-array.pl @@ -13,134 +13,134 @@ ## from perl { - ## set some javascript objects - $js->eval(q{ - function Users (name, age, isAdmin){ - this.name = name; - this.age = age; - this.role = isAdmin; - } - - function Roles (role){ - this.admin = role.admin; - this.developer = role.developer; - } - }); - - ## getting both Users & Roles objects from - ## javascript land as perl objects - my $users = $js->get_object('Users'); - my $role = $js->get_object('Roles'); - - ## add userList javascript array - ## but this time from perl - $js->set('usersList', [ - $users->new('Joe The Admin', 36, $role->new({ admin => true, developer => false })), - $users->new('Doe The Developer', 28, $role->new({ admin => false, developer => true })) - ]); - - ## did we get this right ? - $js->eval(q{ - print(usersList[0].name); // => Joe - print(usersList[1].age); // => 28 - }); - - ## get userList from perl again!! - ## not sure if you ever need to do this :) - my $usersList = $js->get_object('usersList'); - - ## set a map function, we are going to use it - ## from javascript to map our userList - ## and set admins - $duk->push_perl_function( sub { - - # javascript array map prototype pass - # three arguments, (current element, element index, whole array) - # so getting argument at index 0 for each array element - - # we need to extract it as javascript object - # because we need to do some stuff with it - # so instead of using to_perl method - # we use to_perl_object - my $user = $duk->to_perl_object(0); - - # if his role is admin add isAdmin prop - if ($user->role->admin){ - $duk->push_perl($user); - $duk->push_true(); - $duk->put_prop_string(-2, "isAdmin"); - $duk->pop(); - } - - # return array element - $duk->push_perl($user); - - # tell duktape stack that we are pushing/return something - return 1; - }); - - ## push the above created function to duktape stack - ## as a global function with "maps" name - $duk->put_global_string('maps'); - - ## use our maps function from javascript - my $admins = $duk->eval_string(q{ usersList.map(maps); }); - - ## get - $admins = $duk->to_perl_object(-1); - - ## don't forget to pop eval results - ## we already have it mapped to perl - $duk->pop(); - - ## admins should be a javascript array object - ## let's check if forEach works - $admins->forEach( sub { - my $user = $duk->to_perl_object(0); - if ($user->isAdmin) { - print "==================================\n"; - print "found an admin\n"; - print "his name is : "; - print $user->name, "\n"; - print "==================================\n"; - } - }); - - ## $admin is a javascript array prototype - ## so instead of using map from javascript we can - ## also use it from perl land too, and we will - ## assign new created array to $dev array - my $dev = $admins->map( sub { - my $user = $duk->to_perl_object(0); - if (!$user->isAdmin){ - return $user; - } - return false; - }); - - ## again since javascript map function - ## creates new Array, $dev is an object to - ## javascript Array - $dev->forEach( sub { - my $user = shift; - if ($user == false){ - print "** only devs allowed\n"; - } else { - print "welcome home ", $user->{name}, "\n"; - } - }); - - print "==================================\n"; - ## now back to perl again, let's check who's admin - ## we can also get list as a perl array - ## eval function will not convert results as objects - ## it will return as perl data so .. - $admins = $js->eval(q{ usersList.map(maps); }); - for (@{$admins}){ - if (!$_->{isAdmin}) { - print "found a Developer\n"; - print "his name is : "; - print $_->{name}, "\n"; - } - } + ## set some javascript objects + $js->eval(q{ + function Users (name, age, isAdmin){ + this.name = name; + this.age = age; + this.role = isAdmin; + } + + function Roles (role){ + this.admin = role.admin; + this.developer = role.developer; + } + }); + + ## getting both Users & Roles objects from + ## javascript land as perl objects + my $users = $js->get_object('Users'); + my $role = $js->get_object('Roles'); + + ## add userList javascript array + ## but this time from perl + $js->set('usersList', [ + $users->new('Joe The Admin', 36, $role->new({ admin => true, developer => false })), + $users->new('Doe The Developer', 28, $role->new({ admin => false, developer => true })) + ]); + + ## did we get this right ? + $js->eval(q{ + print(usersList[0].name); // => Joe + print(usersList[1].age); // => 28 + }); + + ## get userList from perl again!! + ## not sure if you ever need to do this :) + my $usersList = $js->get_object('usersList'); + + ## set a map function, we are going to use it + ## from javascript to map our userList + ## and set admins + $duk->push_perl_function( sub { + + # javascript array map prototype pass + # three arguments, (current element, element index, whole array) + # so getting argument at index 0 for each array element + + # we need to extract it as javascript object + # because we need to do some stuff with it + # so instead of using to_perl method + # we use to_perl_object + my $user = $duk->to_perl_object(0); + + # if his role is admin add isAdmin prop + if ($user->role->admin){ + $duk->push_perl($user); + $duk->push_true(); + $duk->put_prop_string(-2, "isAdmin"); + $duk->pop(); + } + + # return array element + $duk->push_perl($user); + + # tell duktape stack that we are pushing/return something + return 1; + }); + + ## push the above created function to duktape stack + ## as a global function with "maps" name + $duk->put_global_string('maps'); + + ## use our maps function from javascript + my $admins = $duk->eval_string(q{ usersList.map(maps); }); + + ## get + $admins = $duk->to_perl_object(-1); + + ## don't forget to pop eval results + ## we already have it mapped to perl + $duk->pop(); + + ## admins should be a javascript array object + ## let's check if forEach works + $admins->forEach( sub { + my $user = $duk->to_perl_object(0); + if ($user->isAdmin) { + print "==================================\n"; + print "found an admin\n"; + print "his name is : "; + print $user->name, "\n"; + print "==================================\n"; + } + }); + + ## $admin is a javascript array prototype + ## so instead of using map from javascript we can + ## also use it from perl land too, and we will + ## assign new created array to $dev array + my $dev = $admins->map( sub { + my $user = $duk->to_perl_object(0); + if (!$user->isAdmin){ + return $user; + } + return false; + }); + + ## again since javascript map function + ## creates new Array, $dev is an object to + ## javascript Array + $dev->forEach( sub { + my $user = shift; + if ($user == false){ + print "** only devs allowed\n"; + } else { + print "welcome home ", $user->{name}, "\n"; + } + }); + + print "==================================\n"; + ## now back to perl again, let's check who's admin + ## we can also get list as a perl array + ## eval function will not convert results as objects + ## it will return as perl data so .. + $admins = $js->eval(q{ usersList.map(maps); }); + for (@{$admins}){ + if (!$_->{isAdmin}) { + print "found a Developer\n"; + print "his name is : "; + print $_->{name}, "\n"; + } + } } diff --git a/examples/array.pl b/examples/array.pl index 5de88ab..1a3fb49 100644 --- a/examples/array.pl +++ b/examples/array.pl @@ -14,8 +14,8 @@ # check if it's really set in JavaScript $js->eval(q{ - print(numbers[0]); // => 1 - print(numbers[4]); // => 5 + print(numbers[0]); // => 1 + print(numbers[4]); // => 5 }); @@ -34,8 +34,8 @@ # 1 => 3 # 2 => 4 $numbers->forEach(sub { - my ($value, $index, $ar) = @_; - print $index, " => ", $value, "\n"; + my ($value, $index, $ar) = @_; + print $index, " => ", $value, "\n"; }); print "We ar now reversed \n"; @@ -46,6 +46,6 @@ # 1 => 3 # 2 => 2 $reversed->forEach(sub { - my ($value, $index, $ar) = @_; - print $index, " => ", $value, "\n"; + my ($value, $index, $ar) = @_; + print $index, " => ", $value, "\n"; }); diff --git a/examples/date.pl b/examples/date.pl index a281771..122fbe4 100644 --- a/examples/date.pl +++ b/examples/date.pl @@ -8,10 +8,10 @@ my $duk = $js->duk; $js->eval(q{ - var today = new Date(); - print(today.getMinutes()); - var unixTimestamp = Date.now(); - print(unixTimestamp); + var today = new Date(); + print(today.getMinutes()); + var unixTimestamp = Date.now(); + print(unixTimestamp); }); my $date = $js->get_object('Date'); diff --git a/examples/this.pl b/examples/this.pl index 3f4ce6f..75a636f 100644 --- a/examples/this.pl +++ b/examples/this.pl @@ -8,15 +8,15 @@ my $duk = $js->duk; $js->eval(q{ - function Person (fname, lname) { - this.firstName = fname; - this.lastName = lname; - this.getName = getName; - } + function Person (fname, lname) { + this.firstName = fname; + this.lastName = lname; + this.getName = getName; + } }); $js->set('getName', sub { - return this->firstName . ' ' . this->lastName; + return this->firstName . ' ' . this->lastName; }); diff --git a/t/api/c-constructor.t b/t/api/c-constructor.t index b65618a..d98b0dc 100644 --- a/t/api/c-constructor.t +++ b/t/api/c-constructor.t @@ -12,25 +12,25 @@ my $duk = $js->duk; SET_PRINT_METHOD($duk); sub my_constructor { - return 0; + return 0; } sub test1 { - $duk->push_global_object(); - $duk->push_function(\&my_constructor, 0); # constructor (function) */ - $duk->push_object(); # prototype object -> [ global cons proto ] */ - $duk->push_string("inherited value"); - $duk->put_prop_string(-2, "inherited"); # set proto.inherited = "inherited value" */ - $duk->put_prop_string(-2, "prototype"); # set cons.prototype = proto; stack -> [ global cons ] */ - $duk->put_prop_string(-2, "MyConstructor"); # set global.MyConstructor = cons; stack -> [ global ] */ - $duk->pop(); - - $duk->eval_string("var obj = new MyConstructor(); print(obj.inherited);"); - # $duk->dump(); - $duk->pop(); - - printf("top at end: %ld\n", $duk->get_top()); - return 0; + $duk->push_global_object(); + $duk->push_function(\&my_constructor, 0); # constructor (function) */ + $duk->push_object(); # prototype object -> [ global cons proto ] */ + $duk->push_string("inherited value"); + $duk->put_prop_string(-2, "inherited"); # set proto.inherited = "inherited value" */ + $duk->put_prop_string(-2, "prototype"); # set cons.prototype = proto; stack -> [ global cons ] */ + $duk->put_prop_string(-2, "MyConstructor"); # set global.MyConstructor = cons; stack -> [ global ] */ + $duk->pop(); + + $duk->eval_string("var obj = new MyConstructor(); print(obj.inherited);"); + # $duk->dump(); + $duk->pop(); + + printf("top at end: %ld\n", $duk->get_top()); + return 0; } TEST_SAFE_CALL($duk, \&test1, 'test1'); diff --git a/t/api/check-type.t b/t/api/check-type.t index 77aee5a..1316e26 100644 --- a/t/api/check-type.t +++ b/t/api/check-type.t @@ -28,9 +28,9 @@ my $i = 0; my $n = $duk->get_top(); for ($i = 0; $i < $n + 1; $i++) { # end on invalid index on purpose - printf("stack[%ld] --> DUK_TYPE_NUMBER=%ld DUK_TYPE_NONE=%ld\n", - $i, $duk->check_type($i, DUK_TYPE_NUMBER), - $duk->check_type($i, DUK_TYPE_NONE)); + printf("stack[%ld] --> DUK_TYPE_NUMBER=%ld DUK_TYPE_NONE=%ld\n", + $i, $duk->check_type($i, DUK_TYPE_NUMBER), + $duk->check_type($i, DUK_TYPE_NONE)); } test_stdout(); diff --git a/t/api/compile.t b/t/api/compile.t index ccf0a2e..c205c6d 100644 --- a/t/api/compile.t +++ b/t/api/compile.t @@ -12,67 +12,67 @@ my $duk = $js->duk; SET_PRINT_METHOD($duk); sub test_1 { - $duk->set_top(0); - - $duk->push_string("print('program');\n" - . "function hello() { print('Hello world!'); }\n" - . "123;"); - $duk->push_string("program"); - $duk->compile(0); - $duk->call(0); # [ func filename ] -> [ result ] */ - printf("program result: %lf\n", $duk->get_number(-1)); - $duk->pop(); - - printf("final top: %ld\n", $duk->get_top()); - return 0; + $duk->set_top(0); + + $duk->push_string("print('program');\n" + . "function hello() { print('Hello world!'); }\n" + . "123;"); + $duk->push_string("program"); + $duk->compile(0); + $duk->call(0); # [ func filename ] -> [ result ] */ + printf("program result: %lf\n", $duk->get_number(-1)); + $duk->pop(); + + printf("final top: %ld\n", $duk->get_top()); + return 0; } sub test_2 { - $duk->set_top(0); + $duk->set_top(0); - $duk->push_string("2+3"); - $duk->push_string("eval"); - $duk->compile(DUK_COMPILE_EVAL); - $duk->call(0); # [ func ] -> [ result ] */ - printf("eval result: %lf\n", $duk->get_number(-1)); - $duk->pop(); + $duk->push_string("2+3"); + $duk->push_string("eval"); + $duk->compile(DUK_COMPILE_EVAL); + $duk->call(0); # [ func ] -> [ result ] */ + printf("eval result: %lf\n", $duk->get_number(-1)); + $duk->pop(); - printf("final top: %ld\n", $duk->get_top()); - return 0; + printf("final top: %ld\n", $duk->get_top()); + return 0; } sub test_3 { - $duk->set_top(0); - - $duk->push_string("function (x,y) { return x+y; }"); - $duk->push_string("function"); - $duk->compile(DUK_COMPILE_FUNCTION); - $duk->push_int(5); - $duk->push_int(6); - $duk->call(2); # [ func 5 6 ] -> [ result ] */ - printf("function result: %lf\n", $duk->get_number(-1)); - $duk->pop(); - - printf("final top: %ld\n", $duk->get_top()); - return 0; + $duk->set_top(0); + + $duk->push_string("function (x,y) { return x+y; }"); + $duk->push_string("function"); + $duk->compile(DUK_COMPILE_FUNCTION); + $duk->push_int(5); + $duk->push_int(6); + $duk->call(2); # [ func 5 6 ] -> [ result ] */ + printf("function result: %lf\n", $duk->get_number(-1)); + $duk->pop(); + + printf("final top: %ld\n", $duk->get_top()); + return 0; } sub test_4 { - $duk->set_top(0); + $duk->set_top(0); - # SyntaxError while compiling */ + # SyntaxError while compiling */ - $duk->push_string("print('program');\n" - . "function hello() { print('Hello world!'); }\n" - . "123; obj={"); - $duk->push_string("program"); - my $rc = $duk->pcompile(0); - printf("compile result: %s (rc=%d)\n", $duk->safe_to_string(-1), $rc); - $duk->pop(); + $duk->push_string("print('program');\n" + . "function hello() { print('Hello world!'); }\n" + . "123; obj={"); + $duk->push_string("program"); + my $rc = $duk->pcompile(0); + printf("compile result: %s (rc=%d)\n", $duk->safe_to_string(-1), $rc); + $duk->pop(); - printf("final top: %ld\n", $duk->get_top()); - return 0; + printf("final top: %ld\n", $duk->get_top()); + return 0; } diff --git a/t/api/dev-cfunc-name.t b/t/api/dev-cfunc-name.t index 3f5cf8d..0aa4534 100644 --- a/t/api/dev-cfunc-name.t +++ b/t/api/dev-cfunc-name.t @@ -13,53 +13,53 @@ my $js = JavaScript::Duktape->new(); my $duk = $js->duk; SET_PRINT_METHOD($duk); sub my_func { - # die; - $duk->push_current_function(); - $duk->get_prop_string(-1, "name"); - printf("my name is: '%s'\n", $duk->safe_to_string(-1)); - $duk->pop_2(); + # die; + $duk->push_current_function(); + $duk->get_prop_string(-1, "name"); + printf("my name is: '%s'\n", $duk->safe_to_string(-1)); + $duk->pop_2(); - return -7; + return -7; } sub test_without_name { - $duk->push_c_function(\&my_func, 0); - $duk->put_global_string("MyFunc"); + $duk->push_c_function(\&my_func, 0); + $duk->put_global_string("MyFunc"); - $duk->eval_string_noresult( - "try {\n" - . " [1].forEach(MyFunc);\n" - . "} catch (e) {\n" - . " print(sanitize(e.stack || e));\n" - . "}\n" - ); + $duk->eval_string_noresult( + "try {\n" + . " [1].forEach(MyFunc);\n" + . "} catch (e) {\n" + . " print(sanitize(e.stack || e));\n" + . "}\n" + ); - return 0; + return 0; } sub test_with_name { - $duk->get_global_string("MyFunc"); - $duk->push_string("name"); - $duk->push_string("my_func"); - $duk->def_prop(-3, DUK_DEFPROP_HAVE_VALUE); - $duk->pop(); + $duk->get_global_string("MyFunc"); + $duk->push_string("name"); + $duk->push_string("my_func"); + $duk->def_prop(-3, DUK_DEFPROP_HAVE_VALUE); + $duk->pop(); - $duk->eval_string_noresult( - "try {\n" - . " [1].forEach(MyFunc);\n" - . "} catch (e) {\n" - . " print(sanitize(e.stack || e));\n" - . "}\n" - ); + $duk->eval_string_noresult( + "try {\n" + . " [1].forEach(MyFunc);\n" + . "} catch (e) {\n" + . " print(sanitize(e.stack || e));\n" + . "}\n" + ); - return 0; + return 0; } $duk->eval_string_noresult( - "var sanitize = function(v) {\n" - . " v = v.replace(/eval \\S+/, 'eval XXX');\n" - . " return v;\n" - . "}\n" + "var sanitize = function(v) {\n" + . " v = v.replace(/eval \\S+/, 'eval XXX');\n" + . " return v;\n" + . "}\n" ); TEST_SAFE_CALL($duk, \&test_without_name, 'test_without_name'); diff --git a/t/api/dup.t b/t/api/dup.t index 3852417..0239538 100644 --- a/t/api/dup.t +++ b/t/api/dup.t @@ -15,63 +15,63 @@ my $duk = $js->duk; sub test_1 { - $duk->set_top(0); + $duk->set_top(0); - $duk->push_int(123); + $duk->push_int(123); - $duk->push_int(234); - $duk->dup(-2); #-> [ 123 234 123 ] */ - $duk->dup_top(); # -> [ 123 234 123 123 ] */ + $duk->push_int(234); + $duk->dup(-2); #-> [ 123 234 123 ] */ + $duk->dup_top(); # -> [ 123 234 123 123 ] */ - my $n = $duk->get_top(); - for (my $i = 0; $i < $n; $i++) { - printf("%ld: %s\n", $i, $duk->to_string($i)); - } + my $n = $duk->get_top(); + for (my $i = 0; $i < $n; $i++) { + printf("%ld: %s\n", $i, $duk->to_string($i)); + } - printf("final top: %ld\n", $duk->get_top()); - return 0; + printf("final top: %ld\n", $duk->get_top()); + return 0; } sub test_2a { - $duk->set_top(0); + $duk->set_top(0); - $duk->push_int(123); - $duk->push_int(234); - $duk->dup(-3); # out of bounds + $duk->push_int(123); + $duk->push_int(234); + $duk->dup(-3); # out of bounds - printf("final top: %ld\n", $duk->get_top()); - return 0; + printf("final top: %ld\n", $duk->get_top()); + return 0; } sub test_2b { - $duk->set_top(0); + $duk->set_top(0); - $duk->push_int(123); - $duk->push_int(234); - $duk->dup(2); # out of bounds */ + $duk->push_int(123); + $duk->push_int(234); + $duk->dup(2); # out of bounds */ - printf("final top: %ld\n", $duk->get_top()); - return 0; + printf("final top: %ld\n", $duk->get_top()); + return 0; } sub test_2c { - $duk->set_top(0); + $duk->set_top(0); - $duk->push_int(123); - $duk->push_int(234); - $duk->dup(-2147483648); #invalid index + $duk->push_int(123); + $duk->push_int(234); + $duk->dup(-2147483648); #invalid index - printf("final top: %ld\n", $duk->get_top()); - return 0; + printf("final top: %ld\n", $duk->get_top()); + return 0; } sub test_3a { - $duk->set_top(0); + $duk->set_top(0); - $duk->dup_top(); #empty + $duk->dup_top(); #empty - printf("final top: %ld\n", $duk->get_top()); - return 0; + printf("final top: %ld\n", $duk->get_top()); + return 0; } TEST_SAFE_CALL($duk, \&test_1, 'test_1'); diff --git a/t/api/eval-string.t b/t/api/eval-string.t index c66c702..561a253 100644 --- a/t/api/eval-string.t +++ b/t/api/eval-string.t @@ -12,88 +12,88 @@ my $duk = $js->duk; SET_PRINT_METHOD($duk); sub test_string { - my $rc; + my $rc; - $duk->eval_string("print('Hello world!'); 123;"); - printf("return value is: %lf\n", $duk->get_number(-1)); - $duk->pop(); + $duk->eval_string("print('Hello world!'); 123;"); + printf("return value is: %lf\n", $duk->get_number(-1)); + $duk->pop(); - $duk->eval_string("'testString'.toUpperCase()"); - printf("result is: '%s'\n", $duk->get_string(-1)); - $duk->pop(); + $duk->eval_string("'testString'.toUpperCase()"); + printf("result is: '%s'\n", $duk->get_string(-1)); + $duk->pop(); - $rc = $duk->peval_string("print('Hello world!'); 123;"); - printf("return value is: %s (rc=%ld)\n", $duk->safe_to_string(-1), $rc); - $duk->pop(); + $rc = $duk->peval_string("print('Hello world!'); 123;"); + printf("return value is: %s (rc=%ld)\n", $duk->safe_to_string(-1), $rc); + $duk->pop(); - $rc = $duk->peval_string("throw new Error('eval error');"); - printf("return value is: %s (rc=%ld)\n", $duk->safe_to_string(-1), $rc); - $duk->pop(); + $rc = $duk->peval_string("throw new Error('eval error');"); + printf("return value is: %s (rc=%ld)\n", $duk->safe_to_string(-1), $rc); + $duk->pop(); - $rc = $duk->peval_string("throw new Error('eval error'); obj = {"); - printf("return value is: %s (rc=%ld)\n", $duk->safe_to_string(-1), $rc); - $duk->pop(); + $rc = $duk->peval_string("throw new Error('eval error'); obj = {"); + printf("return value is: %s (rc=%ld)\n", $duk->safe_to_string(-1), $rc); + $duk->pop(); - #noresult variants */ + #noresult variants */ - printf("top=%ld\n", $duk->get_top()); - $duk->eval_string_noresult("print('Hello world!'); 123;"); + printf("top=%ld\n", $duk->get_top()); + $duk->eval_string_noresult("print('Hello world!'); 123;"); - printf("top=%ld\n", $duk->get_top()); - $rc = $duk->peval_string_noresult("print('Hello world!'); 123;"); - printf("no result, rc=%ld\n", $rc); + printf("top=%ld\n", $duk->get_top()); + $rc = $duk->peval_string_noresult("print('Hello world!'); 123;"); + printf("no result, rc=%ld\n", $rc); - printf("top=%ld\n", $duk->get_top()); - $rc = $duk->peval_string_noresult("print('Hello world!'); obj = {"); - printf("no result, rc=%ld\n", $rc); + printf("top=%ld\n", $duk->get_top()); + $rc = $duk->peval_string_noresult("print('Hello world!'); obj = {"); + printf("no result, rc=%ld\n", $rc); - printf("top: %ld\n", $duk->get_top()); - return 0; + printf("top: %ld\n", $duk->get_top()); + return 0; } sub test_lstring { - my $rc; - my $src1 = "print('Hello world!'); 123;@"; - my $src2 = "'testString'.toUpperCase()@"; - my $src3 = "throw new Error('eval error');@"; - my $src4 = "throw new Error('eval error'); obj = {@"; - my $src5 = "print('Hello world!'); obj = {@"; + my $rc; + my $src1 = "print('Hello world!'); 123;@"; + my $src2 = "'testString'.toUpperCase()@"; + my $src3 = "throw new Error('eval error');@"; + my $src4 = "throw new Error('eval error'); obj = {@"; + my $src5 = "print('Hello world!'); obj = {@"; - $duk->eval_lstring($src1, length($src1) - 1); - printf("return value is: %lf\n", $duk->get_number(-1)); - $duk->pop(); + $duk->eval_lstring($src1, length($src1) - 1); + printf("return value is: %lf\n", $duk->get_number(-1)); + $duk->pop(); - $duk->eval_lstring($src2, length($src2) - 1); - printf("result is: '%s'\n", $duk->get_string(-1)); - $duk->pop(); + $duk->eval_lstring($src2, length($src2) - 1); + printf("result is: '%s'\n", $duk->get_string(-1)); + $duk->pop(); - $rc = $duk->peval_lstring($src1, length($src1) - 1); - printf("return value is: %s (rc=%ld)\n", $duk->safe_to_string(-1), $rc); - $duk->pop(); + $rc = $duk->peval_lstring($src1, length($src1) - 1); + printf("return value is: %s (rc=%ld)\n", $duk->safe_to_string(-1), $rc); + $duk->pop(); - $rc = $duk->peval_lstring($src3, length($src3) - 1); - printf("return value is: %s (rc=%ld)\n", $duk->safe_to_string(-1), $rc); - $duk->pop(); + $rc = $duk->peval_lstring($src3, length($src3) - 1); + printf("return value is: %s (rc=%ld)\n", $duk->safe_to_string(-1), $rc); + $duk->pop(); - $rc = $duk->peval_lstring($src4, length($src4) - 1); - printf("return value is: %s (rc=%ld)\n", $duk->safe_to_string(-1), $rc); - $duk->pop(); + $rc = $duk->peval_lstring($src4, length($src4) - 1); + printf("return value is: %s (rc=%ld)\n", $duk->safe_to_string(-1), $rc); + $duk->pop(); - #noresult variants */ + #noresult variants */ - printf("top=%ld\n", $duk->get_top()); - $duk->eval_lstring_noresult($src1, length($src1) - 1); + printf("top=%ld\n", $duk->get_top()); + $duk->eval_lstring_noresult($src1, length($src1) - 1); - printf("top=%ld\n", $duk->get_top()); - $rc = $duk->peval_lstring_noresult($src1, length($src1) - 1); - printf("no result, rc=%ld\n", $rc); + printf("top=%ld\n", $duk->get_top()); + $rc = $duk->peval_lstring_noresult($src1, length($src1) - 1); + printf("no result, rc=%ld\n", $rc); - printf("top=%ld\n", $duk->get_top()); - $rc = $duk->peval_lstring_noresult($src5, length($src5) - 1); - printf("no result, rc=%ld\n", $rc); + printf("top=%ld\n", $duk->get_top()); + $rc = $duk->peval_lstring_noresult($src5, length($src5) - 1); + printf("no result, rc=%ld\n", $rc); - printf("top: %ld\n", $duk->get_top()); - return 0; + printf("top: %ld\n", $duk->get_top()); + return 0; } diff --git a/t/api/get.pl b/t/api/get.pl index a695567..c17987f 100644 --- a/t/api/get.pl +++ b/t/api/get.pl @@ -14,7 +14,7 @@ print Dumper $perl; if ($perl->{falseVal}){ - die $perl->{falseVal}; + die $perl->{falseVal}; } my $ret = $perl->{func}->(9); diff --git a/t/api/hex.t b/t/api/hex.t index fc5163d..d2f5342 100644 --- a/t/api/hex.t +++ b/t/api/hex.t @@ -10,45 +10,45 @@ my $js = JavaScript::Duktape->new(); my $duk = $js->duk; sub test_encode { - $duk->set_top(0); - $duk->push_string("foo"); - $duk->push_int(123); # dummy */ - printf("hex encode: %s\n", $duk->hex_encode(-2)); - printf("top after: %ld\n", $duk->get_top()); # value + dummy */ - return 0; + $duk->set_top(0); + $duk->push_string("foo"); + $duk->push_int(123); # dummy */ + printf("hex encode: %s\n", $duk->hex_encode(-2)); + printf("top after: %ld\n", $duk->get_top()); # value + dummy */ + return 0; } sub test_decode { - $duk->set_top(0); - $duk->push_string("7465737420737472696e67"); - $duk->push_int(321); # dummy */ - $duk->hex_decode(-2); # buffer */ - printf("hex decode: %s\n", $duk->buffer_to_string(-2)); - printf("top after: %ld\n", $duk->get_top()); # value + dummy */ - $duk->set_top(0); - return 0; + $duk->set_top(0); + $duk->push_string("7465737420737472696e67"); + $duk->push_int(321); # dummy */ + $duk->hex_decode(-2); # buffer */ + printf("hex decode: %s\n", $duk->buffer_to_string(-2)); + printf("top after: %ld\n", $duk->get_top()); # value + dummy */ + $duk->set_top(0); + return 0; } sub test_decode_odd_length { - $duk->set_top(0); - $duk->push_string("7465737420737472696e6"); # odd length */ - $duk->push_int(321); # dummy */ - $duk->hex_decode(-2); # buffer */ - printf("hex decode: %s\n", $duk->buffer_to_string(-2)); - printf("top after: %ld\n", $duk->get_top()); # value + dummy */ - $duk->set_top(0); - return 0; + $duk->set_top(0); + $duk->push_string("7465737420737472696e6"); # odd length */ + $duk->push_int(321); # dummy */ + $duk->hex_decode(-2); # buffer */ + printf("hex decode: %s\n", $duk->buffer_to_string(-2)); + printf("top after: %ld\n", $duk->get_top()); # value + dummy */ + $duk->set_top(0); + return 0; } sub test_decode_invalid_char { - $duk->set_top(0); - $duk->push_string("7465737420737g72696e67"); # invalid char */ - $duk->push_int(321); # dummy */ - $duk->hex_decode(-2); # buffer */ - printf("hex decode: %s\n", $duk->buffer_to_string(-2)); - printf("top after: %ld\n", $duk->get_top()); # value + dummy */ - $duk->set_top(0); - return 0; + $duk->set_top(0); + $duk->push_string("7465737420737g72696e67"); # invalid char */ + $duk->push_int(321); # dummy */ + $duk->hex_decode(-2); # buffer */ + printf("hex decode: %s\n", $duk->buffer_to_string(-2)); + printf("top after: %ld\n", $duk->get_top()); # value + dummy */ + $duk->set_top(0); + return 0; } diff --git a/t/api/internal-key-access.t b/t/api/internal-key-access.t index faafcdd..810cb8a 100644 --- a/t/api/internal-key-access.t +++ b/t/api/internal-key-access.t @@ -13,12 +13,12 @@ my $js = JavaScript::Duktape->new(); my $duk = $js->duk; sub test_1 { - $duk->eval_string("new Date(123456)"); - $duk->push_string("\xffValue"); - $duk->get_prop(-2); - printf("Date._Value: %s\n", $duk->safe_to_string(-1)); - printf("final top: %ld\n", $duk->get_top()); - return 0; + $duk->eval_string("new Date(123456)"); + $duk->push_string("\xffValue"); + $duk->get_prop(-2); + printf("Date._Value: %s\n", $duk->safe_to_string(-1)); + printf("final top: %ld\n", $duk->get_top()); + return 0; } TEST_SAFE_CALL($duk, \&test_1, 'test_1'); diff --git a/t/api/internal-property-basics.t b/t/api/internal-property-basics.t index 7b4bf6b..823393d 100644 --- a/t/api/internal-property-basics.t +++ b/t/api/internal-property-basics.t @@ -12,30 +12,30 @@ my $duk = $js->duk; SET_PRINT_METHOD($duk); sub test_1 { - $duk->eval_string("(function (x) { print(Duktape.enc('jx', x)); })"); - $duk->push_object(); - - #Ordinary property */ - $duk->push_int(1); - $duk->put_prop_string(-2, "foo"); # obj.foo = 1 */ - - # /* Internal property \xFF\xFFabc, technically enumerable (based on - # * property attributes) but because of internal property special - # * behavior, does not enumerate. - # */ - - $duk->push_int(2); - $duk->put_prop_string(-2, "\xff\xff" . "abc"); # obj[\xff\xffabc] = 2, internal property */ - - # /* Another property with invalid UTF-8 data but doesn't begin with - # * \xFF => gets enumerated and JX prints out an approximate key. - # */ - - $duk->push_int(3); - $duk->put_prop_string(-2, " \xff" . "bar"); # obj[ \xffbar] = 3, invalid utf-8 but not an internal property */ - $duk->call(1); - printf("final top: %ld\n", $duk->get_top()); - return 0; + $duk->eval_string("(function (x) { print(Duktape.enc('jx', x)); })"); + $duk->push_object(); + + #Ordinary property */ + $duk->push_int(1); + $duk->put_prop_string(-2, "foo"); # obj.foo = 1 */ + + # /* Internal property \xFF\xFFabc, technically enumerable (based on + # * property attributes) but because of internal property special + # * behavior, does not enumerate. + # */ + + $duk->push_int(2); + $duk->put_prop_string(-2, "\xff\xff" . "abc"); # obj[\xff\xffabc] = 2, internal property */ + + # /* Another property with invalid UTF-8 data but doesn't begin with + # * \xFF => gets enumerated and JX prints out an approximate key. + # */ + + $duk->push_int(3); + $duk->put_prop_string(-2, " \xff" . "bar"); # obj[ \xffbar] = 3, invalid utf-8 but not an internal property */ + $duk->call(1); + printf("final top: %ld\n", $duk->get_top()); + return 0; } TEST_SAFE_CALL($duk, \&test_1, 'test_1'); diff --git a/t/api/pcall-perl-function.t b/t/api/pcall-perl-function.t index 6d73786..dce10dc 100644 --- a/t/api/pcall-perl-function.t +++ b/t/api/pcall-perl-function.t @@ -11,9 +11,9 @@ my $duk = $js->duk; sub tt2 { - $duk->require_string(0); - $duk->dump('2'); #never get here - return 0; + $duk->require_string(0); + $duk->dump('2'); #never get here + return 0; } diff --git a/t/api/pcall-prop.t b/t/api/pcall-prop.t index 30df07c..d6a6af0 100644 --- a/t/api/pcall-prop.t +++ b/t/api/pcall-prop.t @@ -12,148 +12,148 @@ my $duk = $js->duk; SET_PRINT_METHOD($duk); sub test_1 { - # basic success case: own property - $duk->eval_string("({ name: 'me', foo: function (x,y) { print(this.name); return x+y; } })"); # idx 1 - $duk->push_string("foo"); - $duk->push_int(10); - $duk->push_int(11); - my $rc = $duk->pcall_prop(1, 2); - printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); - $duk->pop(); # res - $duk->pop(); # obj - - return 0; + # basic success case: own property + $duk->eval_string("({ name: 'me', foo: function (x,y) { print(this.name); return x+y; } })"); # idx 1 + $duk->push_string("foo"); + $duk->push_int(10); + $duk->push_int(11); + my $rc = $duk->pcall_prop(1, 2); + printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); + $duk->pop(); # res + $duk->pop(); # obj + + return 0; } sub test_2 { - # use plain number as 'this', add function to Number.prototype; non-strict handler - #causes this to be coerced to Number. - - $duk->eval_string("Number.prototype.func_nonstrict = function (x,y) { print(typeof this, this); return x+y; };"); - $duk->pop(); # pop result - $duk->push_int(123); # obj - $duk->push_string("func_nonstrict"); - $duk->push_int(10); - $duk->push_int(11); - my $rc = $duk->pcall_prop(-4, 2); # use relative index for a change - printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); - $duk->pop(); # res - $duk->pop(); # obj - - return 0; + # use plain number as 'this', add function to Number.prototype; non-strict handler + #causes this to be coerced to Number. + + $duk->eval_string("Number.prototype.func_nonstrict = function (x,y) { print(typeof this, this); return x+y; };"); + $duk->pop(); # pop result + $duk->push_int(123); # obj + $duk->push_string("func_nonstrict"); + $duk->push_int(10); + $duk->push_int(11); + my $rc = $duk->pcall_prop(-4, 2); # use relative index for a change + printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); + $duk->pop(); # res + $duk->pop(); # obj + + return 0; } sub test_3 { - # use plain number as 'this', add function to Number.prototype; strict handler - #causes this to remain a plain number. - - $duk->eval_string("Number.prototype.func_strict = function (x,y) { 'use strict'; print(typeof this, this); return x+y; };"); - $duk->pop(); # pop result - $duk->push_int(123); # obj - $duk->push_string("func_strict"); - $duk->push_int(10); - $duk->push_int(11); - my $rc = $duk->pcall_prop(1, 2); - printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); - $duk->pop(); # res - $duk->pop(); # obj - - return 0; + # use plain number as 'this', add function to Number.prototype; strict handler + #causes this to remain a plain number. + + $duk->eval_string("Number.prototype.func_strict = function (x,y) { 'use strict'; print(typeof this, this); return x+y; };"); + $duk->pop(); # pop result + $duk->push_int(123); # obj + $duk->push_string("func_strict"); + $duk->push_int(10); + $duk->push_int(11); + my $rc = $duk->pcall_prop(1, 2); + printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); + $duk->pop(); # res + $duk->pop(); # obj + + return 0; } sub test_4 { - # basic error case - $duk->eval_string("({ name: 'me', foo: function (x,y) { throw new Error('my error'); } })"); # idx 1 - $duk->push_string("foo"); - $duk->push_int(10); - $duk->push_int(11); - my $rc = $duk->pcall_prop(1, 2); - printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); - $duk->pop(); # res - $duk->pop(); # obj - - return 0; + # basic error case + $duk->eval_string("({ name: 'me', foo: function (x,y) { throw new Error('my error'); } })"); # idx 1 + $duk->push_string("foo"); + $duk->push_int(10); + $duk->push_int(11); + my $rc = $duk->pcall_prop(1, 2); + printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); + $duk->pop(); # res + $duk->pop(); # obj + + return 0; } sub test_5 { - # property lookup fails: base value does not allow property lookup - $duk->push_undefined(); - $duk->push_string("foo"); - $duk->push_int(10); - $duk->push_int(11); - my $rc = $duk->pcall_prop(1, 2); - printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); - $duk->pop(); # res - $duk->pop(); # obj - - return 0; + # property lookup fails: base value does not allow property lookup + $duk->push_undefined(); + $duk->push_string("foo"); + $duk->push_int(10); + $duk->push_int(11); + my $rc = $duk->pcall_prop(1, 2); + printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); + $duk->pop(); # res + $duk->pop(); # obj + + return 0; } sub test_6 { - # property lookup fails: getter throws - $duk->eval_string("({ get prop() { throw new RangeError('getter error'); } })"); - $duk->push_string("prop"); - $duk->push_int(10); - $duk->push_int(11); - my $rc = $duk->pcall_prop(1, 2); - printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); - $duk->pop(); # res - $duk->pop(); # obj - - return 0; + # property lookup fails: getter throws + $duk->eval_string("({ get prop() { throw new RangeError('getter error'); } })"); + $duk->push_string("prop"); + $duk->push_int(10); + $duk->push_int(11); + my $rc = $duk->pcall_prop(1, 2); + printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); + $duk->pop(); # res + $duk->pop(); # obj + + return 0; } sub test_7 { - # invalid object index - $duk->eval_string("({ foo: 1, bar: 2 })"); - $duk->push_string("foo"); - $duk->push_int(10); - $duk->push_int(11); - my $rc = $duk->pcall_prop(-6, 2); - printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); - $duk->pop(); # res - $duk->pop(); # obj - - return 0; + # invalid object index + $duk->eval_string("({ foo: 1, bar: 2 })"); + $duk->push_string("foo"); + $duk->push_int(10); + $duk->push_int(11); + my $rc = $duk->pcall_prop(-6, 2); + printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); + $duk->pop(); # res + $duk->pop(); # obj + + return 0; } sub test_8 { - # invalid arg count, causes 'key' to be identified with the object in the stack - $duk->eval_string("({ foo: function () { print('foo called'); } })"); - $duk->push_string("foo"); - $duk->push_int(10); - $duk->push_int(11); - my $rc = $duk->pcall_prop(1, 3); - printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); - $duk->pop(); # res - $duk->pop(); # obj - - return 0; + # invalid arg count, causes 'key' to be identified with the object in the stack + $duk->eval_string("({ foo: function () { print('foo called'); } })"); + $duk->push_string("foo"); + $duk->push_int(10); + $duk->push_int(11); + my $rc = $duk->pcall_prop(1, 3); + printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); + $duk->pop(); # res + $duk->pop(); # obj + + return 0; } sub test_9 { - # Invalid arg count, 'key' would be below start of stack. This - # results in an actual (uncaught) error at the moment, and matches - # the behavior of other protected call API functions. + # Invalid arg count, 'key' would be below start of stack. This + # results in an actual (uncaught) error at the moment, and matches + # the behavior of other protected call API functions. - $duk->eval_string("({ foo: function () { print('foo called'); } })"); - $duk->push_string("foo"); - $duk->push_int(10); - $duk->push_int(11); - my $rc = $duk->pcall_prop(1, 8); - printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); - $duk->pop(); # res - $duk->pop(); # obj + $duk->eval_string("({ foo: function () { print('foo called'); } })"); + $duk->push_string("foo"); + $duk->push_int(10); + $duk->push_int(11); + my $rc = $duk->pcall_prop(1, 8); + printf("rc=%d, result='%s'\n", $rc, $duk->safe_to_string(-1)); + $duk->pop(); # res + $duk->pop(); # obj - return 0; + return 0; } $duk->push_string("foo"); diff --git a/t/api/push_this.t b/t/api/push_this.t index 81c25c6..d7c37bb 100644 --- a/t/api/push_this.t +++ b/t/api/push_this.t @@ -10,7 +10,7 @@ my $js = JavaScript::Duktape->new(); my $duk = $js->duk; sub func { - eval{}; + eval{}; $duk->push_this(); my $t = $duk->get_type(-1); printf("this binding: type=%ld, value='%s'\n", $t, $duk->to_string(-1)); diff --git a/t/api/pushers.pl b/t/api/pushers.pl index 0d72df5..76edb6e 100644 --- a/t/api/pushers.pl +++ b/t/api/pushers.pl @@ -11,21 +11,21 @@ sub NULL { "\0" } sub PRINTTOP { - my $clen = 0; - if ($duk->is_string(-1)) { - $clen = $duk->get_length(-1); - } + my $clen = 0; + if ($duk->is_string(-1)) { + $clen = $duk->get_length(-1); + } - printf("top=%ld type=%ld bool=%d num=%.6lf clen=%ld str='%s' str-is-NULL=%d ptr-is-NULL=%d\n", - $duk->get_top(), $duk->get_type(-1), $duk->get_boolean(-1), - $duk->get_number(-1), $clen, $duk->get_string(-1), - ($duk->get_string(-1) ? 0 : 1), - ($duk->get_pointer(-1) ? 0 : 1)); + printf("top=%ld type=%ld bool=%d num=%.6lf clen=%ld str='%s' str-is-NULL=%d ptr-is-NULL=%d\n", + $duk->get_top(), $duk->get_type(-1), $duk->get_boolean(-1), + $duk->get_number(-1), $clen, $duk->get_string(-1), + ($duk->get_string(-1) ? 0 : 1), + ($duk->get_pointer(-1) ? 0 : 1)); } sub PRINTRESTOP { - printf("-> res is %s\n", ((defined $res) ? "non-NULL" : "NULL")); - PRINTTOP(); + printf("-> res is %s\n", ((defined $res) ? "non-NULL" : "NULL")); + PRINTTOP(); } $duk->push_undefined(); PRINTTOP(); diff --git a/t/api/require-lstring.t b/t/api/require-lstring.t index 991402b..2cc02ac 100644 --- a/t/api/require-lstring.t +++ b/t/api/require-lstring.t @@ -10,73 +10,73 @@ my $js = JavaScript::Duktape->new(); my $duk = $js->duk; sub dump_string { - my $p = shift; - printf("string:%s%s\n", (length $p == 0 ? "" : " "), $p); + my $p = shift; + printf("string:%s%s\n", (length $p == 0 ? "" : " "), $p); } sub dump_string_size { - my ($p, $sz) = @_; - printf("string:%s%s (%ld)\n", (length $p == 0 ? "" : " "), $p, $sz); + my ($p, $sz) = @_; + printf("string:%s%s (%ld)\n", (length $p == 0 ? "" : " "), $p, $sz); } sub test_1 { - my $p; - my $sz; + my $p; + my $sz; - $duk->set_top(0); - $duk->push_lstring("foo\0bar", 7); - $duk->push_string(""); + $duk->set_top(0); + $duk->push_lstring("foo\0bar", 7); + $duk->push_string(""); - $sz = 0xdeadbeef; - $p = $duk->require_lstring(0, $sz); - dump_string_size($p, $sz); + $sz = 0xdeadbeef; + $p = $duk->require_lstring(0, $sz); + dump_string_size($p, $sz); - $sz = 0xdeadbeef; - $p = $duk->require_lstring(0, $sz); - dump_string($p); + $sz = 0xdeadbeef; + $p = $duk->require_lstring(0, $sz); + dump_string($p); - $sz = "\0"; - $p = $duk->require_lstring(1, $sz); - dump_string_size($p, $sz); + $sz = "\0"; + $p = $duk->require_lstring(1, $sz); + dump_string_size($p, $sz); - $sz = 'uuu'; - $p = $duk->require_lstring(1, $sz); - dump_string($p); - return 0; + $sz = 'uuu'; + $p = $duk->require_lstring(1, $sz); + dump_string($p); + return 0; } sub test_2 { - my $p; - my $sz; + my $p; + my $sz; - $duk->set_top(0); - $duk->push_null(); + $duk->set_top(0); + $duk->push_null(); - $p = $duk->require_lstring(0, $sz); - printf("string: %s (%ld)\n", $p, $sz); - return 0; + $p = $duk->require_lstring(0, $sz); + printf("string: %s (%ld)\n", $p, $sz); + return 0; } sub test_3 { - my $p; - my $sz; + my $p; + my $sz; - $duk->set_top(0); + $duk->set_top(0); - $p = $duk->require_lstring(0, $sz); - printf("string: %s (%ld)\n", $p, $sz); - return 0; + $p = $duk->require_lstring(0, $sz); + printf("string: %s (%ld)\n", $p, $sz); + return 0; } sub test_4 { - my $p; - my $sz; + my $p; + my $sz; - $duk->set_top(0); + $duk->set_top(0); - $p = $duk->require_lstring(-2147483648, $sz); - printf("string: %s (%ld)\n", $p, $sz); - return 0; + $p = $duk->require_lstring(-2147483648, $sz); + printf("string: %s (%ld)\n", $p, $sz); + return 0; } diff --git a/t/api/safe-call.t b/t/api/safe-call.t index 504ffae..53d55cd 100644 --- a/t/api/safe-call.t +++ b/t/api/safe-call.t @@ -14,63 +14,63 @@ my $js = JavaScript::Duktape->new(); my $duk = $js->duk; sub test_1 { - my $duk = shift; - my $a = $duk->get_number(-3); - my $b = $duk->get_number(-2); - my $c = $duk->get_number(-1); + my $duk = shift; + my $a = $duk->get_number(-3); + my $b = $duk->get_number(-2); + my $c = $duk->get_number(-1); - $duk->push_number($a + $b); + $duk->push_number($a + $b); - # just one return value - return 1; + # just one return value + return 1; } sub test_2 { - # TODO duk->error - # $duk->error(DUK_ERR_INTERNAL_ERROR, "test_2 error"); - $duk->eval_string("throw new Error('test_2 error');"); - printf("1st return value: %s\n", $duk->to_string(-1)); - return 0; + # TODO duk->error + # $duk->error(DUK_ERR_INTERNAL_ERROR, "test_2 error"); + $duk->eval_string("throw new Error('test_2 error');"); + printf("1st return value: %s\n", $duk->to_string(-1)); + return 0; } sub test { - my $rc; - - $duk->set_top(0); - - $duk->push_string("foo"); # dummy - - # /* success case */ - $duk->push_int(10); - $duk->push_int(11); - $duk->push_int(12); - - $rc = $duk->safe_call(\&test_1, 3 , 2 ); - - if ($rc == 0) { - printf("1st return value: %s\n", $duk->to_string(-2)); # 21 - printf("2nd return value: %s\n", $duk->to_string(-1)); # undefined - } else { - printf("error: %s\n", $duk->to_string(-1)); - } - $duk->pop_2(); - - # error case - $duk->push_int(10); - $duk->push_int(11); - $duk->push_int(12); - $rc = $duk->safe_call(\&test_2, 3 , 2); - if ($rc == 0) { - printf("1st return value: %s\n", $duk->to_string(-2)); # 21 - printf("2nd return value: %s\n", $duk->to_string(-1)); # undefined - } else { - printf("error: %s\n", $duk->to_string(-2)); - } - $duk->pop_2(); - - # /* XXX: also test invalid input stack shapes (like not enough args) */ - - printf("final top: %ld\n", $duk->get_top()); + my $rc; + + $duk->set_top(0); + + $duk->push_string("foo"); # dummy + + # /* success case */ + $duk->push_int(10); + $duk->push_int(11); + $duk->push_int(12); + + $rc = $duk->safe_call(\&test_1, 3 , 2 ); + + if ($rc == 0) { + printf("1st return value: %s\n", $duk->to_string(-2)); # 21 + printf("2nd return value: %s\n", $duk->to_string(-1)); # undefined + } else { + printf("error: %s\n", $duk->to_string(-1)); + } + $duk->pop_2(); + + # error case + $duk->push_int(10); + $duk->push_int(11); + $duk->push_int(12); + $rc = $duk->safe_call(\&test_2, 3 , 2); + if ($rc == 0) { + printf("1st return value: %s\n", $duk->to_string(-2)); # 21 + printf("2nd return value: %s\n", $duk->to_string(-1)); # undefined + } else { + printf("error: %s\n", $duk->to_string(-2)); + } + $duk->pop_2(); + + # /* XXX: also test invalid input stack shapes (like not enough args) */ + + printf("final top: %ld\n", $duk->get_top()); } test(); diff --git a/t/api/safe-to-string.t b/t/api/safe-to-string.t index 3c6eafe..09c68fa 100644 --- a/t/api/safe-to-string.t +++ b/t/api/safe-to-string.t @@ -10,65 +10,65 @@ my $js = JavaScript::Duktape->new(); my $duk = $js->duk; sub init_test_values { - $duk->set_top(0); + $duk->set_top(0); - # Simple */ - $duk->push_int(123); + # Simple */ + $duk->push_int(123); - # Object with toString() */ - $duk->eval_string("({ toString: function () { return 'toString result'; } })"); + # Object with toString() */ + $duk->eval_string("({ toString: function () { return 'toString result'; } })"); - # toString() throws an error */ - $duk->eval_string("({ toString: function () { throw new Error('toString error'); } })"); + # toString() throws an error */ + $duk->eval_string("({ toString: function () { throw new Error('toString error'); } })"); - # toString() throws an error which cannot be string coerced */ - $duk->eval_string("({ toString: function () { var e = new Error('cannot string coerce me');" - . " e.toString = function () { throw new Error('coercion error'); };" - . " throw e; } })"); + # toString() throws an error which cannot be string coerced */ + $duk->eval_string("({ toString: function () { var e = new Error('cannot string coerce me');" + . " e.toString = function () { throw new Error('coercion error'); };" + . " throw e; } })"); - # XXX: add an infinite loop and timeout case */ + # XXX: add an infinite loop and timeout case */ } sub test_1 { - # $duk->safe_to_string() */ - init_test_values(); - my $n = $duk->get_top(); - for (my $i = 0; $i < $n; $i++) { - printf("top=%ld\n", $duk->get_top()); - printf("duk_safe_to_string[%ld] = '%s'\n", $i, $duk->safe_to_string($i)); - } - - # $duk->safe_to_lstring() with NULL arg */ - init_test_values(); - $n = $duk->get_top(); - for (my $i = 0; $i < $n; $i++) { - printf("top=%ld\n", $duk->get_top()); - my $str = $duk->safe_to_lstring($i, my $t); - printf("duk_safe_to_lstring_null[%ld] = '%s'\n", $i, $str); - } - - # $duk->safe_to_lstring() */ - init_test_values(); - $n = $duk->get_top(); - for (my $i = 0; $i < $n; $i++) { - my $len; - printf("top=%ld\n", $duk->get_top()); - my $str = $duk->safe_to_lstring($i, $len); - printf("duk_safe_to_lstring[%ld] = '%s', len %lu\n", $i, $str, $len); - } - - # $duk->safe_to_lstring() with negative stack indices */ - init_test_values(); - $n = $duk->get_top(); - for (my $i = 0; $i < $n; $i++) { - my $len; - printf("top=%ld\n", $duk->get_top()); - my $str = $duk->safe_to_lstring(-4 + $i, $len); - printf("duk_safe_to_lstring[%ld] = '%s', len %lu\n", $i, $str, $len); - } - - return 0; + # $duk->safe_to_string() */ + init_test_values(); + my $n = $duk->get_top(); + for (my $i = 0; $i < $n; $i++) { + printf("top=%ld\n", $duk->get_top()); + printf("duk_safe_to_string[%ld] = '%s'\n", $i, $duk->safe_to_string($i)); + } + + # $duk->safe_to_lstring() with NULL arg */ + init_test_values(); + $n = $duk->get_top(); + for (my $i = 0; $i < $n; $i++) { + printf("top=%ld\n", $duk->get_top()); + my $str = $duk->safe_to_lstring($i, my $t); + printf("duk_safe_to_lstring_null[%ld] = '%s'\n", $i, $str); + } + + # $duk->safe_to_lstring() */ + init_test_values(); + $n = $duk->get_top(); + for (my $i = 0; $i < $n; $i++) { + my $len; + printf("top=%ld\n", $duk->get_top()); + my $str = $duk->safe_to_lstring($i, $len); + printf("duk_safe_to_lstring[%ld] = '%s', len %lu\n", $i, $str, $len); + } + + # $duk->safe_to_lstring() with negative stack indices */ + init_test_values(); + $n = $duk->get_top(); + for (my $i = 0; $i < $n; $i++) { + my $len; + printf("top=%ld\n", $duk->get_top()); + my $str = $duk->safe_to_lstring(-4 + $i, $len); + printf("duk_safe_to_lstring[%ld] = '%s', len %lu\n", $i, $str, $len); + } + + return 0; } TEST_SAFE_CALL($duk, \&test_1, 'test_1'); diff --git a/t/eval-function.t b/t/eval-function.t index a18bb7e..27a05ef 100644 --- a/t/eval-function.t +++ b/t/eval-function.t @@ -9,48 +9,48 @@ my $js = JavaScript::Duktape->new(); my $duk = $js->duk; $duk->push_function(sub { - fail("failed from javascript land"); + fail("failed from javascript land"); }, 1); $duk->put_global_string("perlfail"); $duk->push_function(sub { - ok(1, "success from javascript land"); + ok(1, "success from javascript land"); }, 1); $duk->put_global_string("perlok"); $duk->push_string("Hi"); sub safe_fn { - eval { - print "called\n"; - eval { die; }; - $duk->push_string("bye"); - die; - $duk->require_int(99); - print "called\n"; - }; - if ($@){ - ok(1, $@); - $duk->push_string("Error String"); - #this should throw bye string - $duk->throw(); - } - fail("should never get here"); + eval { + print "called\n"; + eval { die; }; + $duk->push_string("bye"); + die; + $duk->require_int(99); + print "called\n"; + }; + if ($@){ + ok(1, $@); + $duk->push_string("Error String"); + #this should throw bye string + $duk->throw(); + } + fail("should never get here"); } $duk->push_function(\&safe_fn, 10); $duk->put_global_string("perlFn"); $duk->peval_string(qq~ - try { - perlFn(); - perlfail(); - } catch (e){ - perlok(); - throw(e); - } - perlfail(); - 9; + try { + perlFn(); + perlfail(); + } catch (e){ + perlok(); + throw(e); + } + perlfail(); + 9; ~); my $top = $duk->get_top(); diff --git a/t/helper.pl b/t/helper.pl index 4f486be..03036eb 100644 --- a/t/helper.pl +++ b/t/helper.pl @@ -3,22 +3,22 @@ use Test::More; sub SET_PRINT_METHOD { - my $duk = shift; - $duk->push_perl(sub { - my $top = $duk->get_top(); - my @str = (); - for (my $i = 0; $i < $top; $i++){ - push @str, $duk->safe_to_string($i); - } - my $str = join " ", @str; - print $str; - print "\n"; - }); - $duk->put_global_string('print'); + my $duk = shift; + $duk->push_perl(sub { + my $top = $duk->get_top(); + my @str = (); + for (my $i = 0; $i < $top; $i++){ + push @str, $duk->safe_to_string($i); + } + my $str = join " ", @str; + print $str; + print "\n"; + }); + $duk->put_global_string('print'); } sub TEST_SAFE_CALL { - my $duk = shift; + my $duk = shift; my $sub = shift; my $name = shift; printf("*** %s (duk_safe_call)\n", $name); @@ -31,42 +31,42 @@ sub TEST_SAFE_CALL { sub test_stdout { - my $data = do { - local $/; - ; - }; + my $data = do { + local $/; + ; + }; - open my $out, "duk_test.out" or die "Could not read from duk_test.out! $!"; - my $outdata = do { - local $/; - <$out>; - }; + open my $out, "duk_test.out" or die "Could not read from duk_test.out! $!"; + my $outdata = do { + local $/; + <$out>; + }; - my @got = split "\n", $outdata; - my @expected = split "\n", $data; + my @got = split "\n", $outdata; + my @expected = split "\n", $data; - print Dumper \@out; - print Dumper \@contents; - my $total_tests = scalar @expected; - for (my $i = 0; $i < scalar @expected; $i++){ - my $got = $got[$i]; - my $expect = $expected[$i]; - $expect =~ s/\r//g; - $got =~ s/\r//g; - if ($expect =~ /^#skip/) { - diag "skip -- $expect"; - --$total_tests; - } else { - is ($got, $expect, $expect); - } - } + print Dumper \@out; + print Dumper \@contents; + my $total_tests = scalar @expected; + for (my $i = 0; $i < scalar @expected; $i++){ + my $got = $got[$i]; + my $expect = $expected[$i]; + $expect =~ s/\r//g; + $got =~ s/\r//g; + if ($expect =~ /^#skip/) { + diag "skip -- $expect"; + --$total_tests; + } else { + is ($got, $expect, $expect); + } + } - done_testing($total_tests); + done_testing($total_tests); } END { - close STDOUT; - unlink 'duk_test.out'; + close STDOUT; + unlink 'duk_test.out'; } 1; diff --git a/t/perl-data.t b/t/perl-data.t index 9b77629..ac8fbdb 100644 --- a/t/perl-data.t +++ b/t/perl-data.t @@ -9,67 +9,67 @@ my $js = JavaScript::Duktape->new(); my $duk = $js->duk; $duk->push_function(sub { - ok(1, "success from javascript land"); + ok(1, "success from javascript land"); }, 1); $duk->put_global_string("perlok"); my $data = { - num => 9, - func => sub { - is(1, $_[0]); - is("Hi", $_[1]); - is($_[2], true); #true - ok($_[2]); #true + num => 9, + func => sub { + is(1, $_[0]); + is("Hi", $_[1]); + is($_[2], true); #true + ok($_[2]); #true - is($_[3], false); #false - ok(!$_[3]); #false + is($_[3], false); #false + ok(!$_[3]); #false - #XXX : test null $_[4] - ok(!$_[4]); - is($_[4], null); + #XXX : test null $_[4] + ok(!$_[4]); + is($_[4], null); - ##fifth argument passed as javascript function - $_[5]->(sub { - my $d = shift; - is($d, "Hi again"); - return [1, 2, 3]; - }); + ##fifth argument passed as javascript function + $_[5]->(sub { + my $d = shift; + is($d, "Hi again"); + return [1, 2, 3]; + }); - return { h => 9999 }; - }, - str => 'Hello', - un => undef, - n => null, - t => true, - f => false + return { h => 9999 }; + }, + str => 'Hello', + un => undef, + n => null, + t => true, + f => false }; $js->set('perl', $data); $duk->peval_string(qq~ - //print(JSON.stringify(perl)); - if (perl.str === 'Hello') perlok(); - if (typeof perl.un === 'undefined') perlok(); - if (perl.n === null) perlok(); - if (perl.t === true) perlok(); - if (perl.f === false) perlok(); - if (typeof perl.func === 'function') perlok(); + //print(JSON.stringify(perl)); + if (perl.str === 'Hello') perlok(); + if (typeof perl.un === 'undefined') perlok(); + if (perl.n === null) perlok(); + if (perl.t === true) perlok(); + if (perl.f === false) perlok(); + if (typeof perl.func === 'function') perlok(); - var obj = perl.func(1, "Hi", true, false, null, function(d){ - var ret = d('Hi again'); - if (typeof ret === 'object') perlok(); - if (ret.length === 3){ - perlok(); - } - }); - if(obj.h === 9999) perlok(); + var obj = perl.func(1, "Hi", true, false, null, function(d){ + var ret = d('Hi again'); + if (typeof ret === 'object') perlok(); + if (ret.length === 3){ + perlok(); + } + }); + if(obj.h === 9999) perlok(); ~); $duk->dump(); if (false){ - print "OK\n"; + print "OK\n"; } done_testing(18); diff --git a/t/prop.t b/t/prop.t index aab9500..80698b6 100644 --- a/t/prop.t +++ b/t/prop.t @@ -10,11 +10,11 @@ my $js = JavaScript::Duktape->new(); my $duk = $js->duk; $duk->push_c_function( sub { - $duk->push_current_function(); - $duk->get_prop_string(-1, "prop_number"); - $duk->dump(); - my $num = $duk->require_number(-1); - is($num, 9, "prop value"); + $duk->push_current_function(); + $duk->get_prop_string(-1, "prop_number"); + $duk->dump(); + my $num = $duk->require_number(-1); + is($num, 9, "prop value"); return 1; }, -1); diff --git a/t/safe-call.t b/t/safe-call.t index 4fd73ea..fb71823 100644 --- a/t/safe-call.t +++ b/t/safe-call.t @@ -11,21 +11,21 @@ my $js = JavaScript::Duktape->new(); my $duk = $js->duk; sub safe_fn { - my $arg = shift; + my $arg = shift; - eval {}; - eval {die "$arg This is Some Fake Error";}; - ok($@ =~ /^Hi This is Some Fake Error/); + eval {}; + eval {die "$arg This is Some Fake Error";}; + ok($@ =~ /^Hi This is Some Fake Error/); - my $top = $duk->get_top; - is($top,3); - ok "must be called"; + my $top = $duk->get_top; + is($top,3); + ok "must be called"; - ###Editing above this line should change tests - ###about error line number below - die "From Perl"; - ############################################## - fail "should never reach here after we died"; + ###Editing above this line should change tests + ###about error line number below + die "From Perl"; + ############################################## + fail "should never reach here after we died"; } $duk->push_function(\&safe_fn, 3); @@ -46,42 +46,42 @@ ok($errorstr =~ /Error: From Perl at (.*?)safe-call\.t line 26\./, $errorstr); $duk->reset_top(); { - ##same test above but instead throwing from javascript - sub safe_fn_2 { - my $self = shift; + ##same test above but instead throwing from javascript + sub safe_fn_2 { + my $self = shift; - eval {}; - eval {die "Hi This is Some Fake Error";}; - ok($@ =~ /^Hi This is Some Fake Error/); + eval {}; + eval {die "Hi This is Some Fake Error";}; + ok($@ =~ /^Hi This is Some Fake Error/); - my $top = $duk->get_top; - is($top,3); - ok "must be called"; + my $top = $duk->get_top; + is($top,3); + ok "must be called"; - eval { - $duk->push_string("error from javascript"); - }; + eval { + $duk->push_string("error from javascript"); + }; - $duk->throw(); + $duk->throw(); - die; + die; - fail "should never reach here after we died"; - } + fail "should never reach here after we died"; + } - $duk->push_function(\&safe_fn_2, 3); - $duk->push_string("Hi"); - eval { $duk->pcall(1) }; + $duk->push_function(\&safe_fn_2, 3); + $duk->push_string("Hi"); + eval { $duk->pcall(1) }; - my $top = $duk->get_top; - is($top,1); + my $top = $duk->get_top; + is($top,1); - ##error thrown but it wasn't an instance of Error - my $errcode = $duk->get_error_code(0); - is($errcode, 0); + ##error thrown but it wasn't an instance of Error + my $errcode = $duk->get_error_code(0); + is($errcode, 0); - my $errorstr = $duk->to_string(0); - ok($errorstr =~ /error from javascript/, $errorstr); + my $errorstr = $duk->to_string(0); + ok($errorstr =~ /error from javascript/, $errorstr); } done_testing(12); diff --git a/t/trycatch.t b/t/trycatch.t index c9d83e5..bc1e7b3 100644 --- a/t/trycatch.t +++ b/t/trycatch.t @@ -9,90 +9,90 @@ my $js = JavaScript::Duktape->new(); my $duk = $js->duk; $duk->push_function(sub { - fail("failed from javascript land"); + fail("failed from javascript land"); }, 1); $duk->put_global_string("perlfail"); $duk->push_function(sub { - ok(1, "success from javascript land"); + ok(1, "success from javascript land"); }, 1); $duk->put_global_string("perlok"); { - my $count = 0; - $duk->push_function(sub { - eval { die; }; - $count++; - $duk->push_string("hi"); - eval { die; }; - die; - $duk->require_string(99); - fail("never here"); - return 1; - }, 10); - - $duk->put_global_string("perlFn"); - - my $ret = $duk->peval_string(qq~ - var ret; - try { - ret = new perlFn(9); - //should never get here - perlfail(); - } catch (e){ - throw(e); - }; - //should never get here - perlfail(); - ret; - ~); - - is($ret, 1); #failed call - is($count, 1); - - my $top = $duk->get_top(); - is($top, 1); - ok($duk->get_error_code(-1) > 0, "last stack element should be an error"); - $duk->pop(); + my $count = 0; + $duk->push_function(sub { + eval { die; }; + $count++; + $duk->push_string("hi"); + eval { die; }; + die; + $duk->require_string(99); + fail("never here"); + return 1; + }, 10); + + $duk->put_global_string("perlFn"); + + my $ret = $duk->peval_string(qq~ + var ret; + try { + ret = new perlFn(9); + //should never get here + perlfail(); + } catch (e){ + throw(e); + }; + //should never get here + perlfail(); + ret; + ~); + + is($ret, 1); #failed call + is($count, 1); + + my $top = $duk->get_top(); + is($top, 1); + ok($duk->get_error_code(-1) > 0, "last stack element should be an error"); + $duk->pop(); } { - my $count = 0; - $duk->push_function(sub { - eval { die; }; - $count++; - $duk->push_string("hi"); - eval { die; }; - $duk->require_pointer(99); ##error - return 1; - }, 10); - - $duk->put_global_string("perlFn"); - - my $ret = $duk->peval_string(qq~ - var ret; - try { - ret = new perlFn(9); - } catch (e){ - var error = e.toString(); - if (/^TypeError: pointer required/.test(error)){ - perlok(); - } - perlok(); - }; - //should get here - perlok(); - ret; - ~); - - is($ret, 0, "sucess call"); #no error catched by try {} block - is($count, 1, "called once"); - my $top = $duk->get_top(); - is($top, 1, "return value undefined"); - $duk->pop(); + my $count = 0; + $duk->push_function(sub { + eval { die; }; + $count++; + $duk->push_string("hi"); + eval { die; }; + $duk->require_pointer(99); ##error + return 1; + }, 10); + + $duk->put_global_string("perlFn"); + + my $ret = $duk->peval_string(qq~ + var ret; + try { + ret = new perlFn(9); + } catch (e){ + var error = e.toString(); + if (/^TypeError: pointer required/.test(error)){ + perlok(); + } + perlok(); + }; + //should get here + perlok(); + ret; + ~); + + is($ret, 0, "sucess call"); #no error catched by try {} block + is($count, 1, "called once"); + my $top = $duk->get_top(); + is($top, 1, "return value undefined"); + $duk->pop(); } done_testing(10); diff --git a/t/uncaught.t b/t/uncaught.t index 82275e7..76d827c 100644 --- a/t/uncaught.t +++ b/t/uncaught.t @@ -11,109 +11,109 @@ my $duk = $js->duk; my $count = 0; $duk->push_function(sub { - eval {}; - $count++; - $duk->push_string("hi"); - die; - $duk->require_string(99); - fail("should never get here"); + eval {}; + $count++; + $duk->push_string("hi"); + die; + $duk->require_string(99); + fail("should never get here"); }); $duk->put_global_string("perlFn"); { #eval with try - eval { - $duk->eval_string(qq~ - try { - perlFn(); - } catch (e){ - throw(e); - }; - ~); - }; - ok ($@, $@); - is($count, 1, "called once"); + eval { + $duk->eval_string(qq~ + try { + perlFn(); + } catch (e){ + throw(e); + }; + ~); + }; + ok ($@, $@); + is($count, 1, "called once"); } { #eval without try - $count = 0; - eval { - $duk->eval_string(qq~ - perlFn(); - ~); - }; - ok ($@, $@); - is($count, 1, "called once"); + $count = 0; + eval { + $duk->eval_string(qq~ + perlFn(); + ~); + }; + ok ($@, $@); + is($count, 1, "called once"); } { #peval with try/catch - #reset - $count = 0; - eval { - $duk->peval_string(qq~ - var ret; - try { - perlFn(); - perlFn(); - } catch (e){ - throw(e); - }; - ~); - }; - - - ok (!$@, 'Eval Error'); - is($count, 1, "called once"); - ok($duk->is_error(-1), "Error is on top"); - $duk->pop(); + #reset + $count = 0; + eval { + $duk->peval_string(qq~ + var ret; + try { + perlFn(); + perlFn(); + } catch (e){ + throw(e); + }; + ~); + }; + + + ok (!$@, 'Eval Error'); + is($count, 1, "called once"); + ok($duk->is_error(-1), "Error is on top"); + $duk->pop(); } { #peval without try/catch - #reset - $count = 0; - eval { - $duk->peval_string(qq~ - perlFn(); - perlFn(); - ~); - }; - - ok (!$@, $@); - is($count, 1, "called once"); - - ok($duk->is_error(-1), "Error is on top"); - my $err_str = $duk->to_string(-1); - ok($err_str =~ /^Error: Died at/, $err_str); + #reset + $count = 0; + eval { + $duk->peval_string(qq~ + perlFn(); + perlFn(); + ~); + }; + + ok (!$@, $@); + is($count, 1, "called once"); + + ok($duk->is_error(-1), "Error is on top"); + my $err_str = $duk->to_string(-1); + ok($err_str =~ /^Error: Died at/, $err_str); } { - #overwrite perl function - $js->set('perlFn', sub { - eval {}; - $count++; - $duk->push_string("hi"); - $duk->require_string(99); - fail("should never get here"); - }); - - $duk->peval_string("perlFn"); - eval { - $duk->call(0); - }; - - ok ($@ =~ /^uncaught/, $@); - - $duk->eval_string("perlFn"); - eval { - $duk->pcall(0); - }; - ok (!$@); - - my $str = $duk->to_string(-1); - is($str, "TypeError: string required, found none (stack index 99)"); + #overwrite perl function + $js->set('perlFn', sub { + eval {}; + $count++; + $duk->push_string("hi"); + $duk->require_string(99); + fail("should never get here"); + }); + + $duk->peval_string("perlFn"); + eval { + $duk->call(0); + }; + + ok ($@ =~ /^uncaught/, $@); + + $duk->eval_string("perlFn"); + eval { + $duk->pcall(0); + }; + ok (!$@); + + my $str = $duk->to_string(-1); + is($str, "TypeError: string required, found none (stack index 99)"); } done_testing(14);