Browse Source

fix protected/safe call sites in code examples to omit errhandler_index

pull/2/head
Sami Vaarala 11 years ago
parent
commit
b91f6e7124
  1. 8
      examples/cmdline/duk_cmdline.c
  2. 4
      examples/eval/eval.c
  3. 4
      examples/eventloop/c_eventloop.c
  4. 4
      examples/eventloop/main.c

8
examples/cmdline/duk_cmdline.c

@ -120,7 +120,7 @@ static void print_error(duk_context *ctx, FILE *f) {
* Note that getting the stack trace may throw an error
* so this also needs to be safe call wrapped.
*/
(void) duk_safe_call(ctx, get_stack_raw, 1 /*nargs*/, 1 /*nrets*/, DUK_INVALID_INDEX);
(void) duk_safe_call(ctx, get_stack_raw, 1 /*nargs*/, 1 /*nrets*/);
fprintf(f, "%s\n", duk_safe_to_string(ctx, -1));
fflush(f);
duk_pop(ctx);
@ -216,7 +216,7 @@ int handle_fh(duk_context *ctx, FILE *f, const char *filename) {
interactive_mode = 0; /* global */
rc = duk_safe_call(ctx, wrapped_compile_execute, 2 /*nargs*/, 1 /*nret*/, DUK_INVALID_INDEX);
rc = duk_safe_call(ctx, wrapped_compile_execute, 2 /*nargs*/, 1 /*nret*/);
if (rc != DUK_EXEC_SUCCESS) {
print_error(ctx, stderr);
goto error;
@ -308,7 +308,7 @@ int handle_interactive(duk_context *ctx) {
interactive_mode = 1; /* global */
rc = duk_safe_call(ctx, wrapped_compile_execute, 2 /*nargs*/, 1 /*nret*/, DUK_INVALID_INDEX);
rc = duk_safe_call(ctx, wrapped_compile_execute, 2 /*nargs*/, 1 /*nret*/);
if (rc != DUK_EXEC_SUCCESS) {
/* in interactive mode, write to stdout */
print_error(ctx, stdout);
@ -369,7 +369,7 @@ int handle_interactive(duk_context *ctx) {
interactive_mode = 1; /* global */
rc = duk_safe_call(ctx, wrapped_compile_execute, 2 /*nargs*/, 1 /*nret*/, DUK_INVALID_INDEX);
rc = duk_safe_call(ctx, wrapped_compile_execute, 2 /*nargs*/, 1 /*nret*/);
if (rc != DUK_EXEC_SUCCESS) {
/* in interactive mode, write to stdout */
print_error(ctx, stdout);

4
examples/eval/eval.c

@ -35,8 +35,8 @@ int main(int argc, char *argv[]) {
for (i = 1; i < argc; i++) {
printf("=== eval: '%s' ===\n", argv[i]);
duk_push_string(ctx, argv[i]);
duk_safe_call(ctx, eval_raw, 1 /*nargs*/, 1 /*nrets*/, DUK_INVALID_INDEX);
duk_safe_call(ctx, tostring_raw, 1 /*nargs*/, 1 /*nrets*/, DUK_INVALID_INDEX);
duk_safe_call(ctx, eval_raw, 1 /*nargs*/, 1 /*nrets*/);
duk_safe_call(ctx, tostring_raw, 1 /*nargs*/, 1 /*nrets*/);
res = duk_get_string(ctx, -1);
printf("%s\n", res ? res : "null");
duk_pop(ctx);

4
examples/eventloop/c_eventloop.c

@ -175,7 +175,7 @@ static void expire_timers(duk_context *ctx) {
duk_push_number(ctx, (double) t->id);
duk_get_prop(ctx, -2); /* -> [ ... stash eventTimers func ] */
rc = duk_pcall(ctx, 0 /*nargs*/, DUK_INVALID_INDEX); /* -> [ ... stash eventTimers retval ] */
rc = duk_pcall(ctx, 0 /*nargs*/); /* -> [ ... stash eventTimers retval ] */
if (rc != 0) {
#if 0
fprintf(stderr, "timer callback failed for timer %d: %s\n", (int) t->id, duk_to_string(ctx, -1));
@ -374,7 +374,7 @@ int eventloop_run(duk_context *ctx) {
duk_dup(ctx, idx_eventloop);
duk_push_int(ctx, pfd->fd);
duk_push_int(ctx, pfd->revents);
rc = duk_pcall_method(ctx, 2 /*nargs*/, DUK_INVALID_INDEX);
rc = duk_pcall_method(ctx, 2 /*nargs*/);
if (rc) {
#if 0
fprintf(stderr, "fd callback failed for fd %d: %s\n", (int) pfd->fd, duk_to_string(ctx, -1));

4
examples/eventloop/main.c

@ -82,7 +82,7 @@ int wrapped_compile_execute(duk_context *ctx) {
if (c_evloop) {
fprintf(stderr, "calling eventloop_run()\n");
fflush(stderr);
rc = duk_safe_call(ctx, eventloop_run, 0 /*nargs*/, 1 /*nrets*/, DUK_INVALID_INDEX);
rc = duk_safe_call(ctx, eventloop_run, 0 /*nargs*/, 1 /*nrets*/);
if (rc != 0) {
fprintf(stderr, "eventloop_run() failed: %s\n", duk_to_string(ctx, -1));
fflush(stderr);
@ -125,7 +125,7 @@ int handle_fh(duk_context *ctx, FILE *f, const char *filename) {
free(buf);
buf = NULL;
rc = duk_safe_call(ctx, wrapped_compile_execute, 2 /*nargs*/, 1 /*nret*/, DUK_INVALID_INDEX);
rc = duk_safe_call(ctx, wrapped_compile_execute, 2 /*nargs*/, 1 /*nret*/);
if (rc != DUK_EXEC_SUCCESS) {
print_error(ctx, stderr);
goto error;

Loading…
Cancel
Save