mirror of https://github.com/svaarala/duktape.git
Sami Vaarala
8 years ago
committed by
GitHub
14 changed files with 185 additions and 41 deletions
@ -0,0 +1,41 @@ |
|||
/* |
|||
* Coroutine with initial bound function. |
|||
*/ |
|||
|
|||
/*=== |
|||
mythread starting |
|||
object mythis |
|||
["FOO","BAR","foo"] |
|||
1 |
|||
2 |
|||
3 |
|||
undefined |
|||
===*/ |
|||
|
|||
function test() { |
|||
function mythread(a,b,c) { |
|||
print('mythread starting'); |
|||
print(typeof this, this); |
|||
print(JSON.stringify([a,b,c])); |
|||
Duktape.Thread.yield(1); |
|||
Duktape.Thread.yield(2); |
|||
Duktape.Thread.yield(3); |
|||
} |
|||
|
|||
var T = new Duktape.Thread(mythread.bind('mythis', 'FOO', 'BAR')); |
|||
|
|||
// Only one argument can be given for the initial call, but the bound
|
|||
// arguments are still prepended as normal.
|
|||
print(Duktape.Thread.resume(T, 'foo')); |
|||
|
|||
// No difference in further resumes.
|
|||
print(Duktape.Thread.resume(T, 'foo')); |
|||
print(Duktape.Thread.resume(T, 'foo')); |
|||
print(Duktape.Thread.resume(T, 'foo')); |
|||
} |
|||
|
|||
try { |
|||
test(); |
|||
} catch (e) { |
|||
print(e.stack || e); |
|||
} |
@ -0,0 +1,27 @@ |
|||
/* |
|||
* Native function not allowed as an initial function. |
|||
*/ |
|||
|
|||
/*=== |
|||
caught error |
|||
TypeError |
|||
===*/ |
|||
|
|||
function test() { |
|||
var T = new Duktape.Thread(Math.cos); |
|||
|
|||
print(Duktape.Thread.resume(T, 'foo')); |
|||
print(Duktape.Thread.resume(T, 'foo')); |
|||
print(Duktape.Thread.resume(T, 'foo')); |
|||
print(Duktape.Thread.resume(T, 'foo')); |
|||
} |
|||
|
|||
try { |
|||
test(); |
|||
} catch (e) { |
|||
// Print when we get here: if the executor RESUME longjmp handler, we
|
|||
// *won't* come here at all. Rather, the error is propagated out of the
|
|||
// executor (as an "internal error").
|
|||
print('caught error'); |
|||
print(e.name); |
|||
} |
Loading…
Reference in new issue