Browse Source

Merge branch 'pc2line-refactor'

pull/20/head
Sami Vaarala 11 years ago
parent
commit
2336c406c1
  1. 13
      src/duk_bi_duktape.c
  2. 11
      src/duk_bi_error.c
  3. 15
      src/duk_error_augment.c
  4. 2
      src/duk_hobject.h
  5. 18
      src/duk_hobject_pc2line.c

13
src/duk_bi_duktape.c

@ -116,7 +116,6 @@ duk_ret_t duk_bi_duktape_object_act(duk_context *ctx) {
duk_hthread *thr = (duk_hthread *) ctx; duk_hthread *thr = (duk_hthread *) ctx;
duk_activation *act; duk_activation *act;
duk_hobject *h_func; duk_hobject *h_func;
duk_hbuffer_fixed *pc2line;
duk_uint_fast32_t pc; duk_uint_fast32_t pc;
duk_uint_fast32_t line; duk_uint_fast32_t line;
duk_int_t level; duk_int_t level;
@ -140,17 +139,7 @@ duk_ret_t duk_bi_duktape_object_act(duk_context *ctx) {
pc = (duk_uint_fast32_t) act->pc; pc = (duk_uint_fast32_t) act->pc;
duk_push_int(ctx, (int) pc); /* FIXME: typing */ duk_push_int(ctx, (int) pc); /* FIXME: typing */
duk_get_prop_stridx(ctx, -2, DUK_STRIDX_INT_PC2LINE); line = duk_hobject_pc2line_query(ctx, -2, pc);
if (duk_is_buffer(ctx, -1)) {
pc2line = (duk_hbuffer_fixed *) duk_get_hbuffer(ctx, -1);
DUK_ASSERT(!DUK_HBUFFER_HAS_DYNAMIC((duk_hbuffer *) pc2line));
pc = (duk_uint_fast32_t) act->pc;
line = duk_hobject_pc2line_query(pc2line, (duk_uint_fast32_t) pc);
} else {
line = 0;
}
duk_pop(ctx);
duk_push_int(ctx, (int) line); /* FIXME: typing */ duk_push_int(ctx, (int) line); /* FIXME: typing */
/* Providing access to e.g. act->lex_env would be dangerous: these /* Providing access to e.g. act->lex_env would be dangerous: these

11
src/duk_bi_error.c

@ -179,16 +179,7 @@ static int duk__traceback_getter_helper(duk_context *ctx, int output_type) {
duk_get_prop_stridx(ctx, -3, DUK_STRIDX_FILE_NAME); duk_get_prop_stridx(ctx, -3, DUK_STRIDX_FILE_NAME);
#if defined(DUK_USE_PC2LINE) #if defined(DUK_USE_PC2LINE)
duk_get_prop_stridx(ctx, -4, DUK_STRIDX_INT_PC2LINE); line = duk_hobject_pc2line_query(ctx, -4, (duk_uint_fast32_t) pc);
if (duk_is_buffer(ctx, -1)) {
duk_hbuffer_fixed *pc2line;
pc2line = (duk_hbuffer_fixed *) duk_get_hbuffer(ctx, -1);
DUK_ASSERT(!DUK_HBUFFER_HAS_DYNAMIC((duk_hbuffer *) pc2line));
line = duk_hobject_pc2line_query(pc2line, (duk_uint_fast32_t) pc);
} else {
line = 0;
}
duk_pop(ctx);
#else #else
line = 0; line = 0;
#endif #endif

15
src/duk_error_augment.c

@ -313,7 +313,6 @@ static void duk__err_augment_builtin_throw(duk_hthread *thr, duk_hthread *thr_ca
} else if (thr_callstack->callstack_top > 0) { } else if (thr_callstack->callstack_top > 0) {
duk_activation *act; duk_activation *act;
duk_hobject *func; duk_hobject *func;
duk_hbuffer *pc2line;
act = thr_callstack->callstack + thr_callstack->callstack_top - 1; act = thr_callstack->callstack + thr_callstack->callstack_top - 1;
DUK_ASSERT(act >= thr_callstack->callstack && act < thr_callstack->callstack + thr_callstack->callstack_size); DUK_ASSERT(act >= thr_callstack->callstack && act < thr_callstack->callstack + thr_callstack->callstack_size);
@ -343,17 +342,11 @@ static void duk__err_augment_builtin_throw(duk_hthread *thr, duk_hthread *thr_ca
duk_push_number(ctx, pc); duk_push_number(ctx, pc);
duk_def_prop_stridx(ctx, -3, DUK_STRIDX_PC, DUK_PROPDESC_FLAGS_WC | DUK_PROPDESC_FLAGS_NO_OVERWRITE); duk_def_prop_stridx(ctx, -3, DUK_STRIDX_PC, DUK_PROPDESC_FLAGS_WC | DUK_PROPDESC_FLAGS_NO_OVERWRITE);
#endif #endif
line = duk_hobject_pc2line_query(ctx, -1, (duk_uint_fast32_t) pc);
duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_PC2LINE); if (line > 0) {
if (duk_is_buffer(ctx, -1)) { duk_push_u32(ctx, (duk_uint32_t) line); /* -> [ ... error func line ] */
pc2line = duk_get_hbuffer(ctx, -1); duk_def_prop_stridx(ctx, -3, DUK_STRIDX_LINE_NUMBER, DUK_PROPDESC_FLAGS_WC | DUK_PROPDESC_FLAG_NO_OVERWRITE);
DUK_ASSERT(pc2line != NULL);
DUK_ASSERT(!DUK_HBUFFER_HAS_DYNAMIC(pc2line));
line = duk_hobject_pc2line_query((duk_hbuffer_fixed *) pc2line, (duk_uint_fast32_t) pc);
duk_push_number(ctx, (double) line); /* -> [ ... error func pc2line line ] */ /* FIXME: u32 */
duk_def_prop_stridx(ctx, -4, DUK_STRIDX_LINE_NUMBER, DUK_PROPDESC_FLAGS_WC | DUK_PROPDESC_FLAG_NO_OVERWRITE);
} }
duk_pop(ctx);
} else { } else {
/* Native function, no relevant lineNumber. */ /* Native function, no relevant lineNumber. */
} }

2
src/duk_hobject.h

@ -702,7 +702,7 @@ void duk_hobject_run_finalizer(duk_hthread *thr, duk_hobject *obj);
/* pc2line */ /* pc2line */
#if defined(DUK_USE_PC2LINE) #if defined(DUK_USE_PC2LINE)
void duk_hobject_pc2line_pack(duk_hthread *thr, duk_compiler_instr *instrs, duk_uint_fast32_t length); void duk_hobject_pc2line_pack(duk_hthread *thr, duk_compiler_instr *instrs, duk_uint_fast32_t length);
duk_uint_fast32_t duk_hobject_pc2line_query(duk_hbuffer_fixed *buf, duk_uint_fast32_t pc); duk_uint_fast32_t duk_hobject_pc2line_query(duk_context *ctx, duk_idx_t idx_func, duk_uint_fast32_t pc);
#endif #endif
/* misc */ /* misc */

18
src/duk_hobject_pc2line.c

@ -126,7 +126,7 @@ void duk_hobject_pc2line_pack(duk_hthread *thr, duk_compiler_instr *instrs, duk_
* it will map to a large PC which is out of bounds and causes a zero to be * it will map to a large PC which is out of bounds and causes a zero to be
* returned. * returned.
*/ */
duk_uint_fast32_t duk_hobject_pc2line_query(duk_hbuffer_fixed *buf, duk_uint_fast32_t pc) { static duk_uint_fast32_t duk__hobject_pc2line_query_raw(duk_hbuffer_fixed *buf, duk_uint_fast32_t pc) {
duk_bitdecoder_ctx bd_ctx_alloc; duk_bitdecoder_ctx bd_ctx_alloc;
duk_bitdecoder_ctx *bd_ctx = &bd_ctx_alloc; duk_bitdecoder_ctx *bd_ctx = &bd_ctx_alloc;
duk_uint32_t *hdr; duk_uint32_t *hdr;
@ -215,4 +215,20 @@ duk_uint_fast32_t duk_hobject_pc2line_query(duk_hbuffer_fixed *buf, duk_uint_fas
return 0; return 0;
} }
duk_uint_fast32_t duk_hobject_pc2line_query(duk_context *ctx, duk_idx_t idx_func, duk_uint_fast32_t pc) {
duk_hbuffer_fixed *pc2line;
duk_uint_fast32_t line;
duk_get_prop_stridx(ctx, idx_func, DUK_STRIDX_INT_PC2LINE);
pc2line = (duk_hbuffer_fixed *) duk_get_hbuffer(ctx, -1);
if (pc2line != NULL) {
DUK_ASSERT(!DUK_HBUFFER_HAS_DYNAMIC((duk_hbuffer *) pc2line));
line = duk__hobject_pc2line_query_raw(pc2line, (duk_uint_fast32_t) pc);
} else {
line = 0;
}
duk_pop(ctx);
return line;
}
#endif /* DUK_USE_PC2LINE */ #endif /* DUK_USE_PC2LINE */

Loading…
Cancel
Save