Skip to content

Commit e94ece9

Browse files
committed
iwhoops fixed bugy
1 parent daa72b5 commit e94ece9

3 files changed

Lines changed: 143 additions & 134 deletions

File tree

v4-cokapi/backends/javascript/jslogger.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,6 @@ function encodeObject(o) {
307307
} else if (typeof o === 'symbol') {
308308
// ES6 symbol
309309
return ['JS_SPECIAL_VAL', String(o)];
310-
} else if (o.__proto__.toString() === canonicalSet.__proto__.toString()) {
311-
var ret = ['SET'];
312-
// ES6 Set (TODO: add WeakSet)
313-
for (let item of o) {
314-
ret.push(encodeObject(item));
315-
}
316-
return ret;
317-
} else if (o.__proto__.toString() === canonicalMap.__proto__.toString()) {
318-
// ES6 Map (TODO: add WeakMap)
319-
var ret = ['DICT'];
320-
for (var [key, value] of o) {
321-
ret.push([encodeObject(key), encodeObject(value)]);
322-
}
323-
return ret;
324310
} else {
325311
// render these as heap objects
326312

@@ -413,6 +399,18 @@ function bar(x) {
413399
for (i = 0; i < o.length; i++) {
414400
newEncodedObj.push(encodeObject(o[i]));
415401
}
402+
} else if (o.__proto__.toString() === canonicalSet.__proto__.toString()) { // dunno why 'instanceof' doesn't work :(
403+
newEncodedObj.push('SET');
404+
// ES6 Set (TODO: add WeakSet)
405+
for (let item of o) {
406+
newEncodedObj.push(encodeObject(item));
407+
}
408+
} else if (o.__proto__.toString() === canonicalMap.__proto__.toString()) { // dunno why 'instanceof' doesn't work :(
409+
// ES6 Map (TODO: add WeakMap)
410+
newEncodedObj.push('DICT'); // use the Python 'DICT' type since it's close enough; adjust display in frontend
411+
for (let [key, value] of o) {
412+
newEncodedObj.push([encodeObject(key), encodeObject(value)]);
413+
}
416414
} else {
417415
// a true object
418416

v4-cokapi/backends/javascript/tests/es6-map.golden

Lines changed: 103 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -17,212 +17,223 @@
1717
func_name: '',
1818
stack_to_render: [],
1919
globals:
20-
{ myMap: [ 'DICT' ],
20+
{ myMap: [ 'REF', 1 ],
2121
keyString: [ 'JS_SPECIAL_VAL', 'undefined' ],
2222
keyObj: [ 'JS_SPECIAL_VAL', 'undefined' ],
2323
keyFunc: [ 'JS_SPECIAL_VAL', 'undefined' ] },
2424
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
2525
line: 4,
2626
col: 0,
2727
event: 'step_line',
28-
heap: {} },
28+
heap: { '1': [ 'DICT' ] } },
2929
{ stdout: '',
3030
func_name: '',
3131
stack_to_render: [],
3232
globals:
33-
{ myMap: [ 'DICT' ],
33+
{ myMap: [ 'REF', 1 ],
3434
keyString: 'a string',
35-
keyObj: [ 'REF', 1 ],
36-
keyFunc: [ 'REF', 2 ] },
35+
keyObj: [ 'REF', 2 ],
36+
keyFunc: [ 'REF', 3 ] },
3737
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
3838
line: 9,
3939
col: 0,
4040
event: 'step_line',
4141
heap:
42-
{ '1': [ 'INSTANCE', '' ],
43-
'2': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
42+
{ '1': [ 'DICT' ],
43+
'2': [ 'INSTANCE', '' ],
44+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
4445
{ stdout: '',
4546
func_name: '',
4647
stack_to_render: [],
4748
globals:
48-
{ myMap: [ 'DICT', [ 'a string', 'value associated with \'a string\'' ] ],
49+
{ myMap: [ 'REF', 1 ],
4950
keyString: 'a string',
50-
keyObj: [ 'REF', 1 ],
51-
keyFunc: [ 'REF', 2 ] },
51+
keyObj: [ 'REF', 2 ],
52+
keyFunc: [ 'REF', 3 ] },
5253
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
5354
line: 10,
5455
col: 0,
5556
event: 'step_line',
5657
heap:
57-
{ '1': [ 'INSTANCE', '' ],
58-
'2': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
58+
{ '1': [ 'DICT', [ 'a string', 'value associated with \'a string\'' ] ],
59+
'2': [ 'INSTANCE', '' ],
60+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
5961
{ stdout: '',
6062
func_name: '',
6163
stack_to_render: [],
6264
globals:
63-
{ myMap:
64-
[ 'DICT',
65-
[ 'a string', 'value associated with \'a string\'' ],
66-
[ [ 'REF', 1 ], 'value associated with keyObj' ] ],
65+
{ myMap: [ 'REF', 1 ],
6766
keyString: 'a string',
68-
keyObj: [ 'REF', 1 ],
69-
keyFunc: [ 'REF', 2 ] },
67+
keyObj: [ 'REF', 2 ],
68+
keyFunc: [ 'REF', 3 ] },
7069
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
7170
line: 11,
7271
col: 0,
7372
event: 'step_line',
7473
heap:
75-
{ '1': [ 'INSTANCE', '' ],
76-
'2': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
74+
{ '1':
75+
[ 'DICT',
76+
[ 'a string', 'value associated with \'a string\'' ],
77+
[ [ 'REF', 2 ], 'value associated with keyObj' ] ],
78+
'2': [ 'INSTANCE', '' ],
79+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
7780
{ stdout: '',
7881
func_name: '',
7982
stack_to_render: [],
8083
globals:
81-
{ myMap:
82-
[ 'DICT',
83-
[ 'a string', 'value associated with \'a string\'' ],
84-
[ [ 'REF', 1 ], 'value associated with keyObj' ],
85-
[ [ 'REF', 2 ], 'value associated with keyFunc' ] ],
84+
{ myMap: [ 'REF', 1 ],
8685
keyString: 'a string',
87-
keyObj: [ 'REF', 1 ],
88-
keyFunc: [ 'REF', 2 ] },
86+
keyObj: [ 'REF', 2 ],
87+
keyFunc: [ 'REF', 3 ] },
8988
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
9089
line: 13,
9190
col: 0,
9291
event: 'step_line',
9392
heap:
94-
{ '1': [ 'INSTANCE', '' ],
95-
'2': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
93+
{ '1':
94+
[ 'DICT',
95+
[ 'a string', 'value associated with \'a string\'' ],
96+
[ [ 'REF', 2 ], 'value associated with keyObj' ],
97+
[ [ 'REF', 3 ], 'value associated with keyFunc' ] ],
98+
'2': [ 'INSTANCE', '' ],
99+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
96100
{ stdout: 'true\n',
97101
func_name: '',
98102
stack_to_render: [],
99103
globals:
100-
{ myMap:
101-
[ 'DICT',
102-
[ 'a string', 'value associated with \'a string\'' ],
103-
[ [ 'REF', 1 ], 'value associated with keyObj' ],
104-
[ [ 'REF', 2 ], 'value associated with keyFunc' ] ],
104+
{ myMap: [ 'REF', 1 ],
105105
keyString: 'a string',
106-
keyObj: [ 'REF', 1 ],
107-
keyFunc: [ 'REF', 2 ] },
106+
keyObj: [ 'REF', 2 ],
107+
keyFunc: [ 'REF', 3 ] },
108108
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
109109
line: 16,
110110
col: 0,
111111
event: 'step_line',
112112
heap:
113-
{ '1': [ 'INSTANCE', '' ],
114-
'2': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
113+
{ '1':
114+
[ 'DICT',
115+
[ 'a string', 'value associated with \'a string\'' ],
116+
[ [ 'REF', 2 ], 'value associated with keyObj' ],
117+
[ [ 'REF', 3 ], 'value associated with keyFunc' ] ],
118+
'2': [ 'INSTANCE', '' ],
119+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
115120
{ stdout: 'true\nvalue associated with \'a string\'\n',
116121
func_name: '',
117122
stack_to_render: [],
118123
globals:
119-
{ myMap:
120-
[ 'DICT',
121-
[ 'a string', 'value associated with \'a string\'' ],
122-
[ [ 'REF', 1 ], 'value associated with keyObj' ],
123-
[ [ 'REF', 2 ], 'value associated with keyFunc' ] ],
124+
{ myMap: [ 'REF', 1 ],
124125
keyString: 'a string',
125-
keyObj: [ 'REF', 1 ],
126-
keyFunc: [ 'REF', 2 ] },
126+
keyObj: [ 'REF', 2 ],
127+
keyFunc: [ 'REF', 3 ] },
127128
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
128129
line: 17,
129130
col: 0,
130131
event: 'step_line',
131132
heap:
132-
{ '1': [ 'INSTANCE', '' ],
133-
'2': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
133+
{ '1':
134+
[ 'DICT',
135+
[ 'a string', 'value associated with \'a string\'' ],
136+
[ [ 'REF', 2 ], 'value associated with keyObj' ],
137+
[ [ 'REF', 3 ], 'value associated with keyFunc' ] ],
138+
'2': [ 'INSTANCE', '' ],
139+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
134140
{ stdout: 'true\nvalue associated with \'a string\'\nvalue associated with keyObj\n',
135141
func_name: '',
136142
stack_to_render: [],
137143
globals:
138-
{ myMap:
139-
[ 'DICT',
140-
[ 'a string', 'value associated with \'a string\'' ],
141-
[ [ 'REF', 1 ], 'value associated with keyObj' ],
142-
[ [ 'REF', 2 ], 'value associated with keyFunc' ] ],
144+
{ myMap: [ 'REF', 1 ],
143145
keyString: 'a string',
144-
keyObj: [ 'REF', 1 ],
145-
keyFunc: [ 'REF', 2 ] },
146+
keyObj: [ 'REF', 2 ],
147+
keyFunc: [ 'REF', 3 ] },
146148
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
147149
line: 18,
148150
col: 0,
149151
event: 'step_line',
150152
heap:
151-
{ '1': [ 'INSTANCE', '' ],
152-
'2': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
153+
{ '1':
154+
[ 'DICT',
155+
[ 'a string', 'value associated with \'a string\'' ],
156+
[ [ 'REF', 2 ], 'value associated with keyObj' ],
157+
[ [ 'REF', 3 ], 'value associated with keyFunc' ] ],
158+
'2': [ 'INSTANCE', '' ],
159+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
153160
{ stdout: 'true\nvalue associated with \'a string\'\nvalue associated with keyObj\nvalue associated with keyFunc\n',
154161
func_name: '',
155162
stack_to_render: [],
156163
globals:
157-
{ myMap:
158-
[ 'DICT',
159-
[ 'a string', 'value associated with \'a string\'' ],
160-
[ [ 'REF', 1 ], 'value associated with keyObj' ],
161-
[ [ 'REF', 2 ], 'value associated with keyFunc' ] ],
164+
{ myMap: [ 'REF', 1 ],
162165
keyString: 'a string',
163-
keyObj: [ 'REF', 1 ],
164-
keyFunc: [ 'REF', 2 ] },
166+
keyObj: [ 'REF', 2 ],
167+
keyFunc: [ 'REF', 3 ] },
165168
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
166169
line: 20,
167170
col: 0,
168171
event: 'step_line',
169172
heap:
170-
{ '1': [ 'INSTANCE', '' ],
171-
'2': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
173+
{ '1':
174+
[ 'DICT',
175+
[ 'a string', 'value associated with \'a string\'' ],
176+
[ [ 'REF', 2 ], 'value associated with keyObj' ],
177+
[ [ 'REF', 3 ], 'value associated with keyFunc' ] ],
178+
'2': [ 'INSTANCE', '' ],
179+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
172180
{ stdout: 'true\nvalue associated with \'a string\'\nvalue associated with keyObj\nvalue associated with keyFunc\nvalue associated with \'a string\'\n',
173181
func_name: '',
174182
stack_to_render: [],
175183
globals:
176-
{ myMap:
177-
[ 'DICT',
178-
[ 'a string', 'value associated with \'a string\'' ],
179-
[ [ 'REF', 1 ], 'value associated with keyObj' ],
180-
[ [ 'REF', 2 ], 'value associated with keyFunc' ] ],
184+
{ myMap: [ 'REF', 1 ],
181185
keyString: 'a string',
182-
keyObj: [ 'REF', 1 ],
183-
keyFunc: [ 'REF', 2 ] },
186+
keyObj: [ 'REF', 2 ],
187+
keyFunc: [ 'REF', 3 ] },
184188
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
185189
line: 22,
186190
col: 0,
187191
event: 'step_line',
188192
heap:
189-
{ '1': [ 'INSTANCE', '' ],
190-
'2': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
193+
{ '1':
194+
[ 'DICT',
195+
[ 'a string', 'value associated with \'a string\'' ],
196+
[ [ 'REF', 2 ], 'value associated with keyObj' ],
197+
[ [ 'REF', 3 ], 'value associated with keyFunc' ] ],
198+
'2': [ 'INSTANCE', '' ],
199+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
191200
{ stdout: 'true\nvalue associated with \'a string\'\nvalue associated with keyObj\nvalue associated with keyFunc\nvalue associated with \'a string\'\nundefined\n',
192201
func_name: '',
193202
stack_to_render: [],
194203
globals:
195-
{ myMap:
196-
[ 'DICT',
197-
[ 'a string', 'value associated with \'a string\'' ],
198-
[ [ 'REF', 1 ], 'value associated with keyObj' ],
199-
[ [ 'REF', 2 ], 'value associated with keyFunc' ] ],
204+
{ myMap: [ 'REF', 1 ],
200205
keyString: 'a string',
201-
keyObj: [ 'REF', 1 ],
202-
keyFunc: [ 'REF', 2 ] },
206+
keyObj: [ 'REF', 2 ],
207+
keyFunc: [ 'REF', 3 ] },
203208
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
204209
line: 23,
205210
col: 0,
206211
event: 'step_line',
207212
heap:
208-
{ '1': [ 'INSTANCE', '' ],
209-
'2': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
213+
{ '1':
214+
[ 'DICT',
215+
[ 'a string', 'value associated with \'a string\'' ],
216+
[ [ 'REF', 2 ], 'value associated with keyObj' ],
217+
[ [ 'REF', 3 ], 'value associated with keyFunc' ] ],
218+
'2': [ 'INSTANCE', '' ],
219+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } },
210220
{ stdout: 'true\nvalue associated with \'a string\'\nvalue associated with keyObj\nvalue associated with keyFunc\nvalue associated with \'a string\'\nundefined\nundefined\n',
211221
func_name: '',
212222
stack_to_render: [],
213223
globals:
214-
{ myMap:
215-
[ 'DICT',
216-
[ 'a string', 'value associated with \'a string\'' ],
217-
[ [ 'REF', 1 ], 'value associated with keyObj' ],
218-
[ [ 'REF', 2 ], 'value associated with keyFunc' ] ],
224+
{ myMap: [ 'REF', 1 ],
219225
keyString: 'a string',
220-
keyObj: [ 'REF', 1 ],
221-
keyFunc: [ 'REF', 2 ] },
226+
keyObj: [ 'REF', 2 ],
227+
keyFunc: [ 'REF', 3 ] },
222228
ordered_globals: [ 'myMap', 'keyString', 'keyObj', 'keyFunc' ],
223229
line: 23,
224230
col: 87,
225231
event: 'step_line',
226232
heap:
227-
{ '1': [ 'INSTANCE', '' ],
228-
'2': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } } ] }
233+
{ '1':
234+
[ 'DICT',
235+
[ 'a string', 'value associated with \'a string\'' ],
236+
[ [ 'REF', 2 ], 'value associated with keyObj' ],
237+
[ [ 'REF', 3 ], 'value associated with keyFunc' ] ],
238+
'2': [ 'INSTANCE', '' ],
239+
'3': [ 'JS_FUNCTION', '', 'function () {}', null, null ] } } ] }

0 commit comments

Comments
 (0)