Skip to content

Commit

Permalink
#23: do not rely on V8's metadata
Browse files Browse the repository at this point in the history
Hardcode handling of V8_SCOPEINFO_IDX_FIRST_VARS' fallback value for
different versions of V8.
Do not rely on V8's metadata for getting
V8_SCOPEINFO_OFFSET_STACK_LOCALS' value, use V8_CONSTANT_FALLBACK
instead.
  • Loading branch information
Julien Gilli committed Sep 9, 2015
1 parent ccda2ad commit b438426
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
22 changes: 20 additions & 2 deletions src/mdb_v8.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ static v8_constant_t v8_constants[] = {
V8_CONSTANT_FALLBACK(3, 7), 2 },
{ &V8_SCOPEINFO_OFFSET_STACK_LOCALS,
"v8dbg_scopeinfo_offset_stack_locals",
V8_CONSTANT_ADDED_SINCE(4, 4) },
V8_CONSTANT_FALLBACK(4, 4), 1 },
{ &V8_SCOPEINFO_IDX_NCONTEXTLOCALS,
"v8dbg_scopeinfo_idx_ncontextlocals",
V8_CONSTANT_FALLBACK(3, 7), 3 },
{ &V8_SCOPEINFO_IDX_FIRST_VARS, "v8dbg_scopeinfo_idx_first_vars",
V8_CONSTANT_FALLBACK(3, 7), 4 },
V8_CONSTANT_FALLBACK(4, 5), 6 },
};

static int v8_nconstants = sizeof (v8_constants) / sizeof (v8_constants[0]);
Expand Down Expand Up @@ -809,6 +809,24 @@ autoconfigure(v8_cfg_t *cfgp)
if (V8_OFF_MAP_BIT_FIELD2 == -1)
V8_OFF_MAP_BIT_FIELD2 = V8_OFF_MAP_INSTANCE_ATTRIBUTES + 3;

/*
* V8_SCOPEINFO_IDX_FIRST_VARS' value was 4 in V8 3.7 and up,
* then 5 when StrongModeFreeVariableCount was added with
* https://codereview.chromium.org/1005063002, and 6 when
* ContextGlobalCount was added with
* https://codereview.chromium.org/1218783005.
* Since the current V8_CONSTANT_FALLBACK macro doesn't allow
* us to specify different values for different V8 versions,
* these are hardcoded below.
*/
if (V8_SCOPEINFO_IDX_FIRST_VARS == -1) {
if (v8_major > 4 || (v8_major == 4 && v8_minor >= 3)) {
V8_SCOPEINFO_IDX_FIRST_VARS = 5;
} else if (v8_major > 3 || (v8_major == 3 && v8_minor >= 7)) {
V8_SCOPEINFO_IDX_FIRST_VARS = 4;
}
}

return (failed ? -1 : 0);
}

Expand Down
24 changes: 6 additions & 18 deletions src/mdb_v8_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,19 +387,8 @@ v8scopeinfo_iter_vars(v8scopeinfo_t *sip,
nvars = v8scopeinfo_vartype_nvars(sip, scopevartype);

/*
* A ScopeInfo instance has two distinct parts:
*
* 1) A static part that contains information about the number of
* entries for each variable type.
*
* 2) A dynamic part of variable size that contains the actual data for
* each variable type (parameters, stack local and context local
* entries' names).
*
* V8_SCOPEINFO_IDX_FIRST_VARS is the offset from the beginning of the
* ScopeInfo layout to the start of the variable part that contains the
* actual information for each variable type, so we start by skipping to
* that offset.
* Skip to the start of the ScopeInfo's dynamic part. See mdb_v8_db.h
* for more details on the layout of ScopeInfo objects.
*/
nskip = V8_SCOPEINFO_IDX_FIRST_VARS;

Expand All @@ -425,8 +414,8 @@ v8scopeinfo_iter_vars(v8scopeinfo_t *sip,
}

/*
* The current variable type is the one we're interested in,
* do not add anything to the offset, we're done.
* If the current variable type is the one we're interested in,
* do not add anything to the offset. We're done.
*/
if (*(ogrp->v8vti_idx_countp) == *(vtip->v8vti_idx_countp)) {
break;
Expand All @@ -435,9 +424,8 @@ v8scopeinfo_iter_vars(v8scopeinfo_t *sip,
/*
* The data for the current variable type is before the one
* we're interested in in the variable part of the ScopeInfo
* layout.
* Add the number of entries for this variable type to the
* offset.
* layout. Add the number of entries for this variable type to
* the offset.
*/
nskip += v8scopeinfo_vartype_nvars(sip, ogrp->v8vti_vartype);
}
Expand Down

0 comments on commit b438426

Please sign in to comment.