Skip to content

Commit b73e042

Browse files
committed
src,test: support node.js >= 8
Teach the object property decoder to recognize the layout of objects in newer versions of V8. Fixes: #81 PR-URL: #82 Refs: https://codereview.chromium.org/2842843004/ Refs: nodejs/node#12722 Reviewed-By: Howard Hellyer <[email protected]>
1 parent 8d0446a commit b73e042

File tree

4 files changed

+83
-15
lines changed

4 files changed

+83
-15
lines changed

Diff for: src/llv8-constants.cc

+30-7
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,36 @@ void DescriptorArray::Load() {
423423
kPropertyIndexShift = LoadConstant("prop_index_shift");
424424
kPropertyTypeMask = LoadConstant("prop_type_mask");
425425

426+
if (kPropertyTypeMask == -1) { // node.js >= 8
427+
kPropertyAttributesMask = LoadConstant("prop_attributes_mask");
428+
kPropertyAttributesShift = LoadConstant("prop_attributes_shift");
429+
kPropertyAttributesEnum_NONE = LoadConstant("prop_attributes_NONE");
430+
kPropertyAttributesEnum_READ_ONLY =
431+
LoadConstant("prop_attributes_READ_ONLY");
432+
kPropertyAttributesEnum_DONT_ENUM =
433+
LoadConstant("prop_attributes_DONT_ENUM");
434+
kPropertyAttributesEnum_DONT_DELETE =
435+
LoadConstant("prop_attributes_DONT_ENUM");
436+
437+
kPropertyKindMask = LoadConstant("prop_kind_mask");
438+
kPropertyKindShift = LoadConstant("prop_kind_shift", int64_t(0));
439+
kPropertyKindEnum_kAccessor = LoadConstant("prop_kind_Accessor");
440+
kPropertyKindEnum_kData = LoadConstant("prop_kind_Data");
441+
442+
kPropertyLocationMask = LoadConstant("prop_location_mask");
443+
kPropertyLocationShift = LoadConstant("prop_location_shift");
444+
kPropertyLocationEnum_kDescriptor =
445+
LoadConstant("prop_location_Descriptor");
446+
kPropertyLocationEnum_kField = LoadConstant("prop_location_Field");
447+
} else { // node.js <= 7
448+
kFieldType = LoadConstant("prop_type_field");
449+
kConstFieldType = LoadConstant("prop_type_const_field");
450+
if (kConstFieldType == -1) {
451+
// TODO(indutny): check V8 version?
452+
kConstFieldType = kFieldType | 0x2;
453+
}
454+
}
455+
426456
kRepresentationShift = LoadConstant("prop_representation_shift");
427457
kRepresentationMask = LoadConstant("prop_representation_mask");
428458

@@ -432,13 +462,6 @@ void DescriptorArray::Load() {
432462
kRepresentationMask = ((1 << 4) - 1) << kRepresentationShift;
433463
}
434464

435-
kFieldType = LoadConstant("prop_type_field");
436-
kConstFieldType = LoadConstant("prop_type_const_field");
437-
if (kConstFieldType == -1) {
438-
// TODO(indutny): check V8 version?
439-
kConstFieldType = kFieldType | 0x2;
440-
}
441-
442465
kRepresentationDouble = LoadConstant("prop_representation_double");
443466
if (kRepresentationDouble == -1) {
444467
// TODO(indutny): check V8 version?

Diff for: src/llv8-constants.h

+23-3
Original file line numberDiff line numberDiff line change
@@ -374,17 +374,37 @@ class DescriptorArray : public Module {
374374

375375
int64_t kPropertyIndexMask;
376376
int64_t kPropertyIndexShift;
377-
int64_t kPropertyTypeMask;
378377
int64_t kRepresentationMask;
379378
int64_t kRepresentationShift;
380379

381-
int64_t kFieldType;
382-
int64_t kConstFieldType;
383380
int64_t kRepresentationDouble;
384381

385382
int64_t kFirstIndex;
386383
int64_t kSize;
387384

385+
// node.js <= 7
386+
int64_t kPropertyTypeMask = -1;
387+
int64_t kConstFieldType = -1;
388+
int64_t kFieldType = -1;
389+
390+
// node.js >= 8
391+
int64_t kPropertyAttributesMask = -1;
392+
int64_t kPropertyAttributesShift = -1;
393+
int64_t kPropertyAttributesEnum_NONE = -1;
394+
int64_t kPropertyAttributesEnum_READ_ONLY = -1;
395+
int64_t kPropertyAttributesEnum_DONT_ENUM = -1;
396+
int64_t kPropertyAttributesEnum_DONT_DELETE = -1;
397+
398+
int64_t kPropertyKindMask = -1;
399+
int64_t kPropertyKindShift = -1;
400+
int64_t kPropertyKindEnum_kAccessor = -1;
401+
int64_t kPropertyKindEnum_kData = -1;
402+
403+
int64_t kPropertyLocationMask = -1;
404+
int64_t kPropertyLocationShift = -1;
405+
int64_t kPropertyLocationEnum_kDescriptor = -1;
406+
int64_t kPropertyLocationEnum_kField = -1;
407+
388408
protected:
389409
void Load();
390410
};

Diff for: src/llv8-inl.h

+22-4
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,31 @@ inline Value DescriptorArray::GetValue(int index, Error& err) {
352352
}
353353

354354
inline bool DescriptorArray::IsFieldDetails(Smi details) {
355-
return (details.GetValue() & v8()->descriptor_array()->kPropertyTypeMask) ==
356-
v8()->descriptor_array()->kFieldType;
355+
// node.js <= 7
356+
if (v8()->descriptor_array()->kPropertyTypeMask != -1) {
357+
return (details.GetValue() & v8()->descriptor_array()->kPropertyTypeMask) ==
358+
v8()->descriptor_array()->kFieldType;
359+
}
360+
361+
// node.js >= 8
362+
return (details.GetValue() &
363+
v8()->descriptor_array()->kPropertyLocationMask) ==
364+
(v8()->descriptor_array()->kPropertyLocationEnum_kField
365+
<< v8()->descriptor_array()->kPropertyLocationShift);
357366
}
358367

359368
inline bool DescriptorArray::IsConstFieldDetails(Smi details) {
360-
return (details.GetValue() & v8()->descriptor_array()->kPropertyTypeMask) ==
361-
v8()->descriptor_array()->kConstFieldType;
369+
// node.js <= 7
370+
if (v8()->descriptor_array()->kPropertyTypeMask != -1) {
371+
return (details.GetValue() & v8()->descriptor_array()->kPropertyTypeMask) ==
372+
v8()->descriptor_array()->kConstFieldType;
373+
}
374+
375+
// node.js >= 8
376+
return (details.GetValue() &
377+
v8()->descriptor_array()->kPropertyAttributesMask) ==
378+
(v8()->descriptor_array()->kPropertyAttributesEnum_READ_ONLY
379+
<< v8()->descriptor_array()->kPropertyAttributesShift);
362380
}
363381

364382
inline bool DescriptorArray::IsDoubleField(Smi details) {

Diff for: test/scan-test.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ tape('v8 findrefs and friends', (t) => {
6868
});
6969

7070
sess.linesUntil(/lldb\-/, (lines) => {
71-
t.ok(/Deflate\._handle/.test(lines.join('\n')), 'Should find reference');
71+
// `class Deflate extends Zlib` makes instances show up as
72+
// Transform objects (which Zlib inherits from) in node.js >= 8.
73+
// Note that the version check will have to be redone for node.js >= 10
74+
// but that is still a year out and by then llnode probably needs more
75+
// fixups anyway.
76+
const re =
77+
(process.version >= 'v8.' ? /Transform\._handle/ : /Deflate\._handle/);
78+
t.ok(re.test(lines.join('\n')), 'Should find reference');
7279
t.ok(/Object\.holder/.test(lines.join('\n')), 'Should find reference #2');
7380
t.ok(/\(Array\)\[1\]/.test(lines.join('\n')), 'Should find reference #3');
7481

0 commit comments

Comments
 (0)