Skip to content

Commit 28f2bfa

Browse files
author
David Pacheco
committed
#27 want streaming way to iterate array elements
#100 jsprint shows more "hole" values than it should #101 test suite could use common mechanism for standalone tests #104 test suite should take more care to avoid GC during gcore Reviewed by: Julien Gilli <[email protected]> Approved by: Julien Gilli <[email protected]>
1 parent ab8ef17 commit 28f2bfa

21 files changed

+1825
-249
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
build
2+
node_modules
3+
make_stamps
24
tools/mdbv8diff/node_modules

CHANGES.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
-->
66

77
<!--
8-
Copyright (c) 2017, Joyent, Inc.
8+
Copyright (c) 2018, Joyent, Inc.
99
-->
1010

1111
# mdb_v8 changelog
@@ -14,6 +14,12 @@
1414

1515
None.
1616

17+
## v1.3.0 (2018-01)
18+
19+
* #27 want streaming way to iterate array elements
20+
* #100 jsprint shows more "hole" values than it should
21+
* #101 test suite could use common mechanism for standalone tests
22+
1723
## v1.2.1 (2017-09-20)
1824

1925
* #96 jsclosure crash on invalid context index

GNUmakefile

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66

77
#
8-
# Copyright (c) 2015, Joyent, Inc.
8+
# Copyright (c) 2018, Joyent, Inc.
99
#
1010

1111
#
@@ -48,6 +48,7 @@ MDBV8_VERS_TAG = "dev"
4848
#
4949
MDBV8_SOURCES = \
5050
mdb_v8.c \
51+
mdb_v8_array.c \
5152
mdb_v8_cfg.c \
5253
mdb_v8_function.c \
5354
mdb_v8_strbuf.c \
@@ -122,6 +123,18 @@ MAKESO = $(CC) -o $@ -shared $(SOFLAGS) $(LDFLAGS) $^
122123
GITDESCRIBE = $(shell git describe --all --long --dirty | \
123124
awk -F'-g' '{print $$NF}')
124125

126+
#
127+
# Include eng.git Makefile for managing "node_modules" directory. A number of
128+
# items that are normally provided by Makefile.defs are specified here directly.
129+
#
130+
TOP = $(shell pwd)
131+
NPM = npm
132+
MAKE_STAMPS_DIR = make_stamps
133+
CLEAN_FILES += $(MAKE_STAMPS_DIR)
134+
MAKE_STAMP_REMOVE = mkdir -p $(@D); rm -f $(@)
135+
MAKE_STAMP_CREATE = mkdir -p $(@D); touch $(@)
136+
include ./tools/mk/Makefile.node_modules.defs
137+
125138
#
126139
# TARGETS
127140
#
@@ -137,7 +150,7 @@ check-cstyle:
137150
CLEAN_FILES += $(MDBV8_BUILD)
138151

139152
.PHONY: test
140-
test: $(MDBV8_ALLTARGETS)
153+
test: $(MDBV8_ALLTARGETS) $(STAMP_NODE_MODULES)
141154
$(CATEST) -a
142155

143156
.PHONY: prepush
@@ -172,6 +185,8 @@ $(MDBV8_BUILD):
172185
$(MKDIRP)
173186

174187
#
175-
# Include common Joyent Makefile for JavaScript "check" targets.
188+
# Include common Joyent Makefile for JavaScript "check" targets and
189+
# "node_modules" management targets.
176190
#
177-
include Makefile.targ
191+
include ./Makefile.targ
192+
include ./tools/mk/Makefile.node_modules.targ

docs/usage.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,84 @@ Of course, you can use other commands to inspect these values further.
617617

618618
See also: `jsfunction`
619619

620+
### jsarray
621+
622+
addr::jsarray [-i]
623+
624+
Given an address `addr` of an instance of the JavaScript "Array" class, print
625+
the contents of the array. Each element of the array is printed on its own
626+
line. With no options, the result can be piped to `::jsprint` to print each
627+
element.
628+
629+
For example, take this snippet:
630+
631+
var x = [ 'one', 'two', 'three' ];
632+
633+
With `::jsarray`, this prints three pointers, one for each string:
634+
635+
> 9d780985::jsarray
636+
8bc27629
637+
8bc27639
638+
8bc27649
639+
640+
We can pipe this to `::jsprint` to see the strings:
641+
642+
> 9d780985::jsarray | ::jsprint
643+
"one"
644+
"two"
645+
"three"
646+
647+
With "-i", each value is prefixed with its integer index in the array:
648+
649+
> 9d780985::jsarray -i
650+
0 8bc27629
651+
1 8bc27639
652+
2 8bc27649
653+
654+
Note that JavaScript arrays can contain holes, where there is no element for a
655+
particular index (not even "undefined"). These appear when an element was
656+
removed using the `delete` keyword or when an array was initialized with a
657+
specific length, but not all of the elements were filled in.
658+
659+
When `::jsarray` encounters a hole, the hole is printed out using a special
660+
value that `::jsprint` shows indicates a hole. For example, take this snippet:
661+
662+
var x = new Array(4);
663+
x[0] = 'one';
664+
x[1] = 'two';
665+
x[2] = 'three';
666+
delete (x[1]);
667+
668+
This produces an array with two holes: one at index 1 (because it was deleted)
669+
and one at index 3 (because it was never initialized, but the length was
670+
initialized to include this index). If you print this out with `console.log`,
671+
you'd see:
672+
673+
[ 'one', , 'three', ]
674+
675+
(Note the extra commas where there are holes.)
676+
677+
`::jsarray` prints the holes, which may look like ordinary values:
678+
679+
> 81780a0d::jsarray
680+
aba27661
681+
b4d080c1
682+
aba27681
683+
b4d080c1
684+
685+
but are recognized by `::jsprint` as special:
686+
687+
> 81780a0d::jsarray | ::jsprint
688+
"one"
689+
hole
690+
"three"
691+
hole
692+
693+
The default behavior around the printing of hole values may change in the
694+
future.
695+
696+
See also: `walk jselement`
697+
620698
### jsconstructor
621699

622700
addr::jsconstructor [-v]
@@ -875,6 +953,34 @@ With "-f", show only frames for function `function`. With "-p", show only
875953
With "-a", show all information about hidden frames, the frame pointer for each
876954
frame, and other native objects for each frame (e.g., JSFunction addresses).
877955

956+
### walk jselement
957+
958+
addr::walk jselement
959+
960+
Given a JavaScript array identified by `addr`, enumerates the elements of the
961+
array. This behaves very similarly to `::jsarray`. See the notes about holes
962+
under `::jsarray`.
963+
964+
For example, the array created by this code:
965+
966+
var x = [ 'one', 'two', 'three' ]
967+
968+
is enumerated in the debugger like this:
969+
970+
> 9d780985::walk jselement
971+
0x8bc27629
972+
0x8bc27639
973+
0x8bc27649
974+
975+
The results can be piped to `::jsprint` to print the actual values:
976+
977+
> 9d780985::walk jselement | ::jsprint
978+
"one"
979+
"two"
980+
"three"
981+
982+
See also: `jsarray`.
983+
878984
### walk jsframe
879985

880986
::walk jsframe

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "mdb_v8_deps",
3+
"version": "1.0.0",
4+
"description": "package used only to install devDependencies for mdb_v8",
5+
"private": true,
6+
"devDependencies": {
7+
"vasync": "^2.2.0",
8+
"verror": "^1.10.0"
9+
}
10+
}

0 commit comments

Comments
 (0)